gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
debug.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * Copyright (c) 2010 The Hewlett-Packard Development Company
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 #ifndef __BASE_DEBUG_HH__
31 #define __BASE_DEBUG_HH__
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
37 namespace Debug {
38 
39 void breakpoint();
40 
41 class Flag
42 {
43  protected:
44  const char *_name;
45  const char *_desc;
46 
47  public:
48  Flag(const char *name, const char *desc);
49  virtual ~Flag();
50 
51  std::string name() const { return _name; }
52  std::string desc() const { return _desc; }
54 
55  virtual void enable() = 0;
56  virtual void disable() = 0;
57  virtual void sync() {}
58 };
59 
60 class SimpleFlag : public Flag
61 {
62  static bool _active; // whether debug tracings are enabled
63  protected:
64  bool _tracing; // tracing is enabled and flag is on
65  bool _status; // flag status
66 
67  public:
68  SimpleFlag(const char *name, const char *desc)
69  : Flag(name, desc), _status(false)
70  { }
71 
72  bool status() const { return _tracing; }
73  operator bool() const { return _tracing; }
74  bool operator!() const { return !_tracing; }
75 
76  void enable() { _status = true; sync(); }
77  void disable() { _status = false; sync(); }
78 
79  void sync() { _tracing = _active && _status; }
80 
81  static void enableAll();
82  static void disableAll();
83 };
84 
85 class CompoundFlag : public Flag
86 {
87  protected:
89 
90  void
92  {
93  if (f != nullptr)
94  _kids.push_back(f);
95  }
96 
97  public:
98  CompoundFlag(const char *name, const char *desc,
99  Flag *f00 = nullptr, Flag *f01 = nullptr,
100  Flag *f02 = nullptr, Flag *f03 = nullptr,
101  Flag *f04 = nullptr, Flag *f05 = nullptr,
102  Flag *f06 = nullptr, Flag *f07 = nullptr,
103  Flag *f08 = nullptr, Flag *f09 = nullptr,
104  Flag *f10 = nullptr, Flag *f11 = nullptr,
105  Flag *f12 = nullptr, Flag *f13 = nullptr,
106  Flag *f14 = nullptr, Flag *f15 = nullptr,
107  Flag *f16 = nullptr, Flag *f17 = nullptr,
108  Flag *f18 = nullptr, Flag *f19 = nullptr)
109  : Flag(name, desc)
110  {
111  addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
112  addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
113  addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
114  addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
115  }
116 
117  std::vector<Flag *> kids() { return _kids; }
118 
119  void enable();
120  void disable();
121 };
122 
123 typedef std::map<std::string, Flag *> FlagsMap;
124 FlagsMap &allFlags();
125 
126 Flag *findFlag(const std::string &name);
127 
128 extern Flag *const All;
129 
130 bool changeFlag(const char *s, bool value);
131 
132 } // namespace Debug
133 
134 void setDebugFlag(const char *string);
135 
136 void clearDebugFlag(const char *string);
137 
138 void dumpDebugFlags();
139 
140 #if TRACING_ON
141 # define DTRACE(x) (Debug::x)
142 #else // !TRACING_ON
143 # define DTRACE(x) (false)
144 #endif // TRACING_ON
145 
146 #endif // __BASE_DEBUG_HH__
const char * _name
Definition: debug.hh:44
void disable()
Definition: debug.hh:77
void enable()
Definition: debug.hh:76
void setDebugFlag(const char *string)
Definition: debug.cc:177
void breakpoint()
Definition: debug.cc:50
Flag *const All
Definition: debug.cc:156
void clearDebugFlag(const char *string)
Definition: debug.cc:183
virtual void sync()
Definition: debug.hh:57
std::map< std::string, Flag * > FlagsMap
Definition: debug.hh:123
std::string name() const
Definition: debug.hh:51
void addFlag(Flag *f)
Definition: debug.hh:91
bool changeFlag(const char *s, bool value)
Definition: debug.cc:159
static bool _active
Definition: debug.hh:62
CompoundFlag(const char *name, const char *desc, Flag *f00=nullptr, Flag *f01=nullptr, Flag *f02=nullptr, Flag *f03=nullptr, Flag *f04=nullptr, Flag *f05=nullptr, Flag *f06=nullptr, Flag *f07=nullptr, Flag *f08=nullptr, Flag *f09=nullptr, Flag *f10=nullptr, Flag *f11=nullptr, Flag *f12=nullptr, Flag *f13=nullptr, Flag *f14=nullptr, Flag *f15=nullptr, Flag *f16=nullptr, Flag *f17=nullptr, Flag *f18=nullptr, Flag *f19=nullptr)
Definition: debug.hh:98
bool status() const
Definition: debug.hh:72
Flag * findFlag(const std::string &name)
Definition: debug.cc:73
bool operator!() const
Definition: debug.hh:74
virtual std::vector< Flag * > kids()
Definition: debug.hh:53
STL vector class.
Definition: stl.hh:37
Bitfield< 6 > f
FlagsMap & allFlags()
Definition: debug.cc:64
void dumpDebugFlags()
Definition: debug.cc:189
virtual void disable()=0
Flag(const char *name, const char *desc)
Definition: debug.cc:81
std::vector< Flag * > _kids
Definition: debug.hh:88
Bitfield< 4 > s
virtual void enable()=0
std::string desc() const
Definition: debug.hh:52
virtual ~Flag()
Definition: debug.cc:93
Definition: debug.cc:42
std::vector< Flag * > kids()
Definition: debug.hh:117
SimpleFlag(const char *name, const char *desc)
Definition: debug.hh:68
const char * _desc
Definition: debug.hh:45
void sync()
Definition: debug.hh:79

Generated on Mon Jun 8 2020 15:45:07 for gem5 by doxygen 1.8.13