Debug all called Objective-C methods

Once in a while I need to know which methods are called in my code. The simplest solution is to add a breakpoint on the function called objc_msgSend. This function is responsible for the call of every method in Objective-C

id objc_msgSend(id theReceiver, SEL theSelector, ...)

In Xcode you can add actions to breakpoints. In my case add a debugger command to evaluate the receiver and the selector. So I added following command:

expr -- (void)printf("[%s %s]\n",(char *) object_getClassName(*(long*)($rdi)), (char *)($rsi))

You might ask where I get the register names from. I found a good article on expaining the various registers of the different platforms: “Inspecting Obj-C parameters in gdb”.

Important is that you enable “Automatically continue after evaluating”.

Breakpoint-objc_msgSend

Now you get a Output like this

[__NSCFConstantString copy]
[__NSCFConstantString copyWithZone:]
[NSObject valueWithRect:]
[NSObject valueWithBytes:objCType:]
[NSConcreteValue init]
[NSObject resolveInstanceMethod:]
[NSConcreteValue description]
[NSConcreteValue getValue:]
[NSObject stringWithFormat:]

Back