This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Suggestion for debugging options.
- To: Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Suggestion for debugging options.
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Fri, 5 May 2000 10:24:31 +0200 (MEST)
Hello everybody.
I'd like to suggest the following idea:
* Debugging options in guile are macros prefixed with SCM_DEBUG_
* They are always defined and have to be either 0 or 1
* By default, they are 0.
Currently, these options are prefixed with GUILE_, which is in contrast to
our claim to only use the SCM_ namespace. Further, the fact that a
debugging option is enabled is encoded by the distinction between whether
the corresponding macro is defined or not forces us to use a lot of #ifdef
#endif nestings, which makes some code very hard understandable. Also,
within macros such information can not be used.
In contrast, instead of:
#ifdef GUILE_DEBUG_MALLOC
some_code();
#else
some_other_code();
#endif
with the above proposal we could write:
if (SCM_DEBUG_MALLOC)
some_code();
else
some_other_code();
which is easier to read, can even be part of a macro and will compile to
the same code, since the compiler will eliminate the dead
branch. Especially the fact that macros then can contain references to
debug options will allow for more flexibility.
For example, the current way interrupts are tested is
#ifdef SCM_CAREFUL_INTS
#define SCM_CHECK_NOT_DISABLED \
if (scm_ints_disabled) \
fputs("ints already disabled\n", stderr); \
#else
#define SCM_CHECK_NOT_DISABLED
#endif
#define SCM_DEFER_INTS \
do { \
SCM_FENCE; \
SCM_CHECK_NOT_DISABLED; \
SCM_THREAD_DEFER; \
SCM_FENCE; \
scm_ints_disabled = 1; \
SCM_FENCE; \
} while (0)
Then it would be:
#define SCM_CHECK_NOT_DISABLED \
if (scm_ints_disabled) \
fputs("ints already disabled\n", stderr); \
#define SCM_DEFER_INTS \
do { \
SCM_FENCE; \
if (SCM_DEBUG_CRITICAL_SECTIONS) \
SCM_CHECK_NOT_DISABLED; \
SCM_THREAD_DEFER; \
SCM_FENCE; \
scm_ints_disabled = 1; \
SCM_FENCE; \
} while (0)
which I personally find easier to read. And, since the nature of
SCM_DEBUG_ macros is clearly defined, it is easier to see when checks are
actually performed by looking at SCM_DEFER_INTS.
Best regards
Dirk Herrmann