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

If you edit a breakpoint from Xcode, there is a super-useful option to add an β€œAction” to automatically execute every time you hit a breakpoint.

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

+7
source share
1 answer

Easy peasy with breakpoint command add . Type help breakpoint command add for more information, but here is an example.

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

Run lldb. First, put a breakpoint on the source line with a β€œbreak” somewhere in it (a nice shorthand for examples like this, but basically it is needed for grep over your sources, therefore not useful for large projects)

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

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

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

Let the control point print the current value of i and the back trace when it reaches:

 (lldb) br com add 1 Enter your debugger command(s). Type 'DONE' to end. > pi > 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 ac:6, stop reason = breakpoint 1.1 #0: 0x0000000100000f5f a.out`main + 31 at ac: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 ac:6, stop reason = breakpoint 1.1 #0: 0x0000000100000f5f a.out`main + 31 at ac:6 #1: 0x00007fff8c2a17e1 libdyld.dylib`start + 1 
+18
source

All Articles