From 43fa556fa98f76434539c66dc5abfb99f9647e52 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 8 Mar 2023 16:14:34 +0100 Subject: [PATCH] Enable debug messages with -d Allows the user to easily enable debug messages, which are the only way to debug problems with channels. --- src/common.c | 7 +++++++ src/common.h | 11 ++++++----- src/emu/emu_args.c | 9 +++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/common.c b/src/common.c index def8496..b502d52 100644 --- a/src/common.c +++ b/src/common.c @@ -10,6 +10,7 @@ #include char *progname = NULL; +int is_debug_enabled = 0; void progname_set(char *name) @@ -17,6 +18,12 @@ progname_set(char *name) progname = name; } +void +enable_debug(void) +{ + is_debug_enabled = 1; +} + static void vaerr(const char *prefix, const char *func, const char *errstr, va_list ap) { diff --git a/src/common.h b/src/common.h index b1a7caf..0892230 100644 --- a/src/common.h +++ b/src/common.h @@ -6,9 +6,12 @@ #include +extern int is_debug_enabled; + /* Debug macros */ void progname_set(char *name); +void enable_debug(void); void verr(const char *prefix, const char *func, const char *errstr, ...); void vdie(const char *prefix, const char *func, const char *errstr, ...); @@ -20,11 +23,9 @@ void vdie(const char *prefix, const char *func, const char *errstr, ...); #define info(...) verr("INFO", NULL, __VA_ARGS__) #define warn(...) verr("WARN", NULL, __VA_ARGS__) -#ifdef ENABLE_DEBUG -# define dbg(...) verr("DEBUG", __func__, __VA_ARGS__) -#else -# define dbg(...) do { if (0) { verr("DEBUG", __func__, __VA_ARGS__); } } while(0) -#endif +#define dbg(...) do { \ + if (unlikely(is_debug_enabled)) verr("DEBUG", __func__, __VA_ARGS__); \ +} while (0); #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) diff --git a/src/emu/emu_args.c b/src/emu/emu_args.c index e2aa39e..3a29923 100644 --- a/src/emu/emu_args.c +++ b/src/emu/emu_args.c @@ -17,7 +17,7 @@ usage(void) { rerr("%s -- version %s\n", progname, version); rerr("\n"); - rerr("Usage: %s [-c offsetfile] [-blh] tracedir\n", progname); + rerr("Usage: %s [-c offsetfile] [-bdlh] tracedir\n", progname); rerr("\n"); rerr("Options:\n"); rerr(" -c offsetfile Use the given offset file to correct\n"); @@ -26,6 +26,8 @@ usage(void) rerr("\n"); rerr(" -b Enable breakdown model (costly)\n"); rerr("\n"); + rerr(" -d Enable debug output (very verbose)\n"); + rerr("\n"); rerr(" -l Enable linter mode. Extra tests will\n"); rerr(" be performed.\n"); rerr("\n"); @@ -44,7 +46,7 @@ emu_args_init(struct emu_args *args, int argc, char *argv[]) memset(args, 0, sizeof(struct emu_args)); int opt; - while ((opt = getopt(argc, argv, "bc:lh")) != -1) { + while ((opt = getopt(argc, argv, "bdc:lh")) != -1) { switch (opt) { case 'c': args->clock_offset_file = optarg; @@ -55,6 +57,9 @@ emu_args_init(struct emu_args *args, int argc, char *argv[]) case 'b': args->breakdown = 1; break; + case 'd': + enable_debug(); + break; case 'h': default: /* '?' */ usage();