trace.hh (10259:ebb376f73dd2) trace.hh (10292:933dfb9d8279)
1/*
1/*
2 * Copyright (c) 2014 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
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>
36
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"
42
43namespace Trace {
44
45using Debug::SimpleFlag;
46using Debug::CompoundFlag;
47
48std::ostream &output();
49void setOutput(const std::string &filename);
50
51extern bool enabled;
52bool changeFlag(const char *str, bool value);
53void dumpStatus();
54
55extern ObjectMatch ignore;
56extern const std::string DefaultName;
57
14 * Copyright (c) 2001-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Nathan Binkert
41 * Steve Reinhardt
42 */
43
44#ifndef __BASE_TRACE_HH__
45#define __BASE_TRACE_HH__
46
47#include <string>
48
49#include "base/cprintf.hh"
50#include "base/debug.hh"
51#include "base/match.hh"
52#include "base/types.hh"
53#include "sim/core.hh"
54
55namespace Trace {
56
57using Debug::SimpleFlag;
58using Debug::CompoundFlag;
59
60std::ostream &output();
61void setOutput(const std::string &filename);
62
63extern bool enabled;
64bool changeFlag(const char *str, bool value);
65void dumpStatus();
66
67extern ObjectMatch ignore;
68extern const std::string DefaultName;
69
58void dprintf(Tick when, const std::string &name, const char *format,
59 CPRINTF_DECLARATION);
70bool __dprintf_prologue(Tick when, const std::string &name);
71
72template<typename ...Args> void
73dprintf(Tick when, const std::string &name, const char *format,
74 const Args &...args)
75{
76 if (!__dprintf_prologue(when, name))
77 return;
78
79 std::ostream &os(output());
80 ccprintf(os, format, args...);
81 os.flush();
82}
83
60void dump(Tick when, const std::string &name, const void *data, int len);
61
62} // namespace Trace
63
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
66struct StringWrap
67{
68 std::string str;
69 StringWrap(const std::string &s) : str(s) {}
70 const std::string &operator()() const { return str; }
71};
72
73inline const std::string &name() { return Trace::DefaultName; }
74
75// Interface for things with names. (cf. SimObject but without other
76// functionality). This is useful when using DPRINTF
77class Named
78{
79 protected:
80 const std::string _name;
81
82 public:
83 Named(const std::string &name_) : _name(name_) { }
84
85 public:
86 const std::string &name() const { return _name; }
87};
88
89//
90// DPRINTF is a debugging trace facility that allows one to
91// selectively enable tracing statements. To use DPRINTF, there must
92// be a function or functor called name() that returns a const
93// std::string & in the current scope.
94//
95// If you desire that the automatic printing not occur, use DPRINTFR
96// (R for raw)
97//
98
99#if TRACING_ON
100
101#define DTRACE(x) ((Debug::x) && Trace::enabled)
102
103#define DDUMP(x, data, count) do { \
104 using namespace Debug; \
105 if (DTRACE(x)) \
106 Trace::dump(curTick(), name(), data, count); \
107} while (0)
108
109#define DPRINTF(x, ...) do { \
110 using namespace Debug; \
111 if (DTRACE(x)) \
112 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
113} while (0)
114
115#define DPRINTFS(x, s, ...) do { \
116 using namespace Debug; \
117 if (DTRACE(x)) \
118 Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \
119} while (0)
120
121#define DPRINTFR(x, ...) do { \
122 using namespace Debug; \
123 if (DTRACE(x)) \
124 Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
125} while (0)
126
127#define DDUMPN(data, count) do { \
128 Trace::dump(curTick(), name(), data, count); \
129} while (0)
130
131#define DPRINTFN(...) do { \
132 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
133} while (0)
134
135#define DPRINTFNR(...) do { \
136 Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \
137} while (0)
138
139#else // !TRACING_ON
140
141#define DTRACE(x) (false)
142#define DDUMP(x, data, count) do {} while (0)
143#define DPRINTF(x, ...) do {} while (0)
144#define DPRINTFS(x, ...) do {} while (0)
145#define DPRINTFR(...) do {} while (0)
146#define DDUMPN(data, count) do {} while (0)
147#define DPRINTFN(...) do {} while (0)
148#define DPRINTFNR(...) do {} while (0)
149
150#endif // TRACING_ON
151
152#endif // __BASE_TRACE_HH__
84void dump(Tick when, const std::string &name, const void *data, int len);
85
86} // namespace Trace
87
88// This silly little class allows us to wrap a string in a functor
89// object so that we can give a name() that DPRINTF will like
90struct StringWrap
91{
92 std::string str;
93 StringWrap(const std::string &s) : str(s) {}
94 const std::string &operator()() const { return str; }
95};
96
97inline const std::string &name() { return Trace::DefaultName; }
98
99// Interface for things with names. (cf. SimObject but without other
100// functionality). This is useful when using DPRINTF
101class Named
102{
103 protected:
104 const std::string _name;
105
106 public:
107 Named(const std::string &name_) : _name(name_) { }
108
109 public:
110 const std::string &name() const { return _name; }
111};
112
113//
114// DPRINTF is a debugging trace facility that allows one to
115// selectively enable tracing statements. To use DPRINTF, there must
116// be a function or functor called name() that returns a const
117// std::string & in the current scope.
118//
119// If you desire that the automatic printing not occur, use DPRINTFR
120// (R for raw)
121//
122
123#if TRACING_ON
124
125#define DTRACE(x) ((Debug::x) && Trace::enabled)
126
127#define DDUMP(x, data, count) do { \
128 using namespace Debug; \
129 if (DTRACE(x)) \
130 Trace::dump(curTick(), name(), data, count); \
131} while (0)
132
133#define DPRINTF(x, ...) do { \
134 using namespace Debug; \
135 if (DTRACE(x)) \
136 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
137} while (0)
138
139#define DPRINTFS(x, s, ...) do { \
140 using namespace Debug; \
141 if (DTRACE(x)) \
142 Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \
143} while (0)
144
145#define DPRINTFR(x, ...) do { \
146 using namespace Debug; \
147 if (DTRACE(x)) \
148 Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
149} while (0)
150
151#define DDUMPN(data, count) do { \
152 Trace::dump(curTick(), name(), data, count); \
153} while (0)
154
155#define DPRINTFN(...) do { \
156 Trace::dprintf(curTick(), name(), __VA_ARGS__); \
157} while (0)
158
159#define DPRINTFNR(...) do { \
160 Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \
161} while (0)
162
163#else // !TRACING_ON
164
165#define DTRACE(x) (false)
166#define DDUMP(x, data, count) do {} while (0)
167#define DPRINTF(x, ...) do {} while (0)
168#define DPRINTFS(x, ...) do {} while (0)
169#define DPRINTFR(...) do {} while (0)
170#define DDUMPN(data, count) do {} while (0)
171#define DPRINTFN(...) do {} while (0)
172#define DPRINTFNR(...) do {} while (0)
173
174#endif // TRACING_ON
175
176#endif // __BASE_TRACE_HH__