gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
52namespace gem5
53{
54
55namespace debug
56{
57
58//
59// This function will cause the process to signal itself with a
60// SIGTRAP which is ignored if not in gdb, but will cause the debugger
61// to break if in gdb.
62//
63void
65{
66#ifndef NDEBUG
67 kill(getpid(), SIGTRAP);
68#else
69 cprintf("debug::breakpoint suppressed, compiled with NDEBUG\n");
70#endif
71}
72
73// Used to check the freshness of cached views of all flags.
76{
77 // Ensure that the special "All" compound debug flag has been created,
78 // and avoid infinite recursion.
79 static bool done = false;
80 if (!done) {
81 done = true;
83 }
84 static FlagsMap flags;
85 return flags;
86}
87
88bool Flag::_globalEnable = false;
89
90Flag *
91findFlag(const std::string &name)
92{
93 FlagsMap::iterator i = allFlags().find(name);
94 if (i == allFlags().end()) {
95 return NULL;
96 }
97 return i->second;
98}
99
100Flag::Flag(const char *name, const char *desc)
101 : _name(name), _desc(desc)
102{
104 allFlags().insert(std::make_pair(name, this));
105
106 panic_if(!result.second, "Flag %s already defined!", name);
107
108 sync();
109}
110
112{
113 allFlags().erase(name());
114}
115
116void
118{
119 _globalEnable = true;
120 for (auto& i : allFlags())
121 i.second->sync();
122}
123
124void
126{
127 _globalEnable = false;
128 for (auto& i : allFlags())
129 i.second->sync();
130}
131
132SimpleFlag::SimpleFlag(const char *name, const char *desc, bool is_format)
133 : Flag(name, desc), _isFormat(is_format)
134{
135 // Add non-format flags to the special "All" compound flag.
136 if (!isFormat())
138}
139
140void
142{
143 for (auto& k : _kids)
144 k->enable();
145}
146
147void
149{
150 for (auto& k : _kids)
151 k->disable();
152}
153
155 "Controls all debug flags. It should not be used within C++ code.", {})
156{}
157
158void
160{
161 ++_version;
162 _kids.push_back(flag);
163}
164
166
169{
170 static AllFlagsFlag flag;
171 return flag;
172}
173
174bool
175changeFlag(const char *s, bool value)
176{
177 Flag *f = findFlag(s);
178 if (!f)
179 return false;
180
181 if (value)
182 f->enable();
183 else
184 f->disable();
185
186 return true;
187}
188
189} // namespace debug
190
191// add a set of functions that can easily be invoked from gdb
192void
193setDebugFlag(const char *string)
194{
195 debug::changeFlag(string, true);
196}
197
198void
199clearDebugFlag(const char *string)
200{
201 debug::changeFlag(string, false);
202}
203
204void
205dumpDebugFlags(std::ostream &os)
206{
207 using namespace debug;
208 FlagsMap::iterator i = allFlags().begin();
209 FlagsMap::iterator end = allFlags().end();
210 for (; i != end; ++i) {
211 SimpleFlag *f = dynamic_cast<SimpleFlag *>(i->second);
212 if (f && f->tracing())
213 ccprintf(os, "%s\n", f->name());
214 }
215}
216
217} // namespace gem5
static AllFlagsFlag & instance()
Definition debug.cc:168
void add(SimpleFlag *flag)
Definition debug.cc:159
void enable() override
Definition debug.cc:141
void disable() override
Definition debug.cc:148
std::vector< Flag * > _kids
Definition debug.hh:119
std::string name() const
Definition debug.hh:77
virtual void sync()
Definition debug.hh:71
static void globalEnable()
Definition debug.cc:117
static bool _globalEnable
Definition debug.hh:64
virtual ~Flag()
Definition debug.cc:111
static void globalDisable()
Definition debug.cc:125
Flag(const char *name, const char *desc)
Definition debug.cc:100
bool isFormat() const
Checks whether this flag is a conventional debug flag, or a flag that modifies the way debug informat...
Definition debug.hh:113
SimpleFlag(const char *name, const char *desc, bool is_format=false)
Definition debug.cc:132
STL pair class.
Definition stl.hh:58
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
uint8_t flags
Definition helpers.cc:87
Bitfield< 4 > s
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 23 > k
Bitfield< 17 > os
Definition misc.hh:838
FlagsMap & allFlags()
Definition debug.cc:75
std::map< std::string, Flag * > FlagsMap
Definition debug.hh:150
bool changeFlag(const char *s, bool value)
Definition debug.cc:175
Flag * findFlag(const std::string &name)
Definition debug.cc:91
void breakpoint()
Definition debug.cc:64
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void setDebugFlag(const char *string)
Definition debug.cc:193
void cprintf(const char *format, const Args &...args)
Definition cprintf.hh:155
void clearDebugFlag(const char *string)
Definition debug.cc:199
void dumpDebugFlags(std::ostream &os)
Definition debug.cc:205
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0