Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -29,7 +48,6 @@ def test_finish_from_empty_function(self):
)
self.assertTrue(safety_bp.IsValid())

error = lldb.SBError()
thread.StepOut(error)
self.assertTrue(error.Success())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
void done() {}
int main() {
puts("in main");
done(); // Set breakpoint here
done();
puts("leaving main");
return 0;
Expand Down
Loading