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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gnychis
  • 7,289
  • 18
  • 75
  • 113
  • Duplicate of: http://stackoverflow.com/questions/2450001/how-can-i-find-out-where-is-my-code-causing-glib-gobject-critical but this question is clearer, so I'm voting to close that other one. – ptomato Apr 26 '11 at 08:13

2 Answers2

25

You should add an environment variable like this:

G_DEBUG=fatal_warnings gdb ...
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lovebug356
  • 463
  • 5
  • 6
  • 4
    `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](https://developer.gnome.org/glib/stable/glib-running.html#G-DEBUG:CAPS). 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 `run` – Nelson Mar 02 '15 at 15:21
20

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

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • 11
    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_WARNING` – Mildred Jul 06 '11 at 07:08