Enable debug messages with -d
Allows the user to easily enable debug messages, which are the only way to debug problems with channels.
This commit is contained in:
parent
31f24a2a55
commit
43fa556fa9
@ -10,6 +10,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
char *progname = NULL;
|
char *progname = NULL;
|
||||||
|
int is_debug_enabled = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
progname_set(char *name)
|
progname_set(char *name)
|
||||||
@ -17,6 +18,12 @@ progname_set(char *name)
|
|||||||
progname = name;
|
progname = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
enable_debug(void)
|
||||||
|
{
|
||||||
|
is_debug_enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vaerr(const char *prefix, const char *func, const char *errstr, va_list ap)
|
vaerr(const char *prefix, const char *func, const char *errstr, va_list ap)
|
||||||
{
|
{
|
||||||
|
11
src/common.h
11
src/common.h
@ -6,9 +6,12 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern int is_debug_enabled;
|
||||||
|
|
||||||
/* Debug macros */
|
/* Debug macros */
|
||||||
|
|
||||||
void progname_set(char *name);
|
void progname_set(char *name);
|
||||||
|
void enable_debug(void);
|
||||||
void verr(const char *prefix, const char *func, const char *errstr, ...);
|
void verr(const char *prefix, const char *func, const char *errstr, ...);
|
||||||
void vdie(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 info(...) verr("INFO", NULL, __VA_ARGS__)
|
||||||
#define warn(...) verr("WARN", NULL, __VA_ARGS__)
|
#define warn(...) verr("WARN", NULL, __VA_ARGS__)
|
||||||
|
|
||||||
#ifdef ENABLE_DEBUG
|
#define dbg(...) do { \
|
||||||
# define dbg(...) verr("DEBUG", __func__, __VA_ARGS__)
|
if (unlikely(is_debug_enabled)) verr("DEBUG", __func__, __VA_ARGS__); \
|
||||||
#else
|
} while (0);
|
||||||
# define dbg(...) do { if (0) { verr("DEBUG", __func__, __VA_ARGS__); } } while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define likely(x) __builtin_expect(!!(x), 1)
|
#define likely(x) __builtin_expect(!!(x), 1)
|
||||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
@ -17,7 +17,7 @@ usage(void)
|
|||||||
{
|
{
|
||||||
rerr("%s -- version %s\n", progname, version);
|
rerr("%s -- version %s\n", progname, version);
|
||||||
rerr("\n");
|
rerr("\n");
|
||||||
rerr("Usage: %s [-c offsetfile] [-blh] tracedir\n", progname);
|
rerr("Usage: %s [-c offsetfile] [-bdlh] tracedir\n", progname);
|
||||||
rerr("\n");
|
rerr("\n");
|
||||||
rerr("Options:\n");
|
rerr("Options:\n");
|
||||||
rerr(" -c offsetfile Use the given offset file to correct\n");
|
rerr(" -c offsetfile Use the given offset file to correct\n");
|
||||||
@ -26,6 +26,8 @@ usage(void)
|
|||||||
rerr("\n");
|
rerr("\n");
|
||||||
rerr(" -b Enable breakdown model (costly)\n");
|
rerr(" -b Enable breakdown model (costly)\n");
|
||||||
rerr("\n");
|
rerr("\n");
|
||||||
|
rerr(" -d Enable debug output (very verbose)\n");
|
||||||
|
rerr("\n");
|
||||||
rerr(" -l Enable linter mode. Extra tests will\n");
|
rerr(" -l Enable linter mode. Extra tests will\n");
|
||||||
rerr(" be performed.\n");
|
rerr(" be performed.\n");
|
||||||
rerr("\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));
|
memset(args, 0, sizeof(struct emu_args));
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "bc:lh")) != -1) {
|
while ((opt = getopt(argc, argv, "bdc:lh")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
args->clock_offset_file = optarg;
|
args->clock_offset_file = optarg;
|
||||||
@ -55,6 +57,9 @@ emu_args_init(struct emu_args *args, int argc, char *argv[])
|
|||||||
case 'b':
|
case 'b':
|
||||||
args->breakdown = 1;
|
args->breakdown = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
enable_debug();
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
usage();
|
usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user