2005-01-23 19:07:34 +01:00
|
|
|
#ifndef DEBUG_H__
|
|
|
|
#define DEBUG_H__
|
|
|
|
|
2005-01-25 19:27:00 +01:00
|
|
|
// we need to include the platform-specific version here, so it can
|
|
|
|
// define debug_break. if it can be implemented as a macro (e.g. on ia32),
|
|
|
|
// the debugger will break directly at the target, instead of one function
|
|
|
|
// below it as with a conventional implementation.
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include "win/wdbg.h"
|
|
|
|
#else
|
|
|
|
# include "unix/udbg.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
//
|
|
|
|
// logging
|
|
|
|
//
|
|
|
|
|
|
|
|
// output to the debugger (may take ~1 ms!)
|
|
|
|
extern void debug_out(const char* fmt, ...);
|
|
|
|
|
|
|
|
// log to memory buffer (fast)
|
|
|
|
#define MICROLOG debug_microlog
|
2005-01-23 19:07:34 +01:00
|
|
|
extern void debug_microlog(const wchar_t* fmt, ...);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const size_t DBG_SYMBOL_LEN = 1000;
|
|
|
|
const size_t DBG_FILE_LEN = 100;
|
|
|
|
|
|
|
|
extern void* debug_get_nth_caller(uint n);
|
|
|
|
|
2005-01-25 19:27:00 +01:00
|
|
|
extern int debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file, int* line);
|
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// crash notification
|
|
|
|
//
|
|
|
|
|
|
|
|
// notify the user that an assertion failed.
|
|
|
|
// displays a stack trace with local variables on Windows.
|
|
|
|
// return values: 0 = continue; 1 = suppress; 2 = break
|
|
|
|
// .. or exits the program if the user so chooses.
|
|
|
|
extern int debug_assert_failed(const char* source_file, int line, const char* assert_expr);
|
|
|
|
|
2005-01-23 19:07:34 +01:00
|
|
|
extern int debug_write_crashlog(const char* file, const wchar_t* header, void* context);
|
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
|
2005-01-23 19:07:34 +01:00
|
|
|
extern void debug_check_heap(void);
|
2004-08-02 15:47:38 +02:00
|
|
|
|
2005-01-25 19:27:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
// superassert
|
|
|
|
// recommended use: assert2(expr && "descriptive string")
|
2005-02-02 04:35:25 +01:00
|
|
|
#define assert2(expr) STMT(\
|
2005-01-25 19:27:00 +01:00
|
|
|
static int suppress__ = 0;\
|
2005-01-26 01:33:45 +01:00
|
|
|
if(!suppress__ && !(expr))\
|
2005-02-02 04:35:25 +01:00
|
|
|
switch(debug_assert_failed(__FILE__, __LINE__, #expr))\
|
|
|
|
{\
|
|
|
|
case 1:\
|
|
|
|
suppress__ = 1;\
|
|
|
|
break;\
|
|
|
|
case 2:\
|
|
|
|
debug_break();\
|
|
|
|
break;\
|
|
|
|
}\
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define debug_warn(str) assert2(0 && (str))
|
|
|
|
#else
|
|
|
|
# define debug_warn(str) debug_out("Debug Warning Fired at %s:%d: %s\n", __FILE__, __LINE__, str)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-01-25 19:27:00 +01:00
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
|
2005-01-23 19:07:34 +01:00
|
|
|
#endif // #ifndef DEBUG_H__
|