2 * Copyright (c) 2001-2004 The Regents of The University of Michigan
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.
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.
29 #ifndef __BASE_TRACE_HH__
30 #define __BASE_TRACE_HH__
34 #include "base/cprintf.hh"
35 #include "base/match.hh"
36 #include "sim/host.hh"
37 #include "sim/universe.hh"
47 #include "base/traceflags.hh"
51 typedef std::vector<bool> FlagVec;
58 const bool On = false;
68 void dump(const uint8_t *data, int count);
83 virtual void dump(std::ostream &) = 0;
86 class PrintfRecord : public Record
90 const std::string &name;
94 PrintfRecord(const char *_format, cp::ArgList &_args,
95 Tick cycle, const std::string &_name)
96 : Record(cycle), format(_format), name(_name), args(_args)
100 virtual ~PrintfRecord();
102 virtual void dump(std::ostream &);
105 class DataRecord : public Record
108 const std::string &name;
113 DataRecord(Tick cycle, const std::string &name,
114 const void *_data, int _len);
115 virtual ~DataRecord();
117 virtual void dump(std::ostream &);
123 int size; // number of records in log
124 Record **buffer; // array of 'size' Record ptrs (circular buf)
125 Record **nextRecPtr; // next slot to use in buffer
126 Record **wrapRecPtr; // &buffer[size], for quick wrap check
133 void init(int _size);
135 void append(Record *); // append trace record to log
136 void dump(std::ostream &); // dump contents to stream
141 extern ObjectMatch ignore;
144 dprintf(const char *format, cp::ArgList &args, Tick cycle,
145 const std::string &name)
147 if (name.empty() || !ignore.match(name))
148 theLog.append(new Trace::PrintfRecord(format, args, cycle, name));
152 dataDump(Tick cycle, const std::string &name, const void *data, int len)
154 theLog.append(new Trace::DataRecord(cycle, name, data, len));
157 extern const std::string DefaultName;
160 // This silly little class allows us to wrap a string in a functor
161 // object so that we can give a name() that DPRINTF will like
165 StringWrap(const std::string &s) : str(s) {}
166 const std::string &operator()() const { return str; }
169 inline const std::string &name() { return Trace::DefaultName; }
170 std::ostream &DebugOut();
173 // DPRINTF is a debugging trace facility that allows one to
174 // selectively enable tracing statements. To use DPRINTF, there must
175 // be a function or functor called name() that returns a const
176 // std::string & in the current scope.
178 // If you desire that the automatic printing not occur, use DPRINTFR
184 #define DTRACE(x) (Trace::IsOn(Trace::x))
186 #define DCOUT(x) if (Trace::IsOn(Trace::x)) DebugOut()
188 #define DDUMP(x, data, count) \
190 if (Trace::IsOn(Trace::x)) \
191 Trace::dataDump(curTick, name(), data, count); \
194 #define __dprintf(cycle, name, format, args...) \
195 Trace::dprintf(format, (*(new cp::ArgList), args), cycle, name)
197 #define DPRINTF(x, args...) \
199 if (Trace::IsOn(Trace::x)) \
200 __dprintf(curTick, name(), args, cp::ArgListNull()); \
203 #define DPRINTFR(x, args...) \
205 if (Trace::IsOn(Trace::x)) \
206 __dprintf((Tick)-1, string(), args, cp::ArgListNull()); \
209 #define DPRINTFN(args...) \
211 __dprintf(curTick, name(), args, cp::ArgListNull()); \
214 #define DPRINTFNR(args...) \
216 __dprintf((Tick)-1, string(), args, cp::ArgListNull()); \
221 #define DTRACE(x) (false)
222 #define DCOUT(x) if (0) DebugOut()
223 #define DPRINTF(x, args...) do {} while (0)
224 #define DPRINTFR(args...) do {} while (0)
225 #define DPRINTFN(args...) do {} while (0)
226 #define DPRINTFNR(args...) do {} while (0)
227 #define DDUMP(x, data, count) do {} while (0)
231 #endif // __BASE_TRACE_HH__