gem5  v20.1.0.0
debugfaults.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Advanced Micro Devices, Inc.
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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_GENERIC_DEBUGFAULTS_HH__
39 #define __ARCH_GENERIC_DEBUGFAULTS_HH__
40 
41 #include <string>
42 
43 #include "base/logging.hh"
44 #include "sim/faults.hh"
45 
46 namespace GenericISA
47 {
48 
49 class M5DebugFault : public FaultBase
50 {
51  protected:
52  std::string _message;
53  virtual void debugFunc() = 0;
54  void
56  {
57  if (inst) {
58  auto pc = tc->pcState();
59  inst->advancePC(pc);
60  tc->pcState(pc);
61  }
62  }
63 
64  public:
65  M5DebugFault(std::string _m) : _message(_m) {}
66 
67  template <class ...Args>
68  M5DebugFault(const std::string &format, const Args &...args) :
69  _message(csprintf(format, args...))
70  {}
71 
72  std::string message() { return _message; }
73 
74  void
75  invoke(ThreadContext *tc, const StaticInstPtr &inst =
77  {
78  debugFunc();
79  advancePC(tc, inst);
80  }
81 };
82 
83 // The "Flavor" template parameter is to keep warn, hack or inform messages
84 // with the same token from blocking each other.
85 template <class Flavor>
87 {
88  protected:
89  bool &once;
90 
91  template <class F, class OnceToken>
92  static bool &
93  lookUpToken(const OnceToken &token)
94  {
95  static std::map<OnceToken, bool> tokenMap;
96  return tokenMap[token];
97  }
98 
99  public:
100  template <class OnceToken, class ...Args>
101  M5DebugOnceFault(const OnceToken &token, const std::string &format,
102  const Args &...args) :
103  M5DebugFault(format, args...), once(lookUpToken<Flavor>(token))
104  {}
105 
106  void
107  invoke(ThreadContext *tc, const StaticInstPtr &inst =
109  {
110  if (!once) {
111  once = true;
112  debugFunc();
113  }
114  advancePC(tc, inst);
115  }
116 };
117 
119 {
120  public:
122  void debugFunc() override { panic(message()); }
123  FaultName name() const override { return "panic fault"; }
124 };
125 
127 {
128  public:
130  void debugFunc() override { fatal(message()); }
131  FaultName name() const override { return "fatal fault"; }
132 };
133 
134 template <class Base>
135 class M5WarnFaultBase : public Base
136 {
137  public:
138  using Base::Base;
139  void debugFunc() override { warn(this->message()); }
140  FaultName name() const override { return "warn fault"; }
141 };
142 
145 
146 template <class Base>
147 class M5HackFaultBase : public Base
148 {
149  public:
150  using Base::Base;
151  void debugFunc() override { hack(this->message()); }
152  FaultName name() const override { return "hack fault"; }
153 };
154 
157 
158 template <class Base>
159 class M5InformFaultBase : public Base
160 {
161  public:
162  using Base::Base;
163  void debugFunc() override { inform(this->message()); }
164  FaultName name() const override { return "inform fault"; }
165 };
166 
168 using M5InformOnceFault =
170 
171 } // namespace GenericISA
172 
173 #endif // __ARCH_GENERIC_DEBUGFAULTS_HH__
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
warn
#define warn(...)
Definition: logging.hh:239
GenericISA::M5HackFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:152
GenericISA::M5HackFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:151
StaticInst::advancePC
virtual void advancePC(TheISA::PCState &pcState) const =0
GenericISA::M5InformFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:163
GenericISA::M5DebugFault::advancePC
void advancePC(ThreadContext *tc, const StaticInstPtr &inst)
Definition: debugfaults.hh:55
GenericISA::M5DebugOnceFault
Definition: debugfaults.hh:86
GenericISA::M5DebugFault::message
std::string message()
Definition: debugfaults.hh:72
GenericISA::M5DebugOnceFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: debugfaults.hh:107
GenericISA::M5DebugFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: debugfaults.hh:75
GenericISA::M5HackFaultBase
Definition: debugfaults.hh:147
GenericISA::M5PanicFault::name
FaultName name() const override
Definition: debugfaults.hh:123
GenericISA::M5DebugFault::debugFunc
virtual void debugFunc()=0
GenericISA::M5DebugFault::_message
std::string _message
Definition: debugfaults.hh:52
faults.hh
GenericISA::M5DebugOnceFault::lookUpToken
static bool & lookUpToken(const OnceToken &token)
Definition: debugfaults.hh:93
GenericISA::M5WarnFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:140
hack
#define hack(...)
Definition: logging.hh:241
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
GenericISA::M5DebugFault::M5DebugFault
M5DebugFault(const std::string &format, const Args &...args)
Definition: debugfaults.hh:68
GenericISA::M5PanicFault
Definition: debugfaults.hh:118
GenericISA::M5FatalFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:130
FaultName
const typedef char * FaultName
Definition: faults.hh:49
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
GenericISA::M5InformFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:164
GenericISA::M5WarnFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:139
StaticInst::nullStaticInstPtr
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:237
GenericISA::M5WarnFaultBase
Definition: debugfaults.hh:135
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
GenericISA::M5PanicFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:122
inform
#define inform(...)
Definition: logging.hh:240
GenericISA::M5FatalFault::name
FaultName name() const override
Definition: debugfaults.hh:131
GenericISA::M5DebugOnceFault::M5DebugOnceFault
M5DebugOnceFault(const OnceToken &token, const std::string &format, const Args &...args)
Definition: debugfaults.hh:101
logging.hh
GenericISA::M5FatalFault
Definition: debugfaults.hh:126
GenericISA::M5DebugFault::M5DebugFault
M5DebugFault(std::string _m)
Definition: debugfaults.hh:65
RefCountingPtr< StaticInst >
ArmISA::format
Bitfield< 31, 29 > format
Definition: miscregs_types.hh:640
GenericISA::M5InformFaultBase
Definition: debugfaults.hh:159
GenericISA::M5DebugOnceFault::once
bool & once
Definition: debugfaults.hh:89
FaultBase
Definition: faults.hh:54
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
GenericISA::M5DebugFault
Definition: debugfaults.hh:49
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
GenericISA
Definition: debugfaults.hh:46

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17