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,
69 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
70 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
76 Debug(const std::string & name, const std::vector<std::string> & argv);
77 Debug( const char *filterString, const char *verboseString,
78 Time filterStartTime, const char *filename );
84 static bool getProtocolTrace() { return m_protocol_trace; }
85 bool validDebug(int module, PriorityLevel priority);
86 void printVerbosity(std::ostream& out) const;
87 void setVerbosity(VerbosityLevel vb);
88 static bool checkVerbosityString(const char *verb_str);
89 bool setVerbosityString(const char *);
90 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
92 static bool checkFilter( char);
93 static bool checkFilterString(const char *);
94 bool setFilterString(const char *);
95 void setDebugTime(Time);
96 Time getDebugTime() const { return m_starting_cycle; }
100 void print(std::ostream& out) const;
101 /* old school debugging "vararg": sends messages to screen and log */
102 void debugMsg( const char *fmt, ... );
104 void setDebugOutputFile (const char * filename);
105 void closeDebugOutputFile ();
106 static void usageInstructions(void);
111 // Private copy constructor and assignment operator
112 Debug(const Debug& obj);
113 Debug& operator=(const Debug& obj);
115 // Data Members (m_ prefix)
116 static bool m_protocol_trace;
117 VerbosityLevel m_verbosityLevel;
119 Time m_starting_cycle;
124 // Output operator declaration
125 std::ostream& operator<<(std::ostream& out, const Debug& obj);
127 // ******************* Definitions *******************
129 // Output operator definition
131 std::ostream& operator<<(std::ostream& out, const Debug& obj)
138 const bool ERROR_MESSAGE_FLAG = true;
139 const bool WARNING_MESSAGE_FLAG = true;
141 #ifdef RUBY_NO_ASSERT
142 const bool ASSERT_FLAG = false;
144 const bool ASSERT_FLAG = true;
148 #define assert(EXPR) ASSERT(EXPR)
150 #define ASSERT(EXPR)\
154 cerr << "failed assertion '"\
155 << #EXPR << "' at fn "\
156 << __PRETTY_FUNCTION__ << " in "\
158 << __LINE__ << endl << flush;\
159 (* debug_cout_ptr) << "failed assertion '"\
160 << #EXPR << "' at fn "\
161 << __PRETTY_FUNCTION__ << " in "\
163 << __LINE__ << endl << flush;\
164 if(isatty(STDIN_FILENO)) {\
165 cerr << "At this point you might want to attach a debug to ";\
166 cerr << "the running and get to the" << endl;\
167 cerr << "crash site; otherwise press enter to continue" << endl;\
168 cerr << "PID: " << getpid();\
169 cerr << endl << flush; \
180 cerr << "breakpoint '"\
181 << #X << "' reached at fn "\
182 << __PRETTY_FUNCTION__ << " in "\
184 << __LINE__ << endl << flush;\
185 if(isatty(STDIN_FILENO)) {\
186 cerr << "press enter to continue" << endl;\
187 cerr << "PID: " << getpid();\
188 cerr << endl << flush; \
194 #define ERROR_MSG(MESSAGE)\
196 if (ERROR_MESSAGE_FLAG) {\
197 cerr << "Fatal Error: in fn "\
198 << __PRETTY_FUNCTION__ << " in "\
201 << (MESSAGE) << endl << flush;\
202 (* debug_cout_ptr) << "Fatal Error: in fn "\
203 << __PRETTY_FUNCTION__ << " in "\
206 << (MESSAGE) << endl << flush;\
211 #define WARN_MSG(MESSAGE)\
213 if (WARNING_MESSAGE_FLAG) {\
214 cerr << "Warning: in fn "\
215 << __PRETTY_FUNCTION__ << " in "\
218 << (MESSAGE) << endl << flush;\
219 (* debug_cout_ptr) << "Warning: in fn "\
220 << __PRETTY_FUNCTION__ << " in "\
223 << (MESSAGE) << endl << flush;\
227 #define WARN_EXPR(EXPR)\
229 if (WARNING_MESSAGE_FLAG) {\
230 cerr << "Warning: in fn "\
231 << __PRETTY_FUNCTION__ << " in "\
235 << (EXPR) << endl << flush;\
236 (* debug_cout_ptr) << "Warning: in fn "\
237 << __PRETTY_FUNCTION__ << " in "\
241 << (EXPR) << endl << flush;\
245 #define DEBUG_MSG(module, priority, MESSAGE)\
248 if (g_debug_ptr->validDebug(module, priority)) {\
249 (* debug_cout_ptr) << "Debug: in fn "\
250 << __PRETTY_FUNCTION__\
251 << " in " << __FILE__ << ":"\
253 << (MESSAGE) << endl << flush;\
258 #define DEBUG_EXPR(module, priority, EXPR)\
261 if (g_debug_ptr->validDebug(module, priority)) {\
262 (* debug_cout_ptr) << "Debug: in fn "\
263 << __PRETTY_FUNCTION__\
264 << " in " << __FILE__ << ":"\
267 << (EXPR) << endl << flush;\
272 #define DEBUG_NEWLINE(module, priority)\
275 if (g_debug_ptr->validDebug(module, priority)) {\
276 (* debug_cout_ptr) << endl << flush;\
281 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
284 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
285 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
290 #define DEBUG_OUT( rest... ) \
293 cout << "Debug: in fn "\
294 << __PRETTY_FUNCTION__\
295 << " in " << __FILE__ << ":"\
296 << __LINE__ << ": "; \
297 g_debug_ptr->debugMsg(rest); \
301 #define ERROR_OUT( rest... ) \
303 if (ERROR_MESSAGE_FLAG) {\
304 cout << "error: in fn "\
305 << __PRETTY_FUNCTION__ << " in "\
307 << __LINE__ << ": ";\
308 g_debug_ptr->debugMsg(rest); \