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.
40 #include "config/ruby_debug.hh"
42 extern std::ostream * debug_cout_ptr;
44 // component enumeration
58 NETWORK_INTERNALS_COMP,
66 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
67 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
72 Debug( const char *filterString, const char *verboseString,
73 Time filterStartTime, const char *filename );
79 bool validDebug(int module, PriorityLevel priority);
80 void printVerbosity(ostream& out) const;
81 void setVerbosity(VerbosityLevel vb);
82 static bool checkVerbosityString(const char *verb_str);
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(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);
105 // Private copy constructor and assignment operator
106 Debug(const Debug& obj);
107 Debug& operator=(const Debug& obj);
109 // Data Members (m_ prefix)
110 VerbosityLevel m_verbosityLevel;
112 Time m_starting_cycle;
117 // Output operator declaration
118 ostream& operator<<(ostream& out, const Debug& obj);
120 // ******************* Definitions *******************
122 // Output operator definition
124 ostream& operator<<(ostream& out, const Debug& obj)
131 const bool ERROR_MESSAGE_FLAG = true;
132 const bool WARNING_MESSAGE_FLAG = true;
134 #ifdef RUBY_NO_ASSERT
135 const bool ASSERT_FLAG = false;
137 const bool ASSERT_FLAG = true;
141 #define assert(EXPR) ASSERT(EXPR)
143 #define ASSERT(EXPR)\
147 cerr << "failed assertion '"\
148 << #EXPR << "' at fn "\
149 << __PRETTY_FUNCTION__ << " in "\
151 << __LINE__ << endl << flush;\
152 (* debug_cout_ptr) << "failed assertion '"\
153 << #EXPR << "' at fn "\
154 << __PRETTY_FUNCTION__ << " in "\
156 << __LINE__ << endl << flush;\
157 if(isatty(STDIN_FILENO)) {\
158 cerr << "At this point you might want to attach a debug to ";\
159 cerr << "the running and get to the" << endl;\
160 cerr << "crash site; otherwise press enter to continue" << endl;\
161 cerr << "PID: " << getpid();\
162 cerr << endl << flush; \
173 cerr << "breakpoint '"\
174 << #X << "' reached at fn "\
175 << __PRETTY_FUNCTION__ << " in "\
177 << __LINE__ << endl << flush;\
178 if(isatty(STDIN_FILENO)) {\
179 cerr << "press enter to continue" << endl;\
180 cerr << "PID: " << getpid();\
181 cerr << endl << flush; \
187 #define ERROR_MSG(MESSAGE)\
189 if (ERROR_MESSAGE_FLAG) {\
190 cerr << "Fatal Error: in fn "\
191 << __PRETTY_FUNCTION__ << " in "\
194 << (MESSAGE) << endl << flush;\
195 (* debug_cout_ptr) << "Fatal Error: in fn "\
196 << __PRETTY_FUNCTION__ << " in "\
199 << (MESSAGE) << endl << flush;\
204 #define WARN_MSG(MESSAGE)\
206 if (WARNING_MESSAGE_FLAG) {\
207 cerr << "Warning: in fn "\
208 << __PRETTY_FUNCTION__ << " in "\
211 << (MESSAGE) << endl << flush;\
212 (* debug_cout_ptr) << "Warning: in fn "\
213 << __PRETTY_FUNCTION__ << " in "\
216 << (MESSAGE) << endl << flush;\
220 #define WARN_EXPR(EXPR)\
222 if (WARNING_MESSAGE_FLAG) {\
223 cerr << "Warning: in fn "\
224 << __PRETTY_FUNCTION__ << " in "\
228 << (EXPR) << endl << flush;\
229 (* debug_cout_ptr) << "Warning: in fn "\
230 << __PRETTY_FUNCTION__ << " in "\
234 << (EXPR) << endl << flush;\
238 #define DEBUG_MSG(module, priority, MESSAGE)\
241 if (g_debug_ptr->validDebug(module, priority)) {\
242 (* debug_cout_ptr) << "Debug: in fn "\
243 << __PRETTY_FUNCTION__\
244 << " in " << __FILE__ << ":"\
246 << (MESSAGE) << endl << flush;\
251 #define DEBUG_EXPR(module, priority, EXPR)\
254 if (g_debug_ptr->validDebug(module, priority)) {\
255 (* debug_cout_ptr) << "Debug: in fn "\
256 << __PRETTY_FUNCTION__\
257 << " in " << __FILE__ << ":"\
260 << (EXPR) << endl << flush;\
265 #define DEBUG_NEWLINE(module, priority)\
268 if (g_debug_ptr->validDebug(module, priority)) {\
269 (* debug_cout_ptr) << endl << flush;\
274 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
277 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
278 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
283 #define DEBUG_OUT( rest... ) \
286 cout << "Debug: in fn "\
287 << __PRETTY_FUNCTION__\
288 << " in " << __FILE__ << ":"\
289 << __LINE__ << ": "; \
290 g_debug_ptr->debugMsg(rest); \
294 #define ERROR_OUT( rest... ) \
296 if (ERROR_MESSAGE_FLAG) {\
297 cout << "error: in fn "\
298 << __PRETTY_FUNCTION__ << " in "\
300 << __LINE__ << ": ";\
301 g_debug_ptr->debugMsg(rest); \