gem5  v20.1.0.0
debug.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2003-2005 The Regents of The University of Michigan
15  * Copyright (c) 2010 The Hewlett-Packard Development Company
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #ifndef __BASE_DEBUG_HH__
43 #define __BASE_DEBUG_HH__
44 
45 #include <initializer_list>
46 #include <map>
47 #include <string>
48 #include <vector>
49 
50 namespace Debug {
51 
52 void breakpoint();
53 
54 class Flag
55 {
56  protected:
57  static bool _globalEnable; // whether debug tracings are enabled
58 
59  const char *_name;
60  const char *_desc;
61 
62  virtual void sync() { }
63 
64  public:
65  Flag(const char *name, const char *desc);
66  virtual ~Flag();
67 
68  std::string name() const { return _name; }
69  std::string desc() const { return _desc; }
70 
71  virtual void enable() = 0;
72  virtual void disable() = 0;
73  virtual bool status() const = 0;
74 
75  operator bool() const { return status(); }
76  bool operator!() const { return !status(); }
77 
78  static void globalEnable();
79  static void globalDisable();
80 };
81 
82 class SimpleFlag : public Flag
83 {
84  protected:
85  bool _tracing; // tracing is enabled and flag is on
86  bool _status; // flag status
87 
88  void sync() override { _tracing = _globalEnable && _status; }
89 
90  public:
91  SimpleFlag(const char *name, const char *desc)
92  : Flag(name, desc), _status(false)
93  { }
94 
95  bool status() const override { return _tracing; }
96 
97  void enable() override { _status = true; sync(); }
98  void disable() override { _status = false; sync(); }
99 };
100 
101 class CompoundFlag : public Flag
102 {
103  protected:
105 
106  public:
107  template<typename... Args>
108  CompoundFlag(const char *name, const char *desc,
109  std::initializer_list<Flag *> flags)
110  : Flag(name, desc),
111  _kids(flags)
112  {
113  }
114 
115  const std::vector<Flag *> &kids() const { return _kids; }
116 
117  void enable() override;
118  void disable() override;
119  bool status() const override;
120 };
121 
122 typedef std::map<std::string, Flag *> FlagsMap;
123 FlagsMap &allFlags();
124 
125 Flag *findFlag(const std::string &name);
126 
127 bool changeFlag(const char *s, bool value);
128 
129 } // namespace Debug
130 
131 void setDebugFlag(const char *string);
132 
133 void clearDebugFlag(const char *string);
134 
135 void dumpDebugFlags();
136 
143 #if TRACING_ON
144 # define DTRACE(x) (Debug::x)
145 #else // !TRACING_ON
146 # define DTRACE(x) (false)
147 #endif // TRACING_ON
148  // end of api_trace
149 
150 #endif // __BASE_DEBUG_HH__
Debug::Flag::disable
virtual void disable()=0
Debug::CompoundFlag::disable
void disable() override
Definition: debug.cc:134
Debug::CompoundFlag
Definition: debug.hh:101
Debug::Flag::_globalEnable
static bool _globalEnable
Definition: debug.hh:57
Debug::Flag::_desc
const char * _desc
Definition: debug.hh:60
Debug::breakpoint
void breakpoint()
Definition: debug.cc:62
Debug::CompoundFlag::CompoundFlag
CompoundFlag(const char *name, const char *desc, std::initializer_list< Flag * > flags)
Definition: debug.hh:108
Debug::Flag::operator!
bool operator!() const
Definition: debug.hh:76
Debug::findFlag
Flag * findFlag(const std::string &name)
Definition: debug.cc:85
Debug::Flag::Flag
Flag(const char *name, const char *desc)
Definition: debug.cc:93
Debug::CompoundFlag::kids
const std::vector< Flag * > & kids() const
Definition: debug.hh:115
Debug::allFlags
FlagsMap & allFlags()
Definition: debug.cc:76
std::vector
STL vector class.
Definition: stl.hh:37
Debug::Flag::desc
std::string desc() const
Definition: debug.hh:69
Debug::SimpleFlag::disable
void disable() override
Definition: debug.hh:98
Debug::SimpleFlag::_status
bool _status
Definition: debug.hh:86
Debug::SimpleFlag
Definition: debug.hh:82
Debug::SimpleFlag::enable
void enable() override
Definition: debug.hh:97
Debug::CompoundFlag::enable
void enable() override
Definition: debug.cc:127
Debug::CompoundFlag::_kids
std::vector< Flag * > _kids
Definition: debug.hh:104
Debug::SimpleFlag::status
bool status() const override
Definition: debug.hh:95
setDebugFlag
void setDebugFlag(const char *string)
Definition: debug.cc:173
Debug::FlagsMap
std::map< std::string, Flag * > FlagsMap
Definition: debug.hh:122
Debug::Flag::globalEnable
static void globalEnable()
Definition: debug.cc:111
Debug::Flag
Definition: debug.hh:54
Debug::changeFlag
bool changeFlag(const char *s, bool value)
Definition: debug.cc:155
Debug::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:119
name
const std::string & name()
Definition: trace.cc:50
clearDebugFlag
void clearDebugFlag(const char *string)
Definition: debug.cc:179
Debug::CompoundFlag::status
bool status() const override
Definition: debug.cc:141
Debug::Flag::status
virtual bool status() const =0
Debug
Definition: debug.cc:54
Debug::SimpleFlag::SimpleFlag
SimpleFlag(const char *name, const char *desc)
Definition: debug.hh:91
Debug::SimpleFlag::_tracing
bool _tracing
Definition: debug.hh:85
Debug::Flag::name
std::string name() const
Definition: debug.hh:68
Debug::Flag::_name
const char * _name
Definition: debug.hh:59
Debug::Flag::~Flag
virtual ~Flag()
Definition: debug.cc:105
Debug::Flag::enable
virtual void enable()=0
Debug::SimpleFlag::sync
void sync() override
Definition: debug.hh:88
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
Debug::Flag::sync
virtual void sync()
Definition: debug.hh:62
dumpDebugFlags
void dumpDebugFlags()
Definition: debug.cc:185

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17