Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add breakpoint actions via the LLDB command line?

If you edit a breakpoint from Xcode, there is the super-useful option to add an "Action" to be automatically executed every time the breakpoint is hit.

How can you add such actions from the LLDB command line?

like image 475
PHD Avatar asked May 02 '13 18:05

PHD


People also ask

What command do you use to set a breakpoint?

Breakpoints are set with the break command (abbreviated b ). The debugger convenience variable `$bpnum' records the number of the breakpoint you've set most recently; see section Convenience variables, for a discussion of what you can do with convenience variables.

How do I debug a command line application?

To debug applications on a running correlator, run the following command: engine_debug [ [ global-options ] [command [options]] ... ] To obtain a usage message, run the command with the help option. Sending events to the correlator continues to put events on the input queue of each public context.

Can LLDB debug Python?

LLDB has been structured from the beginning to be scriptable in two ways – a Unix Python session can initiate/run a debug session non-interactively using LLDB; and within the LLDB debugger tool, Python scripts can be used to help with many tasks, including inspecting program data, iterating over containers and ...

How do I stop LLDB?

Type quit to exit the lldb session.


1 Answers

Easy peasy with the breakpoint command add command. Type help breakpoint command add for details but here's an example.

int main ()
{
    int i = 0;
    while (i < 30)
    {
        i++; // break here
    }
}

Run lldb on this. First, put a breakpoint on the source line with "break" somewhere in it (nice shorthand for examples like this but it basically has to grep over your sources, so not useful for larger projects)

(lldb) br s -p break
Breakpoint 1: where = a.out`main + 31 at a.c:6, address = 0x0000000100000f5f

Add a breakpoint condition so the breakpoint only stops when i is a multiple of 5:

(lldb) br mod -c 'i % 5 == 0' 1

Have the breakpoint print the current value of i and backtrace when it hits:

(lldb) br com add 1
Enter your debugger command(s).  Type 'DONE' to end.
> p i
> bt
> DONE

and then use it:

Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped
* thread #1: tid = 0x1c03, 0x0000000100000f5f a.out`main + 31 at a.c:6, stop reason = breakpoint 1.1
    #0: 0x0000000100000f5f a.out`main + 31 at a.c:6
   3        int i = 0;
   4        while (i < 30)
   5        {
-> 6            i++; // break here
   7        }
   8    }
(int) $25 = 20
* thread #1: tid = 0x1c03, 0x0000000100000f5f a.out`main + 31 at a.c:6, stop reason = breakpoint 1.1
    #0: 0x0000000100000f5f a.out`main + 31 at a.c:6
    #1: 0x00007fff8c2a17e1 libdyld.dylib`start + 1
like image 84
Jason Molenda Avatar answered Oct 08 '22 12:10

Jason Molenda