gem5  v22.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 <iostream>
47 #include <map>
48 #include <string>
49 #include <vector>
50 
51 #include "base/compiler.hh"
52 
53 namespace gem5
54 {
55 
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.") // end of api_trace
175 
176 } // namespace gem5
177 
178 #endif // __BASE_DEBUG_HH__
static int version()
Definition: debug.hh:148
static AllFlagsFlag & instance()
Definition: debug.cc:169
void add(SimpleFlag *flag)
Definition: debug.cc:160
void enable() override
Definition: debug.cc:142
const std::vector< Flag * > & kids() const
Definition: debug.hh:131
void disable() override
Definition: debug.cc:149
std::vector< Flag * > _kids
Definition: debug.hh:120
CompoundFlag(const char *name, const char *desc, std::initializer_list< Flag * > flags)
Definition: debug.hh:124
std::string name() const
Definition: debug.hh:78
virtual void sync()
Definition: debug.hh:72
const char * _desc
Definition: debug.hh:70
static void globalEnable()
Definition: debug.cc:118
static bool _globalEnable
Definition: debug.hh:65
virtual void enable()=0
virtual void disable()=0
const char * _name
Definition: debug.hh:69
virtual ~Flag()
Definition: debug.cc:112
static void globalDisable()
Definition: debug.cc:126
Flag(const char *name, const char *desc)
Definition: debug.cc:101
std::string desc() const
Definition: debug.hh:79
bool tracing() const
Definition: debug.hh:81
void enable() override
Definition: debug.hh:105
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
SimpleFlag(const char *name, const char *desc, bool is_format=false)
Definition: debug.cc:133
const bool _isFormat
Whether this flag changes debug formatting.
Definition: debug.hh:96
void sync() override
Definition: debug.hh:100
void disable() override
Definition: debug.hh:106
STL vector class.
Definition: stl.hh:37
uint8_t flags
Definition: helpers.cc:66
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 17 > os
Definition: misc.hh:810
FlagsMap & allFlags()
Definition: debug.cc:76
std::map< std::string, Flag * > FlagsMap
Definition: debug.hh:151
bool changeFlag(const char *s, bool value)
Definition: debug.cc:176
Flag * findFlag(const std::string &name)
Definition: debug.cc:92
void breakpoint()
Definition: debug.cc:65
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void setDebugFlag(const char *string)
Definition: debug.cc:194
void clearDebugFlag(const char *string)
Definition: debug.cc:200
void dumpDebugFlags(std::ostream &os)
Definition: debug.cc:206
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1