views:

239

answers:

3

I am working on an iPhone app which is using an external library for which I have the source. During debugging some of the objects are listed as 0x0 in the debugger but the app runs fine. Also, some of the objects addresses point to the wrong thing. These symbols are in the external library. The addresses are fine if I am tracing through a file actually in the external library.

Does anyone have suggestions how to stop this behavior?

A: 

As zPesk notes, 0x0 is nil, which is a common value for objects that have not been initialized (particularly instance variables). I'm not certain what you mean by "point to the wrong thing." If you haven't initialized a local (stack) variable, it may point to any random address until it is initialized. What behavior are you having trouble with?

Rob Napier
It is pointing to the wrong thing in the sense that the pointers I see in the debugger are pointing to other things which I know about, but those pointers should never point there.I have been working for some time on the program and this is the first time it's ever happened. I tried checking the debuggers lazy symbol loading to no avail.
John Smith
It is extremely unlikely that you have found a bug in gdb here. Perhaps more details of the code and what gdb is returning would help a lot here. You don't have compiler optimizations turned on do you? That can always lead to surprising debugger results.
Rob Napier
Also, if you doubt what gdb is telling you, you should always add NSLog() statements and compare the results.
Rob Napier
+1  A: 

UPDATE: target settings > Build tab > GCC 4.2 Code Generation > "Compile for Thumb"

I turned off this target setting and the gdb problem went away.

--

Hi John.

I understand what you're referring to. I'm also seeing a problem where gdb and NSLog() are giving me different results for pointers in certain parts of my code.

In a boiled-down example, gdb fails to report the proper value for "pointer" when I set a breakpoint on any line in this function:

id testPointer( id pointer )
{
    NSLog( @"pointer value: %p", pointer );

    @try
    {
        NSLog( @"foo" );
    }
    @catch ( NSException *e )
    { }
    @finally
    { }

    return pointer;
}
otto
A: 

Hi -- Were you ever able to resolve this issue? I, too, am noticing strange behavior in gdb when mixing Thumb and ARM modes. For example, it appears that the addresses of variables reported by gdb are off by exactly 64 bytes from the addresses reported using printf("%p\n") statements. Perhaps gdb needs to be explicitly told whether the current operating mode is ARM or Thumb...?

Zachary Kulis