[LLVMdev] debug macros

Nathan Jeffords blunted2night at gmail.com
Wed May 12 09:07:01 PDT 2010


Their are a pair of debug macros I use in almost every project I work on and
I would like to add them to LLVM if acceptable.

The existing DEBUG macro is good for a lot of things, but inadequate for
certain situations. The may be cases where you wan't to run calculations in
the debug version that lead up to assertions. In a scenario like this, you
will likely need a temporary variable, and you calculations need to execute
unconditionally.

For this type of scenario I use the _dbg macro:

#ifndef NDEBUG
#define _dbg(x)  x
#else
#define _dbg(x)
#endif

The other macro is just a slight variation on the existing DEBUG macro, but
for the common case of printing something out to the debug console, its
simpler to write, and in my opinion easier to read.

#define dbgout(x) DEBUG(dbgs()<<x)
#define dbgoutc(y,x) DEBUG_WITH_TYPE(x,dbgs()<<y)

-Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100512/5003077e/attachment.html>


More information about the llvm-dev mailing list