2011-04-21 75 views
1

打印一个Objective-C场在GDB我得到一个分段错误,如果我试图做到以下几点:分段故障试图在gdb

print bg->top 

代码看起来有点像这样:

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

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

我得到的消息是:

(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. 

这是为什么?

我正在使用GNU Objective-C运行时,而我没有使用GNUStep。

回答

1

'bg'是如何申报的?通过使用GNU GDB雪碧* BG

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

ID BG或雪碧*使用 '身份证BG' 必须转换BG正确类BG

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

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

(GDB)在linux下7.3.50.20110421-cvs ,你用的是哪个版本的gdb?

是在主应用程序中分别在DLL /库或 中实现的Sprite类?

其可能也可能是 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39465

+0

我使用'雪碧* bg'和我的GDB版本的一些表现是使用MINGW32 windows下7.2。 'Sprite'在主应用程序中实现。 – Justin 2011-04-21 08:43:34

+0

你的应用程序是否使用*任何*静态库? – matt 2011-04-21 13:35:08

+0

是 - '-lobjc -lglfw -lSOIL -lopengl32',为什么这可能会有所作为?这发生在所有Objective-C对象上,而不仅仅是'Sprite'。 – Justin 2011-04-22 06:09:23