Skip to content

Commit def07ea

Browse files
committed
[lldb][test] Fix TestEmptyFuncThreadStepOut.py
The test did not work as intended when the empty function 'done()' contained epilog code, because a breakpoint was set on the first instruction of the epilog instead of on the last instruction of the function. This caused the test to pass even with the fix from #126838 reverted.
1 parent a7016c4 commit def07ea

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,23 @@ class FinishFromEmptyFunctionTestCase(TestBase):
1515
def test_finish_from_empty_function(self):
1616
"""Test that when stopped at a breakpoint in an empty function, finish leaves it correctly."""
1717
self.build()
18-
exe = self.getBuildArtifact("a.out")
19-
target, process, thread, _ = lldbutil.run_to_name_breakpoint(
20-
self, "done", exe_name=exe
18+
target, _, thread, _ = lldbutil.run_to_source_breakpoint(
19+
self, "// Set breakpoint here", lldb.SBFileSpec("main.c")
2120
)
21+
# Find the last instruction address of 'done()' and set a breakpoint there.
22+
error = lldb.SBError()
23+
ret_bp_addr = lldb.SBAddress()
24+
while True:
25+
thread.StepInstruction(False, error)
26+
self.assertTrue(error.Success())
27+
frame = thread.GetSelectedFrame()
28+
if "done" in frame.GetFunctionName():
29+
ret_bp_addr = frame.GetPCAddress()
30+
elif ret_bp_addr.IsValid():
31+
break
32+
ret_bp = target.BreakpointCreateByAddress(ret_bp_addr.GetLoadAddress(target))
33+
self.assertTrue(ret_bp.IsValid())
34+
self.runCmd("cont")
2235
if self.TraceOn():
2336
self.runCmd("bt")
2437

@@ -29,7 +42,6 @@ def test_finish_from_empty_function(self):
2942
)
3043
self.assertTrue(safety_bp.IsValid())
3144

32-
error = lldb.SBError()
3345
thread.StepOut(error)
3446
self.assertTrue(error.Success())
3547

lldb/test/API/functionalities/thread/finish-from-empty-func/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
void done() {}
33
int main() {
44
puts("in main");
5+
done(); // Set breakpoint here
56
done();
67
puts("leaving main");
78
return 0;

0 commit comments

Comments
 (0)