2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __MEM_RUBY_COMMON_DEBUG_HH__
30 #define __MEM_RUBY_COMMON_DEBUG_HH__
39 #include "mem/ruby/common/Global.hh"
40 #include "sim/sim_object.hh"
42 #include "params/RubyDebug.hh"
44 extern std::ostream * debug_cout_ptr;
46 // component enumeration
60 NETWORK_INTERNALS_COMP,
68 enum PriorityLevel {HighPrio, MedPrio, LowPrio};
69 enum VerbosityLevel {No_Verb, Low_Verb, Med_Verb, High_Verb};
71 class Debug : public SimObject
74 typedef RubyDebugParams Params;
75 Debug(const Params *p);
78 static bool getProtocolTrace() { return m_protocol_trace; }
79 bool validDebug(int module, PriorityLevel priority);
80 void printVerbosity(std::ostream& out) const;
81 void setVerbosity(VerbosityLevel vb);
82 bool setVerbosityString(const char *);
83 VerbosityLevel getVerbosity() const { return m_verbosityLevel; }
85 static bool checkFilter( char);
86 static bool checkFilterString(const char *);
87 bool setFilterString(const char *);
88 void setDebugTime(Time);
89 Time getDebugTime() const { return m_starting_cycle; }
93 void print(std::ostream& out) const;
94 /* old school debugging "vararg": sends messages to screen and log */
95 void debugMsg(const char *fmt, ...);
97 void setDebugOutputFile (const char * filename);
98 void closeDebugOutputFile ();
99 static void usageInstructions(void);
102 // Private copy constructor and assignment operator
103 Debug(const Debug& obj);
104 Debug& operator=(const Debug& obj);
106 static bool m_protocol_trace;
107 VerbosityLevel m_verbosityLevel;
109 Time m_starting_cycle;
115 operator<<(std::ostream& out, const Debug& obj)
123 #define assert(EXPR) ASSERT(EXPR)
128 #define ASSERT(EXPR) do { \
129 using namespace std; \
131 cerr << "failed assertion '" \
132 << #EXPR << "' at fn " \
133 << __PRETTY_FUNCTION__ << " in " \
135 << __LINE__ << endl << flush; \
136 (*debug_cout_ptr) << "failed assertion '" \
137 << #EXPR << "' at fn " \
138 << __PRETTY_FUNCTION__ << " in " \
140 << __LINE__ << endl << flush; \
141 if (isatty(STDIN_FILENO)) { \
142 cerr << "At this point you might want to attach a debug to " \
143 << "the running and get to the" << endl \
144 << "crash site; otherwise press enter to continue" \
146 << "PID: " << getpid() \
157 #define ASSERT(EXPR) do {} while (0)
161 #endif // __MEM_RUBY_COMMON_DEBUG_HH__