Objective-C - parameters of the printing method using GDB

I am trying to debug my Objective-C program using GDB. I have a function - (NSString *)reverse:(NSString *)someString that I want to debug.

Here's how I set a breakpoint:

 (gdb) break -[MyClass reverse:] 

Now that the code hits a breakpoint, how do I print the addresses or even better than the self value and the method argument? I did some searches and found sentences like po $rdx , but didn't find anything.

How can i solve this?

+2
objective-c gdb
source share
3 answers

Clark Cox wrote the best explanation of this I have ever seen. I link to this page all the time and made a local copy in case it ever disappears.

http://www.clarkcox.com/blog/2009/02/04/inspecting-obj-c-parameters-in-gdb/

Fast version for x86_64 and non-floating-point options:

 first ObjC arg => $rdx second ObjC arg => $rcx third ObjC arg => $r8 fourth ObjC arg => $r9 

Remember that the first two things passed to the method (in $ rdi and $ rsi) are self and _cmd . I do not consider them here.

If you pass floating points, structures, or more than four arguments, things get complicated and you should read the calling conventions in the AMD64 ABI 3.2.3 section. If you are dealing with i386, PPC or ARM, see Clark's post, which describes these cases well for general cases.

+11
source share

When debugging with gdb, you can print with po and print ()

 po self po someString print (int) myInt 

po acts like NSLog(@"%@", self); print () acts like NSLog(@"%d", myInt);

* you can print more types than int

+3
source share

Inject the description method into your class. You can format the values ​​as you like. From the docs:

The print-object debugger command indirectly calls this method to create a textual description of the object.

+1
source share

All Articles