gem5  v21.1.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
debug.cc
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  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "base/debug.hh"
42 
43 #include <sys/types.h>
44 #include <unistd.h>
45 
46 #include <algorithm>
47 #include <csignal>
48 
49 #include "base/cprintf.hh"
50 #include "base/logging.hh"
51 
52 namespace gem5
53 {
54 
55 GEM5_DEPRECATED_NAMESPACE(Debug, debug);
56 namespace debug
57 {
58 
59 //
60 // This function will cause the process to signal itself with a
61 // SIGTRAP which is ignored if not in gdb, but will cause the debugger
62 // to break if in gdb.
63 //
64 void
66 {
67 #ifndef NDEBUG
68  kill(getpid(), SIGTRAP);
69 #else
70  cprintf("debug::breakpoint suppressed, compiled with NDEBUG\n");
71 #endif
72 }
73 
74 //
75 // Flags for debugging purposes. Primarily for trace.hh
76 //
78 FlagsMap &
80 {
81  static FlagsMap flags;
82  return flags;
83 }
84 
85 bool Flag::_globalEnable = false;
86 
87 Flag *
88 findFlag(const std::string &name)
89 {
90  FlagsMap::iterator i = allFlags().find(name);
91  if (i == allFlags().end())
92  return NULL;
93  return i->second;
94 }
95 
96 Flag::Flag(const char *name, const char *desc)
97  : _name(name), _desc(desc)
98 {
100  allFlags().insert(std::make_pair(name, this));
101 
102  panic_if(!result.second, "Flag %s already defined!", name);
103 
104  ++allFlagsVersion;
105 
106  sync();
107 }
108 
110 {
111  allFlags().erase(name());
112 }
113 
114 void
116 {
117  _globalEnable = true;
118  for (auto& i : allFlags())
119  i.second->sync();
120 }
121 
122 void
124 {
125  _globalEnable = false;
126  for (auto& i : allFlags())
127  i.second->sync();
128 }
129 
130 void
132 {
133  for (auto& k : _kids)
134  k->enable();
135 }
136 
137 void
139 {
140  for (auto& k : _kids)
141  k->disable();
142 }
143 
144 bool
145 changeFlag(const char *s, bool value)
146 {
147  Flag *f = findFlag(s);
148  if (!f)
149  return false;
150 
151  if (value)
152  f->enable();
153  else
154  f->disable();
155 
156  return true;
157 }
158 
159 } // namespace debug
160 
161 // add a set of functions that can easily be invoked from gdb
162 void
163 setDebugFlag(const char *string)
164 {
165  debug::changeFlag(string, true);
166 }
167 
168 void
169 clearDebugFlag(const char *string)
170 {
171  debug::changeFlag(string, false);
172 }
173 
174 void
175 dumpDebugFlags(std::ostream &os)
176 {
177  using namespace debug;
178  FlagsMap::iterator i = allFlags().begin();
179  FlagsMap::iterator end = allFlags().end();
180  for (; i != end; ++i) {
181  SimpleFlag *f = dynamic_cast<SimpleFlag *>(i->second);
182  if (f && f->tracing())
183  ccprintf(os, "%s\n", f->name());
184  }
185 }
186 
187 } // namespace gem5
gem5::debug::Flag
Definition: debug.hh:62
gem5::debug::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:123
gem5::cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
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::ArmISA::f
Bitfield< 6 > f
Definition: misc_types.hh:67
gem5::debug::breakpoint
void breakpoint()
Definition: debug.cc:65
gem5::debug::CompoundFlag::_kids
std::vector< Flag * > _kids
Definition: debug.hh:122
gem5::clearDebugFlag
void clearDebugFlag(const char *string)
Definition: debug.cc:169
gem5::debug::allFlags
FlagsMap & allFlags()
Definition: debug.cc:79
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
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::allFlagsVersion
int allFlagsVersion
Definition: debug.cc:77
gem5::debug::Flag::sync
virtual void sync()
Definition: debug.hh:72
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
gem5::debug::Flag::_globalEnable
static bool _globalEnable
Definition: debug.hh:65
debug.hh
cprintf.hh
std::pair
STL pair class.
Definition: stl.hh:58
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::Flag::~Flag
virtual ~Flag()
Definition: debug.cc:109
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
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
logging.hh
gem5::MipsISA::k
Bitfield< 23 > k
Definition: dt_constants.hh:81
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

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