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,
69 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
70 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
72 class Debug : public SimObject
75 typedef RubyDebugParams Params;
76 Debug(const Params *p);
79 static bool getProtocolTrace() { return m_protocol_trace; }
80 bool validDebug(int module, PriorityLevel priority);
81 void printVerbosity(std::ostream& out) const;
82 void setVerbosity(VerbosityLevel vb);
83 bool setVerbosityString(const char *);
84 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
86 static bool checkFilter( char);
87 static bool checkFilterString(const char *);
88 bool setFilterString(const char *);
89 void setDebugTime(Time);
90 Time getDebugTime() const { return m_starting_cycle; }
94 void print(std::ostream& out) const;
95 /* old school debugging "vararg": sends messages to screen and log */
96 void debugMsg(const char *fmt, ...);
98 void setDebugOutputFile (const char * filename);
99 void closeDebugOutputFile ();
100 static void usageInstructions(void);
103 // Private copy constructor and assignment operator
104 Debug(const Debug& obj);
105 Debug& operator=(const Debug& obj);
107 static bool m_protocol_trace;
108 VerbosityLevel m_verbosityLevel;
110 Time m_starting_cycle;
116 operator<<(std::ostream& out, const Debug& obj)
123 const bool ERROR_MESSAGE_FLAG = true;
124 const bool WARNING_MESSAGE_FLAG = true;
126 #ifdef RUBY_NO_ASSERT
127 const bool ASSERT_FLAG = false;
129 const bool ASSERT_FLAG = true;
133 #define assert(EXPR) ASSERT(EXPR)
135 #define ASSERT(EXPR) do { \
136 using namespace std; \
139 cerr << "failed assertion '" \
140 << #EXPR << "' at fn " \
141 << __PRETTY_FUNCTION__ << " in " \
143 << __LINE__ << endl << flush; \
144 (*debug_cout_ptr) << "failed assertion '" \
145 << #EXPR << "' at fn " \
146 << __PRETTY_FUNCTION__ << " in " \
148 << __LINE__ << endl << flush; \
149 if (isatty(STDIN_FILENO)) { \
150 cerr << "At this point you might want to attach a debug to " \
151 << "the running and get to the" << endl \
152 << "crash site; otherwise press enter to continue" \
154 << "PID: " << getpid() \
164 #define BREAK(X) do { \
165 using namespace std; \
166 cerr << "breakpoint '" \
167 << #X << "' reached at fn " \
168 << __PRETTY_FUNCTION__ << " in " \
170 << __LINE__ << endl << flush; \
171 if(isatty(STDIN_FILENO)) { \
172 cerr << "press enter to continue" << endl; \
173 cerr << "PID: " << getpid(); \
174 cerr << endl << flush; \
180 #define ERROR_MSG(MESSAGE) do { \
181 using namespace std; \
182 if (ERROR_MESSAGE_FLAG) { \
183 cerr << "Fatal Error: in fn " \
184 << __PRETTY_FUNCTION__ << " in " \
186 << __LINE__ << ": " \
187 << (MESSAGE) << endl << flush; \
188 (* debug_cout_ptr) << "Fatal Error: in fn " \
189 << __PRETTY_FUNCTION__ << " in " \
191 << __LINE__ << ": " \
192 << (MESSAGE) << endl << flush; \
197 #define WARN_MSG(MESSAGE) do { \
198 using namespace std; \
199 if (WARNING_MESSAGE_FLAG) { \
200 cerr << "Warning: in fn " \
201 << __PRETTY_FUNCTION__ << " in " \
203 << __LINE__ << ": " \
204 << (MESSAGE) << endl << flush; \
205 (* debug_cout_ptr) << "Warning: in fn " \
206 << __PRETTY_FUNCTION__ << " in " \
208 << __LINE__ << ": " \
209 << (MESSAGE) << endl << flush; \
213 #define WARN_EXPR(EXPR) do { \
214 using namespace std; \
215 if (WARNING_MESSAGE_FLAG) { \
216 cerr << "Warning: in fn " \
217 << __PRETTY_FUNCTION__ << " in " \
219 << __LINE__ << ": " \
221 << (EXPR) << endl << flush; \
222 (* debug_cout_ptr) << "Warning: in fn " \
223 << __PRETTY_FUNCTION__ << " in " \
225 << __LINE__ << ": " \
227 << (EXPR) << endl << flush; \
231 #define DEBUG_MSG(module, priority, MESSAGE) do { \
232 using namespace std; \
234 if (g_debug_ptr->validDebug(module, priority)) { \
235 (* debug_cout_ptr) << "Debug: in fn " \
236 << __PRETTY_FUNCTION__ \
237 << " in " << __FILE__ << ":" \
238 << __LINE__ << ": " \
239 << (MESSAGE) << endl << flush; \
244 #define DEBUG_EXPR(module, priority, EXPR) do { \
245 using namespace std; \
247 if (g_debug_ptr->validDebug(module, priority)) { \
248 (* debug_cout_ptr) << "Debug: in fn " \
249 << __PRETTY_FUNCTION__ \
250 << " in " << __FILE__ << ":" \
251 << __LINE__ << ": " \
253 << (EXPR) << endl << flush; \
258 #define DEBUG_NEWLINE(module, priority) do { \
259 using namespace std; \
261 if (g_debug_ptr->validDebug(module, priority)) { \
262 (* debug_cout_ptr) << endl << flush; \
267 #define DEBUG_SLICC(priority, LINE, MESSAGE) do { \
268 using namespace std; \
270 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) { \
271 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush; \
276 #define DEBUG_OUT(rest... ) do { \
277 using namespace std; \
279 cout << "Debug: in fn " \
280 << __PRETTY_FUNCTION__ \
281 << " in " << __FILE__ << ":" \
282 << __LINE__ << ": "; \
283 g_debug_ptr->debugMsg(rest); \
287 #define ERROR_OUT( rest... ) do { \
288 using namespace std; \
289 if (ERROR_MESSAGE_FLAG) { \
290 cout << "error: in fn " \
291 << __PRETTY_FUNCTION__ << " in " \
293 << __LINE__ << ": "; \
294 g_debug_ptr->debugMsg(rest); \
298 #endif // __MEM_RUBY_COMMON_DEBUG_HH__