导致 Gtk 在断言时中止 [英] Causing Gtk to abort on assert

查看:29
本文介绍了导致 Gtk 在断言时中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须调试一个严重依赖 Gtk 的程序.问题在于,由于某种原因,在使用 GtkWindow 对象时开始出现许多运行时警告.问题是,即使 Gtk 抱怨严重错误,它也不会因这些错误而中止.我没有代码库的更改历史记录,所以我唯一的选择似乎是遍历所有似乎可疑的 gtk 调用,看看问题出在哪里.但是,如果我能以某种方式导致 Gtk 在此错误上中止,我可以使用 gdb 运行它并尝试获取回溯并定位错误的确切位置.知道如何做到这一点吗?

I have to debug a program which is heavily dependent on Gtk. The issue is that for some reason a lot of runtime warnings have started appearing when working with GtkWindow objects. The problem is, even though Gtk complains of critical errors, it does not abort on these errors. I don't have the change history for the code base so my only option seems to be to wade though all gtk calls which seem suspect and see where the problem is. If however, I can somehow cause Gtk to abort on this error, I can run it with gdb and try to get the backtrace and locate the exact position of the error. Any idea how this can be done?

GLib-GObject-WARNING **: invalid uninstantiatable type `<invalid>' in cast to `GObject'
GLib-GObject-CRITICAL **: g_object_get_data: assertion `G_IS_OBJECT (object)' failed
GLib-GObject-WARNING **: invalid uninstantiatable type `<invalid>' in cast to `GObject'
GLib-GObject-CRITICAL **: g_object_get_data: assertion `G_IS_OBJECT (object)' failed
GLib-GObject-WARNING **: invalid uninstantiatable type `<invalid>' in cast to `GObject'
GLib-GObject-CRITICAL **: g_object_get_data: assertion `G_IS_OBJECT (object)' failed

推荐答案

我正在收集 Matt 提到的方法以及我发现的方法,以便在此处提供完整的答案.我会将其标记为已选择的答案并为马特的答案投票.

I am collecting the methods Matt mentioned and the one I found out to provide the complete answer here. I will mark it as the chosen answer and up-vote Matt's answer.

强制 gtk 出错的三种方法:

Three ways to force gtk to agort on error:

  1. G_DEBUG=fatal_warnings ./myprog ...
  2. ./myprog -prog-args --g-fatal-warnings
  3. 使用 g_log_set_handler 和/或 g_log_default_handler 并提供您自己设计的 GLogFunc,该 GLogFunc 基于为每条消息传递给它的 GLogLevelFlags 中止.

我还应该提及 g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING); 以使列表完整,即使总是致命"不是我想要的.

I should also mention g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING); to make the list complete even though "always fatal" is not what I was looking for.

这篇关于导致 Gtk 在断言时中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆