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

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6