Bochs/bochs/patches/patch.logfilefmteip
Christophe Bothamy a926744628 I reworked and included Carl's patch to have a new bochsrc directive
to describe the format of the log prefix. This option can be any string
with special tokens being replaced at run time :
  #   %t : 11 decimal digits timer tick
  #   %i : 8 hexadecimal digits of cpu0 current eip
  #   %e : 1 character event type ('i'nfo, 'd'ebug, 'p'anic, 'e'rror)
  #   %d : 5 characters string of the device, between brackets
the default is "%t%i%d", so the logprefix is the same as before.

New tokens can be easily added or changed if needed.


Modified Files:
  .bochsrc bochs.h logio.cc main.cc gui/control.cc
  gui/siminterface.h gui/siminterface.cc
  patches/patch.logfilefmteip
2002-06-26 14:42:35 +00:00

433 lines
13 KiB
Plaintext

----------------------------------------------------------------------
Patch name: patch.logfilefmteip
Author: Carl Sopchak
Date: May, 26th 2002
Detailed description:
I reworked and included Carl's patch to have a new bochsrc directive
to describe the format of the log prefix. This option can be any string
with special tokens being replaced at run time :
# %t : 11 decimal digits timer tick
# %i : 8 hexadecimal digits of cpu0 current eip
# %e : 1 character event type ('i'nfo, 'd'ebug, 'p'anic, 'e'rror)
# %d : 5 characters string of the device, between brackets
the default is "%t%i%d", so the logprefix is the same as before.
New tokens can be easily added or changed if needed.
Original Detailed description:
While working with Bela Lubkin of Caldera, trying to
get bochs to install SCO OSR5, Bela asked me to add the
EIP to the log file. The attached patch changes the
timestamp portion of a log file entry to
tttttttttt-x-@eeeeeee[sssss]
where tttttttttt is the ticks, x is the type of entry
(error, panic, info, debug), eeeeeeee is the EIP (in
hex), and sssss remains the subsystem (e.g., HD, FDD,
BIOS, etc)
Please make this part of the standard bochs package.
Thanks,
Carl
Patch was created with:
cvs diff -u
Apply patch to what version:
cvs checked out on May, 26th 2002
Instructions:
To patch, go to main bochs directory.
Type "patch -p0 < THIS_PATCH_FILE".
----------------------------------------------------------------------
Index: .bochsrc
===================================================================
RCS file: /cvsroot/bochs/bochs/.bochsrc,v
retrieving revision 1.41
diff -u -r1.41 .bochsrc
--- .bochsrc 4 May 2002 16:00:40 -0000 1.41
+++ .bochsrc 26 Jun 2002 14:39:43 -0000
@@ -152,6 +152,22 @@
log: bochsout.txt
#=======================================================================
+# LOGPREFIX:
+# This handles the format of the string prepended to each log line :
+# You may use those special tokens :
+# %t : 11 decimal digits timer tick
+# %i : 8 hexadecimal digits of cpu0 current eip
+# %e : 1 character event type ('i'nfo, 'd'ebug, 'p'anic, 'e'rror)
+# %d : 5 characters string of the device, between brackets
+#
+# Default : %t%e%d
+# Examples:
+# logprefix: %t-%e-@%i-%d
+# logprefix: %i%e%d
+#=======================================================================
+#logprefix: %t%e%d
+
+#=======================================================================
# LOG CONTROLS
#
# Bochs now has four severity levels for event logging.
Index: bochs.h
===================================================================
RCS file: /cvsroot/bochs/bochs/bochs.h,v
retrieving revision 1.65
diff -u -r1.65 bochs.h
--- bochs.h 16 Jun 2002 15:02:27 -0000 1.65
+++ bochs.h 26 Jun 2002 14:39:44 -0000
@@ -277,12 +277,16 @@
}
} logfunc_t;
+#define BX_LOGPREFIX_SIZE 51
+
class iofunctions {
- int showtick,magic;
+ int magic;
+ char logprefix[BX_LOGPREFIX_SIZE];
FILE *logfd;
class logfunctions *log;
void init(void);
void flush(void);
+ void setlogprefix(void);
// Log Class defines
#define IOLOG 0
#define FDLOG 1
@@ -589,6 +593,7 @@
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];
Index: logio.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/logio.cc,v
retrieving revision 1.18
diff -u -r1.18 logio.cc
--- logio.cc 1 Jun 2002 07:39:19 -0000 1.18
+++ logio.cc 26 Jun 2002 14:39:44 -0000
@@ -45,12 +45,48 @@
}
}
+// This converts the option string to a printf style string with the following args:
+// 1. timer, 2. event, 3. cpu0 eip, 4. device
+void
+iofunctions::setlogprefix(void) {
+ int i=0;
+ char *s;
+ char *f;
+
+ s=bx_options.log.Oprefix->getptr ();
+ strcpy(logprefix,"");
+ while (*s!=0) {
+ if (*s!='%') {
+ if (strlen(logprefix)<sizeof(logprefix)-1)
+ strncat(logprefix,s,1);
+ else break;
+ }
+ else {
+ f="";
+ switch (*(++s)) {
+ case 't': f="%1$011lld"; break;
+ case 'i': f="%3$08x"; break;
+ case 'e': f="%2$c"; break;
+ case 'd': f="%4$s"; break;
+ case '%': f="%%"; break;
+ }
+ if(strlen(logprefix)+strlen(f)<sizeof(logprefix)-1)
+ strcat(logprefix,f);
+ else break;
+ if(*s==0)break;
+ }
+ s++;
+ }
+}
+
void
iofunctions::init(void) {
// iofunctions methods must not be called before this magic
// number is set.
magic=MAGIC_LOGNUM;
- showtick = 1;
+
+ // sets the default logprefix
+ strcpy(logprefix,"%1$011lld%2$c%4$s");
n_logfn = 0;
init_log(stderr);
log = new logfunc_t(this);
@@ -92,6 +128,8 @@
}
logfd = newfd;
logfn = newfn;
+
+ setlogprefix();
}
void
@@ -107,6 +145,7 @@
} else {
logfn = "(unknown)";
}
+
}
void
@@ -135,8 +174,8 @@
assert (this != NULL);
assert (logfd != NULL);
- if( showtick )
- fprintf(logfd, "%011lld", bx_pc_system.time_ticks());
+ //if( showtick )
+ // fprintf(logfd, "%011lld", bx_pc_system.time_ticks());
switch(l) {
case LOGLEV_INFO: c='i'; break;
@@ -145,10 +184,13 @@
case LOGLEV_DEBUG: c='d'; break;
default: break;
}
- fprintf(logfd, "%c",c);
+ //fprintf(logfd, "-%c",c);
+
+ //if(prefix != NULL)
+ // fprintf(logfd, "%s ", prefix);
- if(prefix != NULL)
- fprintf(logfd, "%s ", prefix);
+ fprintf(logfd, logprefix, bx_pc_system.time_ticks(), c, BX_CPU(0)->eip, prefix==NULL?"":prefix);
+ fprintf(logfd," ");
if(l==LOGLEV_PANIC)
fprintf(logfd, ">>PANIC<< ");
Index: main.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/main.cc,v
retrieving revision 1.101
diff -u -r1.101 main.cc
--- main.cc 25 May 2002 13:16:55 -0000 1.101
+++ main.cc 26 Jun 2002 14:39:44 -0000
@@ -103,7 +103,7 @@
NULL, // newHardDriveSupport
{ 0, NULL, NULL, NULL }, // load32bitOSImage hack stuff
// log options: ignore debug, report info and error, crash on panic.
- { NULL, { ACT_IGNORE, ACT_REPORT, ACT_REPORT, ACT_ASK } },
+ { NULL, NULL, { ACT_IGNORE, ACT_REPORT, ACT_REPORT, ACT_ASK } },
{ NULL, NULL }, // KeyboardMapping
};
@@ -832,6 +832,12 @@
"-", BX_PATHNAME_LEN);
bx_options.log.Ofilename->set_ask_format ("Enter log filename: [%s] ");
+ bx_options.log.Oprefix = new bx_param_string_c (BXP_LOG_PREFIX,
+ "logprefix:prefix",
+ "Prefix prepended to log output",
+ "%t%e%d", BX_PATHNAME_LEN);
+ bx_options.log.Oprefix->set_ask_format ("Enter log prefix: [%s] ");
+
// loader
bx_options.load32bitOSImage.OwhichOS = new bx_param_enum_c (BXP_LOAD32BITOS_WHICH,
"Which operating system?",
@@ -1693,6 +1699,12 @@
}
bx_options.log.Ofilename->set (params[1]);
}
+ else if (!strcmp(params[0], "logprefix")) {
+ if (num_params != 2) {
+ BX_PANIC(("%s: logprefix directive has wrong # args.", context));
+ }
+ bx_options.log.Oprefix->set (params[1]);
+ }
else if (!strcmp(params[0], "panic")) {
if (num_params != 2) {
BX_PANIC(("%s: panic directive malformed.", context));
@@ -2277,6 +2289,7 @@
bx_write_log_options (FILE *fp, bx_log_options *opt)
{
fprintf (fp, "log: %s\n", opt->Ofilename->getptr ());
+ fprintf (fp, "logprefix: %s\n", opt->Oprefix->getptr ());
// no syntax to describe all the possible action settings for every
// device. Instead, take a vote and record the most popular action
// for each level of event.
Index: gui/control.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/gui/control.cc,v
retrieving revision 1.50
diff -u -r1.50 control.cc
--- gui/control.cc 23 Jun 2002 18:02:55 -0000 1.50
+++ gui/control.cc 26 Jun 2002 14:39:44 -0000
@@ -102,6 +102,30 @@
return s;
}
+void
+double_percent (char *s, int max_len)
+{
+ char d[CPANEL_PATH_LEN];
+ int i=0,j=0;
+
+ if (max_len>CPANEL_PATH_LEN)
+ max_len=CPANEL_PATH_LEN;
+
+ max_len--;
+
+ while((s[i]!=0)&&(j<max_len))
+ {
+ d[j++]=s[i];
+ if((s[i]=='%')&&(j<max_len))
+ {
+ d[j++]=s[i];
+ }
+ i++;
+ }
+ d[j]=0;
+ strcpy(s,d);
+}
+
/* returns 0 on success, -1 on failure. The value goes into out. */
int
ask_uint (char *prompt, Bit32u min, Bit32u max, Bit32u the_default, Bit32u *out, int base)
@@ -292,15 +316,16 @@
"------------------\n"
"0. Return to previous menu\n"
"1. Log file: %s\n"
-"2. Log options for all devices\n"
-"3. Log options for individual devices\n"
-"4. Memory options\n"
-"5. Interface options\n"
-"6. Disk options\n"
-"7. Serial or Parallel port options\n"
-"8. Sound Blaster 16 options\n"
-"9. NE2000 network card options\n"
-"10. Other options\n"
+"2. Log prefix: %s\n"
+"3. Log options for all devices\n"
+"4. Log options for individual devices\n"
+"5. Memory options\n"
+"6. Interface options\n"
+"7. Disk options\n"
+"8. Serial or Parallel port options\n"
+"9. Sound Blaster 16 options\n"
+"10. NE2000 network card options\n"
+"11. Other options\n"
"\n"
"Please choose one: [0] ";
@@ -444,23 +469,32 @@
case BX_CPANEL_START_OPTS:
{
char prompt[CPANEL_PATH_LEN];
- char oldpath[CPANEL_PATH_LEN];
- int retval = SIM->get_log_file (oldpath, CPANEL_PATH_LEN);
- assert (retval >= 0);
- sprintf (prompt, startup_options_prompt, oldpath);
- if (ask_uint (prompt, 0, 10, 0, &choice, 10) < 0) return -1;
+ char oldpath[CPANEL_PATH_LEN];
+ char oldprefix[CPANEL_PATH_LEN];
+ int retval;
+
+ retval = SIM->get_log_file (oldpath, CPANEL_PATH_LEN);
+ assert (retval >= 0);
+ double_percent(oldpath,CPANEL_PATH_LEN);
+ retval = SIM->get_log_prefix (oldprefix, CPANEL_PATH_LEN);
+ assert (retval >= 0);
+ double_percent(oldprefix,CPANEL_PATH_LEN);
+
+ sprintf (prompt, startup_options_prompt, oldpath, oldprefix);
+ if (ask_uint (prompt, 0, 11, 0, &choice, 10) < 0) return -1;
switch (choice) {
case 0: return 0;
case 1: askparam (BXP_LOG_FILENAME); break;
- case 2: bx_log_options (0); break;
- case 3: bx_log_options (1); break;
- case 4: do_menu (BXP_MENU_MEMORY); break;
- case 5: do_menu (BXP_MENU_INTERFACE); break;
- case 6: do_menu (BXP_MENU_DISK); break;
- case 7: do_menu (BXP_MENU_SERIAL_PARALLEL); break;
- case 8: do_menu (BXP_SB16); break;
- case 9: do_menu (BXP_NE2K); break;
- case 10: do_menu (BXP_MENU_MISC); break;
+ case 2: askparam (BXP_LOG_PREFIX); break;
+ case 3: bx_log_options (0); break;
+ case 4: bx_log_options (1); break;
+ case 5: do_menu (BXP_MENU_MEMORY); break;
+ case 6: do_menu (BXP_MENU_INTERFACE); break;
+ case 7: do_menu (BXP_MENU_DISK); break;
+ case 8: do_menu (BXP_MENU_SERIAL_PARALLEL); break;
+ case 9: do_menu (BXP_SB16); break;
+ case 10: do_menu (BXP_NE2K); break;
+ case 11: do_menu (BXP_MENU_MISC); break;
default: BAD_OPTION(menu, choice);
}
}
Index: gui/siminterface.h
===================================================================
RCS file: /cvsroot/bochs/bochs/gui/siminterface.h,v
retrieving revision 1.37
diff -u -r1.37 siminterface.h
--- gui/siminterface.h 2 May 2002 07:54:22 -0000 1.37
+++ gui/siminterface.h 26 Jun 2002 14:39:44 -0000
@@ -103,6 +103,7 @@
BXP_I440FX_SUPPORT,
BXP_NEWHARDDRIVESUPPORT,
BXP_LOG_FILENAME,
+ BXP_LOG_PREFIX,
BXP_CMOS_PATH,
BXP_CMOS_IMAGE,
BXP_CMOS_TIME0,
@@ -596,6 +597,8 @@
virtual int write_rc (char *rc, int overwrite) {return -1;}
virtual int get_log_file (char *path, int len) {return -1;}
virtual int set_log_file (char *path) {return -1;}
+ virtual int get_log_prefix (char *prefix, int len) {return -1;}
+ virtual int set_log_prefix (char *prefix) {return -1;}
virtual int get_floppy_options (int drive, bx_floppy_options *out) {return -1;}
virtual int get_cdrom_options (int drive, bx_cdrom_options *out) {return -1;}
virtual char *get_floppy_type_name (int type) {return NULL;}
Index: gui/siminterface.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/gui/siminterface.cc,v
retrieving revision 1.41
diff -u -r1.41 siminterface.cc
--- gui/siminterface.cc 23 Apr 2002 07:44:34 -0000 1.41
+++ gui/siminterface.cc 26 Jun 2002 14:39:44 -0000
@@ -69,6 +69,8 @@
virtual int write_rc (char *path, int overwrite);
virtual int get_log_file (char *path, int len);
virtual int set_log_file (char *path);
+ virtual int get_log_prefix (char *prefix, int len);
+ virtual int set_log_prefix (char *prefix);
virtual int get_floppy_options (int drive, bx_floppy_options *out);
virtual int get_cdrom_options (int drive, bx_cdrom_options *out);
virtual char *get_floppy_type_name (int type);
@@ -290,6 +292,20 @@
bx_real_sim_c::set_log_file (char *path)
{
bx_options.log.Ofilename->set (path);
+ return 0;
+}
+
+int
+bx_real_sim_c::get_log_prefix (char *prefix, int len)
+{
+ strncpy (prefix, bx_options.log.Oprefix->getptr (), len);
+ return 0;
+}
+
+int
+bx_real_sim_c::set_log_prefix (char *prefix)
+{
+ bx_options.log.Oprefix->set (prefix);
return 0;
}