40c40
< #include "base/trace.hh"
---
> #include "base/output.hh"
41a42
> #include "base/trace.hh"
58,63c59,60
<
< ObjectMatch ignore;
<
< Log theLog;
<
< Log::Log()
---
> ostream &
> output()
65,66c62
< size = 0;
< buffer = NULL;
---
> return *dprintf_stream;
69d64
<
71c66
< Log::init(int _size)
---
> setOutput(const string &filename)
73,86c68
< 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);
88a71
> ObjectMatch ignore;
90c73,75
< Log::~Log()
---
> void
> dprintf(Tick when, const std::string &name, const char *format,
> CPRINTF_DEFINITION)
92,94c77,78
< for (int i = 0; i < size; ++i) {
< delete buffer[i];
< }
---
> if (!name.empty() && ignore.match(name))
> return;
96,97c80
< delete [] buffer;
< }
---
> std::ostream &os = *dprintf_stream;
98a82,83
> string fmt = "";
> CPrintfArgsList args(VARARGS_ALLARGS);
100,107c85,87
< 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);
---
> if (!name.empty()) {
> fmt = "%s: " + fmt;
> args.push_front(name);
110,113c90,92
< // no buffering: justget rid of it now
< if (buffer == NULL) {
< delete rec;
< return;
---
> if (when != (Tick)-1) {
> fmt = "%7d: " + fmt;
> args.push_front(when);
116c95
< Record *oldRec = *nextRecPtr;
---
> fmt += format;
118,127c97,98
< if (oldRec != NULL) {
< // log has wrapped: overwrite
< delete oldRec;
< }
<
< *nextRecPtr = rec;
<
< if (++nextRecPtr == wrapRecPtr) {
< nextRecPtr = &buffer[0];
< }
---
> ccprintf(os, fmt.c_str(), args);
> os.flush();
130d100
<
132c102
< Log::dump(ostream &os)
---
> dump(Tick when, const std::string &name, const void *d, int len)
134c104
< if (buffer == NULL) {
---
> if (!name.empty() && ignore.match(name))
136d105
< }
138c107
< Record **bufPtr = nextRecPtr;
---
> std::ostream &os = *dprintf_stream;
140,162d108
< 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()
< {}
<
< void
< PrintfRecord::dump(ostream &os)
< {
163a110
> CPrintfArgsList args;
170c117
< if (cycle != (Tick)-1) {
---
> if (when != (Tick)-1) {
172c119
< args.push_front(cycle);
---
> args.push_front(when);
175,196c122
< 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);
198d123
<
200c125,126
< ccprintf(os, "%d: %s: %08x ", cycle, name, i);
---
> ccprintf(os, fmt, args);
> ccprintf(os, "%08x ", i);
216,217c142
< ccprintf(os,
< "%c", (char)(isprint(ch) ? ch : ' '));
---
> ccprintf(os, "%c", (char)(isprint(ch) ? ch : ' '));
226c151,213
< } // 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" */ }