summaryrefslogtreecommitdiff
path: root/lldb/test/API/functionalities/thread/finish-from-empty-func
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/test/API/functionalities/thread/finish-from-empty-func')
-rw-r--r--lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py28
-rw-r--r--lldb/test/API/functionalities/thread/finish-from-empty-func/main.c1
2 files changed, 24 insertions, 5 deletions
diff --git a/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py b/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
index f5d3da530f4f..c95a57ff5581 100644
--- a/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
+++ b/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
@@ -13,12 +13,31 @@ class FinishFromEmptyFunctionTestCase(TestBase):
@skipIf(compiler="clang", compiler_version=['<', '17.0'])
def test_finish_from_empty_function(self):
- """Test that when stopped at a breakpoint in an empty function, finish leaves it correctly."""
+ """Test that when stopped at a breakpoint located at the last instruction
+ of a function, finish leaves it correctly."""
self.build()
- exe = self.getBuildArtifact("a.out")
- target, process, thread, _ = lldbutil.run_to_name_breakpoint(
- self, "done", exe_name=exe
+ target, _, thread, _ = lldbutil.run_to_source_breakpoint(
+ self, "// Set breakpoint here", lldb.SBFileSpec("main.c")
)
+ # Find the address of the last instruction of 'done()' and set a breakpoint there.
+ # Even though 'done()' is empty, it may contain prologue and epilogue code, so
+ # simply setting a breakpoint at the function can place it before 'ret'.
+ error = lldb.SBError()
+ ret_bp_addr = lldb.SBAddress()
+ while True:
+ thread.StepInstruction(False, error)
+ self.assertTrue(error.Success())
+ frame = thread.GetSelectedFrame()
+ if "done" in frame.GetFunctionName():
+ ret_bp_addr = frame.GetPCAddress()
+ elif ret_bp_addr.IsValid():
+ # The entire function 'done()' has been stepped through, so 'ret_bp_addr'
+ # now contains the address of its last instruction, i.e. 'ret'.
+ break
+ ret_bp = target.BreakpointCreateByAddress(ret_bp_addr.GetLoadAddress(target))
+ self.assertTrue(ret_bp.IsValid())
+ # Resume the execution and hit the new breakpoint.
+ self.runCmd("cont")
if self.TraceOn():
self.runCmd("bt")
@@ -29,7 +48,6 @@ class FinishFromEmptyFunctionTestCase(TestBase):
)
self.assertTrue(safety_bp.IsValid())
- error = lldb.SBError()
thread.StepOut(error)
self.assertTrue(error.Success())
diff --git a/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c b/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
index bc66a548a89d..b3f90db5e256 100644
--- a/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
+++ b/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
@@ -2,6 +2,7 @@
void done() {}
int main() {
puts("in main");
+ done(); // Set breakpoint here
done();
puts("leaving main");
return 0;