Hi, I am trying to step through LLDB code using LLDB itself. I want to find all the LLDB functions that are called when a
breakpoint command add <id> command is executed by LLDB.
I plan to insert a breakpoint at this DoExecute function and then see the backtrace, but I don’t know how to pass commands to LLDB while debugging it through LLDB?
Is this possible? How can this be achieved?
If the question is unclear please let me know.
I think what you are trying to do is run lldb under lldb, much like you would run
<random program> under lldb, to debug it. This is fine, you can debug a debugger, with a debugger, it’s just like any other program.
The usual advice applies, the lldb being debugged needs to be built with debug information included (
-DCMAKE_BUILD_TYPE=Debug. You don’t have to use the same versions of lldb either, system lldb is fine or use gdb if you want to.
So it’d be something like this:
$ ./bin/lldb ./bin/lldb -- /tmp/sometestprogram
Then you can
b <the function you want> and
run. That runs the lldb being debugged. Now run
breakpoint command add <id> and it should hit the breakpoint and bring you back into the top level lldb.
lldb (b DoExecute)
-> lldb (breakpoint command add <id>)
-> test program
What I tend to do is debug lldb with gdb and vice versa, just so I have some clues as to which level I’m at. You can also change the
prompt setting for one of them so you have
(lldb debugee) depending on where you are.
Once you are done with looking at the breakpoint hit
continue will take you back to the debugee lldb, but it won’t print the
(lldb) prompt out for you again. What I do here is type in some random garbage
sdfsdfsd and hit enter. That’s obviously going to get rejected, and it’ll print a new prompt for you (don’t press enter because it’ll run the last command you did).
Otherwise it can be hard to tell if the debugee lldb has started running again or not.
Does any of that help?