2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-12-13 22:10:38 +03:00
|
|
|
// $Id: logio.cc,v 1.49 2004-12-13 19:10:31 vruppert Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-06-19 20:25:41 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.h"
|
2001-06-19 20:25:41 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2002-12-17 08:58:45 +03:00
|
|
|
#if BX_WITH_CARBON
|
2004-02-14 09:33:29 +03:00
|
|
|
#define Float32 KLUDGE_Float32
|
|
|
|
#define Float64 KLUDGE_Float64
|
2002-12-17 08:58:45 +03:00
|
|
|
#include <Carbon/Carbon.h>
|
2004-02-14 09:33:29 +03:00
|
|
|
#undef Float32
|
|
|
|
#undef Float64
|
2002-12-17 08:58:45 +03:00
|
|
|
#endif
|
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
// Just for the iofunctions
|
|
|
|
|
|
|
|
|
|
|
|
int Allocio=0;
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::flush(void) {
|
|
|
|
if(logfd && magic == MAGIC_LOGNUM) {
|
|
|
|
fflush(logfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::init(void) {
|
|
|
|
// iofunctions methods must not be called before this magic
|
|
|
|
// number is set.
|
|
|
|
magic=MAGIC_LOGNUM;
|
2002-06-26 18:42:35 +04:00
|
|
|
|
|
|
|
// sets the default logprefix
|
2002-07-16 16:04:46 +04:00
|
|
|
strcpy(logprefix,"%t%e%d");
|
2001-06-19 20:25:41 +04:00
|
|
|
n_logfn = 0;
|
|
|
|
init_log(stderr);
|
|
|
|
log = new logfunc_t(this);
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
log->put("IO");
|
|
|
|
log->settype(IOLOG);
|
|
|
|
log->ldebug ("Init(log file: '%s').",logfn);
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::add_logfn (logfunc_t *fn)
|
|
|
|
{
|
|
|
|
assert (n_logfn < MAX_LOGFNS);
|
|
|
|
logfn_list[n_logfn++] = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::set_log_action (int loglevel, int action)
|
|
|
|
{
|
|
|
|
for (int i=0; i<n_logfn; i++)
|
|
|
|
logfn_list[i]->setonoff(loglevel, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
iofunctions::init_log(const char *fn)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
assert (magic==MAGIC_LOGNUM);
|
|
|
|
// use newfd/newfn so that we can log the message to the OLD log
|
|
|
|
// file descriptor.
|
|
|
|
FILE *newfd = stderr;
|
|
|
|
char *newfn = "/dev/stderr";
|
|
|
|
if( strcmp( fn, "-" ) != 0 ) {
|
|
|
|
newfd = fopen(fn, "w");
|
|
|
|
if(newfd != NULL) {
|
|
|
|
newfn = strdup(fn);
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
log->ldebug ("Opened log file '%s'.", fn );
|
2001-06-19 20:25:41 +04:00
|
|
|
} else {
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
// in constructor, genlog might not exist yet, so do it the safe way.
|
2002-10-27 16:20:25 +03:00
|
|
|
log->error("Couldn't open log file: %s, using stderr instead", fn);
|
|
|
|
newfd = stderr;
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
logfd = newfd;
|
|
|
|
logfn = newfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::init_log(FILE *fs)
|
|
|
|
{
|
|
|
|
assert (magic==MAGIC_LOGNUM);
|
|
|
|
logfd = fs;
|
|
|
|
|
|
|
|
if(fs == stderr) {
|
|
|
|
logfn = "/dev/stderr";
|
|
|
|
} else if(fs == stdout) {
|
|
|
|
logfn = "/dev/stdout";
|
|
|
|
} else {
|
|
|
|
logfn = "(unknown)";
|
|
|
|
}
|
2002-06-26 18:42:35 +04:00
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iofunctions::init_log(int fd)
|
|
|
|
{
|
|
|
|
assert (magic==MAGIC_LOGNUM);
|
|
|
|
FILE *tmpfd;
|
|
|
|
if( (tmpfd = fdopen(fd,"w")) == NULL ) {
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
log->panic("Couldn't open fd %d as a stream for writing", fd);
|
2001-06-19 20:25:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_log(tmpfd);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
// all other functions may use genlog safely.
|
|
|
|
#define LOG_THIS genlog->
|
|
|
|
|
2002-06-28 18:03:47 +04:00
|
|
|
// 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::set_log_prefix(const char* prefix) {
|
|
|
|
|
2002-07-16 16:04:46 +04:00
|
|
|
strcpy(logprefix,prefix);
|
2002-06-28 18:03:47 +04:00
|
|
|
}
|
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
// iofunctions::out( class, level, prefix, fmt, ap)
|
|
|
|
// DO NOT nest out() from ::info() and the like.
|
|
|
|
// fmt and ap retained for direct printinf from iofunctions only!
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
iofunctions::out(int f, int l, const char *prefix, const char *fmt, va_list ap)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
2002-07-16 16:04:46 +04:00
|
|
|
char c=' ', *s;
|
2001-06-19 20:25:41 +04:00
|
|
|
assert (magic==MAGIC_LOGNUM);
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (logfd != NULL);
|
|
|
|
|
2001-08-31 20:06:32 +04:00
|
|
|
switch(l) {
|
|
|
|
case LOGLEV_INFO: c='i'; break;
|
|
|
|
case LOGLEV_PANIC: c='p'; break;
|
2002-12-17 06:36:53 +03:00
|
|
|
case LOGLEV_PASS: c='s'; break;
|
2001-08-31 20:06:32 +04:00
|
|
|
case LOGLEV_ERROR: c='e'; break;
|
|
|
|
case LOGLEV_DEBUG: c='d'; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2002-06-26 18:42:35 +04:00
|
|
|
//fprintf(logfd, "-%c",c);
|
|
|
|
|
|
|
|
//if(prefix != NULL)
|
|
|
|
// fprintf(logfd, "%s ", prefix);
|
2001-06-19 20:25:41 +04:00
|
|
|
|
2002-07-16 16:04:46 +04:00
|
|
|
s=logprefix;
|
|
|
|
while(*s) {
|
|
|
|
switch(*s) {
|
|
|
|
case '%':
|
|
|
|
if(*(s+1))s++;
|
|
|
|
else break;
|
|
|
|
switch(*s) {
|
|
|
|
case 'd':
|
|
|
|
fprintf(logfd, "%s", prefix==NULL?"":prefix);
|
|
|
|
break;
|
|
|
|
case 't':
|
2004-09-19 22:38:09 +04:00
|
|
|
fprintf(logfd, FMT_TICK, bx_pc_system.time_ticks());
|
2002-07-16 16:04:46 +04:00
|
|
|
break;
|
|
|
|
case 'i':
|
2003-08-24 14:30:07 +04:00
|
|
|
fprintf(logfd, "%08x", BX_CPU(0)==NULL?0:BX_CPU(0)->dword.eip);
|
2002-07-16 16:04:46 +04:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
fprintf(logfd, "%c", c);
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
fprintf(logfd,"%%");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(logfd,"%%%c",*s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
fprintf(logfd,"%c",*s);
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
2002-06-26 18:42:35 +04:00
|
|
|
fprintf(logfd," ");
|
2001-06-19 20:25:41 +04:00
|
|
|
|
|
|
|
if(l==LOGLEV_PANIC)
|
|
|
|
fprintf(logfd, ">>PANIC<< ");
|
2002-12-17 06:36:53 +03:00
|
|
|
if(l==LOGLEV_PASS)
|
|
|
|
fprintf(logfd, ">>PASS<< ");
|
2001-06-19 20:25:41 +04:00
|
|
|
|
|
|
|
vfprintf(logfd, fmt, ap);
|
|
|
|
fprintf(logfd, "\n");
|
|
|
|
fflush(logfd);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iofunctions::iofunctions(FILE *fs)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
init_log(fs);
|
|
|
|
}
|
|
|
|
|
2001-11-12 21:28:07 +03:00
|
|
|
iofunctions::iofunctions(const char *fn)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
init_log(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
iofunctions::iofunctions(int fd)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
init_log(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
iofunctions::iofunctions(void)
|
|
|
|
{
|
|
|
|
this->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
iofunctions::~iofunctions(void)
|
|
|
|
{
|
|
|
|
// flush before erasing magic number, or flush does nothing.
|
|
|
|
this->flush();
|
|
|
|
this->magic=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOG_THIS genlog->
|
|
|
|
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
int logfunctions::default_onoff[N_LOGLEV] = {
|
|
|
|
ACT_IGNORE, // ignore debug
|
|
|
|
ACT_REPORT, // report info
|
|
|
|
ACT_REPORT, // report error
|
2002-09-25 22:35:06 +04:00
|
|
|
#if BX_WITH_WX
|
2002-12-17 06:36:53 +03:00
|
|
|
ACT_ASK, // on panic, ask user what to do
|
2002-09-25 22:35:06 +04:00
|
|
|
#else
|
2002-12-17 06:36:53 +03:00
|
|
|
ACT_FATAL, // on panic, quit
|
2002-09-25 22:35:06 +04:00
|
|
|
#endif
|
2002-12-17 06:36:53 +03:00
|
|
|
ACT_FATAL
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
};
|
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
logfunctions::logfunctions(void)
|
|
|
|
{
|
2001-12-21 22:33:18 +03:00
|
|
|
prefix = NULL;
|
2001-06-27 23:16:01 +04:00
|
|
|
put(" ");
|
2001-06-19 20:25:41 +04:00
|
|
|
settype(GENLOG);
|
2001-12-21 22:33:18 +03:00
|
|
|
if (io == NULL && Allocio == 0) {
|
2001-06-19 20:25:41 +04:00
|
|
|
Allocio = 1;
|
|
|
|
io = new iofunc_t(stderr);
|
|
|
|
}
|
|
|
|
setio(io);
|
|
|
|
// 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++)
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
onoff[i] = get_default_action(i);
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
logfunctions::logfunctions(iofunc_t *iofunc)
|
|
|
|
{
|
2001-12-21 22:33:18 +03:00
|
|
|
prefix = NULL;
|
2001-06-27 23:16:01 +04:00
|
|
|
put(" ");
|
2001-06-19 20:25:41 +04:00
|
|
|
settype(GENLOG);
|
|
|
|
setio(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++)
|
- 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
2002-09-20 21:56:22 +04:00
|
|
|
onoff[i] = get_default_action(i);
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
logfunctions::~logfunctions(void)
|
|
|
|
{
|
2001-12-21 22:33:18 +03:00
|
|
|
if ( this->prefix )
|
|
|
|
{
|
|
|
|
free(this->prefix);
|
|
|
|
this->prefix = NULL;
|
|
|
|
}
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
logfunctions::setio(iofunc_t *i)
|
|
|
|
{
|
|
|
|
// add pointer to iofunction object to use
|
|
|
|
this->logio = i;
|
|
|
|
// give iofunction a pointer to me
|
|
|
|
i->add_logfn (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-06-27 23:16:01 +04:00
|
|
|
logfunctions::put(char *p)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
2001-06-20 01:36:09 +04:00
|
|
|
char *tmpbuf;
|
|
|
|
tmpbuf=strdup("[ ]");// if we ever have more than 32 chars,
|
|
|
|
// we need to rethink this
|
2001-12-21 22:33:18 +03:00
|
|
|
|
|
|
|
if ( tmpbuf == NULL)
|
|
|
|
{
|
|
|
|
return ; /* allocation not successful */
|
|
|
|
}
|
|
|
|
if ( this->prefix != NULL )
|
|
|
|
{
|
|
|
|
free(this->prefix); /* free previously allocated memory */
|
|
|
|
this->prefix = NULL;
|
|
|
|
}
|
2001-06-20 01:36:09 +04:00
|
|
|
int len=strlen(p);
|
|
|
|
for(int i=1;i<len+1;i++) {
|
|
|
|
tmpbuf[i]=p[i-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(len) {
|
|
|
|
case 1: tmpbuf[2]=' ';
|
|
|
|
case 2: tmpbuf[3]=' ';
|
|
|
|
case 3: tmpbuf[4]=' ';
|
|
|
|
case 4: tmpbuf[5]=' ';
|
|
|
|
default: tmpbuf[6]=']'; tmpbuf[7]='\0'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->prefix=tmpbuf;
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
logfunctions::settype(int t)
|
|
|
|
{
|
|
|
|
type=t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
logfunctions::info(const char *fmt, ...)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (this->logio != NULL);
|
|
|
|
|
|
|
|
if(!onoff[LOGLEV_INFO]) return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
this->logio->out(this->type,LOGLEV_INFO,this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_INFO] == ACT_ASK)
|
|
|
|
ask (LOGLEV_INFO, this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_INFO] == ACT_FATAL)
|
2002-12-17 06:36:53 +03:00
|
|
|
fatal (this->prefix, fmt, ap, 1);
|
2001-06-19 20:25:41 +04:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
logfunctions::error(const char *fmt, ...)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (this->logio != NULL);
|
|
|
|
|
|
|
|
if(!onoff[LOGLEV_ERROR]) return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
this->logio->out(this->type,LOGLEV_ERROR,this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_ERROR] == ACT_ASK)
|
|
|
|
ask (LOGLEV_ERROR, this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_ERROR] == ACT_FATAL)
|
2002-12-17 06:36:53 +03:00
|
|
|
fatal (this->prefix, fmt, ap, 1);
|
2001-06-19 20:25:41 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
logfunctions::panic(const char *fmt, ...)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (this->logio != NULL);
|
|
|
|
|
2001-10-06 18:36:00 +04:00
|
|
|
// Special case for panics since they are so important. Always print
|
|
|
|
// the panic to the log, no matter what the log action says.
|
|
|
|
//if(!onoff[LOGLEV_PANIC]) return;
|
2001-06-19 20:25:41 +04:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
this->logio->out(this->type,LOGLEV_PANIC,this->prefix, fmt, ap);
|
2002-12-03 00:19:09 +03:00
|
|
|
|
|
|
|
// This fixes a funny bug on linuxppc where va_list is no pointer but a struct
|
|
|
|
va_end(ap);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
if (onoff[LOGLEV_PANIC] == ACT_ASK)
|
|
|
|
ask (LOGLEV_PANIC, this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_PANIC] == ACT_FATAL)
|
2002-12-17 06:36:53 +03:00
|
|
|
fatal (this->prefix, fmt, ap, 1);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
logfunctions::pass(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (this->logio != NULL);
|
|
|
|
|
|
|
|
// Special case for panics since they are so important. Always print
|
|
|
|
// the panic to the log, no matter what the log action says.
|
|
|
|
//if(!onoff[LOGLEV_PASS]) return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
this->logio->out(this->type,LOGLEV_PASS,this->prefix, fmt, ap);
|
|
|
|
|
|
|
|
// This fixes a funny bug on linuxppc where va_list is no pointer but a struct
|
|
|
|
va_end(ap);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
if (onoff[LOGLEV_PASS] == ACT_ASK)
|
|
|
|
ask (LOGLEV_PASS, this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_PASS] == ACT_FATAL)
|
|
|
|
fatal (this->prefix, fmt, ap, 101);
|
2001-06-19 20:25:41 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
logfunctions::ldebug(const char *fmt, ...)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert (this != NULL);
|
|
|
|
assert (this->logio != NULL);
|
|
|
|
|
|
|
|
if(!onoff[LOGLEV_DEBUG]) return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
this->logio->out(this->type,LOGLEV_DEBUG,this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_DEBUG] == ACT_ASK)
|
|
|
|
ask (LOGLEV_DEBUG, this->prefix, fmt, ap);
|
|
|
|
if (onoff[LOGLEV_DEBUG] == ACT_FATAL)
|
2002-12-17 06:36:53 +03:00
|
|
|
fatal (this->prefix, fmt, ap, 1);
|
2001-06-19 20:25:41 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 21:28:07 +03:00
|
|
|
logfunctions::ask (int level, const char *prefix, const char *fmt, va_list ap)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
2002-08-27 21:03:03 +04:00
|
|
|
// Guard against reentry on ask() function. The danger is that some
|
|
|
|
// function that's called within ask() could trigger another
|
|
|
|
// BX_PANIC that could call ask() again, leading to infinite
|
|
|
|
// recursion and infinite asks.
|
2002-06-01 11:39:19 +04:00
|
|
|
static char in_ask_already = 0;
|
2002-08-28 07:06:12 +04:00
|
|
|
char buf1[1024];
|
2002-06-01 11:39:19 +04:00
|
|
|
if (in_ask_already) {
|
|
|
|
fprintf (stderr, "logfunctions::ask() should not reenter!!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_ask_already = 1;
|
2004-02-08 14:02:42 +03:00
|
|
|
vsnprintf (buf1, sizeof(buf1), fmt, ap);
|
2001-06-19 20:25:41 +04:00
|
|
|
// FIXME: facility set to 0 because it's unknown.
|
2002-06-01 11:39:19 +04:00
|
|
|
|
|
|
|
// update vga screen. This is useful because sometimes useful messages
|
|
|
|
// are printed on the screen just before a panic. It's also potentially
|
|
|
|
// dangerous if this function calls ask again... That's why I added
|
|
|
|
// the reentry check above.
|
2002-10-25 01:07:56 +04:00
|
|
|
if (SIM->get_init_done()) DEV_vga_refresh();
|
2002-06-01 11:39:19 +04:00
|
|
|
|
2002-09-23 19:39:53 +04:00
|
|
|
#if !BX_EXTERNAL_DEBUGGER
|
2002-12-06 22:34:32 +03:00
|
|
|
// ensure the text screen is showing
|
|
|
|
SIM->set_display_mode (DISP_MODE_CONFIG);
|
2002-08-28 07:06:12 +04:00
|
|
|
int val = SIM->log_msg (prefix, level, buf1);
|
2001-06-19 20:25:41 +04:00
|
|
|
switch (val)
|
|
|
|
{
|
2002-09-25 22:35:06 +04:00
|
|
|
case BX_LOG_ASK_CHOICE_CONTINUE:
|
2001-06-19 20:25:41 +04:00
|
|
|
break;
|
2002-09-25 22:35:06 +04:00
|
|
|
case BX_LOG_ASK_CHOICE_CONTINUE_ALWAYS:
|
|
|
|
// user said continue, and don't "ask" for this facility again.
|
2001-06-19 20:25:41 +04:00
|
|
|
setonoff (level, ACT_REPORT);
|
|
|
|
break;
|
2002-09-25 22:35:06 +04:00
|
|
|
case BX_LOG_ASK_CHOICE_DIE:
|
2003-05-27 22:19:13 +04:00
|
|
|
bx_user_quit = 1;
|
2002-08-27 21:03:03 +04:00
|
|
|
in_ask_already = 0; // because fatal will longjmp out
|
2002-12-17 06:36:53 +03:00
|
|
|
fatal (prefix, fmt, ap, 1);
|
2002-08-27 21:03:03 +04:00
|
|
|
// should never get here
|
|
|
|
BX_PANIC (("in ask(), fatal() should never return!"));
|
2002-06-01 11:39:19 +04:00
|
|
|
break;
|
2002-09-25 22:35:06 +04:00
|
|
|
case BX_LOG_ASK_CHOICE_DUMP_CORE:
|
2001-10-07 04:35:35 +04:00
|
|
|
fprintf (stderr, "User chose to dump core...\n");
|
|
|
|
#if BX_HAVE_ABORT
|
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
// do something highly illegal that should kill the process.
|
|
|
|
// Hey, this is fun!
|
|
|
|
{
|
|
|
|
char *crashptr = (char *)0; char c = *crashptr;
|
|
|
|
}
|
|
|
|
fprintf (stderr, "Sorry, I couldn't find your abort() function. Exiting.");
|
|
|
|
exit (0);
|
|
|
|
#endif
|
2001-10-06 09:51:34 +04:00
|
|
|
#if BX_DEBUGGER
|
2002-09-25 22:35:06 +04:00
|
|
|
case BX_LOG_ASK_CHOICE_ENTER_DEBUG:
|
2001-10-06 09:51:34 +04:00
|
|
|
// user chose debugger. To "drop into the debugger" we just set the
|
|
|
|
// interrupt_requested bit and continue execution. Before the next
|
|
|
|
// instruction, it should notice the user interrupt and return to
|
|
|
|
// the debugger.
|
|
|
|
bx_guard.interrupt_requested = 1;
|
2004-10-05 22:59:20 +04:00
|
|
|
/*
|
|
|
|
// Russ Cox's CPU panic debug patch from Oct 2003 ->
|
|
|
|
// caused compilation errors when BX_DEBUGGER enabled
|
2004-01-17 11:36:29 +03:00
|
|
|
|
|
|
|
// actually, if this is a panic, it's very likely the caller will
|
|
|
|
// not be able to cope gracefully if we return and try to keep
|
|
|
|
// executing. so longjmp back to the cpu loop immediately.
|
|
|
|
if (level == LOGLEV_PANIC) {
|
|
|
|
BX_CPU_THIS_PTR stop_reason = STOP_CPU_PANIC;
|
|
|
|
bx_guard.special_unwind_stack = 1;
|
|
|
|
in_ask_already = 0;
|
|
|
|
longjmp(BX_CPU_THIS_PTR jmp_buf_env, 1); // go back to main decode loop
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BX_GDBSTUB
|
|
|
|
case BX_LOG_ASK_CHOICE_ENTER_DEBUG:
|
|
|
|
// user chose debugger (we're using gdb)
|
|
|
|
in_ask_already = 0;
|
|
|
|
BX_CPU_THIS_PTR ispanic = 1;
|
|
|
|
longjmp(BX_CPU_THIS_PTR jmp_buf_env, 1); // go back to main decode loop
|
2004-10-05 22:59:20 +04:00
|
|
|
*/
|
2001-10-06 09:51:34 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2001-10-07 02:23:10 +04:00
|
|
|
// this happens if panics happen before the callback is initialized
|
|
|
|
// in gui/control.cc.
|
2002-04-18 04:22:20 +04:00
|
|
|
fprintf (stderr, "WARNING: log_msg returned unexpected value %d\n", val);
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
2002-09-23 19:39:53 +04:00
|
|
|
#else
|
|
|
|
// external debugger ask code goes here
|
|
|
|
#endif
|
2002-12-06 22:34:32 +03:00
|
|
|
// return to simulation mode
|
|
|
|
SIM->set_display_mode (DISP_MODE_SIM);
|
2002-06-01 11:39:19 +04:00
|
|
|
in_ask_already = 0;
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
2002-12-17 08:58:45 +03:00
|
|
|
#if BX_WITH_CARBON
|
|
|
|
/* Panic button to display fatal errors.
|
|
|
|
Completely self contained, can't rely on carbon.cc being available */
|
|
|
|
static void carbonFatalDialog(const char *error, const char *exposition)
|
|
|
|
{
|
|
|
|
DialogRef alertDialog;
|
|
|
|
CFStringRef cfError;
|
|
|
|
CFStringRef cfExposition;
|
|
|
|
DialogItemIndex index;
|
|
|
|
AlertStdCFStringAlertParamRec alertParam = {0};
|
|
|
|
|
|
|
|
// Init libraries
|
|
|
|
InitCursor();
|
|
|
|
// Assemble dialog
|
|
|
|
cfError = CFStringCreateWithCString(NULL, error, kCFStringEncodingASCII);
|
|
|
|
if(exposition != NULL)
|
|
|
|
{
|
|
|
|
cfExposition = CFStringCreateWithCString(NULL, exposition, kCFStringEncodingASCII);
|
|
|
|
}
|
|
|
|
else { cfExposition = NULL; }
|
|
|
|
alertParam.version = kStdCFStringAlertVersionOne;
|
|
|
|
alertParam.defaultText = CFSTR("Quit");
|
|
|
|
alertParam.position = kWindowDefaultPosition;
|
|
|
|
alertParam.defaultButton = kAlertStdAlertOKButton;
|
|
|
|
// Display Dialog
|
|
|
|
CreateStandardAlert(
|
|
|
|
kAlertStopAlert,
|
|
|
|
cfError,
|
|
|
|
cfExposition, /* can be NULL */
|
|
|
|
&alertParam, /* can be NULL */
|
|
|
|
&alertDialog);
|
|
|
|
RunStandardAlert( alertDialog, NULL, &index);
|
|
|
|
// Cleanup
|
|
|
|
CFRelease( cfError );
|
|
|
|
if( cfExposition != NULL ) { CFRelease( cfExposition ); }
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-06-19 20:25:41 +04:00
|
|
|
void
|
2002-12-17 06:36:53 +03:00
|
|
|
logfunctions::fatal (const char *prefix, const char *fmt, va_list ap, int exit_status)
|
2001-06-19 20:25:41 +04:00
|
|
|
{
|
|
|
|
bx_atexit();
|
2002-12-17 08:58:45 +03:00
|
|
|
#if BX_WITH_CARBON
|
|
|
|
if(!isatty(STDIN_FILENO) && !SIM->get_init_done())
|
|
|
|
{
|
|
|
|
char buf1[1024];
|
|
|
|
char buf2[1024];
|
2004-02-08 14:02:42 +03:00
|
|
|
vsnprintf (buf1, sizeof(buf1), fmt, ap);
|
|
|
|
snprintf (buf2, sizeof(buf2), "Bochs startup error\n%s", buf1);
|
2002-12-17 08:58:45 +03:00
|
|
|
carbonFatalDialog(buf2,
|
|
|
|
"For more information, try running Bochs within Terminal by clicking on \"bochs.scpt\".");
|
|
|
|
}
|
|
|
|
#endif
|
2002-09-05 20:40:18 +04:00
|
|
|
#if !BX_WITH_WX
|
2002-09-15 15:02:22 +04:00
|
|
|
static char *divider = "========================================================================";
|
2001-06-19 20:25:41 +04:00
|
|
|
fprintf (stderr, "%s\n", divider);
|
|
|
|
fprintf (stderr, "Bochs is exiting with the following message:\n");
|
|
|
|
fprintf (stderr, "%s ", prefix);
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
fprintf (stderr, "\n%s\n", divider);
|
2002-09-05 20:40:18 +04:00
|
|
|
#endif
|
2001-06-19 20:25:41 +04:00
|
|
|
#if 0 && defined(WIN32)
|
2002-08-27 21:03:03 +04:00
|
|
|
#error disabled because it is not working yet!
|
2001-06-19 20:25:41 +04:00
|
|
|
// wait for a keypress before quitting. Depending on how bochs is
|
|
|
|
// installed, the console window can disappear before the user has
|
|
|
|
// a chance to read the final message.
|
|
|
|
fprintf (stderr, "\n\nPress Enter to exit...\n");
|
|
|
|
char buf[8];
|
|
|
|
fgets (buf, 8, stdin);
|
|
|
|
#endif
|
|
|
|
#if !BX_DEBUGGER
|
2002-12-17 06:36:53 +03:00
|
|
|
BX_EXIT(exit_status);
|
2001-06-19 20:25:41 +04:00
|
|
|
#else
|
2002-10-25 15:44:41 +04:00
|
|
|
static bx_bool dbg_exit_called = 0;
|
2001-06-19 20:25:41 +04:00
|
|
|
if (dbg_exit_called == 0) {
|
|
|
|
dbg_exit_called = 1;
|
2002-12-17 06:36:53 +03:00
|
|
|
bx_dbg_exit(exit_status);
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
2002-09-25 22:35:06 +04:00
|
|
|
// not safe to use BX_* log functions in here.
|
|
|
|
fprintf (stderr, "fatal() should never return, but it just did\n");
|
2001-06-19 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
iofunc_t *io = NULL;
|
|
|
|
logfunc_t *genlog = NULL;
|
|
|
|
|
|
|
|
void bx_center_print (FILE *file, char *line, int maxwidth)
|
|
|
|
{
|
|
|
|
int imax;
|
2002-11-11 17:10:24 +03:00
|
|
|
int len = strlen(line);
|
|
|
|
if (len > maxwidth)
|
|
|
|
BX_PANIC (("bx_center_print: line is too long: '%s'", line));
|
|
|
|
imax = (maxwidth - len) >> 1;
|
2001-06-19 20:25:41 +04:00
|
|
|
for (int i=0; i<imax; i++) fputc (' ', file);
|
|
|
|
fputs (line, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|