GNOME Bugzilla – Bug 61228
Fatal warnings env variable
Last modified: 2011-02-18 15:47:32 UTC
I want to add an environment variable to GLib which sets fatal warnings, then set this in the session manager for the entire GNOME 2 development cycle, so all apps crash noticeably on warning. (This bug is a reminder to myself to do it.)
Please assign this to a milestone.
Wouldn't it be nicer to have one GLIB_DEBUG envvar, similar to GTK_DEBUG/GDK_DEBUG/GRUNTIME_DEBUG instead of scattering debug envvars throughout the code ? The win32 port already has some obscure debugging envvars which should be cleaned up as well if we go for GLIB_DEBUG.
A debug var makes sense, but would be more expensive than it is for GTK+, etc, since "G_NOTE()" would have to: - Lock a global lock - Check to see if we've parsed the debug var before - If not, parse it - Unlock the global lock As long as we don't use this in any fast path code (GHashTable, g_malloc()) the penalty for --enable-debug shouldn't be bad, however, and without --enable-debug it wouldn't matter. The main disadvantage of the "debug environment variable" setup is that it would only be availalble for --enable-debug builds, though I suppose we could parse the debug vars unconditionally and only make G_NOTE conditional. Putting on 2.0.1, since it's only convenience functionality, and not entirely trivial.
Wouldn't this be faster and still correct ? Check to see if we've parsed the debug var before If not, Lock a global lock Check to see if we've parsed the debug var before If not, parse it Unlock the global lock Use the parsed value The "parsed value" is written only once, so this should be ok.
Consider the case where you have processor B hitting the code while processor A initializing. There is no guarantee that processor B won't see the "initialized flag" written to memory _before_ the value of the debug flags is written to memory, even if A writes them in the correct order. But there is actually an easy thing to do... just make sure that g_thread_init() always causes the debug envvar to be parsed; we _do_ have an init function in the threaded case, just not in the non-threaded case.
I was kind of assuming that the "parsed value" and the "initialized flag" could be the same thing and could be written atomically. But of course, doing the thing in g_thread_init() sounds like a clever way out.
We had this discussion before. Whenever there is cache coherency guaranteed, then you can rely on that. I don't think, GLib will be ported to a non-cache-coherency platform any time soon. The best solution probably is to introduce GOnce, which does something along the lines of pthread_once_t and works optimized for the current platform (i.e. for a set of known platforms uses the method of avoid locking in the common poth) and falls back to full locking in case of an unknown platform. Sounds like 2.2 stuff. BTW: Of course the pragmatic solution to parse it at g_thread_init time (preferably from within g_messages_init to increase the locality) is fine for the time being.
This isn't quite the discussion we had before; it's case that is somewhat more likely to break because we aren't talking about: pointer A => newly allocated structure B But rather: integer A integer B I believe the second case _will_ break on a number of currently available reasonably common architectures. Anyways, pretty irrelevant to this bug.
The case pointer A => newly allocated structure B might seem different, than integer A integer B but if you cross a memory barrier between setting B to a new value and setting A to "B is written", it is essentially the same, I'd say. But as you pointed out, this quite irrelevant to this bug. I'll however add a wishlist future bug to add GOnce to nicly do things.
Speaking about g_messages_init, shouldn't the parsing of G_MESSAGES_PREFIXED be done in there as well, so that the lock can be removed from g_log_write_prefix ?
Moving the G_MESSAGES_PREFIXED parsing sounds fine to me.
Here's a patch which does the lock-removing for the message prefix stuff and adds generic support for a GLIB_DEBUG envvar. Currently the only recognized debug flag is "fatal_warnings" with the same meaning as --g-fatal-warnings and with the extra twist that it is effective even if compiled without G_DEBUG (the G_NOTE macro in the new header gdebug.h, however, is vacuous in that case).
Created attachment 6669 [details] [review] the patch
Looks good to commit. Except that - gdebug.h should not be installed (put it in SOURCES rather than HEADERS) - g_debug_init(), g_debug_initialized(), g_debug_flags() should all be _g_debug_* and not exported. - Need to add gdebug.h to IGNORE_HFILES in the docs And would be better to avoid adding the trailing new lines on files.
Committed with your corrections and with documentation. I ended up naming the envvar G_DEBUG instead of GLIB_DEBUG for consistency with the other G_ prefixed envvars.