3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __MEM_RUBY_DEBUG_HH__
35 #define __MEM_RUBY_DEBUG_HH__
42 #include "config/ruby_debug.hh"
43 #include "mem/ruby/common/Global.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};
77 Debug(const std::string & name, const std::vector<std::string> & argv);
78 Debug( const char *filterString, const char *verboseString,
79 Time filterStartTime, const char *filename );
85 static bool getProtocolTrace() { return m_protocol_trace; }
86 bool validDebug(int module, PriorityLevel priority);
87 void printVerbosity(std::ostream& out) const;
88 void setVerbosity(VerbosityLevel vb);
89 static bool checkVerbosityString(const char *verb_str);
90 bool setVerbosityString(const char *);
91 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
93 static bool checkFilter( char);
94 static bool checkFilterString(const char *);
95 bool setFilterString(const char *);
96 void setDebugTime(Time);
97 Time getDebugTime() const { return m_starting_cycle; }
101 void print(std::ostream& out) const;
102 /* old school debugging "vararg": sends messages to screen and log */
103 void debugMsg( const char *fmt, ... );
105 void setDebugOutputFile (const char * filename);
106 void closeDebugOutputFile ();
107 static void usageInstructions(void);
112 // Private copy constructor and assignment operator
113 Debug(const Debug& obj);
114 Debug& operator=(const Debug& obj);
116 // Data Members (m_ prefix)
117 static bool m_protocol_trace;
118 VerbosityLevel m_verbosityLevel;
120 Time m_starting_cycle;
125 // Output operator declaration
126 std::ostream& operator<<(std::ostream& out, const Debug& obj);
128 // ******************* Definitions *******************
130 // Output operator definition
132 std::ostream& operator<<(std::ostream& out, const Debug& obj)
139 const bool ERROR_MESSAGE_FLAG = true;
140 const bool WARNING_MESSAGE_FLAG = true;
142 #ifdef RUBY_NO_ASSERT
143 const bool ASSERT_FLAG = false;
145 const bool ASSERT_FLAG = true;
149 #define assert(EXPR) ASSERT(EXPR)
151 #define ASSERT(EXPR)\
155 cerr << "failed assertion '"\
156 << #EXPR << "' at fn "\
157 << __PRETTY_FUNCTION__ << " in "\
159 << __LINE__ << endl << flush;\
160 (* debug_cout_ptr) << "failed assertion '"\
161 << #EXPR << "' at fn "\
162 << __PRETTY_FUNCTION__ << " in "\
164 << __LINE__ << endl << flush;\
165 if(isatty(STDIN_FILENO)) {\
166 cerr << "At this point you might want to attach a debug to ";\
167 cerr << "the running and get to the" << endl;\
168 cerr << "crash site; otherwise press enter to continue" << endl;\
169 cerr << "PID: " << getpid();\
170 cerr << endl << flush; \
181 cerr << "breakpoint '"\
182 << #X << "' reached at fn "\
183 << __PRETTY_FUNCTION__ << " in "\
185 << __LINE__ << endl << flush;\
186 if(isatty(STDIN_FILENO)) {\
187 cerr << "press enter to continue" << endl;\
188 cerr << "PID: " << getpid();\
189 cerr << endl << flush; \
195 #define ERROR_MSG(MESSAGE)\
197 if (ERROR_MESSAGE_FLAG) {\
198 cerr << "Fatal Error: in fn "\
199 << __PRETTY_FUNCTION__ << " in "\
202 << (MESSAGE) << endl << flush;\
203 (* debug_cout_ptr) << "Fatal Error: in fn "\
204 << __PRETTY_FUNCTION__ << " in "\
207 << (MESSAGE) << endl << flush;\
212 #define WARN_MSG(MESSAGE)\
214 if (WARNING_MESSAGE_FLAG) {\
215 cerr << "Warning: in fn "\
216 << __PRETTY_FUNCTION__ << " in "\
219 << (MESSAGE) << endl << flush;\
220 (* debug_cout_ptr) << "Warning: in fn "\
221 << __PRETTY_FUNCTION__ << " in "\
224 << (MESSAGE) << endl << flush;\
228 #define WARN_EXPR(EXPR)\
230 if (WARNING_MESSAGE_FLAG) {\
231 cerr << "Warning: in fn "\
232 << __PRETTY_FUNCTION__ << " in "\
236 << (EXPR) << endl << flush;\
237 (* debug_cout_ptr) << "Warning: in fn "\
238 << __PRETTY_FUNCTION__ << " in "\
242 << (EXPR) << endl << flush;\
246 #define DEBUG_MSG(module, priority, MESSAGE)\
249 if (g_debug_ptr->validDebug(module, priority)) {\
250 (* debug_cout_ptr) << "Debug: in fn "\
251 << __PRETTY_FUNCTION__\
252 << " in " << __FILE__ << ":"\
254 << (MESSAGE) << endl << flush;\
259 #define DEBUG_EXPR(module, priority, EXPR)\
262 if (g_debug_ptr->validDebug(module, priority)) {\
263 (* debug_cout_ptr) << "Debug: in fn "\
264 << __PRETTY_FUNCTION__\
265 << " in " << __FILE__ << ":"\
268 << (EXPR) << endl << flush;\
273 #define DEBUG_NEWLINE(module, priority)\
276 if (g_debug_ptr->validDebug(module, priority)) {\
277 (* debug_cout_ptr) << endl << flush;\
282 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
285 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
286 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
291 #define DEBUG_OUT( rest... ) \
294 cout << "Debug: in fn "\
295 << __PRETTY_FUNCTION__\
296 << " in " << __FILE__ << ":"\
297 << __LINE__ << ": "; \
298 g_debug_ptr->debugMsg(rest); \
302 #define ERROR_OUT( rest... ) \
304 if (ERROR_MESSAGE_FLAG) {\
305 cout << "error: in fn "\
306 << __PRETTY_FUNCTION__ << " in "\
308 << __LINE__ << ": ";\
309 g_debug_ptr->debugMsg(rest); \