- How to handle default log options has been somewhat confused for a long

time, so I've tried to improve it.  Now the logfunctions class has a
  static field default_onoff[] which represents the default actions for
  each kind of log message.  Default_onoff[] is initialized with static
  data so it should be valid by the time it's used.  This can be reached by
  static accesors logfunctions::set_default_action and
  logfunctions::get_default_action.  It seemed appropriate to put the defaults
  inside the logfunctions class, rather than in bx_options or siminterface.
  However, to make them accessible to the config interface, I added similar
  methods in siminterface that map to the accessors in logfunctions.
- logio.cc had two different definitions of LOG_THIS for different halves
  of the file, which was ugly and confusing.  (LOG_THIS is needed for BX_INFO,
  BX_DEBUG, etc.)  I removed the first definition and fixed the minor compile
  problems that ensued.  In the initializers for iofunctions, everything
  is complicated because of the unpredictable order that constructors get
  called.  They must use this->log to print things, because genlog hasn't
  been initialized yet.
- now if SIM->set_log_action(int mod, int level, int action) is called
  with mod<0, it sets the action for all modules/devices instead of just one.
- modified: bochs.h logio.cc main.cc gui/siminterface.cc gui/siminterface.h
This commit is contained in:
Bryce Denney 2002-09-20 17:56:22 +00:00
parent a33f144f6c
commit eca3ef17dc
5 changed files with 73 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: bochs.h,v 1.93 2002-09-13 00:15:23 kevinlawton Exp $
// $Id: bochs.h,v 1.94 2002-09-20 17:56:21 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -240,11 +240,6 @@ extern Bit8u DTPageDirty[];
#define MAGIC_LOGNUM 0x12345678
#define DEFAULT_LOG_ACTIONS(level) \
(level<=LOGLEV_INFO ? ACT_IGNORE \
: level==LOGLEV_ERROR ? ACT_REPORT \
: ACT_REPORT)
typedef class logfunctions {
char *prefix;
int type;
@ -256,6 +251,9 @@ typedef class logfunctions {
#define N_ACT 4
int onoff[N_LOGLEV];
class iofunctions *logio;
// default log actions for all devices, declared and initialized
// in logio.cc.
static int default_onoff[N_LOGLEV];
public:
logfunctions(void);
logfunctions(class iofunctions *);
@ -279,6 +277,15 @@ public:
assert (level>=0 && level<N_LOGLEV);
return onoff[level];
}
static void set_default_action (int loglev, int action) {
assert (loglev >= 0 && loglev < N_LOGLEV);
assert (action >= 0 && action < N_ACT);
default_onoff[loglev] = action;
}
static int get_default_action (int loglev) {
assert (loglev >= 0 && loglev < N_LOGLEV);
return default_onoff[loglev];
}
} logfunc_t;
#define BX_LOGPREFIX_SIZE 51
@ -593,9 +600,6 @@ typedef struct {
typedef struct {
bx_param_string_c *Ofilename;
bx_param_string_c *Oprefix;
// one array item for each log level, indexed by LOGLEV_*.
// values: ACT_IGNORE, ACT_REPORT, ACT_ASK, ACT_FATAL
unsigned char actions[N_LOGLEV];
} bx_log_options;
typedef struct {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.63 2002-09-17 04:47:54 bdenney Exp $
// $Id: siminterface.cc,v 1.64 2002-09-20 17:56:21 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -55,6 +55,12 @@ public:
virtual int get_log_action (int mod, int level);
virtual void set_log_action (int mod, int level, int action);
virtual char *get_action_name (int action);
virtual int get_default_log_action (int level) {
return logfunctions::get_default_action (level);
}
virtual void set_default_log_action (int level, int action) {
logfunctions::set_default_action (level, action);
}
virtual const char *get_log_level_name (int level);
virtual int get_max_log_level ();
virtual void quit_sim (int code);
@ -219,8 +225,16 @@ bx_real_sim_c::get_log_action (int mod, int level)
void
bx_real_sim_c::set_log_action (int mod, int level, int action)
{
logfunc_t *logfn = io->get_logfn (mod);
logfn->setonoff (level, action);
// normal
if (mod >= 0) {
logfunc_t *logfn = io->get_logfn (mod);
logfn->setonoff (level, action);
return;
}
// if called with mod<0 loop over all
int nmod = get_n_log_modules ();
for (mod=0; mod<nmod; mod++)
set_log_action (mod, level, action);
}
char *

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.68 2002-09-20 17:39:07 bdenney Exp $
// $Id: siminterface.h,v 1.69 2002-09-20 17:56:22 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Before I can describe what this file is for, I have to make the
@ -986,6 +986,8 @@ public:
virtual char *get_prefix (int mod) {return 0;}
virtual int get_log_action (int mod, int level) {return -1;}
virtual void set_log_action (int mod, int level, int action) {}
virtual int get_default_log_action (int level) {return -1;}
virtual void set_default_log_action (int level, int action) {}
virtual char *get_action_name (int action) {return 0;}
virtual const char *get_log_level_name (int level) {return 0;}
virtual int get_max_log_level () {return -1;}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: logio.cc,v 1.29 2002-09-15 11:02:22 bdenney Exp $
// $Id: logio.cc,v 1.30 2002-09-20 17:56:21 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -32,7 +32,6 @@
// Just for the iofunctions
#define LOG_THIS this->log->
int Allocio=0;
@ -54,9 +53,9 @@ iofunctions::init(void) {
n_logfn = 0;
init_log(stderr);
log = new logfunc_t(this);
LOG_THIS put("IO");
LOG_THIS settype(IOLOG);
BX_DEBUG(("Init(log file: '%s').",logfn));
log->put("IO");
log->settype(IOLOG);
log->ldebug ("Init(log file: '%s').",logfn);
}
void
@ -85,9 +84,10 @@ iofunctions::init_log(const char *fn)
newfd = fopen(fn, "w");
if(newfd != NULL) {
newfn = strdup(fn);
BX_DEBUG(("Opened log file '%s'.", fn ));
log->ldebug ("Opened log file '%s'.", fn );
} else {
BX_PANIC(("Couldn't open log file: %s", fn));
// in constructor, genlog might not exist yet, so do it the safe way.
log->ldebug("Couldn't open log file: %s", fn);
}
}
logfd = newfd;
@ -116,7 +116,7 @@ iofunctions::init_log(int fd)
assert (magic==MAGIC_LOGNUM);
FILE *tmpfd;
if( (tmpfd = fdopen(fd,"w")) == NULL ) {
BX_PANIC(("Couldn't open fd %d as a stream for writing", fd));
log->panic("Couldn't open fd %d as a stream for writing", fd);
return;
}
@ -124,6 +124,9 @@ iofunctions::init_log(int fd)
return;
};
// all other functions may use genlog safely.
#define LOG_THIS genlog->
// This converts the option string to a printf style string with the following args:
// 1. timer, 2. event, 3. cpu0 eip, 4. device
void
@ -233,9 +236,15 @@ iofunctions::~iofunctions(void)
this->magic=0;
}
#undef LOG_THIS
#define LOG_THIS genlog->
int logfunctions::default_onoff[N_LOGLEV] = {
ACT_IGNORE, // ignore debug
ACT_REPORT, // report info
ACT_REPORT, // report error
ACT_FATAL // die on panic
};
logfunctions::logfunctions(void)
{
prefix = NULL;
@ -249,7 +258,7 @@ logfunctions::logfunctions(void)
// 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; i<N_LOGLEV; i++)
onoff[i] = DEFAULT_LOG_ACTIONS(i);
onoff[i] = get_default_action(i);
}
logfunctions::logfunctions(iofunc_t *iofunc)
@ -261,7 +270,7 @@ logfunctions::logfunctions(iofunc_t *iofunc)
// 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; i<N_LOGLEV; i++)
onoff[i] = DEFAULT_LOG_ACTIONS(i);
onoff[i] = get_default_action(i);
}
logfunctions::~logfunctions(void)

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.141 2002-09-09 07:19:23 cbothamy Exp $
// $Id: main.cc,v 1.142 2002-09-20 17:56:21 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -269,10 +269,6 @@ void bx_init_options ()
char name[1024], descr[1024];
memset (&bx_options, 0, sizeof(bx_options));
bx_options.log.actions[0] = ACT_IGNORE;
bx_options.log.actions[1] = ACT_REPORT;
bx_options.log.actions[2] = ACT_REPORT;
bx_options.log.actions[3] = ACT_ASK;
// quick start option, set by command line arg
new bx_param_bool_c (BXP_QUICK_START,
@ -1296,7 +1292,7 @@ bx_do_text_config_interface (int argc, char *argv[])
if (enable_config_interface) {
// update log actions before starting configuration interface
for (int level=0; level<N_LOGLEV; level++) {
int action = bx_options.log.actions[level];
int action = SIM->get_default_log_action (level);
io->set_log_action (level, action);
}
// Display the pre-simulation configuration interface.
@ -1370,7 +1366,7 @@ bx_read_configuration (char *rcfile)
// update log actions if configuration interface is enabled
if (enable_config_interface) {
for (int level=0; level<N_LOGLEV; level++) {
int action = bx_options.log.actions[level];
int action = SIM->get_default_log_action (level);
io->set_log_action (level, action);
}
}
@ -1396,7 +1392,7 @@ bx_init_hardware()
if (!enable_config_interface) {
for (int level=0; level<N_LOGLEV; level++) {
int action = bx_options.log.actions[level];
int action = SIM->get_default_log_action (level);
#if !BX_USE_CONFIG_INTERFACE
if (action == ACT_ASK) action = ACT_FATAL;
#endif
@ -1983,13 +1979,13 @@ parse_line_formatted(char *context, int num_params, char *params[])
}
char *action = 7 + params[1];
if (!strcmp(action, "fatal"))
bx_options.log.actions[LOGLEV_PANIC] = ACT_FATAL;
SIM->set_default_log_action (LOGLEV_PANIC, ACT_FATAL);
else if (!strcmp (action, "report"))
bx_options.log.actions[LOGLEV_PANIC] = ACT_REPORT;
SIM->set_default_log_action (LOGLEV_PANIC, ACT_REPORT);
else if (!strcmp (action, "ignore"))
bx_options.log.actions[LOGLEV_PANIC] = ACT_IGNORE;
SIM->set_default_log_action (LOGLEV_PANIC, ACT_IGNORE);
else if (!strcmp (action, "ask"))
bx_options.log.actions[LOGLEV_PANIC] = ACT_ASK;
SIM->set_default_log_action (LOGLEV_PANIC, ACT_ASK);
else {
BX_PANIC(("%s: panic directive malformed.", context));
}
@ -2003,13 +1999,13 @@ parse_line_formatted(char *context, int num_params, char *params[])
}
char *action = 7 + params[1];
if (!strcmp(action, "fatal"))
bx_options.log.actions[LOGLEV_ERROR] = ACT_FATAL;
SIM->set_default_log_action (LOGLEV_ERROR, ACT_FATAL);
else if (!strcmp (action, "report"))
bx_options.log.actions[LOGLEV_ERROR] = ACT_REPORT;
SIM->set_default_log_action (LOGLEV_ERROR, ACT_REPORT);
else if (!strcmp (action, "ignore"))
bx_options.log.actions[LOGLEV_ERROR] = ACT_IGNORE;
SIM->set_default_log_action (LOGLEV_ERROR, ACT_IGNORE);
else if (!strcmp (action, "ask"))
bx_options.log.actions[LOGLEV_ERROR] = ACT_ASK;
SIM->set_default_log_action (LOGLEV_ERROR, ACT_ASK);
else {
BX_PANIC(("%s: error directive malformed.", context));
}
@ -2023,13 +2019,13 @@ parse_line_formatted(char *context, int num_params, char *params[])
}
char *action = 7 + params[1];
if (!strcmp(action, "fatal"))
bx_options.log.actions[LOGLEV_INFO] = ACT_FATAL;
SIM->set_default_log_action (LOGLEV_INFO, ACT_FATAL);
else if (!strcmp (action, "report"))
bx_options.log.actions[LOGLEV_INFO] = ACT_REPORT;
SIM->set_default_log_action (LOGLEV_INFO, ACT_REPORT);
else if (!strcmp (action, "ignore"))
bx_options.log.actions[LOGLEV_INFO] = ACT_IGNORE;
SIM->set_default_log_action (LOGLEV_INFO, ACT_IGNORE);
else if (!strcmp (action, "ask"))
bx_options.log.actions[LOGLEV_INFO] = ACT_ASK;
SIM->set_default_log_action (LOGLEV_INFO, ACT_ASK);
else {
BX_PANIC(("%s: info directive malformed.", context));
}
@ -2043,13 +2039,13 @@ parse_line_formatted(char *context, int num_params, char *params[])
}
char *action = 7 + params[1];
if (!strcmp(action, "fatal"))
bx_options.log.actions[LOGLEV_DEBUG] = ACT_FATAL;
SIM->set_default_log_action (LOGLEV_DEBUG, ACT_FATAL);
else if (!strcmp (action, "report"))
bx_options.log.actions[LOGLEV_DEBUG] = ACT_REPORT;
SIM->set_default_log_action (LOGLEV_DEBUG, ACT_REPORT);
else if (!strcmp (action, "ignore"))
bx_options.log.actions[LOGLEV_DEBUG] = ACT_IGNORE;
SIM->set_default_log_action (LOGLEV_DEBUG, ACT_IGNORE);
else if (!strcmp (action, "ask"))
bx_options.log.actions[LOGLEV_DEBUG] = ACT_ASK;
SIM->set_default_log_action (LOGLEV_DEBUG, ACT_ASK);
else {
BX_PANIC(("%s: debug directive malformed.", context));
}