X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=cfg%2Fdebug.h;h=73f22eb77393b416b116d85489176645163fc908;hb=2af1187034ad89752015b943c639ed180bebfbcf;hp=d8406bb05a6c2ff993ce48a822c02b9103065c2b;hpb=af9c555446161016fdd76c1cdff96ce76bb6cba2;p=bertos.git diff --git a/cfg/debug.h b/cfg/debug.h index d8406bb0..73f22eb7 100755 --- a/cfg/debug.h +++ b/cfg/debug.h @@ -17,6 +17,27 @@ /*#* *#* $Log$ + *#* Revision 1.9 2006/02/23 08:40:33 bernie + *#* TRACEMSG() support for compilers with no variadic macros. + *#* + *#* Revision 1.8 2006/02/23 08:33:04 bernie + *#* Fix for compilers without variadic macros support. + *#* + *#* Revision 1.7 2006/02/20 02:01:56 bernie + *#* Depend on cfg/os.h. + *#* + *#* Revision 1.6 2006/02/17 22:28:37 bernie + *#* Support TRACE() and TRACEMSG() on hosted targets. + *#* + *#* Revision 1.5 2005/11/04 16:09:03 bernie + *#* Doxygen workaround. + *#* + *#* Revision 1.4 2005/07/03 15:18:52 bernie + *#* Typo. + *#* + *#* Revision 1.3 2005/06/27 21:23:55 bernie + *#* Rename cfg/config.h to appconfig.h. + *#* *#* Revision 1.2 2005/04/11 19:10:27 bernie *#* Include top-level headers from cfg/ subdir. *#* @@ -50,16 +71,7 @@ #ifndef DEVLIB_DEBUG_H #define DEVLIB_DEBUG_H -/* - * Try to guess whether we're running in a hosted or embedded environment. - */ -#ifndef OS_HOSTED - #if defined(__unix__) || defined(_WIN32) - #define OS_HOSTED 1 - #else - #define OS_HOSTED 0 - #endif -#endif /* !OS_HOSTED */ +#include #if OS_HOSTED /* @@ -101,7 +113,7 @@ * This preprocessor symbol is defined only in debug builds. * * The build infrastructure must arrange for _DEBUG to - * be prepredefined for all source files being compiled. + * be predefined for all source files being compiled. * * This is compatible with the Microsoft convention for * the default Debug and Release targets. @@ -136,7 +148,7 @@ /*! * This macro can be used to conditionally exclude one or more * statements conditioned on \c _DEBUG, avoiding the clutter - * of #ifdef/#endif pairs. + * of ifdef/endif pairs. * * \code * struct FooBar @@ -169,15 +181,17 @@ } /* G++ can't inline functions with variable arguments... */ #define kprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) + #define kvprintf(fmt, ap) vfprintf(stderr, fmt, ap) void kdump(const void *buf, size_t len); /* UNIMPLEMENTED */ #ifndef ASSERT #include #define ASSERT(x) assert(x) #endif /* ASSERT */ + #define ASSERT2(x, help) ASSERT(help && x) - /*! - * Check that the given pointer is not NULL or pointing to raw memory. + /** + * Check that the given pointer is either NULL or pointing to valid memory. * * The assumption here is that valid pointers never point to low * memory regions. This helps catching pointers taken from @@ -185,10 +199,35 @@ */ #define ASSERT_VALID_PTR(p) ASSERT((unsigned long)(p) > 0x200) + /** + * Check that the given pointer is not pointing to invalid memory. + * + * \see ASSERT_VALID_PTR() + */ #define ASSERT_VALID_PTR_OR_NULL(p) ASSERT((((p) == NULL) || ((unsigned long)(p) >= 0x200))) + + #if !CONFIG_KDEBUG_DISABLE_TRACE + #define TRACE kprintf("%s()\n", __func__) + #if COMPILER_VARIADIC_MACROS + #define TRACEMSG(msg,...) kprintf("%s(): " msg, __func__, ## __VA_ARGS__) + #else + INLINE void TRACEMSG(const char *fmt, ...) + { + va_list va; + va_start(va, fmt); + kprintf("%s(): ", __func__); + kvprintf(fmt, va); + va_end(va); + } + #endif + #else + #define TRACE do {} while(0) + #define TRACEMSG(...) do {} while(0) + #endif + #else /* !OS_HOSTED */ - #include /* CONFIG_KDEBUG_ASSERT_NO_TEXT */ + #include /* CONFIG_KDEBUG_ASSERT_NO_TEXT */ #include /* CPU_HARVARD */ /* These are implemented in drv/kdebug.c */ @@ -331,7 +370,14 @@ #define ASSERT_VALID_PTR_OR_NULL(p) ((void)0) #define ASSERT_VALID_OBJ(_t, _o) ((void)0) #define TRACE do {} while (0) - #define TRACEMSG(x,...) do {} while (0) + #if COMPILER_VARIADIC_MACROS + #define TRACEMSG(x, ...) do {} while (0) + #else + INLINE void TRACEMSG(UNUSED_ARG(const char *, msg), ...) + { + /* NOP */ + } + #endif #define DECLARE_WALL(name, size) /* nothing */ #define FWD_DECLARE_WALL(name, size) /* nothing */ @@ -351,12 +397,12 @@ INLINE void kputs(UNUSED_ARG(const char *, str)) { /* nop */ } INLINE void kdump(UNUSED_ARG(const void *, buf), UNUSED_ARG(size_t, len)) { /* nop */ } - #ifdef __cplusplus + #if defined(__cplusplus) && COMPILER_VARIADIC_MACROS /* G++ can't inline functions with variable arguments... */ #define kprintf(fmt,...) do { (void)(fmt); } while(0) #else /* ...but GCC can. */ - INLINE void kprintf(UNUSED_ARG(const char *, fmt), ...) { /* nop */ } + INLINE void kprintf(UNUSED_ARG(const char *, fmt), ...) { /* nop */ } #endif #endif /* _DEBUG */