Use GDB to examine Objective C class from crash (HandleDelegateSource bad access)-Collection of common programming errors

I am trying to debug an intermittent error on the iPhone, a crash with a trace that looks like:

objc_message_send
__invoking__
[NSInvocation invoke]
HandleDelegateSource
MainRunLoop
....

When GDB stops, I’d like to be able to determine details about what selector the system is attempting to be invoked – I’ve set a break point now around [NSInvocation Invoke], but from that point cannot figure out how to examine details of the NSInvocation object I am stopped in.

  1. This article, recently published at Phrack should answer all your questions. Enlightening reading.

  2. A simple final answer – in GDB you can simply view the register with the name of the selector being called (theSelector parameter in lothar’s answer). It’s a C string, so you observe it using one of the following commands (depending on if you are running in the simulator or the device):

    Simulator: display /s $ecx
    Device: display /s $r1
    
  3. If you look at the reference information for objc_msgSend you will see that the selector is the second argument. Now it should be easier to decipher the debugger output.

    objc_msgSend Sends a message with a simple return value to an instance of a class.

    id objc_msgSend(id theReceiver, SEL theSelector, …)

    Parameters theReceiver A pointer that points to the instance of the class that is to receive the message. theSelector The selector of the method that handles the message. …

    A variable argument list containing the arguments to the method.