sim/stat_context.cc
sim/stat_control.cc
sim/system.cc
- sim/trace_control.cc
''')
trace_reader_sources = Split('''
#include <vector>
#include "base/misc.hh"
-#include "base/trace.hh"
+#include "base/output.hh"
#include "base/str.hh"
+#include "base/trace.hh"
#include "base/varargs.hh"
using namespace std;
// output.
//
ostream *dprintf_stream = &cerr;
-
-ObjectMatch ignore;
-
-Log theLog;
-
-Log::Log()
+ostream &
+output()
{
- size = 0;
- buffer = NULL;
+ return *dprintf_stream;
}
-
void
-Log::init(int _size)
+setOutput(const string &filename)
{
- if (buffer != NULL) {
- fatal("Trace::Log::init called twice!");
- }
-
- size = _size;
-
- buffer = new Record *[size];
-
- for (int i = 0; i < size; ++i) {
- buffer[i] = NULL;
- }
-
- nextRecPtr = &buffer[0];
- wrapRecPtr = &buffer[size];
+ dprintf_stream = simout.find(filename);
}
+ObjectMatch ignore;
-Log::~Log()
+void
+dprintf(Tick when, const std::string &name, const char *format,
+ CPRINTF_DEFINITION)
{
- for (int i = 0; i < size; ++i) {
- delete buffer[i];
- }
-
- delete [] buffer;
-}
+ if (!name.empty() && ignore.match(name))
+ return;
+ std::ostream &os = *dprintf_stream;
-void
-Log::append(Record *rec)
-{
- // dump record to output stream if there's one open
- if (dprintf_stream != NULL) {
- rec->dump(*dprintf_stream);
- } else {
- rec->dump(cout);
- }
+ string fmt = "";
+ CPrintfArgsList args(VARARGS_ALLARGS);
- // no buffering: justget rid of it now
- if (buffer == NULL) {
- delete rec;
- return;
+ if (!name.empty()) {
+ fmt = "%s: " + fmt;
+ args.push_front(name);
}
- Record *oldRec = *nextRecPtr;
-
- if (oldRec != NULL) {
- // log has wrapped: overwrite
- delete oldRec;
+ if (when != (Tick)-1) {
+ fmt = "%7d: " + fmt;
+ args.push_front(when);
}
- *nextRecPtr = rec;
+ fmt += format;
- if (++nextRecPtr == wrapRecPtr) {
- nextRecPtr = &buffer[0];
- }
+ ccprintf(os, fmt.c_str(), args);
+ os.flush();
}
-
void
-Log::dump(ostream &os)
+dump(Tick when, const std::string &name, const void *d, int len)
{
- if (buffer == NULL) {
+ if (!name.empty() && ignore.match(name))
return;
- }
-
- Record **bufPtr = nextRecPtr;
-
- if (*bufPtr == NULL) {
- // next record slot is empty: log must not be full yet.
- // start dumping from beginning of buffer
- bufPtr = buffer;
- }
-
- do {
- Record *rec = *bufPtr;
-
- rec->dump(os);
- if (++bufPtr == wrapRecPtr) {
- bufPtr = &buffer[0];
- }
- } while (bufPtr != nextRecPtr);
-}
-
-PrintfRecord::~PrintfRecord()
-{}
+ std::ostream &os = *dprintf_stream;
-void
-PrintfRecord::dump(ostream &os)
-{
string fmt = "";
+ CPrintfArgsList args;
if (!name.empty()) {
fmt = "%s: " + fmt;
args.push_front(name);
}
- if (cycle != (Tick)-1) {
+ if (when != (Tick)-1) {
fmt = "%7d: " + fmt;
- args.push_front(cycle);
+ args.push_front(when);
}
- fmt += format;
-
- ccprintf(os, fmt.c_str(), args);
- os.flush();
-}
-
-DataRecord::DataRecord(Tick _cycle, const string &_name,
- const void *_data, int _len)
- : Record(_cycle), name(_name), len(_len)
-{
- data = new uint8_t[len];
- memcpy(data, _data, len);
-}
-
-DataRecord::~DataRecord()
-{
- delete [] data;
-}
-
-void
-DataRecord::dump(ostream &os)
-{
+ const char *data = static_cast<const char *>(d);
int c, i, j;
-
for (i = 0; i < len; i += 16) {
- ccprintf(os, "%d: %s: %08x ", cycle, name, i);
+ ccprintf(os, fmt, args);
+ ccprintf(os, "%08x ", i);
c = len - i;
if (c > 16) c = 16;
for (j = 0; j < c; j++) {
int ch = data[i + j] & 0x7f;
- ccprintf(os,
- "%c", (char)(isprint(ch) ? ch : ' '));
+ ccprintf(os, "%c", (char)(isprint(ch) ? ch : ' '));
}
ccprintf(os, "\n");
break;
}
}
-} // namespace Trace
+
+bool
+changeFlag(const char *s, bool value)
+{
+ using namespace Trace;
+ std::string str(s);
+
+ for (int i = 0; i < numFlagStrings; ++i) {
+ if (str != flagStrings[i])
+ continue;
+
+ if (i < NumFlags) {
+ flags[i] = value;
+ } else {
+ i -= NumFlags;
+
+ const Flags *flagVec = compoundFlags[i];
+ for (int j = 0; flagVec[j] != -1; ++j) {
+ if (flagVec[j] < NumFlags)
+ flags[flagVec[j]] = value;
+ }
+ }
+
+ return true;
+ }
+
+ // the flag was not found.
+ return false;
+}
+
+void
+dumpStatus()
+{
+ using namespace Trace;
+ for (int i = 0; i < numFlagStrings; ++i) {
+ if (flags[i])
+ cprintf("%s\n", flagStrings[i]);
+ }
+}
+
+/* namespace Trace */ }
+
+
+// add a set of functions that can easily be invoked from gdb
+extern "C" {
+ void
+ setTraceFlag(const char *string)
+ {
+ Trace::changeFlag(string, true);
+ }
+
+ void
+ clearTraceFlag(const char *string)
+ {
+ Trace::changeFlag(string, false);
+ }
+
+ void
+ dumpTraceStatus()
+ {
+ Trace::dumpStatus();
+ }
+/* extern "C" */ }
#ifndef __BASE_TRACE_HH__
#define __BASE_TRACE_HH__
+#include <string>
#include <vector>
#include "base/cprintf.hh"
#include "base/match.hh"
+#include "base/traceflags.hh"
#include "sim/host.hh"
#include "sim/root.hh"
-#include "base/traceflags.hh"
-
namespace Trace {
- typedef std::vector<bool> FlagVec;
-
- extern FlagVec flags;
-
- extern std::ostream *dprintf_stream;
-
- inline bool
- IsOn(int t)
- {
- return flags[t];
- }
-
- extern bool enabled;
-
- void dump(const uint8_t *data, int count);
-
- class Record
- {
- protected:
- Tick cycle;
-
- Record(Tick _cycle)
- : cycle(_cycle)
- {
- }
-
- public:
- virtual ~Record() {}
-
- virtual void dump(std::ostream &) = 0;
- };
-
- class PrintfRecord : public Record
- {
- private:
- const std::string &name;
- const char *format;
- CPrintfArgsList args;
-
- public:
- PrintfRecord(Tick cycle, const std::string &_name, const char *_format,
- CPRINTF_DECLARATION)
- : Record(cycle), name(_name), format(_format),
- args(VARARGS_ALLARGS)
- {
- }
-
- virtual ~PrintfRecord();
-
- virtual void dump(std::ostream &);
- };
-
- class DataRecord : public Record
- {
- private:
- const std::string &name;
- uint8_t *data;
- int len;
+std::ostream &output();
+void setOutput(const std::string &filename);
- public:
- DataRecord(Tick cycle, const std::string &name,
- const void *_data, int _len);
- virtual ~DataRecord();
+extern bool enabled;
+typedef std::vector<bool> FlagVec;
+extern FlagVec flags;
+inline bool IsOn(int t) { return flags[t]; }
+bool changeFlag(const char *str, bool value);
+void dumpStatus();
- virtual void dump(std::ostream &);
- };
+extern ObjectMatch ignore;
+extern const std::string DefaultName;
- class Log
- {
- private:
- int size; // number of records in log
- Record **buffer; // array of 'size' Record ptrs (circular buf)
- Record **nextRecPtr; // next slot to use in buffer
- Record **wrapRecPtr; // &buffer[size], for quick wrap check
+void dprintf(Tick when, const std::string &name, const char *format,
+ CPRINTF_DECLARATION);
+void dump(Tick when, const std::string &name, const void *data, int len);
- public:
- Log();
- ~Log();
-
- void init(int _size);
-
- void append(Record *); // append trace record to log
- void dump(std::ostream &); // dump contents to stream
- };
-
- extern Log theLog;
-
- extern ObjectMatch ignore;
-
- inline void
- dprintf(Tick when, const std::string &name, const char *format,
- CPRINTF_DECLARATION)
- {
- if (!name.empty() && ignore.match(name))
- return;
-
- theLog.append(new Trace::PrintfRecord(when, name, format,
- VARARGS_ALLARGS));
- }
-
- inline void
- dataDump(Tick when, const std::string &name, const void *data, int len)
- {
- theLog.append(new Trace::DataRecord(when, name, data, len));
- }
-
- extern const std::string DefaultName;
-
-};
-
-inline std::ostream &
-DebugOut()
-{
- return *Trace::dprintf_stream;
-}
+/* namespace Trace */ }
// This silly little class allows us to wrap a string in a functor
// object so that we can give a name() that DPRINTF will like
#define DDUMP(x, data, count) do { \
if (DTRACE(x)) \
- Trace::dataDump(curTick, name(), data, count); \
+ Trace::dump(curTick, name(), data, count); \
} while (0)
#define DPRINTF(x, ...) do { \
Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
} while (0)
+#define DDUMPN(data, count) do { \
+ Trace::dump(curTick, name(), data, count); \
+} while (0)
+
#define DPRINTFN(...) do { \
Trace::dprintf(curTick, name(), __VA_ARGS__); \
} while (0)
#else // !TRACING_ON
#define DTRACE(x) (false)
+#define DDUMP(x, data, count) do {} while (0)
#define DPRINTF(x, ...) do {} while (0)
#define DPRINTFR(...) do {} while (0)
+#define DDUMPN(data, count) do {} while (0)
#define DPRINTFN(...) do {} while (0)
#define DPRINTFNR(...) do {} while (0)
-#define DDUMP(x, data, count) do {} while (0)
#endif // TRACING_ON
#endif
void
-Trace::InstRecord::dump(ostream &outs)
+Trace::InstRecord::dump()
{
+ ostream &outs = Trace::output();
+
DPRINTF(Sparc, "Instruction: %#X\n", staticInst->machInst);
if (flags[PRINT_REG_DELTA])
{
bool is_trace_system = true;
#endif
if (is_trace_system) {
- ccprintf(outs, "%7d ) ", cycle);
+ ccprintf(outs, "%7d ) ", when);
outs << "0x" << hex << PC << ":\t";
if (staticInst->isLoad()) {
outs << "<RD 0x" << hex << addr;
outs << endl;
}
} else {
- if (flags[PRINT_CYCLE])
- ccprintf(outs, "%7d: ", cycle);
+ if (flags[PRINT_TICKS])
+ ccprintf(outs, "%7d: ", when);
outs << thread->getCpuPtr()->name() << " ";
// We took a trap on a micro-op...
if (wasMicro && !staticInst->isMicroOp())
{
- // let's skip comparing this cycle
+ // let's skip comparing this tick
while (!compared)
if (shared_data->flags == OWN_M5) {
shared_data->flags = OWN_LEGION;
{
flags[TRACE_MISSPEC] = exe_trace_spec;
- flags[PRINT_CYCLE] = exe_trace_print_cycle;
+ flags[PRINT_TICKS] = exe_trace_print_cycle;
flags[PRINT_OP_CLASS] = exe_trace_print_opclass;
flags[PRINT_THREAD_NUM] = exe_trace_print_thread;
flags[PRINT_RESULT_DATA] = exe_trace_print_effaddr;
#include <fstream>
#include <vector>
-#include "sim/host.hh"
-#include "cpu/inst_seq.hh" // for InstSeqNum
#include "base/trace.hh"
-#include "cpu/thread_context.hh"
+#include "cpu/inst_seq.hh" // for InstSeqNum
#include "cpu/static_inst.hh"
+#include "cpu/thread_context.hh"
+#include "sim/host.hh"
class ThreadContext;
namespace Trace {
-class InstRecord : public Record
+class InstRecord
{
protected:
typedef TheISA::IntRegFile IntRegFile;
+ Tick when;
+
// The following fields are initialized by the constructor and
// thus guaranteed to be valid.
ThreadContext *thread;
bool regs_valid;
public:
- InstRecord(Tick _cycle, ThreadContext *_thread,
+ InstRecord(Tick _when, ThreadContext *_thread,
const StaticInstPtr &_staticInst,
Addr _pc, bool spec)
- : Record(_cycle), thread(_thread),
+ : when(_when), thread(_thread),
staticInst(_staticInst), PC(_pc),
misspeculating(spec)
{
cp_seq_valid = false;
}
- virtual ~InstRecord() { }
-
- virtual void dump(std::ostream &outs);
+ ~InstRecord() { }
void setAddr(Addr a) { addr = a; addr_valid = true; }
void setRegs(const IntRegFile ®s);
- void finalize() { theLog.append(this); }
+ void dump();
enum InstExecFlagBits {
TRACE_MISSPEC = 0,
- PRINT_CYCLE,
+ PRINT_TICKS,
PRINT_OP_CLASS,
PRINT_THREAD_NUM,
PRINT_RESULT_DATA,
inline
InstRecord *
-getInstRecord(Tick cycle, ThreadContext *tc,
+getInstRecord(Tick when, ThreadContext *tc,
const StaticInstPtr staticInst,
Addr pc)
{
if (DTRACE(InstExec) &&
(InstRecord::traceMisspec() || !tc->misspeculating())) {
- return new InstRecord(cycle, tc, staticInst, pc,
+ return new InstRecord(when, tc, staticInst, pc,
tc->misspeculating());
}
if (head_inst->traceData) {
head_inst->traceData->setFetchSeq(head_inst->seqNum);
head_inst->traceData->setCPSeq(thread[tid]->numInst);
- head_inst->traceData->finalize();
+ head_inst->traceData->dump();
+ delete head_inst->traceData;
head_inst->traceData = NULL;
}
traceFunctions(thread->readPC());
if (traceData) {
- traceData->finalize();
+ traceData->dump();
+ delete traceData;
+ traceData = NULL;
}
}
void
Printk(TheISA::Arguments args)
{
+ std::ostream &out = Trace::output();
char *p = (char *)args++;
- ios::fmtflags saved_flags = DebugOut().flags();
- char old_fill = DebugOut().fill();
- int old_precision = DebugOut().precision();
+ ios::fmtflags saved_flags = out.flags();
+ char old_fill = out.fill();
+ int old_precision = out.precision();
while (*p) {
switch (*p) {
case 'P':
case 'p': {
if (hexnum)
- DebugOut() << hex;
+ out << hex;
if (octal)
- DebugOut() << oct;
+ out << oct;
if (format) {
if (!zero)
- DebugOut().setf(ios::showbase);
+ out.setf(ios::showbase);
else {
if (hexnum) {
- DebugOut() << "0x";
+ out << "0x";
width -= 2;
} else if (octal) {
- DebugOut() << "0";
+ out << "0";
width -= 1;
}
}
}
if (zero)
- DebugOut().fill('0');
+ out.fill('0');
if (width > 0)
- DebugOut().width(width);
+ out.width(width);
if (leftjustify && !zero)
- DebugOut().setf(ios::left);
+ out.setf(ios::left);
if (sign) {
if (islong)
- DebugOut() << (int64_t)args;
+ out << (int64_t)args;
else
- DebugOut() << (int32_t)args;
+ out << (int32_t)args;
} else {
if (islong)
- DebugOut() << (uint64_t)args;
+ out << (uint64_t)args;
else
- DebugOut() << (uint32_t)args;
+ out << (uint32_t)args;
}
if (zero)
- DebugOut().fill(' ');
+ out.fill(' ');
if (width > 0)
- DebugOut().width(0);
+ out.width(0);
- DebugOut() << dec;
+ out << dec;
++args;
}
s = "<NULL>";
if (width > 0)
- DebugOut().width(width);
+ out.width(width);
if (leftjustify)
- DebugOut().setf(ios::left);
+ out.setf(ios::left);
- DebugOut() << s;
+ out << s;
++args;
}
break;
while (width-- > 0) {
char c = (char)(num & mask);
if (c)
- DebugOut() << c;
+ out << c;
num >>= 8;
}
case 'b': {
uint64_t n = (uint64_t)args++;
char *s = (char *)args++;
- DebugOut() << s << ": " << n;
+ out << s << ": " << n;
}
break;
case 'n':
}
break;
case '%':
- DebugOut() << '%';
+ out << '%';
break;
}
++p;
}
break;
case '\n':
- DebugOut() << endl;
+ out << endl;
++p;
break;
case '\r':
++p;
if (*p != '\n')
- DebugOut() << endl;
+ out << endl;
break;
default: {
size_t len = strcspn(p, "%\n\r\0");
- DebugOut().write(p, len);
+ out.write(p, len);
p += len;
}
}
}
- DebugOut().flags(saved_flags);
- DebugOut().fill(old_fill);
- DebugOut().precision(old_precision);
+ out.flags(saved_flags);
+ out.fill(old_fill);
+ out.precision(old_precision);
}
DumpMbuf(Arguments args)
{
ThreadContext *tc = args.getThreadContext();
+ StringWrap name(tc->getSystemPtr()->name());
Addr addr = (Addr)args;
struct mbuf m;
int count = m.m_pkthdr.len;
- ccprintf(DebugOut(), "m=%#lx, m->m_pkthdr.len=%#d\n", addr,
- m.m_pkthdr.len);
+ DPRINTFN("m=%#lx, m->m_pkthdr.len=%#d\n", addr, m.m_pkthdr.len);
while (count > 0) {
- ccprintf(DebugOut(), "m=%#lx, m->m_data=%#lx, m->m_len=%d\n",
+ DPRINTFN("m=%#lx, m->m_data=%#lx, m->m_len=%d\n",
addr, m.m_data, m.m_len);
char *buffer = new char[m.m_len];
CopyOut(tc, buffer, m.m_data, m.m_len);
- Trace::dataDump(curTick, tc->getSystemPtr()->name(), (uint8_t *)buffer,
- m.m_len);
+ DDUMPN((uint8_t *)buffer, m.m_len);
delete [] buffer;
count -= m.m_len;
void
Printf(TheISA::Arguments args)
{
+ std::ostream &out = Trace::output();
+
char *p = (char *)args++;
- ios::fmtflags saved_flags = DebugOut().flags();
- char old_fill = DebugOut().fill();
- int old_precision = DebugOut().precision();
+ ios::fmtflags saved_flags = out.flags();
+ char old_fill = out.fill();
+ int old_precision = out.precision();
while (*p) {
switch (*p) {
case 'P':
case 'p': {
if (hexnum)
- DebugOut() << hex;
+ out << hex;
if (octal)
- DebugOut() << oct;
+ out << oct;
if (format) {
if (!zero)
- DebugOut().setf(ios::showbase);
+ out.setf(ios::showbase);
else {
if (hexnum) {
- DebugOut() << "0x";
+ out << "0x";
width -= 2;
} else if (octal) {
- DebugOut() << "0";
+ out << "0";
width -= 1;
}
}
}
if (zero)
- DebugOut().fill('0');
+ out.fill('0');
if (width > 0)
- DebugOut().width(width);
+ out.width(width);
if (leftjustify && !zero)
- DebugOut().setf(ios::left);
+ out.setf(ios::left);
if (sign) {
if (islong)
- DebugOut() << (int64_t)args;
+ out << (int64_t)args;
else
- DebugOut() << (int32_t)args;
+ out << (int32_t)args;
} else {
if (islong)
- DebugOut() << (uint64_t)args;
+ out << (uint64_t)args;
else
- DebugOut() << (uint32_t)args;
+ out << (uint32_t)args;
}
if (zero)
- DebugOut().fill(' ');
+ out.fill(' ');
if (width > 0)
- DebugOut().width(0);
+ out.width(0);
- DebugOut() << dec;
+ out << dec;
++args;
}
s = "<NULL>";
if (width > 0)
- DebugOut().width(width);
+ out.width(width);
if (leftjustify)
- DebugOut().setf(ios::left);
+ out.setf(ios::left);
- DebugOut() << s;
+ out << s;
++args;
}
break;
while (width-- > 0) {
char c = (char)(num & mask);
if (c)
- DebugOut() << c;
+ out << c;
num >>= 8;
}
case 'b': {
uint64_t n = (uint64_t)args++;
char *s = (char *)args++;
- DebugOut() << s << ": " << n;
+ out << s << ": " << n;
}
break;
case 'n':
}
break;
case '%':
- DebugOut() << '%';
+ out << '%';
break;
}
++p;
}
break;
case '\n':
- DebugOut() << endl;
+ out << endl;
++p;
break;
case '\r':
++p;
if (*p != '\n')
- DebugOut() << endl;
+ out << endl;
break;
default: {
size_t len = strcspn(p, "%\n\r\0");
- DebugOut().write(p, len);
+ out.write(p, len);
p += len;
}
}
}
- DebugOut().flags(saved_flags);
- DebugOut().fill(old_fill);
- DebugOut().precision(old_precision);
+ out.flags(saved_flags);
+ out.fill(old_fill);
+ out.precision(old_precision);
}
} // namespace Tru64
PrintfEvent::process(ThreadContext *tc)
{
if (DTRACE(Printf)) {
- DebugOut() << curTick << ": " << tc->getCpuPtr()->name() << ": ";
+ StringWrap name(tc->getSystemPtr()->name());
+ DPRINTFN("");
Arguments args(tc);
tru64::Printf(args);
DebugPrintfEvent::process(ThreadContext *tc)
{
if (DTRACE(DebugPrintf)) {
- if (!raw)
- DebugOut() << curTick << ": " << tc->getCpuPtr()->name() << ": ";
+ if (!raw) {
+ StringWrap name(tc->getSystemPtr()->name());
+ DPRINTFN("");
+ }
Arguments args(tc);
tru64::Printf(args);
internal.debug.schedBreakCycle(int(when))
for flag in options.trace_flags:
- internal.trace.setFlag(flag)
+ internal.trace.set(flag)
if options.trace_start is not None:
internal.trace.enabled = False
internal.event.enabled = True
internal.event.create(enable_trace, options.trace_start)
- #if options.trace_file is not None:
- # internal.trace.file(options.trace_file)
+ internal.trace.output(options.trace_file)
for ignore in options.trace_ignore:
internal.trace.ignore(ignore)
%{
#include "base/trace.hh"
#include "sim/host.hh"
-#include "sim/trace_control.hh"
+
+inline void
+output(const char *filename)
+{
+ Trace::setOutput(filename);
+}
inline void
set(const char *flag)
{
- setTraceFlag(flag);
+ Trace::changeFlag(flag, true);
}
inline void
clear(const char *flag)
{
- clearTraceFlag(flag);
+ Trace::changeFlag(flag, false);
}
inline void
%}
%inline %{
-extern void ignore(const char *expr);
+extern void output(const char *string);
extern void set(const char *string);
extern void clear(const char *string);
+extern void ignore(const char *expr);
extern bool enabled;
%}
abortHandler(int sigtype)
{
cerr << "Program aborted at cycle " << curTick << endl;
-
-#if TRACING_ON
- // dump trace buffer, if there is one
- Trace::theLog.dump(cerr);
-#endif
}
int