2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 The Hewlett-Packard Development Company
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Authors: Nathan Binkert
32 #ifndef __BASE_DEBUG_HH__
33 #define __BASE_DEBUG_HH__
50 Flag(const char *name, const char *desc);
53 std::string name() const { return _name; }
54 std::string desc() const { return _desc; }
55 virtual std::vector<Flag *> kids() { return std::vector<Flag*>(); }
57 virtual void enable() = 0;
58 virtual void disable() = 0;
59 virtual void sync() {}
62 class SimpleFlag : public Flag
64 static bool _active; // whether debug tracings are enabled
66 bool _tracing; // tracing is enabled and flag is on
67 bool _status; // flag status
70 SimpleFlag(const char *name, const char *desc)
71 : Flag(name, desc), _status(false)
74 bool status() const { return _tracing; }
75 operator bool() const { return _tracing; }
76 bool operator!() const { return !_tracing; }
78 void enable() { _status = true; sync(); }
79 void disable() { _status = false; sync(); }
81 void sync() { _tracing = _active && _status; }
83 static void enableAll();
84 static void disableAll();
87 class CompoundFlag : public Flag
90 std::vector<Flag *> _kids;
100 CompoundFlag(const char *name, const char *desc,
101 Flag *f00 = nullptr, Flag *f01 = nullptr,
102 Flag *f02 = nullptr, Flag *f03 = nullptr,
103 Flag *f04 = nullptr, Flag *f05 = nullptr,
104 Flag *f06 = nullptr, Flag *f07 = nullptr,
105 Flag *f08 = nullptr, Flag *f09 = nullptr,
106 Flag *f10 = nullptr, Flag *f11 = nullptr,
107 Flag *f12 = nullptr, Flag *f13 = nullptr,
108 Flag *f14 = nullptr, Flag *f15 = nullptr,
109 Flag *f16 = nullptr, Flag *f17 = nullptr,
110 Flag *f18 = nullptr, Flag *f19 = nullptr)
113 addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
114 addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
115 addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
116 addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
119 std::vector<Flag *> kids() { return _kids; }
125 typedef std::map<std::string, Flag *> FlagsMap;
126 FlagsMap &allFlags();
128 Flag *findFlag(const std::string &name);
130 extern Flag *const All;
132 bool changeFlag(const char *s, bool value);
136 void setDebugFlag(const char *string);
138 void clearDebugFlag(const char *string);
140 void dumpDebugFlags();
142 #endif // __BASE_DEBUG_HH__