Search code examples
lldb

LLDB Breakpoint Commands and Finish


Is it possible to run commands after a breakpoint after you have run a 'continuing' command. For example I do something like:

br set -n function -C finish -C something_else

Then I get an error

error: Aborting reading of commands after command #1: 'finish' continued the target.

How do people work around this? I guess I could set another breakpoint at the return instruction and as part of its command make it delete itself but I have no way of knowing the id of the bp I need to delete. Also, this is a conditional breakpoint so I can't just always break on the return instruction and I can't conditionally break on the return instruction because the context I used to break on the function has gone.


Solution

  • You can't do this at present. The lldb command interpreter isn't re-entrant and since your finish could very well hit another breakpoint with its own commands lldb exits reading the first set of breakpoint commands when one of them continues.

    You don't need to delete the return breakpoint in its commands, just make it a one shot breakpoint (break set -o true) and when it gets hit, it will just delete itself.

    Note, if your program is multithreaded and you are stopping in code many threads are likely to pass through concurrently, you really need to make your return breakpoint thread-specific for the current thread. That's actually a little tricky to do in lldb command-line, but you can do it pretty easily using Python breakpoint callbacks:

    https://lldb.llvm.org/use/python-reference.html#running-a-python-script-when-a-breakpoint-gets-hit