2011-04-21 79 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