RFC: debugging-GCC commented-out-code architecture
Bernardo Innocenti
bernie@develer.com
Fri Nov 28 03:28:00 GMT 2003
Chris Lattner wrote:
> You might be interested in how we solved this problem in LLVM. Basically,
> we have a DEBUG macro that people can wrap their debugging code with, like
> this:
>
> ...
> DEBUG(printf("foo happened!\n"));
> ...
On AmigaOS, it was common practice to use an equivalent macro called
DB() or even just D(). I find that a shorter name makes it more
attractive.
Another debug facility I've found useful was Microsoft's
ASSERT_VALID_PTR() and ASSERT_VALID_PTR_OR_NULL(). These macros
should attempt to guess wether a pointer is "valid", perhaps
using a machine-specific, conservative check like this:
/* GCC doesn't accept asm statements in the middle of an
* expression such as `a ? b : asm("something")'.
*/
#define ILLEGAL illegal()
static __inline__ int illegal(void) { asm("illegal"); return 0; }
#define ASSERT_VALID_PTR(x) ( (((long)(x) > 1024) && \
TypeOfMem((x))) ? 0 : \
( DBPRINTF ("\x07%s, %ld: bad ptr: " #x " = $%p\n", \
__FILE__, __LINE__, (x)), ILLEGAL ) )
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
More information about the Gcc-patches
mailing list