build: fix compile problems pointed out by gcc 4.4
[gem5.git] / src / mem / ruby / common / Debug.hh
1
2 /*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
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.
16 *
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.
28 */
29
30 /*
31 * $Id$
32 */
33
34 #ifndef __MEM_RUBY_DEBUG_HH__
35 #define __MEM_RUBY_DEBUG_HH__
36
37 #include <unistd.h>
38 #include <iostream>
39 #include <string>
40 #include <vector>
41
42 #include "config/ruby_debug.hh"
43 #include "mem/ruby/common/Global.hh"
44
45 extern std::ostream * debug_cout_ptr;
46
47 // component enumeration
48 enum DebugComponents
49 {
50 SYSTEM_COMP,
51 NODE_COMP,
52 QUEUE_COMP,
53 EVENTQUEUE_COMP,
54 NETWORK_COMP,
55 SEQUENCER_COMP,
56 TESTER_COMP,
57 GENERATED_COMP,
58 SLICC_COMP,
59 NETWORKQUEUE_COMP,
60 TIME_COMP,
61 NETWORK_INTERNALS_COMP,
62 STOREBUFFER_COMP,
63 CACHE_COMP,
64 PREDICTOR_COMP,
65 ALLOCATOR_COMP,
66 NUMBER_OF_COMPS
67 };
68
69 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
70 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
71
72 class Debug {
73 public:
74 // Constructors
75 Debug();
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 );
79
80 // Destructor
81 ~Debug();
82
83 // Public Methods
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; }
91 void setFilter(int);
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; }
97 bool addFilter(char);
98 void clearFilter();
99 void allFilter();
100 void print(std::ostream& out) const;
101 /* old school debugging "vararg": sends messages to screen and log */
102 void debugMsg( const char *fmt, ... );
103
104 void setDebugOutputFile (const char * filename);
105 void closeDebugOutputFile ();
106 static void usageInstructions(void);
107
108 private:
109 // Private Methods
110
111 // Private copy constructor and assignment operator
112 Debug(const Debug& obj);
113 Debug& operator=(const Debug& obj);
114
115 // Data Members (m_ prefix)
116 static bool m_protocol_trace;
117 VerbosityLevel m_verbosityLevel;
118 int m_filter;
119 Time m_starting_cycle;
120
121 std::fstream m_fout;
122 };
123
124 // Output operator declaration
125 std::ostream& operator<<(std::ostream& out, const Debug& obj);
126
127 // ******************* Definitions *******************
128
129 // Output operator definition
130 extern inline
131 std::ostream& operator<<(std::ostream& out, const Debug& obj)
132 {
133 obj.print(out);
134 out << flush;
135 return out;
136 }
137
138 const bool ERROR_MESSAGE_FLAG = true;
139 const bool WARNING_MESSAGE_FLAG = true;
140
141 #ifdef RUBY_NO_ASSERT
142 const bool ASSERT_FLAG = false;
143 #else
144 const bool ASSERT_FLAG = true;
145 #endif
146
147 #undef assert
148 #define assert(EXPR) ASSERT(EXPR)
149 #undef ASSERT
150 #define ASSERT(EXPR)\
151 {\
152 if (ASSERT_FLAG) {\
153 if (!(EXPR)) {\
154 cerr << "failed assertion '"\
155 << #EXPR << "' at fn "\
156 << __PRETTY_FUNCTION__ << " in "\
157 << __FILE__ << ":"\
158 << __LINE__ << endl << flush;\
159 (* debug_cout_ptr) << "failed assertion '"\
160 << #EXPR << "' at fn "\
161 << __PRETTY_FUNCTION__ << " in "\
162 << __FILE__ << ":"\
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; \
170 char c; \
171 cin.get(c); \
172 }\
173 abort();\
174 }\
175 }\
176 }
177
178 #define BREAK(X)\
179 {\
180 cerr << "breakpoint '"\
181 << #X << "' reached at fn "\
182 << __PRETTY_FUNCTION__ << " in "\
183 << __FILE__ << ":"\
184 << __LINE__ << endl << flush;\
185 if(isatty(STDIN_FILENO)) {\
186 cerr << "press enter to continue" << endl;\
187 cerr << "PID: " << getpid();\
188 cerr << endl << flush; \
189 char c; \
190 cin.get(c); \
191 }\
192 }
193
194 #define ERROR_MSG(MESSAGE)\
195 {\
196 if (ERROR_MESSAGE_FLAG) {\
197 cerr << "Fatal Error: in fn "\
198 << __PRETTY_FUNCTION__ << " in "\
199 << __FILE__ << ":"\
200 << __LINE__ << ": "\
201 << (MESSAGE) << endl << flush;\
202 (* debug_cout_ptr) << "Fatal Error: in fn "\
203 << __PRETTY_FUNCTION__ << " in "\
204 << __FILE__ << ":"\
205 << __LINE__ << ": "\
206 << (MESSAGE) << endl << flush;\
207 abort();\
208 }\
209 }
210
211 #define WARN_MSG(MESSAGE)\
212 {\
213 if (WARNING_MESSAGE_FLAG) {\
214 cerr << "Warning: in fn "\
215 << __PRETTY_FUNCTION__ << " in "\
216 << __FILE__ << ":"\
217 << __LINE__ << ": "\
218 << (MESSAGE) << endl << flush;\
219 (* debug_cout_ptr) << "Warning: in fn "\
220 << __PRETTY_FUNCTION__ << " in "\
221 << __FILE__ << ":"\
222 << __LINE__ << ": "\
223 << (MESSAGE) << endl << flush;\
224 }\
225 }
226
227 #define WARN_EXPR(EXPR)\
228 {\
229 if (WARNING_MESSAGE_FLAG) {\
230 cerr << "Warning: in fn "\
231 << __PRETTY_FUNCTION__ << " in "\
232 << __FILE__ << ":"\
233 << __LINE__ << ": "\
234 << #EXPR << " is "\
235 << (EXPR) << endl << flush;\
236 (* debug_cout_ptr) << "Warning: in fn "\
237 << __PRETTY_FUNCTION__ << " in "\
238 << __FILE__ << ":"\
239 << __LINE__ << ": "\
240 << #EXPR << " is "\
241 << (EXPR) << endl << flush;\
242 }\
243 }
244
245 #define DEBUG_MSG(module, priority, MESSAGE)\
246 {\
247 if (RUBY_DEBUG) {\
248 if (g_debug_ptr->validDebug(module, priority)) {\
249 (* debug_cout_ptr) << "Debug: in fn "\
250 << __PRETTY_FUNCTION__\
251 << " in " << __FILE__ << ":"\
252 << __LINE__ << ": "\
253 << (MESSAGE) << endl << flush;\
254 }\
255 }\
256 }
257
258 #define DEBUG_EXPR(module, priority, EXPR)\
259 {\
260 if (RUBY_DEBUG) {\
261 if (g_debug_ptr->validDebug(module, priority)) {\
262 (* debug_cout_ptr) << "Debug: in fn "\
263 << __PRETTY_FUNCTION__\
264 << " in " << __FILE__ << ":"\
265 << __LINE__ << ": "\
266 << #EXPR << " is "\
267 << (EXPR) << endl << flush;\
268 }\
269 }\
270 }
271
272 #define DEBUG_NEWLINE(module, priority)\
273 {\
274 if (RUBY_DEBUG) {\
275 if (g_debug_ptr->validDebug(module, priority)) {\
276 (* debug_cout_ptr) << endl << flush;\
277 }\
278 }\
279 }
280
281 #define DEBUG_SLICC(priority, LINE, MESSAGE)\
282 {\
283 if (RUBY_DEBUG) {\
284 if (g_debug_ptr->validDebug(SLICC_COMP, priority)) {\
285 (* debug_cout_ptr) << (LINE) << (MESSAGE) << endl << flush;\
286 }\
287 }\
288 }
289
290 #define DEBUG_OUT( rest... ) \
291 {\
292 if (RUBY_DEBUG) {\
293 cout << "Debug: in fn "\
294 << __PRETTY_FUNCTION__\
295 << " in " << __FILE__ << ":"\
296 << __LINE__ << ": "; \
297 g_debug_ptr->debugMsg(rest); \
298 }\
299 }
300
301 #define ERROR_OUT( rest... ) \
302 {\
303 if (ERROR_MESSAGE_FLAG) {\
304 cout << "error: in fn "\
305 << __PRETTY_FUNCTION__ << " in "\
306 << __FILE__ << ":"\
307 << __LINE__ << ": ";\
308 g_debug_ptr->debugMsg(rest); \
309 }\
310 }
311
312 #endif //DEBUG_H
313