I’m struggling to debug my Objective-C program with GDB. I have a function - (NSString *)reverse:(NSString *)someString which I want to debug.
Here’s how I set the breakpoint:
(gdb) break -[MyClass reverse:]
Now, when the code gets to the breakpoint, how do I print the addresses or even better the values of self and the method argument? I’ve done some googling and found suggestions like po $rdx but nothing I found works.
How can I solve this?
Clark Cox has written the best explanation of this I’ve ever found. I refer to this page all the time and have made a local copy in case it ever goes away.
http://www.clarkcox.com/blog/2009/02/04/inspecting-obj-c-parameters-in-gdb/
The quick version for x86_64 and non-floating-point parameters is:
Remember, the first two things passed to a method (in $rdi and $rsi) are
selfand_cmd. I’m not counting those here.If you’re passing floating points, structs, or more than four arguments, things get more complicated, and you should read the calling conventions in the AMD64 ABI section 3.2.3. If you’re dealing with i386, PPC, or ARM, see Clark’s post, which covers those cases well for the common cases.