Debugging in Gnome
People apparently horribly misuse g_return_val_if_fail(). I gather, by the fact that it asserts (crashes) if glib is built with debug, that it’s intended to enforce contracts. And, mostly, that seems to be the way it’s used. However, some programs (*cough* gaim *cough*) seem to use it in place of “if (condition) return (failurecode)”, which means that building glib with debug causes constant cores in gaim. Here’s my most recent example:
if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") ||
(gaim_blist_node_get_string((GaimBlistNode*)chat,
"gtk-autojoin") != NULL))
serv_join_chat(gc, chat->components);
gaim_blist_node_get_<type> calls g_return_val_if_fail(result == <type>). Thus, the above snippet cannot fail to core if there is a gtk-autojoin option for this chat (which there will be), and glib is built with debug. I can only assume that a) Gaim developers don’t know about the assert case in glib; b) Gaim developers know, but don’t ever build glib with debug (and so don’t care); or c) Gaim developers don’t actually use the IRC client.
I’m only picking on gaim here because it’s the most recent example. Since rebuilding my glib with debug almost a month ago, tons of programs have become horribly unstable for the same reason. I’ve been hoping to fix these problems, and make things better for the Gentoo Gnome users, but there’s just too many, and I have to give up. Sorry, Gnome users, I need my desktop working again.
Note: the docs here for g_return_if_fail() don’t mention anything about asserts or contracts. “Critical message” doesn’t imply, to me at least, that it asserts. So, I guess the Gaim developers can’t really be blamed. I’m considering adding a big fat warning to the glib ebuild saying that you really don’t want to build with debug unless you know what you’re doing.
Update: I take it back. As far as I can tell, in glib 2.12, g_return_if_fail() always asserts, unless you actually give –disable-debug to glib (rather than not giving –enable-debug). This means that the above gaim code will always assert on Gentoo. I guess this means I’ll have to patch gaim.
ping: http://blog.catmur.co.uk/ed/2006/08/19/the-use-and-misuse-of-g_return_if_fail/
Do you not have Trackback/Pingback enabled?
I don’t have it on, because I was getting lots of spam trackbacks/pingbacks. I’ll try enabling it again, so see if it’s better.
As for the post, thanks for letting me know. You’re absolutely right, I do have that set in my environment. (However, this assert business has been going on longer than 2.15.9x, I believe, so maybe they set it on the whole development branch? Maybe I’m just misremembering…)
It seems to have been a good idea in my case, becuase I submitted some 10-15 bugs with patches based on those asserts. Now back to liferea 1.1.0, which was unusable with the asserts on…
You’re right; I misremembered how it works.
All development releases of gnome-session have code that checks whether the current date is after the date_of_doom and if so set G_DEBUG=”fatal_criticals” in env. The code is in stable releases, but disabled; the first development release in each cycle enables the code and bumps up the date_of_doom by 6 months.
I’m sure it’s a good idea in principle, but it’s annoying how it affects modules outside the Gnome development cycle.