gem5  v21.2.1.1
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 <iostream>
47 #include <map>
48 #include <string>
49 #include <vector>
50 
51 #include "base/compiler.hh"
52 
53 namespace gem5
54 {
55 
56 GEM5_DEPRECATED_NAMESPACE(Debug, debug);
57 namespace debug
58 {
59 
60 void breakpoint();
61 
62 class Flag
63 {
64  protected:
65  static bool _globalEnable; // whether debug tracings are enabled
66 
67  bool _tracing = false; // tracing is enabled and flag is on
68 
69  const char *_name;
70  const char *_desc;
71 
72  virtual void sync() { }
73 
74  public:
75  Flag(const char *name, const char *desc);
76  virtual ~Flag();
77 
78  std::string name() const { return _name; }
79  std::string desc() const { return _desc; }
80 
81  bool tracing() const { return TRACING_ON && _tracing; }
82 
83  virtual void enable() = 0;
84  virtual void disable() = 0;
85 
86  operator bool() const { return tracing(); }
87 
88  static void globalEnable();
89  static void globalDisable();
90 };
91 
92 class SimpleFlag : public Flag
93 {
94  protected:
96  const bool _isFormat = false;
97 
98  bool _enabled = false; // flag enablement status
99 
100  void sync() override { _tracing = _globalEnable && _enabled; }
101 
102  public:
103  SimpleFlag(const char *name, const char *desc, bool is_format=false);
104 
105  void enable() override { _enabled = true; sync(); }
106  void disable() override { _enabled = false; sync(); }
107 
114  bool isFormat() const { return _isFormat; }
115 };
116 
117 class CompoundFlag : public Flag
118 {
119  protected:
121 
122  public:
123  template<typename... Args>
124  CompoundFlag(const char *name, const char *desc,
125  std::initializer_list<Flag *> flags)
126  : Flag(name, desc),
127  _kids(flags)
128  {
129  }
130 
131  const std::vector<Flag *> &kids() const { return _kids; }
132 
133  void enable() override;
134  void disable() override;
135 };
136 
138 {
139  protected:
140  static int _version;
141 
142  public:
143  AllFlagsFlag();
144 
145  void add(SimpleFlag *flag);
146 
147  static AllFlagsFlag &instance();
148  static int version() { return _version; }
149 };
150 
151 typedef std::map<std::string, Flag *> FlagsMap;
152 FlagsMap &allFlags();
153 
154 Flag *findFlag(const std::string &name);
155 
156 bool changeFlag(const char *s, bool value);
157 
158 } // namespace debug
159 
160 void setDebugFlag(const char *string);
161 
162 void clearDebugFlag(const char *string);
163 
164 void dumpDebugFlags(std::ostream &os=std::cout);
165 
172 #define DTRACE(x) GEM5_DEPRECATED_MACRO(DTRACE, debug::x, \
173  "Replace DTRACE(x) with debug::x.")
174  // end of api_trace
175 
176 } // namespace gem5
177 
178 #endif // __BASE_DEBUG_HH__
gem5::debug::Flag::_tracing
bool _tracing
Definition: debug.hh:67
gem5::debug::Flag
Definition: debug.hh:62
gem5::debug::Flag::_name
const char * _name
Definition: debug.hh:69
gem5::debug::AllFlagsFlag::add
void add(SimpleFlag *flag)
Definition: debug.cc:160
gem5::debug::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:126
gem5::debug::Flag::name
std::string name() const
Definition: debug.hh:78
gem5::debug::Flag::Flag
Flag(const char *name, const char *desc)
Definition: debug.cc:101
gem5::debug::Flag::globalEnable
static void globalEnable()
Definition: debug.cc:118
gem5::debug::breakpoint
void breakpoint()
Definition: debug.cc:65
gem5::debug::AllFlagsFlag::_version
static int _version
Definition: debug.hh:140
gem5::debug::CompoundFlag::_kids
std::vector< Flag * > _kids
Definition: debug.hh:120
gem5::debug::AllFlagsFlag::instance
static AllFlagsFlag & instance()
Definition: debug.cc:169
std::vector
STL vector class.
Definition: stl.hh:37
gem5::debug::SimpleFlag::disable
void disable() override
Definition: debug.hh:106
gem5::clearDebugFlag
void clearDebugFlag(const char *string)
Definition: debug.cc:200
gem5::debug::AllFlagsFlag::version
static int version()
Definition: debug.hh:148
gem5::debug::allFlags
FlagsMap & allFlags()
Definition: debug.cc:76
gem5::dumpDebugFlags
void dumpDebugFlags(std::ostream &os)
Definition: debug.cc:206
gem5::debug::FlagsMap
std::map< std::string, Flag * > FlagsMap
Definition: debug.hh:151
gem5::setDebugFlag
void setDebugFlag(const char *string)
Definition: debug.cc:194
gem5::debug::CompoundFlag
Definition: debug.hh:117
gem5::debug::CompoundFlag::CompoundFlag
CompoundFlag(const char *name, const char *desc, std::initializer_list< Flag * > flags)
Definition: debug.hh:124
gem5::debug::Flag::sync
virtual void sync()
Definition: debug.hh:72
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:562
gem5::debug::CompoundFlag::kids
const std::vector< Flag * > & kids() const
Definition: debug.hh:131
gem5::debug::Flag::_globalEnable
static bool _globalEnable
Definition: debug.hh:65
gem5::debug::Flag::tracing
bool tracing() const
Definition: debug.hh:81
compiler.hh
gem5::debug::Flag::disable
virtual void disable()=0
gem5::debug::SimpleFlag::_enabled
bool _enabled
Definition: debug.hh:98
gem5::debug::SimpleFlag::SimpleFlag
SimpleFlag(const char *name, const char *desc, bool is_format=false)
Definition: debug.cc:133
gem5::debug::findFlag
Flag * findFlag(const std::string &name)
Definition: debug.cc:92
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
name
const std::string & name()
Definition: trace.cc:49
gem5::debug::SimpleFlag
Definition: debug.hh:92
gem5::debug::Flag::~Flag
virtual ~Flag()
Definition: debug.cc:112
gem5::debug::SimpleFlag::_isFormat
const bool _isFormat
Whether this flag changes debug formatting.
Definition: debug.hh:96
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::debug::Flag::enable
virtual void enable()=0
gem5::debug::CompoundFlag::disable
void disable() override
Definition: debug.cc:149
gem5::debug::AllFlagsFlag
Definition: debug.hh:137
gem5::debug::changeFlag
bool changeFlag(const char *s, bool value)
Definition: debug.cc:176
gem5::debug::Flag::desc
std::string desc() const
Definition: debug.hh:79
gem5::debug::CompoundFlag::enable
void enable() override
Definition: debug.cc:142
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::debug::Flag::_desc
const char * _desc
Definition: debug.hh:70
gem5::debug::SimpleFlag::sync
void sync() override
Definition: debug.hh:100
gem5::debug::SimpleFlag::enable
void enable() override
Definition: debug.hh:105
gem5::debug::SimpleFlag::isFormat
bool isFormat() const
Checks whether this flag is a conventional debug flag, or a flag that modifies the way debug informat...
Definition: debug.hh:114
gem5::debug::AllFlagsFlag::AllFlagsFlag
AllFlagsFlag()
Definition: debug.cc:155

Generated on Wed May 4 2022 12:13:51 for gem5 by doxygen 1.8.17