2007-03-30 18:43:25 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2007, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-23 17:54:44 +04:00
|
|
|
#ifndef _DEBUG_H
|
|
|
|
#define _DEBUG_H
|
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#include <BeBuild.h>
|
2007-03-30 18:43:25 +04:00
|
|
|
#include <OS.h>
|
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2003-05-14 21:21:46 +04:00
|
|
|
#include <stdlib.h>
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
|
|
|
|
/* Private */
|
2002-10-23 17:54:44 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2007-10-16 00:13:55 +04:00
|
|
|
extern bool _rtDebugFlag;
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
bool _debugFlag(void);
|
|
|
|
bool _setDebugFlag(bool);
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2007-07-11 22:55:27 +04:00
|
|
|
#if __GNUC__
|
2007-10-16 00:13:55 +04:00
|
|
|
int _debugPrintf(const char *, ...) _PRINTFLIKE(1, 2);
|
|
|
|
int _sPrintf(const char *, ...) _PRINTFLIKE(1, 2);
|
2007-07-11 22:55:27 +04:00
|
|
|
#else
|
|
|
|
int _debugPrintf(const char *, ...);
|
|
|
|
int _sPrintf(const char *, ...);
|
|
|
|
#endif
|
2007-10-16 00:13:55 +04:00
|
|
|
int _xdebugPrintf(const char *, ...);
|
2009-04-30 16:21:20 +04:00
|
|
|
int _debuggerAssert(const char *, int, const char *);
|
2002-10-23 17:54:44 +04:00
|
|
|
#ifdef __cplusplus
|
2007-03-30 18:43:25 +04:00
|
|
|
}
|
2002-10-23 17:54:44 +04:00
|
|
|
#endif
|
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
/* Debug macros */
|
2002-10-23 17:54:44 +04:00
|
|
|
#if DEBUG
|
|
|
|
#define SET_DEBUG_ENABLED(FLAG) _setDebugFlag(FLAG)
|
|
|
|
#define IS_DEBUG_ENABLED() _debugFlag()
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#define SERIAL_PRINT(ARGS) _sPrintf ARGS
|
|
|
|
#define PRINT(ARGS) _debugPrintf ARGS
|
2007-03-30 18:43:25 +04:00
|
|
|
#define PRINT_OBJECT(OBJ) if (_rtDebugFlag) { \
|
2002-10-23 17:54:44 +04:00
|
|
|
PRINT(("%s\t", #OBJ)); \
|
|
|
|
(OBJ).PrintToStream(); \
|
2007-03-30 18:43:25 +04:00
|
|
|
} ((void)0)
|
2012-12-20 23:22:16 +04:00
|
|
|
#define TRACE() _debugPrintf("File: %s, Line: %d, Thread: %" \
|
|
|
|
B_PRId32 "\n", __FILE__, __LINE__, \
|
|
|
|
find_thread(NULL))
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2012-12-20 23:22:16 +04:00
|
|
|
#define SERIAL_TRACE() _sPrintf("File: %s, Line: %d, Thread: %" \
|
|
|
|
B_PRId32 "\n", __FILE__, __LINE__, \
|
|
|
|
find_thread(NULL))
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#define DEBUGGER(MSG) if (_rtDebugFlag) debugger(MSG)
|
|
|
|
#if !defined(ASSERT)
|
|
|
|
#define ASSERT(E) (!(E) ? _debuggerAssert(__FILE__,__LINE__, #E) \
|
|
|
|
: (int)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ASSERT_WITH_MESSAGE(expr, msg) \
|
|
|
|
(!(expr) ? _debuggerAssert( __FILE__,__LINE__, msg) \
|
|
|
|
: (int)0)
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#define TRESPASS() DEBUGGER("Should not be here");
|
2007-03-30 18:43:25 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#define DEBUG_ONLY(arg) arg
|
|
|
|
|
|
|
|
#else /* DEBUG == 0 */
|
2007-03-30 18:43:25 +04:00
|
|
|
#define SET_DEBUG_ENABLED(FLAG) (void)0
|
|
|
|
#define IS_DEBUG_ENABLED() (void)0
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
#define SERIAL_PRINT(ARGS) (void)0
|
|
|
|
#define PRINT(ARGS) (void)0
|
|
|
|
#define PRINT_OBJECT(OBJ) (void)0
|
|
|
|
#define TRACE() (void)0
|
|
|
|
#define SERIAL_TRACE() (void)0
|
|
|
|
|
|
|
|
#define DEBUGGER(MSG) (void)0
|
2002-10-23 17:54:44 +04:00
|
|
|
#if !defined(ASSERT)
|
2007-03-30 18:43:25 +04:00
|
|
|
#define ASSERT(E) (void)0
|
2002-10-23 17:54:44 +04:00
|
|
|
#endif
|
2007-03-30 18:43:25 +04:00
|
|
|
#define ASSERT_WITH_MESSAGE(expr, msg) (void)0
|
|
|
|
#define TRESPASS() (void)0
|
2002-10-23 17:54:44 +04:00
|
|
|
#define DEBUG_ONLY(x)
|
|
|
|
#endif
|
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
/* 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)
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
|
2007-03-30 18:43:25 +04:00
|
|
|
#endif /* _DEBUG_H */
|