Skip to content

Commit 23a01a4

Browse files
authored
More refinement of call site handling in stepping. (#114628)
When you set a "next branch breakpoint" and run to it while stepping, you have to claim the stop at that breakpoint to be the top of the inlined call stack, or you will seem to "step in" and then plans might try to step back out again. This records the PrefferedLineEntry for next branch breakpoints and adds a test to make sure this works.
1 parent e952728 commit 23a01a4

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

lldb/source/Target/ThreadPlanStepRange.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
379379
!m_next_branch_bp_sp->HasResolvedLocations())
380380
m_could_not_resolve_hw_bp = true;
381381

382+
BreakpointLocationSP bp_loc =
383+
m_next_branch_bp_sp->GetLocationAtIndex(0);
382384
if (log) {
383385
lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
384-
BreakpointLocationSP bp_loc =
385-
m_next_branch_bp_sp->GetLocationAtIndex(0);
386386
if (bp_loc) {
387387
BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
388388
if (bp_site) {
@@ -395,7 +395,51 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
395395
m_next_branch_bp_sp->GetID(), bp_site_id,
396396
run_to_address.GetLoadAddress(&m_process.GetTarget()));
397397
}
398-
398+
// The "next branch breakpoint might land on a virtual inlined call
399+
// stack. If that's true, we should always stop at the top of the
400+
// inlined call stack. Only virtual steps should walk deeper into the
401+
// inlined call stack.
402+
Block *block = run_to_address.CalculateSymbolContextBlock();
403+
if (bp_loc && block) {
404+
LineEntry top_most_line_entry;
405+
lldb::addr_t run_to_addr = run_to_address.GetFileAddress();
406+
for (Block *inlined_parent = block->GetContainingInlinedBlock();
407+
inlined_parent;
408+
inlined_parent = inlined_parent->GetInlinedParent()) {
409+
AddressRange range;
410+
if (!inlined_parent->GetRangeContainingAddress(run_to_address,
411+
range))
412+
break;
413+
Address range_start_address = range.GetBaseAddress();
414+
// Only compare addresses here, we may have different symbol
415+
// contexts (for virtual inlined stacks), but we just want to know
416+
// that they are all at the same address.
417+
if (range_start_address.GetFileAddress() != run_to_addr)
418+
break;
419+
const InlineFunctionInfo *inline_info =
420+
inlined_parent->GetInlinedFunctionInfo();
421+
if (!inline_info)
422+
break;
423+
const Declaration &call_site = inline_info->GetCallSite();
424+
top_most_line_entry.line = call_site.GetLine();
425+
top_most_line_entry.column = call_site.GetColumn();
426+
FileSpec call_site_file_spec = call_site.GetFile();
427+
top_most_line_entry.original_file_sp.reset(
428+
new SupportFile(call_site_file_spec));
429+
top_most_line_entry.range = range;
430+
top_most_line_entry.file_sp.reset();
431+
top_most_line_entry.ApplyFileMappings(
432+
GetThread().CalculateTarget());
433+
if (!top_most_line_entry.file_sp)
434+
top_most_line_entry.file_sp =
435+
top_most_line_entry.original_file_sp;
436+
}
437+
if (top_most_line_entry.IsValid()) {
438+
LLDB_LOG(log, "Setting preferred line entry: {0}:{1}",
439+
top_most_line_entry.GetFile(), top_most_line_entry.line);
440+
bp_loc->SetPreferredLineEntry(top_most_line_entry);
441+
}
442+
}
399443
m_next_branch_bp_sp->SetThreadID(m_tid);
400444
m_next_branch_bp_sp->SetBreakpointKind("next-branch-location");
401445

lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class TestInlineStepping(TestBase):
1313
compiler="icc",
1414
bugnumber="# Not really a bug. ICC combines two inlined functions.",
1515
)
16-
@skipIf(oslist=["linux"], archs=["arm"]) # Fails for 32 bit arm
1716
def test_with_python_api(self):
1817
"""Test stepping over and into inlined functions."""
1918
self.build()
@@ -291,7 +290,7 @@ def inline_stepping_step_over(self):
291290
break_1_in_main = target.BreakpointCreateBySourceRegex(
292291
"// At second call of caller_ref_1 in main.", self.main_source_spec
293292
)
294-
self.assertTrue(break_1_in_main, VALID_BREAKPOINT)
293+
self.assertGreater(break_1_in_main.GetNumLocations(), 0, VALID_BREAKPOINT)
295294

296295
# Now launch the process, and do not stop at entry point.
297296
self.process = target.LaunchSimple(
@@ -317,6 +316,24 @@ def inline_stepping_step_over(self):
317316
]
318317
self.run_step_sequence(step_sequence)
319318

319+
# Now make sure that next to a virtual inlined call stack
320+
# gets the call stack depth correct.
321+
break_2_in_main = target.BreakpointCreateBySourceRegex(
322+
"// Call max_value specialized", self.main_source_spec
323+
)
324+
self.assertGreater(break_2_in_main.GetNumLocations(), 0, VALID_BREAKPOINT)
325+
threads = lldbutil.continue_to_breakpoint(self.process, break_2_in_main)
326+
self.assertEqual(len(threads), 1, "Hit our second breakpoint")
327+
self.assertEqual(threads[0].id, self.thread.id, "Stopped at right thread")
328+
self.thread.StepOver()
329+
frame_0 = self.thread.frames[0]
330+
line_entry = frame_0.line_entry
331+
self.assertEqual(
332+
line_entry.file.basename, self.main_source_spec.basename, "File matches"
333+
)
334+
target_line = line_number("calling.cpp", "// At caller_trivial_inline_1")
335+
self.assertEqual(line_entry.line, target_line, "Lines match as well.")
336+
320337
def step_in_template(self):
321338
"""Use Python APIs to test stepping in to templated functions."""
322339
exe = self.getBuildArtifact("a.out")

0 commit comments

Comments
 (0)