1
1
forked from 0ad/0ad

split debug functions out into separate sysdep/debug header

This was SVN commit r883.
This commit is contained in:
janwas 2004-08-02 13:47:38 +00:00
parent 8485fc3d82
commit 05f02111da
3 changed files with 35 additions and 28 deletions

29
source/lib/sysdep/debug.h Executable file
View File

@ -0,0 +1,29 @@
//
// 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
extern void debug_microlog(const wchar_t *fmt, ...);
//
// 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);
extern int debug_write_crashlog(const char* file, wchar_t* header, void* context);
extern void debug_check_heap();
extern void debug_break();

View File

@ -36,7 +36,7 @@ void debug_out(const char* fmt, ...)
} }
void check_heap() inline void check_heap()
{ {
} }
@ -59,11 +59,13 @@ void debug_break()
} }
const int MICROLOG_SIZE = 16384;
wchar_t MicroBuffer[MICROLOG_SIZE]; wchar_t MicroBuffer[MICROLOG_SIZE];
int MicroBuffer_off = 0; int MicroBuffer_off = 0;
void debug_microlog(const wchar_t *fmt, ...) void debug_microlog(const wchar_t *fmt, ...)
{ {
#ifndef NDEBUG
va_list argp; va_list argp;
wchar_t buffer[512]; wchar_t buffer[512];
@ -84,6 +86,7 @@ void debug_microlog(const wchar_t *fmt, ...)
} }
memcpy(&MicroBuffer[MicroBuffer_off], buffer, sizeof(wchar_t)*len); memcpy(&MicroBuffer[MicroBuffer_off], buffer, sizeof(wchar_t)*len);
MicroBuffer_off += len; MicroBuffer_off += len;
#endif
} }

View File

@ -3,6 +3,8 @@
#include "config.h" #include "config.h"
#include "sysdep/debug.h"
#ifdef _WIN32 #ifdef _WIN32
#include "win/win.h" #include "win/win.h"
#include "win/wdbg.h" #include "win/wdbg.h"
@ -18,33 +20,6 @@ extern "C" {
extern void display_msg(const char* caption, const char* msg); extern void display_msg(const char* caption, const char* msg);
extern void wdisplay_msg(const wchar_t* caption, const wchar_t* msg); extern void wdisplay_msg(const wchar_t* caption, const wchar_t* msg);
extern void debug_out(const char* fmt, ...);
extern void debug_break();
// assert with stack trace (including variable / parameter types and values)
// shown in a dialog, which offers
// continue, break, suppress (ignore this assert), and exit
/*
* return values:
* 0 - continue
* 1 - suppress
* 2 - break
*/
extern int debug_assert_failed(const char* source_file, int line, const char* expr);
extern int debug_write_crashlog(const char* file, wchar_t* header, void* context);
// Small fast(ish) log for recording the events leading up to a crash:
#define MICROLOG debug_microlog
//#define MICROLOG (void)
const int MICROLOG_SIZE = 16384;
void debug_microlog(const wchar_t *fmt, ...);
extern void check_heap();
extern int clipboard_set(const wchar_t* text); extern int clipboard_set(const wchar_t* text);
extern wchar_t* clipboard_get(); extern wchar_t* clipboard_get();