gem5  v21.1.0.2
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  : Flag(name, desc), _isFormat(is_format)
105  {}
106 
107  void enable() override { _enabled = true; sync(); }
108  void disable() override { _enabled = false; sync(); }
109 
116  bool isFormat() const { return _isFormat; }
117 };
118 
119 class CompoundFlag : public Flag
120 {
121  protected:
123 
124  public:
125  template<typename... Args>
126  CompoundFlag(const char *name, const char *desc,
127  std::initializer_list<Flag *> flags)
128  : Flag(name, desc),
129  _kids(flags)
130  {
131  }
132 
133  const std::vector<Flag *> &kids() const { return _kids; }
134 
135  void enable() override;
136  void disable() override;
137 };
138 
139 typedef std::map<std::string, Flag *> FlagsMap;
140 FlagsMap &allFlags();
141 
142 Flag *findFlag(const std::string &name);
143 
144 bool changeFlag(const char *s, bool value);
145 
146 } // namespace debug
147 
148 void setDebugFlag(const char *string);
149 
150 void clearDebugFlag(const char *string);
151 
152 void dumpDebugFlags(std::ostream &os=std::cout);
153 
160 #define DTRACE(x) GEM5_DEPRECATED_MACRO(DTRACE, debug::x, \
161  "Replace DTRACE(x) with debug::x.")
162  // end of api_trace
163 
164 } // namespace gem5
165 
166 #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::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:123
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:96
gem5::debug::Flag::globalEnable
static void globalEnable()
Definition: debug.cc:115
gem5::debug::breakpoint
void breakpoint()
Definition: debug.cc:65
gem5::debug::CompoundFlag::_kids
std::vector< Flag * > _kids
Definition: debug.hh:122
std::vector
STL vector class.
Definition: stl.hh:37
gem5::debug::SimpleFlag::disable
void disable() override
Definition: debug.hh:108
gem5::clearDebugFlag
void clearDebugFlag(const char *string)
Definition: debug.cc:169
gem5::debug::allFlags
FlagsMap & allFlags()
Definition: debug.cc:79
gem5::dumpDebugFlags
void dumpDebugFlags(std::ostream &os)
Definition: debug.cc:175
gem5::debug::FlagsMap
std::map< std::string, Flag * > FlagsMap
Definition: debug.hh:139
gem5::setDebugFlag
void setDebugFlag(const char *string)
Definition: debug.cc:163
gem5::debug::CompoundFlag
Definition: debug.hh:119
gem5::debug::CompoundFlag::CompoundFlag
CompoundFlag(const char *name, const char *desc, std::initializer_list< Flag * > flags)
Definition: debug.hh:126
gem5::debug::Flag::sync
virtual void sync()
Definition: debug.hh:72
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
gem5::debug::CompoundFlag::kids
const std::vector< Flag * > & kids() const
Definition: debug.hh:133
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.hh:103
gem5::debug::findFlag
Flag * findFlag(const std::string &name)
Definition: debug.cc:88
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:109
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:138
gem5::debug::changeFlag
bool changeFlag(const char *s, bool value)
Definition: debug.cc:145
gem5::debug::Flag::desc
std::string desc() const
Definition: debug.hh:79
gem5::debug::CompoundFlag::enable
void enable() override
Definition: debug.cc:131
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
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:107
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:116

Generated on Tue Sep 21 2021 12:24:56 for gem5 by doxygen 1.8.17