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 extern std::ostream * debug_cout_ptr;
42 // component enumeration
46 #define DEFINE_COMP(component, character, description) component,
51 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
52 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
57 Debug( const char *filterString, const char *verboseString,
58 Time filterStartTime, const char *filename );
64 bool validDebug(int module, PriorityLevel priority);
65 void printVerbosity(ostream& out) const;
66 void setVerbosity(VerbosityLevel vb);
67 static bool checkVerbosityString(const char *verb_str);
68 bool setVerbosityString(const char *);
69 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
71 static bool checkFilter( char);
72 static bool checkFilterString(const char *);
73 bool setFilterString(const char *);
74 void setDebugTime(Time);
75 Time getDebugTime() const { return m_starting_cycle; }
79 void print(ostream& out) const;
80 /* old school debugging "vararg": sends messages to screen and log */
81 void debugMsg( const char *fmt, ... );
83 void setDebugOutputFile (const char * filename);
84 void closeDebugOutputFile ();
85 static void usageInstructions(void);
90 // Private copy constructor and assignment operator
91 Debug(const Debug& obj);
92 Debug& operator=(const Debug& obj);
94 // Data Members (m_ prefix)
95 VerbosityLevel m_verbosityLevel;
97 Time m_starting_cycle;
102 // Output operator declaration
103 ostream& operator<<(ostream& out, const Debug& obj);
105 // ******************* Definitions *******************
107 // Output operator definition
109 ostream& operator<<(ostream& out, const Debug& obj)
116 const bool ERROR_MESSAGE_FLAG = true;
117 const bool WARNING_MESSAGE_FLAG = true;
119 #ifdef RUBY_NO_ASSERT
120 const bool ASSERT_FLAG = false;
122 const bool ASSERT_FLAG = true;
126 #define assert(EXPR) ASSERT(EXPR)
128 #define ASSERT(EXPR)\
132 cerr << "failed assertion '"\
133 << #EXPR << "' at fn "\
134 << __PRETTY_FUNCTION__ << " in "\
136 << __LINE__ << endl << flush;\
137 (* debug_cout_ptr) << "failed assertion '"\
138 << #EXPR << "' at fn "\
139 << __PRETTY_FUNCTION__ << " in "\
141 << __LINE__ << endl << flush;\
142 if(isatty(STDIN_FILENO)) {\
143 cerr << "At this point you might want to attach a debug to ";\
144 cerr << "the running and get to the" << endl;\
145 cerr << "crash site; otherwise press enter to continue" << endl;\
146 cerr << "PID: " << getpid();\
147 cerr << endl << flush; \
158 cerr << "breakpoint '"\
159 << #X << "' reached at fn "\
160 << __PRETTY_FUNCTION__ << " in "\
162 << __LINE__ << endl << flush;\
163 if(isatty(STDIN_FILENO)) {\
164 cerr << "press enter to continue" << endl;\
165 cerr << "PID: " << getpid();\
166 cerr << endl << flush; \
172 #define ERROR_MSG(MESSAGE)\
174 if (ERROR_MESSAGE_FLAG) {\
175 cerr << "Fatal Error: in fn "\
176 << __PRETTY_FUNCTION__ << " in "\
179 << (MESSAGE) << endl << flush;\
180 (* debug_cout_ptr) << "Fatal Error: in fn "\
181 << __PRETTY_FUNCTION__ << " in "\
184 << (MESSAGE) << endl << flush;\
189 #define WARN_MSG(MESSAGE)\
191 if (WARNING_MESSAGE_FLAG) {\
192 cerr << "Warning: in fn "\
193 << __PRETTY_FUNCTION__ << " in "\
196 << (MESSAGE) << endl << flush;\
197 (* debug_cout_ptr) << "Warning: in fn "\
198 << __PRETTY_FUNCTION__ << " in "\
201 << (MESSAGE) << endl << flush;\
205 #define WARN_EXPR(EXPR)\
207 if (WARNING_MESSAGE_FLAG) {\
208 cerr << "Warning: in fn "\
209 << __PRETTY_FUNCTION__ << " in "\
213 << (EXPR) << endl << flush;\
214 (* debug_cout_ptr) << "Warning: in fn "\
215 << __PRETTY_FUNCTION__ << " in "\
219 << (EXPR) << endl << flush;\
223 #define DEBUG_MSG(module, priority, MESSAGE)\
226 if (g_debug_ptr->validDebug(module, priority)) {\
227 (* debug_cout_ptr) << "Debug: in fn "\
228 << __PRETTY_FUNCTION__\
229 << " in " << __FILE__ << ":"\
231 << (MESSAGE) << endl << flush;\
236 #define DEBUG_EXPR(module, priority, EXPR)\
239 if (g_debug_ptr->validDebug(module, priority)) {\
240 (* debug_cout_ptr) << "Debug: in fn "\
241 << __PRETTY_FUNCTION__\
242 << " in " << __FILE__ << ":"\
245 << (EXPR) << endl << flush;\
250 #define DEBUG_NEWLINE(module, priority)\
253 if (g_debug_ptr->validDebug(module, priority)) {\
254 (* debug_cout_ptr) << endl << flush;\
259 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
262 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
263 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
268 #define DEBUG_OUT( rest... ) \
271 cout << "Debug: in fn "\
272 << __PRETTY_FUNCTION__\
273 << " in " << __FILE__ << ":"\
274 << __LINE__ << ": "; \
275 g_debug_ptr->debugMsg(rest); \
279 #define ERROR_OUT( rest... ) \
281 if (ERROR_MESSAGE_FLAG) {\
282 cout << "error: in fn "\
283 << __PRETTY_FUNCTION__ << " in "\
285 << __LINE__ << ": ";\
286 g_debug_ptr->debugMsg(rest); \