2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 __MEM_RUBY_COMMON_DEBUG_HH__
30 #define __MEM_RUBY_COMMON_DEBUG_HH__
39 #include "config/ruby_debug.hh"
40 #include "mem/ruby/common/Global.hh"
41 #include "sim/sim_object.hh"
43 #include "params/RubyDebug.hh"
45 extern std::ostream * debug_cout_ptr;
47 // component enumeration
61 NETWORK_INTERNALS_COMP,
70 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
71 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
73 class Debug : public SimObject
76 typedef RubyDebugParams Params;
77 Debug(const Params *p);
80 static bool getProtocolTrace() { return m_protocol_trace; }
81 bool validDebug(int module, PriorityLevel priority);
82 void printVerbosity(std::ostream& out) const;
83 void setVerbosity(VerbosityLevel vb);
84 bool setVerbosityString(const char *);
85 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
87 static bool checkFilter( char);
88 static bool checkFilterString(const char *);
89 bool setFilterString(const char *);
90 void setDebugTime(Time);
91 Time getDebugTime() const { return m_starting_cycle; }
95 void print(std::ostream& out) const;
96 /* old school debugging "vararg": sends messages to screen and log */
97 void debugMsg(const char *fmt, ...);
99 void setDebugOutputFile (const char * filename);
100 void closeDebugOutputFile ();
101 static void usageInstructions(void);
104 // Private copy constructor and assignment operator
105 Debug(const Debug& obj);
106 Debug& operator=(const Debug& obj);
108 static bool m_protocol_trace;
109 VerbosityLevel m_verbosityLevel;
111 Time m_starting_cycle;
117 operator<<(std::ostream& out, const Debug& obj)
124 const bool ERROR_MESSAGE_FLAG = true;
125 const bool WARNING_MESSAGE_FLAG = true;
127 #ifdef RUBY_NO_ASSERT
128 const bool ASSERT_FLAG = false;
130 const bool ASSERT_FLAG = true;
134 #define assert(EXPR) ASSERT(EXPR)
136 #define ASSERT(EXPR) do { \
137 using namespace std; \
140 cerr << "failed assertion '" \
141 << #EXPR << "' at fn " \
142 << __PRETTY_FUNCTION__ << " in " \
144 << __LINE__ << endl << flush; \
145 (*debug_cout_ptr) << "failed assertion '" \
146 << #EXPR << "' at fn " \
147 << __PRETTY_FUNCTION__ << " in " \
149 << __LINE__ << endl << flush; \
150 if (isatty(STDIN_FILENO)) { \
151 cerr << "At this point you might want to attach a debug to " \
152 << "the running and get to the" << endl \
153 << "crash site; otherwise press enter to continue" \
155 << "PID: " << getpid() \
165 #define BREAK(X) do { \
166 using namespace std; \
167 cerr << "breakpoint '" \
168 << #X << "' reached at fn " \
169 << __PRETTY_FUNCTION__ << " in " \
171 << __LINE__ << endl << flush; \
172 if(isatty(STDIN_FILENO)) { \
173 cerr << "press enter to continue" << endl; \
174 cerr << "PID: " << getpid(); \
175 cerr << endl << flush; \
181 #define ERROR_MSG(MESSAGE) do { \
182 using namespace std; \
183 if (ERROR_MESSAGE_FLAG) { \
184 cerr << "Fatal Error: in fn " \
185 << __PRETTY_FUNCTION__ << " in " \
187 << __LINE__ << ": " \
188 << (MESSAGE) << endl << flush; \
189 (* debug_cout_ptr) << "Fatal Error: in fn " \
190 << __PRETTY_FUNCTION__ << " in " \
192 << __LINE__ << ": " \
193 << (MESSAGE) << endl << flush; \
198 #define WARN_MSG(MESSAGE) do { \
199 using namespace std; \
200 if (WARNING_MESSAGE_FLAG) { \
201 cerr << "Warning: in fn " \
202 << __PRETTY_FUNCTION__ << " in " \
204 << __LINE__ << ": " \
205 << (MESSAGE) << endl << flush; \
206 (* debug_cout_ptr) << "Warning: in fn " \
207 << __PRETTY_FUNCTION__ << " in " \
209 << __LINE__ << ": " \
210 << (MESSAGE) << endl << flush; \
214 #define WARN_EXPR(EXPR) do { \
215 using namespace std; \
216 if (WARNING_MESSAGE_FLAG) { \
217 cerr << "Warning: in fn " \
218 << __PRETTY_FUNCTION__ << " in " \
220 << __LINE__ << ": " \
222 << (EXPR) << endl << flush; \
223 (* debug_cout_ptr) << "Warning: in fn " \
224 << __PRETTY_FUNCTION__ << " in " \
226 << __LINE__ << ": " \
228 << (EXPR) << endl << flush; \
232 #define DEBUG_MSG(module, priority, MESSAGE) do { \
233 using namespace std; \
235 if (g_debug_ptr->validDebug(module, priority)) { \
236 (* debug_cout_ptr) << "Debug: in fn " \
237 << __PRETTY_FUNCTION__ \
238 << " in " << __FILE__ << ":" \
239 << __LINE__ << ": " \
240 << (MESSAGE) << endl << flush; \
245 #define DEBUG_EXPR(module, priority, EXPR) do { \
246 using namespace std; \
248 if (g_debug_ptr->validDebug(module, priority)) { \
249 (* debug_cout_ptr) << "Debug: in fn " \
250 << __PRETTY_FUNCTION__ \
251 << " in " << __FILE__ << ":" \
252 << __LINE__ << ": " \
254 << (EXPR) << endl << flush; \
259 #define DEBUG_NEWLINE(module, priority) do { \
260 using namespace std; \
262 if (g_debug_ptr->validDebug(module, priority)) { \
263 (* debug_cout_ptr) << endl << flush; \
268 #define DEBUG_SLICC(priority, LINE, MESSAGE) do { \
269 using namespace std; \
271 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) { \
272 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush; \
277 #define DEBUG_OUT(rest... ) do { \
278 using namespace std; \
280 cout << "Debug: in fn " \
281 << __PRETTY_FUNCTION__ \
282 << " in " << __FILE__ << ":" \
283 << __LINE__ << ": "; \
284 g_debug_ptr->debugMsg(rest); \
288 #define ERROR_OUT( rest... ) do { \
289 using namespace std; \
290 if (ERROR_MESSAGE_FLAG) { \
291 cout << "error: in fn " \
292 << __PRETTY_FUNCTION__ << " in " \
294 << __LINE__ << ": "; \
295 g_debug_ptr->debugMsg(rest); \
299 #endif // __MEM_RUBY_COMMON_DEBUG_HH__