gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
53namespace gem5
54{
55
56namespace debug
57{
58
59void breakpoint();
60
61class Flag
62{
63 protected:
64 static bool _globalEnable; // whether debug tracings are enabled
65
66 bool _tracing = false; // tracing is enabled and flag is on
67
68 const char *_name;
69 const char *_desc;
70
71 virtual void sync() { }
72
73 public:
74 Flag(const char *name, const char *desc);
75 virtual ~Flag();
76
77 std::string name() const { return _name; }
78 std::string desc() const { return _desc; }
79
80 bool tracing() const { return TRACING_ON && _tracing; }
81
82 virtual void enable() = 0;
83 virtual void disable() = 0;
84
85 operator bool() const { return tracing(); }
86
87 static void globalEnable();
88 static void globalDisable();
89};
90
91class SimpleFlag : public Flag
92{
93 protected:
95 const bool _isFormat = false;
96
97 bool _enabled = false; // flag enablement status
98
99 void sync() override { _tracing = _globalEnable && _enabled; }
100
101 public:
102 SimpleFlag(const char *name, const char *desc, bool is_format=false);
103
104 void enable() override { _enabled = true; sync(); }
105 void disable() override { _enabled = false; sync(); }
106
113 bool isFormat() const { return _isFormat; }
114};
115
116class CompoundFlag : public Flag
117{
118 protected:
120
121 public:
122 template<typename... Args>
123 CompoundFlag(const char *name, const char *desc,
124 std::initializer_list<Flag *> flags)
125 : Flag(name, desc),
126 _kids(flags)
127 {
128 }
129
130 const std::vector<Flag *> &kids() const { return _kids; }
131
132 void enable() override;
133 void disable() override;
134};
135
137{
138 protected:
139 static int _version;
140
141 public:
142 AllFlagsFlag();
143
144 void add(SimpleFlag *flag);
145
146 static AllFlagsFlag &instance();
147 static int version() { return _version; }
148};
149
150typedef std::map<std::string, Flag *> FlagsMap;
152
153Flag *findFlag(const std::string &name);
154
155bool changeFlag(const char *s, bool value);
156
157} // namespace debug
158
159void setDebugFlag(const char *string);
160
161void clearDebugFlag(const char *string);
162
163void dumpDebugFlags(std::ostream &os=std::cout);
164
171#define DTRACE(x) GEM5_DEPRECATED_MACRO(DTRACE, debug::x, \
172 "Replace DTRACE(x) with debug::x.")
173 // end of api_trace
174
175} // namespace gem5
176
177#endif // __BASE_DEBUG_HH__
static int version()
Definition debug.hh:147
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
CompoundFlag(const char *name, const char *desc, std::initializer_list< Flag * > flags)
Definition debug.hh:123
const std::vector< Flag * > & kids() const
Definition debug.hh:130
std::string name() const
Definition debug.hh:77
virtual void sync()
Definition debug.hh:71
const char * _desc
Definition debug.hh:69
static void globalEnable()
Definition debug.cc:117
static bool _globalEnable
Definition debug.hh:64
virtual void enable()=0
virtual void disable()=0
const char * _name
Definition debug.hh:68
virtual ~Flag()
Definition debug.cc:111
static void globalDisable()
Definition debug.cc:125
Flag(const char *name, const char *desc)
Definition debug.cc:100
std::string desc() const
Definition debug.hh:78
bool tracing() const
Definition debug.hh:80
void enable() override
Definition debug.hh:104
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
const bool _isFormat
Whether this flag changes debug formatting.
Definition debug.hh:95
void sync() override
Definition debug.hh:99
void disable() override
Definition debug.hh:105
STL vector class.
Definition stl.hh:37
uint8_t flags
Definition helpers.cc:87
Bitfield< 4 > s
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 clearDebugFlag(const char *string)
Definition debug.cc:199
void dumpDebugFlags(std::ostream &os)
Definition debug.cc:205
const std::string & name()
Definition trace.cc:48

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