2 * Copyright (c) 2003 The Regents of The University of Michigan
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.
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.
29 #ifndef __PC_EVENT_HH__
30 #define __PC_EVENT_HH__
42 static const Addr badpc = MemReq::inval_addr;
45 std::string description;
50 PCEvent() : queue(0), evpc(badpc) { }
52 PCEvent(const std::string &desc)
53 : description(desc), queue(0), evpc(badpc) { }
55 PCEvent(PCEventQueue *q, Addr pc = badpc) : queue(q), evpc(pc) { }
57 PCEvent(PCEventQueue *q, const std::string &desc, Addr pc = badpc)
58 : description(desc), queue(q), evpc(pc) { }
60 virtual ~PCEvent() { if (queue) remove(); }
62 std::string descr() const { return description; }
63 Addr pc() const { return evpc; }
67 bool schedule(Addr pc);
68 bool schedule(PCEventQueue *q, Addr pc);
69 virtual void process(ExecContext *xc) = 0;
75 typedef PCEvent * record_t;
78 bool operator()(const record_t &l, const record_t &r) const {
79 return l->pc() < r->pc();
81 bool operator()(const record_t &l, Addr pc) const {
84 bool operator()(Addr pc, const record_t &r) const {
88 typedef std::vector<record_t> map_t;
91 typedef map_t::iterator iterator;
92 typedef map_t::const_iterator const_iterator;
95 typedef std::pair<iterator, iterator> range_t;
96 typedef std::pair<const_iterator, const_iterator> const_range_t;
105 bool remove(PCEvent *event);
106 bool schedule(PCEvent *event);
107 bool service(ExecContext *xc);
109 range_t equal_range(Addr pc);
110 range_t equal_range(PCEvent *event) { return equal_range(event->pc()); }
119 panic("cannot remove an uninitialized event;");
121 return queue->remove(this);
127 if (!queue || evpc == badpc)
128 panic("cannot schedule an uninitialized event;");
130 return queue->schedule(this);
134 PCEvent::schedule(Addr pc)
137 panic("cannot switch PC");
144 PCEvent::schedule(PCEventQueue *q, Addr pc)
147 panic("cannot switch event queues");
150 panic("cannot switch addresses");
160 class SkipFuncEvent : public PCEvent
163 SkipFuncEvent(PCEventQueue *q, const std::string &desc)
164 : PCEvent(q, desc) {}
165 virtual void process(ExecContext *xc);
168 class BadAddrEvent : public SkipFuncEvent
171 BadAddrEvent(PCEventQueue *q, const std::string &desc)
172 : SkipFuncEvent(q, desc) {}
173 virtual void process(ExecContext *xc);
176 class PrintfEvent : public PCEvent
179 PrintfEvent(PCEventQueue *q, const std::string &desc)
180 : PCEvent(q, desc) {}
181 virtual void process(ExecContext *xc);
184 class DebugPrintfEvent : public PCEvent
190 DebugPrintfEvent(PCEventQueue *q, const std::string &desc, bool r = false)
191 : PCEvent(q, desc), raw(r) {}
192 virtual void process(ExecContext *xc);
195 class DumpMbufEvent : public PCEvent
198 DumpMbufEvent(PCEventQueue *q, const std::string &desc)
199 : PCEvent(q, desc) {}
200 virtual void process(ExecContext *xc);
204 class BreakPCEvent : public PCEvent
210 BreakPCEvent(PCEventQueue *q, const std::string &desc, bool del = false);
211 virtual void process(ExecContext *xc);
215 #endif // __PC_EVENT_HH__