Add a --debug flag for DEBUG builds

If you compile with:

  DEBUG=true rake build

then all the commands get a --debug flag as an option which will make
the server dump crazy amounts of data to stderr.
This commit is contained in:
Alex Young
2012-05-31 13:31:22 +01:00
parent 268bebd408
commit 623a398767
6 changed files with 85 additions and 35 deletions

View File

@@ -10,6 +10,7 @@
#include "util.h"
static pthread_t main_thread;
static int global_debug;
void error_init()
{
@@ -59,3 +60,23 @@ void* xmalloc(size_t size)
return p;
}
void set_debug(int value) {
global_debug = value;
}
#ifdef DEBUG
# include <sys/times.h>
# include <stdarg.h>
void debug(const char *msg, ...) {
va_list argp;
if ( global_debug ) {
fprintf(stderr, "%08x %4d: ", (int) pthread_self(), (int) clock() );
fprintf(stderr, msg, argp);
fprintf(stderr, "\n");
}
}
#endif