Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 840
gnychis Avatar asked Apr 26 '11 04:04

gnychis


People also ask

How to make breakpoint in GDB?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

How do I debug GLib?

If GLib has been configured with --enable-debug=yes , this variable can be set to a list of debug options, which cause GLib to print out different types of debugging information. Causes GLib to abort the program at the first call to g_warning() or g_critical().


2 Answers

You should add an environment variable like this:

G_DEBUG=fatal_warnings gdb ...
like image 160
lovebug356 Avatar answered Oct 17 '22 22:10

lovebug356


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

like image 25
ptomato Avatar answered Oct 17 '22 22:10

ptomato