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__
40 #include "config/ruby_debug.hh"
41 #include "mem/ruby/common/Global.hh"
43 extern std::ostream * debug_cout_ptr;
45 // component enumeration
59 NETWORK_INTERNALS_COMP,
67 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
68 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
73 Debug( const char *filterString, const char *verboseString,
74 Time filterStartTime, const char *filename );
80 bool validDebug(int module, PriorityLevel priority);
81 void printVerbosity(ostream& out) const;
82 void setVerbosity(VerbosityLevel vb);
83 static bool checkVerbosityString(const char *verb_str);
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(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);
106 // Private copy constructor and assignment operator
107 Debug(const Debug& obj);
108 Debug& operator=(const Debug& obj);
110 // Data Members (m_ prefix)
111 VerbosityLevel m_verbosityLevel;
113 Time m_starting_cycle;
118 // Output operator declaration
119 ostream& operator<<(ostream& out, const Debug& obj);
121 // ******************* Definitions *******************
123 // Output operator definition
125 ostream& operator<<(ostream& out, const Debug& obj)
132 const bool ERROR_MESSAGE_FLAG = true;
133 const bool WARNING_MESSAGE_FLAG = true;
135 #ifdef RUBY_NO_ASSERT
136 const bool ASSERT_FLAG = false;
138 const bool ASSERT_FLAG = true;
142 #define assert(EXPR) ASSERT(EXPR)
144 #define ASSERT(EXPR)\
148 cerr << "failed assertion '"\
149 << #EXPR << "' at fn "\
150 << __PRETTY_FUNCTION__ << " in "\
152 << __LINE__ << endl << flush;\
153 (* debug_cout_ptr) << "failed assertion '"\
154 << #EXPR << "' at fn "\
155 << __PRETTY_FUNCTION__ << " in "\
157 << __LINE__ << endl << flush;\
158 if(isatty(STDERR_FILENO)) {\
159 cerr << "At this point you might want to attach a debug to ";\
160 cerr << "the running and get to the" << endl;\
161 cerr << "crash site; otherwise press enter to continue" << endl;\
162 cerr << "PID: " << getpid();\
163 cerr << endl << flush; \
174 cerr << "breakpoint '"\
175 << #X << "' reached at fn "\
176 << __PRETTY_FUNCTION__ << " in "\
178 << __LINE__ << endl << flush;\
179 if(isatty(STDERR_FILENO)) {\
180 cerr << "press enter to continue" << endl;\
181 cerr << "PID: " << getpid();\
182 cerr << endl << flush; \
188 #define ERROR_MSG(MESSAGE)\
190 if (ERROR_MESSAGE_FLAG) {\
191 cerr << "Fatal Error: in fn "\
192 << __PRETTY_FUNCTION__ << " in "\
195 << (MESSAGE) << endl << flush;\
196 (* debug_cout_ptr) << "Fatal Error: in fn "\
197 << __PRETTY_FUNCTION__ << " in "\
200 << (MESSAGE) << endl << flush;\
205 #define WARN_MSG(MESSAGE)\
207 if (WARNING_MESSAGE_FLAG) {\
208 cerr << "Warning: in fn "\
209 << __PRETTY_FUNCTION__ << " in "\
212 << (MESSAGE) << endl << flush;\
213 (* debug_cout_ptr) << "Warning: in fn "\
214 << __PRETTY_FUNCTION__ << " in "\
217 << (MESSAGE) << endl << flush;\
221 #define WARN_EXPR(EXPR)\
223 if (WARNING_MESSAGE_FLAG) {\
224 cerr << "Warning: in fn "\
225 << __PRETTY_FUNCTION__ << " in "\
229 << (EXPR) << endl << flush;\
230 (* debug_cout_ptr) << "Warning: in fn "\
231 << __PRETTY_FUNCTION__ << " in "\
235 << (EXPR) << endl << flush;\
239 #define DEBUG_MSG(module, priority, MESSAGE)\
242 if (g_debug_ptr->validDebug(module, priority)) {\
243 (* debug_cout_ptr) << "Debug: in fn "\
244 << __PRETTY_FUNCTION__\
245 << " in " << __FILE__ << ":"\
247 << (MESSAGE) << endl << flush;\
252 #define DEBUG_EXPR(module, priority, EXPR)\
255 if (g_debug_ptr->validDebug(module, priority)) {\
256 (* debug_cout_ptr) << "Debug: in fn "\
257 << __PRETTY_FUNCTION__\
258 << " in " << __FILE__ << ":"\
261 << (EXPR) << endl << flush;\
266 #define DEBUG_NEWLINE(module, priority)\
269 if (g_debug_ptr->validDebug(module, priority)) {\
270 (* debug_cout_ptr) << endl << flush;\
275 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
278 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
279 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
284 #define DEBUG_OUT( rest... ) \
287 cout << "Debug: in fn "\
288 << __PRETTY_FUNCTION__\
289 << " in " << __FILE__ << ":"\
290 << __LINE__ << ": "; \
291 g_debug_ptr->debugMsg(rest); \
295 #define ERROR_OUT( rest... ) \
297 if (ERROR_MESSAGE_FLAG) {\
298 cout << "error: in fn "\
299 << __PRETTY_FUNCTION__ << " in "\
301 << __LINE__ << ": ";\
302 g_debug_ptr->debugMsg(rest); \
306 #endif // __MEM_RUBY_DEBUG_HH__