Rewritten Debug.h by Vasilis Kaoutsis.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20473 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+40
-60
@@ -1,25 +1,20 @@
|
|||||||
/******************************************************************************
|
/*
|
||||||
/
|
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
||||||
/ File: Debug.h
|
* Distributed under the terms of the MIT License.
|
||||||
/
|
*/
|
||||||
/ Description: Compile time and runtime switchable debug macros.
|
|
||||||
/
|
|
||||||
/ Copyright 1993-98, Be Incorporated
|
|
||||||
/
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef _DEBUG_H
|
#ifndef _DEBUG_H
|
||||||
#define _DEBUG_H
|
#define _DEBUG_H
|
||||||
|
|
||||||
|
|
||||||
#include <BeBuild.h>
|
#include <BeBuild.h>
|
||||||
#include <SupportDefs.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <OS.h>
|
|
||||||
|
|
||||||
/*------------------------------*/
|
|
||||||
/*----- Private... -------------*/
|
/* Private */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -27,37 +22,32 @@ extern "C" {
|
|||||||
|
|
||||||
_IMPEXP_ROOT bool _debugFlag(void);
|
_IMPEXP_ROOT bool _debugFlag(void);
|
||||||
_IMPEXP_ROOT bool _setDebugFlag(bool);
|
_IMPEXP_ROOT bool _setDebugFlag(bool);
|
||||||
|
|
||||||
_IMPEXP_ROOT int _debugPrintf(const char *, ...);
|
_IMPEXP_ROOT int _debugPrintf(const char *, ...);
|
||||||
_IMPEXP_ROOT int _sPrintf(const char *, ...);
|
_IMPEXP_ROOT int _sPrintf(const char *, ...);
|
||||||
_IMPEXP_ROOT int _xdebugPrintf(const char *, ...);
|
_IMPEXP_ROOT int _xdebugPrintf(const char *, ...);
|
||||||
_IMPEXP_ROOT int _debuggerAssert(const char *, int, char *);
|
_IMPEXP_ROOT int _debuggerAssert(const char *, int, char *);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*-------- ...to here ----------*/
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------*/
|
|
||||||
/*----- Debug macros ------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Debug macros */
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define SET_DEBUG_ENABLED(FLAG) _setDebugFlag(FLAG)
|
#define SET_DEBUG_ENABLED(FLAG) _setDebugFlag(FLAG)
|
||||||
#define IS_DEBUG_ENABLED() _debugFlag()
|
#define IS_DEBUG_ENABLED() _debugFlag()
|
||||||
|
|
||||||
#define SERIAL_PRINT(ARGS) _sPrintf ARGS
|
#define SERIAL_PRINT(ARGS) _sPrintf ARGS
|
||||||
#define PRINT(ARGS) _debugPrintf ARGS
|
#define PRINT(ARGS) _debugPrintf ARGS
|
||||||
#define PRINT_OBJECT(OBJ) if (_rtDebugFlag) { \
|
#define PRINT_OBJECT(OBJ) if (_rtDebugFlag) { \
|
||||||
PRINT(("%s\t", #OBJ)); \
|
PRINT(("%s\t", #OBJ)); \
|
||||||
(OBJ).PrintToStream(); \
|
(OBJ).PrintToStream(); \
|
||||||
} ((void) 0)
|
} ((void)0)
|
||||||
#define TRACE() _debugPrintf("File: %s, Line: %d, Thread: %d\n", \
|
#define TRACE() _debugPrintf("File: %s, Line: %d, Thread: %d\n", \
|
||||||
__FILE__, __LINE__, find_thread(NULL))
|
__FILE__, __LINE__, find_thread(NULL))
|
||||||
|
|
||||||
#define SERIAL_TRACE() _sPrintf("File: %s, Line: %d, Thread: %d\n", \
|
#define SERIAL_TRACE() _sPrintf("File: %s, Line: %d, Thread: %d\n", \
|
||||||
__FILE__, __LINE__, find_thread(NULL))
|
__FILE__, __LINE__, find_thread(NULL))
|
||||||
|
|
||||||
#define DEBUGGER(MSG) if (_rtDebugFlag) debugger(MSG)
|
#define DEBUGGER(MSG) if (_rtDebugFlag) debugger(MSG)
|
||||||
#if !defined(ASSERT)
|
#if !defined(ASSERT)
|
||||||
#define ASSERT(E) (!(E) ? _debuggerAssert(__FILE__,__LINE__, #E) \
|
#define ASSERT(E) (!(E) ? _debuggerAssert(__FILE__,__LINE__, #E) \
|
||||||
@@ -67,48 +57,38 @@ extern "C" {
|
|||||||
#define ASSERT_WITH_MESSAGE(expr, msg) \
|
#define ASSERT_WITH_MESSAGE(expr, msg) \
|
||||||
(!(expr) ? _debuggerAssert( __FILE__,__LINE__, msg) \
|
(!(expr) ? _debuggerAssert( __FILE__,__LINE__, msg) \
|
||||||
: (int)0)
|
: (int)0)
|
||||||
|
|
||||||
#define TRESPASS() DEBUGGER("Should not be here");
|
#define TRESPASS() DEBUGGER("Should not be here");
|
||||||
|
|
||||||
#define DEBUG_ONLY(arg) arg
|
#define DEBUG_ONLY(arg) arg
|
||||||
|
|
||||||
#else /* DEBUG == 0 */
|
#else /* DEBUG == 0 */
|
||||||
#define SET_DEBUG_ENABLED(FLAG) (void)0
|
#define SET_DEBUG_ENABLED(FLAG) (void)0
|
||||||
#define IS_DEBUG_ENABLED() (void)0
|
#define IS_DEBUG_ENABLED() (void)0
|
||||||
|
|
||||||
#define SERIAL_PRINT(ARGS) (void)0
|
#define SERIAL_PRINT(ARGS) (void)0
|
||||||
#define PRINT(ARGS) (void)0
|
#define PRINT(ARGS) (void)0
|
||||||
#define PRINT_OBJECT(OBJ) (void)0
|
#define PRINT_OBJECT(OBJ) (void)0
|
||||||
#define TRACE() (void)0
|
#define TRACE() (void)0
|
||||||
#define SERIAL_TRACE() (void)0
|
#define SERIAL_TRACE() (void)0
|
||||||
|
|
||||||
#define DEBUGGER(MSG) (void)0
|
#define DEBUGGER(MSG) (void)0
|
||||||
#if !defined(ASSERT)
|
#if !defined(ASSERT)
|
||||||
#define ASSERT(E) (void)0
|
#define ASSERT(E) (void)0
|
||||||
#endif
|
#endif
|
||||||
#define ASSERT_WITH_MESSAGE(expr, msg) \
|
#define ASSERT_WITH_MESSAGE(expr, msg) (void)0
|
||||||
(void)0
|
#define TRESPASS() (void)0
|
||||||
#define TRESPASS() (void)0
|
|
||||||
#define DEBUG_ONLY(x)
|
#define DEBUG_ONLY(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* STATIC_ASSERT is a compile-time check that can be used to */
|
||||||
|
/* verify static expressions such as: STATIC_ASSERT(sizeof(int64) == 8); */
|
||||||
|
#define STATIC_ASSERT(x) \
|
||||||
|
do { \
|
||||||
|
struct __staticAssertStruct__ { \
|
||||||
|
char __static_assert_failed__[2*(x) - 1]; \
|
||||||
|
}; \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
#if !__MWERKS__
|
|
||||||
// STATIC_ASSERT is a compile-time check that can be used to
|
|
||||||
// verify static expressions such as: STATIC_ASSERT(sizeof(int64) == 8);
|
|
||||||
#define STATIC_ASSERT(x) \
|
|
||||||
do { \
|
|
||||||
struct __staticAssertStruct__ { \
|
|
||||||
char __static_assert_failed__[2*(x) - 1]; \
|
|
||||||
}; \
|
|
||||||
} while (false)
|
|
||||||
#else
|
|
||||||
#define STATIC_ASSERT(x)
|
|
||||||
// the STATIC_ASSERT above doesn't work too well with mwcc because
|
|
||||||
// of scoping bugs; for now make it do nothing
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------*/
|
#endif /* _DEBUG_H */
|
||||||
/*-------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#endif /* _DEBUG_H */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user