Causing Gtk to abort on assert

后端 未结 2 1260
孤独总比滥情好
孤独总比滥情好 2021-01-02 19:04

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 GtkWi

相关标签:
2条回答
  • 2021-01-02 19:24

    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.

    Three ways to force gtk to agort on error:

    1. G_DEBUG=fatal_warnings ./myprog ...
    2. ./myprog -prog-args --g-fatal-warnings
    3. Use g_log_set_handler, and/or g_log_default_handler and provide a GLogFunc of your own design that aborts based on the GLogLevelFlags passed to it for each message.

    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.

    0 讨论(0)
  • 2021-01-02 19:44

    Use g_log_set_handler, and/or g_log_default_handler and provide a GLogFunc of your own design that aborts based on the GLogLevelFlags passed to it for each message.

    void abort_on_g_log(
        const gchar *log_domain,
        GLogLevelFlags log_level,
        const gchar *message,
        gpointer user_data)
    {
        if (log_level & G_LOG_LEVEL_CRITICAL) abort();
        g_log_default_handler(log_domain, log_level, message, user_data);
    }
    

    Update0

    If you're happy having glib terminate for you, you can use:

    g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
    

    or run with G_DEBUG=fatal_warnings ./myprog ... if glib is correctly configured, see here for more.

    0 讨论(0)
提交回复
热议问题