From a04c65e6420e97c17e1b8c6b589ae9c766a515c1 Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Tue, 22 May 2001 20:01:40 +0000 Subject: [PATCH] - new, partially implemented, lines in .bochsrc allow run-time choice of what action to take on panic, error, info, and debug. The lines don't have any effect quite yet because of an initialization order problem with the logfunctions. --- bochs/.bochsrc | 18 ++++++ bochs/bochs.h | 11 +++- bochs/config.h.in | 6 -- bochs/main.cc | 145 ++++++++++++++++++++++++++++++++++++---------- 4 files changed, 142 insertions(+), 38 deletions(-) diff --git a/bochs/.bochsrc b/bochs/.bochsrc index 4ecea5c2d..dd4422bb9 100644 --- a/bochs/.bochsrc +++ b/bochs/.bochsrc @@ -12,6 +12,24 @@ vgaromimage: bios/VGABIOS-elpin-2.40 # examples. Leave only one of each directive uncommented, # if any. +# Bochs now has four severity levels for event logging. +# panic: cannot proceed. If you choose to continue after a panic, +# don't be surprised if you get unstable behavior. +# error: something went wrong, but it is probably safe to continue the +# simulation. +# info: interesting or useful messages, not 1000's per second. +# debug: messages useful only when debugging the code. This may +# spit out thousands per second. +# +# For events of each level, you can choose to crash, report, or ignore. +# TODO: allow choice based on the facility: e.g. report debug messages +# from the cdrom but ignore debug messages from everything else. +panic: action=crash +error: action=report +info: action=report +debug: action=ignore + + #vgaromimage: :bios:VGABIOS-elpin-2.20 #romimage: file=:bios:BIOS-bochs-981222a, address=0xf0000 #floppya: 1_44=[fd:], status=inserted diff --git a/bochs/bochs.h b/bochs/bochs.h index ab20715db..992cc370d 100644 --- a/bochs/bochs.h +++ b/bochs/bochs.h @@ -224,6 +224,7 @@ public: void error(char *fmt, ...); void panic(char *fmt, ...); void ldebug(char *fmt, ...); + void crash (); void setprefix(char *); void settype(int); void setio(class iofunctions *); @@ -240,16 +241,17 @@ class iofunctions { static char *loglevel[] = { "DEBUG", "INFO", - "PANIC", "ERROR", + "PANIC", }; return loglevel[i]; } // Log Level defines #define LOGLEV_DEBUG 0 #define LOGLEV_INFO 1 -#define LOGLEV_PANIC 2 -#define LOGLEV_ERROR 3 +#define LOGLEV_ERROR 2 +#define LOGLEV_PANIC 3 +#define MAX_LOGLEV 4 char *getclass(int i) { char *logclass[] = { "IO ", @@ -552,6 +554,9 @@ typedef struct { bx_ne2k_options ne2k; Boolean newHardDriveSupport; bx_load32bitOSImage_t load32bitOSImage; + // one array item for each log level, indexed by LOGLEV_*. + // values: 0=ignore event, 1=report event in log, 2=crash + unsigned char log_actions[4]; } bx_options_t; extern bx_options_t bx_options; diff --git a/bochs/config.h.in b/bochs/config.h.in index 4963ec9fe..a26be0bfd 100644 --- a/bochs/config.h.in +++ b/bochs/config.h.in @@ -40,12 +40,6 @@ // USER CONFIGURABLE OPTIONS : EDIT ONLY OPTIONS IN THIS SECTION // /////////////////////////////////////////////////////////////////// -// This switch determines if a call to bx_panic will kill the -// simulation or not. Leave it on by default so that default -// functionality stays the same, but now it's easy to change the -// behavior to suit your taste. -#define BX_PANIC_IS_FATAL 1 - // I rebuilt the code which provides timers to IO devices. // Setting this to 1 will introduce a little code which // will panic out if cases which shouldn't happen occur. diff --git a/bochs/main.cc b/bochs/main.cc index 2f3d8143f..cdc7604da 100644 --- a/bochs/main.cc +++ b/bochs/main.cc @@ -80,7 +80,8 @@ bx_options_t bx_options = { {NULL, 0}, // cmos path, cmos image boolean { 0, 0, 0, {0,0,0,0,0,0}, NULL, NULL }, // ne2k 1, // newHardDriveSupport - { 0, NULL, NULL, NULL } // load32bitOSImage hack stuff + { 0, NULL, NULL, NULL }, // load32bitOSImage hack stuff + { 0, 1, 1, 2 } // ignore debugs, report infos and errors, crash on panics. }; static char bochsrc_path[512]; @@ -239,10 +240,10 @@ logfunctions::logfunctions(void) io = new iofunc_t(stderr); } setio(io); - onoff[LOGLEV_DEBUG]=0; - onoff[LOGLEV_ERROR]=1; - onoff[LOGLEV_PANIC]=1; // XXX careful, disable this, and you disable panics! - onoff[LOGLEV_INFO]=1; + // BUG: unfortunately this can be called before the bochsrc is read, + // which means that the bochsrc has no effect on the actions. + for (int i=0; ilogio->out(this->type,LOGLEV_INFO,this->prefix, fmt, ap); va_end(ap); + + if (onoff[LOGLEV_INFO] > 1) crash (); } void @@ -310,7 +313,9 @@ logfunctions::error(char *fmt, ...) va_start(ap, fmt); this->logio->out(this->type,LOGLEV_ERROR,this->prefix, fmt, ap); va_end(ap); + if (onoff[LOGLEV_ERROR] > 1) crash (); } + void logfunctions::panic(char *fmt, ...) { @@ -324,29 +329,10 @@ logfunctions::panic(char *fmt, ...) va_start(ap, fmt); this->logio->out(this->type,LOGLEV_PANIC,this->prefix, fmt, ap); -#if BX_PANIC_IS_FATAL - // we're about to crash anyway, so we should print the - // panic to stderr so that it's easy to find. -#endif va_end(ap); } - -#if !BX_PANIC_IS_FATAL - return; -#endif - - bx_atexit(); - -#if !BX_DEBUGGER - exit(1); -#else - static Boolean dbg_exit_called = 0; - if (dbg_exit_called == 0) { - dbg_exit_called = 1; - bx_dbg_exit(1); - } -#endif + if (onoff[LOGLEV_PANIC] > 1) crash (); } void @@ -364,6 +350,23 @@ logfunctions::ldebug(char *fmt, ...) va_start(ap, fmt); this->logio->out(this->type,LOGLEV_DEBUG,this->prefix, fmt, ap); va_end(ap); + if (onoff[LOGLEV_DEBUG] > 1) crash (); +} + +void +logfunctions::crash (void) +{ + bx_atexit(); + +#if !BX_DEBUGGER + exit(1); +#else + static Boolean dbg_exit_called = 0; + if (dbg_exit_called == 0) { + dbg_exit_called = 1; + bx_dbg_exit(1); + } +#endif } iofunc_t *io = NULL; @@ -829,6 +832,90 @@ parse_line_formatted(int num_params, char *params[]) } strcpy(logfilename, params[1]); } + else if (!strcmp(params[0], "panic")) { + if (num_params != 2) { + fprintf(stderr, ".bochsrc: panic directive malformed.\n"); + exit(1); + } + if (strncmp(params[1], "action=", 7)) { + fprintf(stderr, ".bochsrc: panic directive malformed.\n"); + exit(1); + } + char *action = 7 + params[1]; + if (!strcmp(action, "crash")) + bx_options.log_actions[LOGLEV_PANIC] = 2; + else if (!strcmp (action, "report")) + bx_options.log_actions[LOGLEV_PANIC] = 1; + else if (!strcmp (action, "ignore")) + bx_options.log_actions[LOGLEV_PANIC] = 0; + else { + fprintf(stderr, ".bochsrc: panic directive malformed.\n"); + exit(1); + } + } + else if (!strcmp(params[0], "error")) { + if (num_params != 2) { + fprintf(stderr, ".bochsrc: error directive malformed.\n"); + exit(1); + } + if (strncmp(params[1], "action=", 7)) { + fprintf(stderr, ".bochsrc: error directive malformed.\n"); + exit(1); + } + char *action = 7 + params[1]; + if (!strcmp(action, "crash")) + bx_options.log_actions[LOGLEV_ERROR] = 2; + else if (!strcmp (action, "report")) + bx_options.log_actions[LOGLEV_ERROR] = 1; + else if (!strcmp (action, "ignore")) + bx_options.log_actions[LOGLEV_ERROR] = 0; + else { + fprintf(stderr, ".bochsrc: error directive malformed.\n"); + exit(1); + } + } + else if (!strcmp(params[0], "info")) { + if (num_params != 2) { + fprintf(stderr, ".bochsrc: info directive malformed.\n"); + exit(1); + } + if (strncmp(params[1], "action=", 7)) { + fprintf(stderr, ".bochsrc: info directive malformed.\n"); + exit(1); + } + char *action = 7 + params[1]; + if (!strcmp(action, "crash")) + bx_options.log_actions[LOGLEV_INFO] = 2; + else if (!strcmp (action, "report")) + bx_options.log_actions[LOGLEV_INFO] = 1; + else if (!strcmp (action, "ignore")) + bx_options.log_actions[LOGLEV_INFO] = 0; + else { + fprintf(stderr, ".bochsrc: info directive malformed.\n"); + exit(1); + } + } + else if (!strcmp(params[0], "debug")) { + if (num_params != 2) { + fprintf(stderr, ".bochsrc: debug directive malformed.\n"); + exit(1); + } + if (strncmp(params[1], "action=", 7)) { + fprintf(stderr, ".bochsrc: debug directive malformed.\n"); + exit(1); + } + char *action = 7 + params[1]; + if (!strcmp(action, "crash")) + bx_options.log_actions[LOGLEV_DEBUG] = 2; + else if (!strcmp (action, "report")) + bx_options.log_actions[LOGLEV_DEBUG] = 1; + else if (!strcmp (action, "ignore")) + bx_options.log_actions[LOGLEV_DEBUG] = 0; + else { + fprintf(stderr, ".bochsrc: debug directive malformed.\n"); + exit(1); + } + } else if (!strcmp(params[0], "romimage")) { if (num_params != 3) { fprintf(stderr, ".bochsrc: romimage directive: wrong # args.\n");