/* debug.c -- Debug channel support code
|
/* debug.c -- Debug channel support code
|
|
|
Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
|
Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
|
Copyright (C) 2008 Embecosm Limited
|
Copyright (C) 2008 Embecosm Limited
|
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
|
|
This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
|
This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
under the terms of the GNU General Public License as published by the Free
|
under the terms of the GNU General Public License as published by the Free
|
Software Foundation; either version 3 of the License, or (at your option)
|
Software Foundation; either version 3 of the License, or (at your option)
|
any later version.
|
any later version.
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
more details.
|
more details.
|
|
|
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along
|
with this program. If not, see <http://www.gnu.org/licenses/>. */
|
with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
/* This program is commented throughout in a fashion suitable for processing
|
/* This program is commented throughout in a fashion suitable for processing
|
with Doxygen. */
|
with Doxygen. */
|
|
|
|
|
/* Autoconf and/or portability configuration */
|
/* Autoconf and/or portability configuration */
|
#include "config.h"
|
#include "config.h"
|
#include "port.h"
|
#include "port.h"
|
|
|
/* System includes */
|
/* System includes */
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
|
|
/* Package includes */
|
/* Package includes */
|
#include "arch.h"
|
#include "arch.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
|
|
#define __ORSIM_NO_DEC_DBCH
|
#define __ORSIM_NO_DEC_DBCH
|
#include "debug.h"
|
#include "debug.h"
|
|
|
#define DECLARE_DEBUG_CHANNEL(dbch) char __orsim_dbch_##dbch[] = "\0"#dbch;
|
#define DECLARE_DEBUG_CHANNEL(dbch) char __orsim_dbch_##dbch[] = "\0"#dbch;
|
#include "dbchs.h"
|
#include "dbchs.h"
|
#undef DECLARE_DEBUG_CHANNEL
|
#undef DECLARE_DEBUG_CHANNEL
|
|
|
#define DECLARE_DEBUG_CHANNEL(dbch) __orsim_dbch_##dbch,
|
#define DECLARE_DEBUG_CHANNEL(dbch) __orsim_dbch_##dbch,
|
static char *__orsim_dbchs[] = {
|
static char *__orsim_dbchs[] = {
|
#include "dbchs.h"
|
#include "dbchs.h"
|
NULL };
|
NULL };
|
#undef DECLARE_DEBUG_CHANNEL
|
#undef DECLARE_DEBUG_CHANNEL
|
|
|
static const char *debug_classes[] = { "trace", "fixme", "warn", "err" };
|
static const char *debug_classes[] = { "trace", "fixme", "warn", "err" };
|
|
|
|
|
void orsim_dbg_log(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch,
|
void orsim_dbg_log(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch,
|
const char *function, const char *format, ...)
|
const char *function, const char *format, ...)
|
{
|
{
|
va_list ap;
|
va_list ap;
|
static int last_lf = 1; /* There *has* to be a better way */
|
static int last_lf = 1; /* There *has* to be a better way */
|
|
|
if(last_lf) {
|
if(last_lf) {
|
if(!TRACE_ON(cycles))
|
if(!TRACE_ON(cycles))
|
fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
|
fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
|
else
|
else
|
fprintf(stderr, "%lld:%s:%s:%s: ", runtime.sim.cycles,
|
fprintf(stderr, "%lld:%s:%s:%s: ", runtime.sim.cycles,
|
debug_classes[dbcl], dbch + 1, function);
|
debug_classes[dbcl], dbch + 1, function);
|
}
|
}
|
last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
|
last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
|
va_start(ap, format);
|
va_start(ap, format);
|
vfprintf(stderr, format, ap);
|
vfprintf(stderr, format, ap);
|
va_end(ap);
|
va_end(ap);
|
}
|
}
|
|
|
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
|
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
|
{
|
{
|
if(on)
|
if(on)
|
dbch[0] |= 1 << dbcl;
|
dbch[0] |= 1 << dbcl;
|
else
|
else
|
dbch[0] &= ~(1 << dbcl);
|
dbch[0] &= ~(1 << dbcl);
|
}
|
}
|
|
|
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
|
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
|
{
|
{
|
char **dbchs = __orsim_dbchs;
|
char **dbchs = __orsim_dbchs;
|
|
|
for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
|
for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
|
if(!strcmp(*dbchs + 1, dbch)) {
|
if(!strcmp(*dbchs + 1, dbch)) {
|
orsim_dbcl_set(dbcl, *dbchs, on);
|
orsim_dbcl_set(dbcl, *dbchs, on);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void parse_dbchs(const char *str)
|
void parse_dbchs(const char *str)
|
{
|
{
|
enum __ORSIM_DEBUG_CLASS dbcl = 0;
|
enum __ORSIM_DEBUG_CLASS dbcl = 0;
|
int i;
|
int i;
|
int disen;
|
int disen;
|
int all;
|
int all;
|
const char *cend;
|
const char *cend;
|
const char *chan_end;
|
const char *chan_end;
|
|
|
while(*str) {
|
while(*str) {
|
cend = strpbrk(str, "+-");
|
cend = strpbrk(str, "+-");
|
chan_end = strchr(str, ',');
|
chan_end = strchr(str, ',');
|
if(!chan_end)
|
if(!chan_end)
|
chan_end = str + strlen(str);
|
chan_end = str + strlen(str);
|
|
|
if(!cend || (cend > chan_end)) {
|
if(!cend || (cend > chan_end)) {
|
disen = 1;
|
disen = 1;
|
cend = --str;
|
cend = --str;
|
} else
|
} else
|
disen = *cend == '+' ? 1 : 0;
|
disen = *cend == '+' ? 1 : 0;
|
|
|
if(cend == str) {
|
if(cend == str) {
|
all = 1;
|
all = 1;
|
} else {
|
} else {
|
for(i = 0; i < 4; i++) {
|
for(i = 0; i < 4; i++) {
|
if(!strncmp(str, debug_classes[i], cend - str)) {
|
if(!strncmp(str, debug_classes[i], cend - str)) {
|
dbcl = i;
|
dbcl = i;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
if(i >= 4)
|
if(i >= 4)
|
fprintf(stderr, "Unknown class specified\n");
|
fprintf(stderr, "Unknown class specified\n");
|
all = 0;
|
all = 0;
|
}
|
}
|
cend++;
|
cend++;
|
|
|
for(i = 0; __orsim_dbchs[i]; i++)
|
for(i = 0; __orsim_dbchs[i]; i++)
|
if(!strncmp(cend, __orsim_dbchs[i] + 1, chan_end - cend))
|
if(!strncmp(cend, __orsim_dbchs[i] + 1, chan_end - cend))
|
break;
|
break;
|
|
|
if(!__orsim_dbchs[i])
|
if(!__orsim_dbchs[i])
|
fprintf(stderr, "Unknown channel specified\n");
|
fprintf(stderr, "Unknown channel specified\n");
|
else if(all) {
|
else if(all) {
|
orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
|
} else
|
} else
|
orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
|
orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
|
if(*chan_end)
|
if(*chan_end)
|
str = chan_end + 1;
|
str = chan_end + 1;
|
else
|
else
|
str = chan_end;
|
str = chan_end;
|
}
|
}
|
}
|
}
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
/*!Internal debug function
|
/*!Internal debug function
|
|
|
Print the message if the level is greater than or equal to that specified
|
Print the message if the level is greater than or equal to that specified
|
in the configuration.
|
in the configuration.
|
|
|
@param[in] level The debug level of this message
|
@param[in] level The debug level of this message
|
@param[in] format Varargs format string
|
@param[in] format Varargs format string
|
@param[in] ... The varargs required by the string */
|
@param[in] ... The varargs required by the string */
|
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
void
|
void
|
debug (int level,
|
debug (int level,
|
const char *format,
|
const char *format,
|
...)
|
...)
|
{
|
{
|
if (config.sim.debug >= level)
|
if (config.sim.debug >= level)
|
{
|
{
|
va_list ap;
|
va_list ap;
|
|
|
va_start (ap, format);
|
va_start (ap, format);
|
vfprintf (runtime.sim.fout, format, ap);
|
vfprintf (runtime.sim.fout, format, ap);
|
fflush (runtime.sim.fout);
|
fflush (runtime.sim.fout);
|
}
|
}
|
} /* debug() */
|
} /* debug() */
|
|
|
|
|
|
|