2 * Copyright (c) 2001-2006 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.
28 * Authors: Nathan Binkert
32 #ifndef __BASE_TRACE_HH__
33 #define __BASE_TRACE_HH__
37 #include "base/cprintf.hh"
38 #include "base/debug.hh"
39 #include "base/match.hh"
40 #include "base/types.hh"
41 #include "sim/core.hh"
45 using Debug::SimpleFlag;
46 using Debug::CompoundFlag;
48 std::ostream &output();
49 void setOutput(const std::string &filename);
52 bool changeFlag(const char *str, bool value);
55 extern ObjectMatch ignore;
56 extern const std::string DefaultName;
58 void dprintf(Tick when, const std::string &name, const char *format,
60 void dump(Tick when, const std::string &name, const void *data, int len);
64 // This silly little class allows us to wrap a string in a functor
65 // object so that we can give a name() that DPRINTF will like
69 StringWrap(const std::string &s) : str(s) {}
70 const std::string &operator()() const { return str; }
73 inline const std::string &name() { return Trace::DefaultName; }
76 // DPRINTF is a debugging trace facility that allows one to
77 // selectively enable tracing statements. To use DPRINTF, there must
78 // be a function or functor called name() that returns a const
79 // std::string & in the current scope.
81 // If you desire that the automatic printing not occur, use DPRINTFR
87 #define DTRACE(x) ((Debug::x) && Trace::enabled)
89 #define DDUMP(x, data, count) do { \
90 using namespace Debug; \
92 Trace::dump(curTick(), name(), data, count); \
95 #define DPRINTF(x, ...) do { \
96 using namespace Debug; \
98 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
101 #define DPRINTFS(x, s, ...) do { \
102 using namespace Debug; \
104 Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \
107 #define DPRINTFR(x, ...) do { \
108 using namespace Debug; \
110 Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
113 #define DDUMPN(data, count) do { \
114 Trace::dump(curTick(), name(), data, count); \
117 #define DPRINTFN(...) do { \
118 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
121 #define DPRINTFNR(...) do { \
122 Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \
127 #define DTRACE(x) (false)
128 #define DDUMP(x, data, count) do {} while (0)
129 #define DPRINTF(x, ...) do {} while (0)
130 #define DPRINTFS(x, ...) do {} while (0)
131 #define DPRINTFR(...) do {} while (0)
132 #define DDUMPN(data, count) do {} while (0)
133 #define DPRINTFN(...) do {} while (0)
134 #define DPRINTFNR(...) do {} while (0)
138 #endif // __BASE_TRACE_HH__