Justin
Justin

Reputation: 86729

Segmentation fault attempting to print an Objective-C field in gdb

In GDB I get a segmentation fault if I attempt to do the following:

print bg->top

The code looks a bit like this:

@interface Sprite : Object
{
@public
    int top;
    /* Other fields */
}
@end

bg = [Sprite load: "test.png"];
/* GDB is at a breakpoint after the above line */

The message I get is:

(gdb) print bg->top

Program received signal SIGSEGV, Segmentation fault.
0x6a7e3048 in libobjc-2!__objc_class_links_resolved () from C:\MinGW\bin\libobjc-2.dll
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on".
Evaluation of the expression containing the function
(objc_lookup_class) will be abandoned.
When the function is done executing, GDB will silently stop.

Why is this?

I'm using the GNU Objective-C runtime and I'm not using GNUStep.

Upvotes: 1

Views: 705

Answers (1)

matt
matt

Reputation: 5614

how is 'bg' declared? id bg or Sprite *bg

using 'id bg' you must cast bg to the correct class,

(gdb) p bg->top
There is no member named top.

(gdb) p ((struct Sprite *)bg)->top
$1 = 0

using Sprite *bg

(gdb) p bg->top
$1 = 0

using GNU gdb (GDB) 7.3.50.20110421-cvs under linux, which version of gdb are you using?

is the Sprite class implemented separately in a DLL/library or in the main application?

its possible it could be some manifestation of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39465

Upvotes: 1

Related Questions