debug.hh (8269:5a9a639ce16f) debug.hh (9554:406fbcf60223)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 The Hewlett-Packard Development Company
4 * All rights reserved.
5 *
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.
16 *
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.
28 *
29 * Authors: Nathan Binkert
30 */
31
32#ifndef __BASE_DEBUG_HH__
33#define __BASE_DEBUG_HH__
34
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 The Hewlett-Packard Development Company
4 * All rights reserved.
5 *
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.
16 *
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.
28 *
29 * Authors: Nathan Binkert
30 */
31
32#ifndef __BASE_DEBUG_HH__
33#define __BASE_DEBUG_HH__
34
35#include <map>
35#include <string>
36#include <vector>
37
38namespace Debug {
39
40void breakpoint();
41
42class Flag
43{
44 protected:
45 const char *_name;
46 const char *_desc;
47 std::vector<Flag *> _kids;
48
49 public:
50 Flag(const char *name, const char *desc);
51 virtual ~Flag();
52
53 std::string name() const { return _name; }
54 std::string desc() const { return _desc; }
55 std::vector<Flag *> kids() { return _kids; }
56
57 virtual void enable() = 0;
58 virtual void disable() = 0;
59};
60
61class SimpleFlag : public Flag
62{
63 protected:
64 bool _status;
65
66 public:
67 SimpleFlag(const char *name, const char *desc)
68 : Flag(name, desc)
69 { }
70
71 bool status() const { return _status; }
72 operator bool() const { return _status; }
73 bool operator!() const { return !_status; }
74
75 void enable() { _status = true; }
76 void disable() { _status = false; }
77};
78
79class CompoundFlag : public SimpleFlag
80{
81 protected:
82 void
83 addFlag(Flag &f)
84 {
85 if (&f != NULL)
86 _kids.push_back(&f);
87 }
88
89 public:
90 CompoundFlag(const char *name, const char *desc,
91 Flag &f00 = *(Flag *)0, Flag &f01 = *(Flag *)0,
92 Flag &f02 = *(Flag *)0, Flag &f03 = *(Flag *)0,
93 Flag &f04 = *(Flag *)0, Flag &f05 = *(Flag *)0,
94 Flag &f06 = *(Flag *)0, Flag &f07 = *(Flag *)0,
95 Flag &f08 = *(Flag *)0, Flag &f09 = *(Flag *)0,
96 Flag &f10 = *(Flag *)0, Flag &f11 = *(Flag *)0,
97 Flag &f12 = *(Flag *)0, Flag &f13 = *(Flag *)0,
98 Flag &f14 = *(Flag *)0, Flag &f15 = *(Flag *)0,
99 Flag &f16 = *(Flag *)0, Flag &f17 = *(Flag *)0,
100 Flag &f18 = *(Flag *)0, Flag &f19 = *(Flag *)0)
101 : SimpleFlag(name, desc)
102 {
103 addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
104 addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
105 addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
106 addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
107 }
108
109 void enable();
110 void disable();
111};
112
36#include <string>
37#include <vector>
38
39namespace Debug {
40
41void breakpoint();
42
43class Flag
44{
45 protected:
46 const char *_name;
47 const char *_desc;
48 std::vector<Flag *> _kids;
49
50 public:
51 Flag(const char *name, const char *desc);
52 virtual ~Flag();
53
54 std::string name() const { return _name; }
55 std::string desc() const { return _desc; }
56 std::vector<Flag *> kids() { return _kids; }
57
58 virtual void enable() = 0;
59 virtual void disable() = 0;
60};
61
62class SimpleFlag : public Flag
63{
64 protected:
65 bool _status;
66
67 public:
68 SimpleFlag(const char *name, const char *desc)
69 : Flag(name, desc)
70 { }
71
72 bool status() const { return _status; }
73 operator bool() const { return _status; }
74 bool operator!() const { return !_status; }
75
76 void enable() { _status = true; }
77 void disable() { _status = false; }
78};
79
80class CompoundFlag : public SimpleFlag
81{
82 protected:
83 void
84 addFlag(Flag &f)
85 {
86 if (&f != NULL)
87 _kids.push_back(&f);
88 }
89
90 public:
91 CompoundFlag(const char *name, const char *desc,
92 Flag &f00 = *(Flag *)0, Flag &f01 = *(Flag *)0,
93 Flag &f02 = *(Flag *)0, Flag &f03 = *(Flag *)0,
94 Flag &f04 = *(Flag *)0, Flag &f05 = *(Flag *)0,
95 Flag &f06 = *(Flag *)0, Flag &f07 = *(Flag *)0,
96 Flag &f08 = *(Flag *)0, Flag &f09 = *(Flag *)0,
97 Flag &f10 = *(Flag *)0, Flag &f11 = *(Flag *)0,
98 Flag &f12 = *(Flag *)0, Flag &f13 = *(Flag *)0,
99 Flag &f14 = *(Flag *)0, Flag &f15 = *(Flag *)0,
100 Flag &f16 = *(Flag *)0, Flag &f17 = *(Flag *)0,
101 Flag &f18 = *(Flag *)0, Flag &f19 = *(Flag *)0)
102 : SimpleFlag(name, desc)
103 {
104 addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
105 addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
106 addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
107 addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
108 }
109
110 void enable();
111 void disable();
112};
113
114typedef std::map<std::string, Flag *> FlagsMap;
115FlagsMap &allFlags();
116
117Flag *findFlag(const std::string &name);
118
119bool changeFlag(const char *s, bool value);
120
113} // namespace Debug
114
121} // namespace Debug
122
123void setDebugFlag(const char *string);
124
125void clearDebugFlag(const char *string);
126
127void dumpDebugFlags();
128
115#endif // __BASE_DEBUG_HH__
129#endif // __BASE_DEBUG_HH__