我该如何找出代码中引起GLib-GObject-CRITICAL错误的位置?

6

当一个C/C++应用程序出现以下CRITICAL错误时,你能告诉我如何找到导致错误的代码吗?

我尝试在调试器中运行它,在程序失败时尝试执行“bt”。但是它没有显示导致CRITICAL错误的代码所在位置:

(process:3155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function

(process:3155): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed

(process:3155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function

(process:3155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function

(process:3155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function

(process:3155): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:3155): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.22.3/gobject/gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function

可能是如何让GDB在GLib断言失败时中断?的重复问题。 - ptomato
3个回答

7
当您在gdb中运行应用程序时,应传递--g-fatal-warnings参数。

1
是的,启用致命警告后,第一次调用g_warning()或g_critical()将会中止程序,从而可以使用gdb或lldb进行调试。 - bratsche
1
我在发表评论之前尝试了一下。我在glib中遇到了很多问题,它没有停止。我现在已经纠正了这些错误,但是重新测试并不容易。如果我能找到一个返回的情况,我会发布结果。如果我能让它工作,我会非常高兴——这是一个非常实用的选项。 - jcoppens
2
尝试在运行程序时设置环境变量G_DEBUG=fatal_warnings - bratsche

6

您可以在g_log处打断点,然后从那里进行回溯。


我该如何在 g_log 处中断程序?由于我没有自己编译 gtk/glib 库,所以我不知道 g_log 的文件/行号是什么?谢谢。 - michael
2
你的调试器应该允许你在函数名处中断。例如,在gdb中,输入“break g_log”。根据你的系统,你可能需要安装一些“debug”包,例如Fedora上的“glib-debuginfo”。通常它已经自动安装了。 - ptomato

2

我认为它确实显示了问题出现的位置(在堆栈跟踪中更深层次):

(gdb) bt
#0  0x00da5422 in __kernel_vsyscall ()
#1  0x00c70e15 in pthread_cond_wait@@GLIBC_2.3.2 ()
    at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:122
#2  0x008a5800 in g_once_init_enter_impl () from /lib/libglib-2.0.so.0
#3  0x00800e36 in g_initially_unowned_get_type ()
   from /usr/lib/libgobject-2.0.so.0
#4  0x00271f15 in gtk_object_get_type () from /usr/lib/libgtk-x11-2.0.so.0
#5  0x0036aa4c in gtk_widget_get_type () from /usr/lib/libgtk-x11-2.0.so.0
#6  0x001b8485 in gtk_container_get_type () from /usr/lib/libgtk-x11-2.0.so.0
#7  0x0031b3b5 in gtk_toolbar_get_type () from /usr/lib/libgtk-x11-2.0.so.0
#8  0x0031d717 in gtk_toolbar_new () from /usr/lib/libgtk-x11-2.0.so.0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接