How do I get GDB to break on a GLib assertion failure?
Asked Answered
D

2

26

Somewhere in a mass of code that I did not write (but I am trying to debug), an assertion fails in the GLib library:

(process:31987): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed

However, GDB and the code keeps on going. I would like GDB to break where this assertion fails so that I can find out why it is failing. I am not given any more information about where this assertion is. Is there a way to get GDB to break on such a failure?

Dewdrop answered 26/4, 2011 at 4:21 Comment(1)
Duplicate of: #2450501 but this question is clearer, so I'm voting to close that other one.Yardage
Y
20

Break on g_log(). This covers all cases like g_warning(), g_critical(), etc.

Yardage answered 26/4, 2011 at 8:10 Comment(1)
The useful gdb commands are: break g_log if log_level == G_LOG_LEVEL_CRITICAL and break g_log if log_level == G_LOG_LEVEL_WARNINGSeraphina
M
26

You should add an environment variable like this:

G_DEBUG=fatal_warnings gdb ...
Mamba answered 7/11, 2011 at 16:14 Comment(1)
G_DEBUG=fatal-errors is not working for me, but G_DEBUG=fatal-warnings and G_DEBUG=fatal-criticals is, also check out rest of options. The line for gdb could be gdb --args PROGRAM ARG1 ARG2 and then inside gdb issue the commands: set env G_DEBUG=fatal-criticals and then runSortie
Y
20

Break on g_log(). This covers all cases like g_warning(), g_critical(), etc.

Yardage answered 26/4, 2011 at 8:10 Comment(1)
The useful gdb commands are: break g_log if log_level == G_LOG_LEVEL_CRITICAL and break g_log if log_level == G_LOG_LEVEL_WARNINGSeraphina

© 2022 - 2024 — McMap. All rights reserved.