尝试在 gdb 中打印 Objective-C 字段时出现分段错误

发布于 2024-11-02 14:32:04 字数 898 浏览 2 评论 0原文

在 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。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-11-09 14:32:04

'bg' 是如何声明的?
id bg 或 Sprite *bg

使用 'id bg'
将 bg 转换为正确的类

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

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

您必须使用 Sprite *bg

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

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

是在 DLL/库中单独实现的 Sprite 类或者
在主应用程序中?

它可能是某种表现
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39465

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文