1/* 2 * Copyright (c) 2001-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 */ 31 32#ifndef __BASE_TRACE_HH__ 33#define __BASE_TRACE_HH__ 34
| 1/* 2 * Copyright (c) 2001-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt 30 */ 31 32#ifndef __BASE_TRACE_HH__ 33#define __BASE_TRACE_HH__ 34
|
| 35#include <string>
|
35#include <vector> 36 37#include "base/cprintf.hh" 38#include "base/match.hh"
| 36#include <vector> 37 38#include "base/cprintf.hh" 39#include "base/match.hh"
|
| 40#include "base/traceflags.hh"
|
39#include "sim/host.hh" 40#include "sim/root.hh" 41
| 41#include "sim/host.hh" 42#include "sim/root.hh" 43
|
42#include "base/traceflags.hh" 43
| |
44namespace Trace { 45
| 44namespace Trace { 45
|
46 typedef std::vector<bool> FlagVec;
| 46std::ostream &output(); 47void setOutput(const std::string &filename);
|
47
| 48
|
48 extern FlagVec flags;
| 49extern bool enabled; 50typedef std::vector<bool> FlagVec; 51extern FlagVec flags; 52inline bool IsOn(int t) { return flags[t]; } 53bool changeFlag(const char *str, bool value); 54void dumpStatus();
|
49
| 55
|
50 extern std::ostream *dprintf_stream;
| 56extern ObjectMatch ignore; 57extern const std::string DefaultName;
|
51
| 58
|
52 inline bool 53 IsOn(int t) 54 { 55 return flags[t]; 56 }
| 59void dprintf(Tick when, const std::string &name, const char *format, 60 CPRINTF_DECLARATION); 61void dump(Tick when, const std::string &name, const void *data, int len);
|
57
| 62
|
58 extern bool enabled;
| 63/* namespace Trace */ }
|
59
| 64
|
60 void dump(const uint8_t *data, int count); 61 62 class Record 63 { 64 protected: 65 Tick cycle; 66 67 Record(Tick _cycle) 68 : cycle(_cycle) 69 { 70 } 71 72 public: 73 virtual ~Record() {} 74 75 virtual void dump(std::ostream &) = 0; 76 }; 77 78 class PrintfRecord : public Record 79 { 80 private: 81 const std::string &name; 82 const char *format; 83 CPrintfArgsList args; 84 85 public: 86 PrintfRecord(Tick cycle, const std::string &_name, const char *_format, 87 CPRINTF_DECLARATION) 88 : Record(cycle), name(_name), format(_format), 89 args(VARARGS_ALLARGS) 90 { 91 } 92 93 virtual ~PrintfRecord(); 94 95 virtual void dump(std::ostream &); 96 }; 97 98 class DataRecord : public Record 99 { 100 private: 101 const std::string &name; 102 uint8_t *data; 103 int len; 104 105 public: 106 DataRecord(Tick cycle, const std::string &name, 107 const void *_data, int _len); 108 virtual ~DataRecord(); 109 110 virtual void dump(std::ostream &); 111 }; 112 113 class Log 114 { 115 private: 116 int size; // number of records in log 117 Record **buffer; // array of 'size' Record ptrs (circular buf) 118 Record **nextRecPtr; // next slot to use in buffer 119 Record **wrapRecPtr; // &buffer[size], for quick wrap check 120 121 public: 122 Log(); 123 ~Log(); 124 125 void init(int _size); 126 127 void append(Record *); // append trace record to log 128 void dump(std::ostream &); // dump contents to stream 129 }; 130 131 extern Log theLog; 132 133 extern ObjectMatch ignore; 134 135 inline void 136 dprintf(Tick when, const std::string &name, const char *format, 137 CPRINTF_DECLARATION) 138 { 139 if (!name.empty() && ignore.match(name)) 140 return; 141 142 theLog.append(new Trace::PrintfRecord(when, name, format, 143 VARARGS_ALLARGS)); 144 } 145 146 inline void 147 dataDump(Tick when, const std::string &name, const void *data, int len) 148 { 149 theLog.append(new Trace::DataRecord(when, name, data, len)); 150 } 151 152 extern const std::string DefaultName; 153 154}; 155 156inline std::ostream & 157DebugOut() 158{ 159 return *Trace::dprintf_stream; 160} 161
| |
162// This silly little class allows us to wrap a string in a functor 163// object so that we can give a name() that DPRINTF will like 164struct StringWrap 165{ 166 std::string str; 167 StringWrap(const std::string &s) : str(s) {} 168 const std::string &operator()() const { return str; } 169}; 170 171inline const std::string &name() { return Trace::DefaultName; } 172 173// 174// DPRINTF is a debugging trace facility that allows one to 175// selectively enable tracing statements. To use DPRINTF, there must 176// be a function or functor called name() that returns a const 177// std::string & in the current scope. 178// 179// If you desire that the automatic printing not occur, use DPRINTFR 180// (R for raw) 181// 182 183#if TRACING_ON 184 185#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled) 186 187#define DDUMP(x, data, count) do { \ 188 if (DTRACE(x)) \
| 65// This silly little class allows us to wrap a string in a functor 66// object so that we can give a name() that DPRINTF will like 67struct StringWrap 68{ 69 std::string str; 70 StringWrap(const std::string &s) : str(s) {} 71 const std::string &operator()() const { return str; } 72}; 73 74inline const std::string &name() { return Trace::DefaultName; } 75 76// 77// DPRINTF is a debugging trace facility that allows one to 78// selectively enable tracing statements. To use DPRINTF, there must 79// be a function or functor called name() that returns a const 80// std::string & in the current scope. 81// 82// If you desire that the automatic printing not occur, use DPRINTFR 83// (R for raw) 84// 85 86#if TRACING_ON 87 88#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled) 89 90#define DDUMP(x, data, count) do { \ 91 if (DTRACE(x)) \
|
189 Trace::dataDump(curTick, name(), data, count); \
| 92 Trace::dump(curTick, name(), data, count); \
|
190} while (0) 191 192#define DPRINTF(x, ...) do { \ 193 if (DTRACE(x)) \ 194 Trace::dprintf(curTick, name(), __VA_ARGS__); \ 195} while (0) 196 197#define DPRINTFR(x, ...) do { \ 198 if (DTRACE(x)) \ 199 Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 200} while (0) 201
| 93} while (0) 94 95#define DPRINTF(x, ...) do { \ 96 if (DTRACE(x)) \ 97 Trace::dprintf(curTick, name(), __VA_ARGS__); \ 98} while (0) 99 100#define DPRINTFR(x, ...) do { \ 101 if (DTRACE(x)) \ 102 Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 103} while (0) 104
|
| 105#define DDUMPN(data, count) do { \ 106 Trace::dump(curTick, name(), data, count); \ 107} while (0) 108
|
202#define DPRINTFN(...) do { \ 203 Trace::dprintf(curTick, name(), __VA_ARGS__); \ 204} while (0) 205 206#define DPRINTFNR(...) do { \ 207 Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 208} while (0) 209 210#else // !TRACING_ON 211 212#define DTRACE(x) (false)
| 109#define DPRINTFN(...) do { \ 110 Trace::dprintf(curTick, name(), __VA_ARGS__); \ 111} while (0) 112 113#define DPRINTFNR(...) do { \ 114 Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 115} while (0) 116 117#else // !TRACING_ON 118 119#define DTRACE(x) (false)
|
| 120#define DDUMP(x, data, count) do {} while (0)
|
213#define DPRINTF(x, ...) do {} while (0) 214#define DPRINTFR(...) do {} while (0)
| 121#define DPRINTF(x, ...) do {} while (0) 122#define DPRINTFR(...) do {} while (0)
|
| 123#define DDUMPN(data, count) do {} while (0)
|
215#define DPRINTFN(...) do {} while (0) 216#define DPRINTFNR(...) do {} while (0)
| 124#define DPRINTFN(...) do {} while (0) 125#define DPRINTFNR(...) do {} while (0)
|
217#define DDUMP(x, data, count) do {} while (0)
| |
218 219#endif // TRACING_ON 220 221#endif // __BASE_TRACE_HH__
| 126 127#endif // TRACING_ON 128 129#endif // __BASE_TRACE_HH__
|