2 * Copyright (c) 2020 ARM Limited
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.
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
41 #include "base/debug.hh"
43 #include <sys/types.h>
49 #include "base/cprintf.hh"
50 #include "base/logging.hh"
57 // This function will cause the process to signal itself with a
58 // SIGTRAP which is ignored if not in gdb, but will cause the debugger
59 // to break if in gdb.
65 kill(getpid(), SIGTRAP
);
67 cprintf("Debug::breakpoint suppressed, compiled with NDEBUG\n");
72 // Flags for debugging purposes. Primarily for trace.hh
74 int allFlagsVersion
= 0;
78 static FlagsMap flags
;
82 bool Flag::_globalEnable
= false;
85 findFlag(const std::string
&name
)
87 FlagsMap::iterator i
= allFlags().find(name
);
88 if (i
== allFlags().end())
93 Flag::Flag(const char *name
, const char *desc
)
94 : _name(name
), _desc(desc
)
96 pair
<FlagsMap::iterator
, bool> result
=
97 allFlags().insert(make_pair(name
, this));
100 panic("Flag %s already defined!", name
);
107 // should find and remove flag.
113 _globalEnable
= true;
114 for (auto& i
: allFlags())
119 Flag::globalDisable()
121 _globalEnable
= false;
122 for (auto& i
: allFlags())
127 CompoundFlag::enable()
129 for (auto& k
: _kids
)
134 CompoundFlag::disable()
136 for (auto& k
: _kids
)
141 CompoundFlag::status() const
146 for (auto& k
: _kids
) {
155 changeFlag(const char *s
, bool value
)
157 Flag
*f
= findFlag(s
);
171 // add a set of functions that can easily be invoked from gdb
173 setDebugFlag(const char *string
)
175 Debug::changeFlag(string
, true);
179 clearDebugFlag(const char *string
)
181 Debug::changeFlag(string
, false);
187 using namespace Debug
;
188 FlagsMap::iterator i
= allFlags().begin();
189 FlagsMap::iterator end
= allFlags().end();
190 for (; i
!= end
; ++i
) {
191 SimpleFlag
*f
= dynamic_cast<SimpleFlag
*>(i
->second
);
192 if (f
&& f
->status())
193 cprintf("%s\n", f
->name());