gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pc_event.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Nathan Binkert
29  * Steve Reinhardt
30  */
31 
32 #include "cpu/pc_event.hh"
33 
34 #include <algorithm>
35 #include <string>
36 #include <utility>
37 
38 #include "base/debug.hh"
39 #include "base/trace.hh"
40 #include "debug/PCEvent.hh"
41 #include "sim/core.hh"
42 #include "sim/system.hh"
43 
44 using namespace std;
45 
47 {}
48 
50 {}
51 
52 bool
54 {
55  int removed = 0;
56  range_t range = equal_range(event);
57  iterator i = range.first;
58  while (i != range.second && i != pcMap.end()) {
59  if (*i == event) {
60  DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
61  event->pc(), event->descr());
62  i = pcMap.erase(i);
63  ++removed;
64  } else {
65  i++;
66  }
67  }
68 
69  return removed > 0;
70 }
71 
72 bool
74 {
75  pcMap.push_back(event);
76  sort(pcMap.begin(), pcMap.end(), MapCompare());
77 
78  DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
79  event->pc(), event->descr());
80 
81  return true;
82 }
83 
84 bool
86 {
87  // Using the raw PC address will fail to break on Alpha PALcode addresses,
88  // but that is a rare use case.
89  int serviced = 0;
90  range_t range = equal_range(pc);
91  for (iterator i = range.first; i != range.second; ++i) {
92  DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
93  (*i)->pc(), (*i)->descr());
94 
95  (*i)->process(tc);
96  ++serviced;
97  }
98 
99  return serviced > 0;
100 }
101 
102 void
104 {
105  const_iterator i = pcMap.begin();
106  const_iterator e = pcMap.end();
107 
108  for (; i != e; ++i)
109  cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
110  (*i)->descr());
111 }
112 
115 {
116  return std::equal_range(pcMap.begin(), pcMap.end(), pc, MapCompare());
117 }
118 
119 BreakPCEvent::BreakPCEvent(PCEventScope *s, const std::string &desc, Addr addr,
120  bool del)
121  : PCEvent(s, desc, addr), remove(del)
122 {
123 }
124 
125 void
127 {
128  StringWrap name("break_event");
129  DPRINTFN("break event %s triggered\n", descr());
131  if (remove)
132  delete this;
133 }
134 
135 PanicPCEvent::PanicPCEvent(PCEventScope *s, const std::string &desc, Addr pc)
136  : PCEvent(s, desc, pc)
137 {
138 }
139 
140 void
142 {
143  StringWrap name("panic_event");
144  panic(descr());
145 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
void breakpoint()
Definition: debug.cc:52
Bitfield< 7 > i
STL pair class.
Definition: stl.hh:61
Addr pc() const
Definition: pc_event.hh:61
ip6_addr_t addr
Definition: inet.hh:335
std::string descr() const
Definition: pc_event.hh:60
virtual void process(ThreadContext *tc)
Definition: pc_event.cc:141
virtual const std::string name() const
Definition: pc_event.hh:58
bool remove(PCEvent *event) override
Definition: pc_event.cc:53
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
Map::const_iterator const_iterator
Definition: pc_event.hh:99
ThreadContext is the external interface to all thread state for anything outside of the CPU...
#define DPRINTFN(...)
Definition: trace.hh:233
void dump() const
Definition: pc_event.cc:103
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Bitfield< 4 > pc
Bitfield< 4 > s
range_t equal_range(Addr pc)
Definition: pc_event.cc:114
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool schedule(PCEvent *event) override
Definition: pc_event.cc:73
Bitfield< 10, 5 > event
PanicPCEvent(PCEventScope *s, const std::string &desc, Addr pc)
Definition: pc_event.cc:135
Bitfield< 9 > e
virtual void process(ThreadContext *tc)
Definition: pc_event.cc:126
Map::iterator iterator
Definition: pc_event.hh:98
BreakPCEvent(PCEventScope *s, const std::string &desc, Addr addr, bool del=false)
Definition: pc_event.cc:119
bool doService(Addr pc, ThreadContext *tc)
Definition: pc_event.cc:85
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:156

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13