LLDB Macro Equivalent to GDB

I have a very useful macro defined in .gdbinit

 define rc call (int)[$arg0 retainCount] end 

Anyway to define the same macro for lldb ?

+7
source share
2 answers

You can do this with the following command definition in lldb:

 command regex rc 's/(.+)/print (int)[%1 retainCount]/' 

Example:

 (lldb) rc indexPath print (int)[indexPath retainCount] (int) $2 = 2 

You can put this in ~/.lldbinit (and restart Xcode).

You need to think that something like

 command alias rc print (int)[%1 retainCount] 

should work, but as explained in I can't get this simple LLDB alias to work . The extension% 1 does not work with the expression, and command regex is a workaround.

+4
source

By the way, on architectures where function arguments are passed to registers (x86_64, armv7), lldb defines a series of register aliases that map to the register used to pass integral values โ€‹โ€‹- arg1, arg2, etc. For example,

 #include <stdio.h> int main () { char *mytext = "hello world\n"; puts (mytext); return 0; } 

and we can easily see which argument is passed to place without having to remember ABI conventions,

  4 char *mytext = "hello world\n"; -> 5 puts (mytext); 6 return 0; 7 } (lldb) p mytext (char *) $0 = 0x0000000100000f54 "hello world\n" (lldb) br se -n puts Breakpoint created: 2: name = 'puts', locations = 1, resolved = 1 (lldb) c Process 2325 resuming Process 2325 stopped libsystem_c.dylib`puts: -> 0x7fff99ce1d9a: pushq %rbp 0x7fff99ce1d9b: movq %rsp, %rbp 0x7fff99ce1d9e: pushq %rbx 0x7fff99ce1d9f: subq $56, %rsp (lldb) p/x $arg1 (unsigned long) $2 = 0x0000000100000f54 (lldb) 

x86_64 and armv7 both pass the first "few" integral values โ€‹โ€‹in registers - except that they can be stored on the stack or in other places, and these aliases do not work. Lldb does not currently provide similar convenience aliases for floating point arguments. But for the most common cases, this applies to what people need.

+2
source

All Articles