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> | ||||
| 
 | ||||
| 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) | ||||
| { | ||||
|  | ||||
							
								
								
									
										11
									
								
								src/common.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/common.h
									
									
									
									
									
								
							| @ -6,9 +6,12 @@ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| 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) | ||||
|  | ||||
| @ -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(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user