[PATCH util-macros] XORG_ENABLE_DEBUG: a configure option to enable code debugging

Gaetan Nadon memsize at videotron.ca
Wed Apr 21 12:03:50 PDT 2010


On Wed, 2010-04-21 at 11:22 +1000, Peter Hutterer wrote:

> On Tue, Apr 20, 2010 at 08:32:46PM -0400, Gaetan Nadon wrote:
> > Provides a common configure option for all x.org modules.
> > Script friendly for turning on debug in several modules.
> > Integrates easily into existing modules debug code.
> > For both source code and makefiles
> > Configurable on/off default setting.
> > 
> > Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
> > ---
> >  xorg-macros.m4.in |   32 ++++++++++++++++++++++++++++++++
> >  1 files changed, 32 insertions(+), 0 deletions(-)
> > 
> > diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
> > index 66c8e98..112db89 100644
> > --- a/xorg-macros.m4.in
> > +++ b/xorg-macros.m4.in
> > @@ -1029,3 +1029,35 @@ test -e \"\$\$OUTFILE\" || echo \"\$\$OUTSTR\" > \"\$\$OUTFILE\"; \
> >  CONTENT=\`cat \$\$OUTFILE\` && test \"\$\$CONTENT\" = \"\$\$OUTSTR\" || echo \$\$OUTSTR > \$\$OUTFILE;"
> >  AC_SUBST([GIT_MODULE_VERSION_CMD])
> >  ]) # XORG_GIT_MODULE_VERSION
> > +
> > +# XORG_ENABLE_DEBUG (enable_debug=no)
> > +# -----------------------------------
> > +# Minimum version: 1.8.0
> > +#
> > +# This macro defines a C preprocessor macro and a makefile conditional
> > +# to compile code for debugging purpose. (Not related to compiler options)
> > +#
> > +# Interface to module:
> > +# HAVE_DEBUG:	  used in makefiles to conditionally build targets
> > +#		  used in source code to conditionally debug code
> > +# --enable-debug: 'yes' user instructs the module to compile debug code
> > +#		 'no' user instructs the module not to compile debug code
> > +# parm1:	specify the default value, yes or no.
> > +#
> > +AC_DEFUN([XORG_ENABLE_DEBUG],[
> > +default=$1
> > +if test "x$default" = x ; then
> > +  default="no"
> > +fi
> > +AC_ARG_ENABLE([debug],
> > +	AS_HELP_STRING([--enable-debug],
> > +	   [Enable debugging code (default: no)]),
> > +	   [enable_debug=$enableval], [enable_debug=$default])
> > +
> > +if test x$enable_debug = xyes; then
> > +    AC_DEFINE([HAVE_DEBUG], [1], [Enable debugging code])
> > +fi
> > +AM_CONDITIONAL([HAVE_DEBUG], [test x$enable_debug = xyes])
> > +AC_MSG_CHECKING([whether to enable debug code])
> > +AC_MSG_RESULT([$enable_debug])
> > +]) # XORG_ENABLE_DEBUG
> > -- 
> > 1.6.0.4
> 
> > There are 4 modules with --enable-debug configure option but many more modules (44) do
> > have something like #define DEBUG with a wide variety of names. One has to dig in the code
> > to figure out how each module does it.
> > 
> > This macro will give the opportunity for modules to have a common configure option where
> > debug can be turned on without having to read all the code and to change it.
> > 
> > It was tempting to use DEBUG as the #define name, but there were already conflicts.
> 
> can you specify what those conflicts were? 
> 
        Existing definitions in various drivers
        #define DEBUG(str,param1) (void)screen
        #define DEBUG(x) 
        #define DEBUG
        #undef DEBUG



> the use of ifdef DEBUG is quite common and having it turned on/off by a
> configure option isn't really a conflict if the package didn't do it before.

No conflict from a configure.ac perspective.

> I'd even argue that this macro should go into the XORG_DEFAULT_OPTIONS.

Sure. 

> 
> > I checked HAVE_DEBUG was not already used so it's easy to wrap whatever #define is there
> > without changing much code.

Except for the 4 modules having a configure options, others edit the c
file to turn debug on.

For example, aiptek has:

        #define DEBUG 1
        #if DEBUG
        #   define     DBG(lvl, f)     {if ((lvl) <= debug_level) f;}
        #else
        #   define     DBG(lvl, f)
        #endif

which can be changed to:

        #ifdef HAVE_DEBUG
        #define DEBUG 1
        #endif
        #if DEBUG
        #   define     DBG(lvl, f)     {if ((lvl) <= debug_level) f;}
        #else
        #   define     DBG(lvl, f)
        #endif

which does not change the rest of the code and prevents conversion
errors. 


> 
> Cheers,
>   Peter
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100421/c3cf945d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100421/c3cf945d/attachment.pgp>


More information about the xorg-devel mailing list