2 * Copyright (c) 2002-2005 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__
34 #include "base/logging.hh"
35 #include "base/types.hh"
45 std::string description;
50 PCEvent(PCEventScope *q, const std::string &desc, Addr pc);
52 virtual ~PCEvent() { if (scope) remove(); }
55 virtual const std::string name() const { return description; }
57 std::string descr() const { return description; }
58 Addr pc() const { return evpc; }
61 virtual void process(ThreadContext *tc) = 0;
67 virtual bool remove(PCEvent *event) = 0;
68 virtual bool schedule(PCEvent *event) = 0;
71 class PCEventQueue : public PCEventScope
77 operator()(PCEvent * const &l, PCEvent * const &r) const
79 return l->pc() < r->pc();
82 operator()(PCEvent * const &l, Addr pc) const
87 operator()(Addr pc, PCEvent * const &r) const
92 typedef std::vector<PCEvent *> Map;
95 typedef Map::iterator iterator;
96 typedef Map::const_iterator const_iterator;
99 typedef std::pair<iterator, iterator> range_t;
100 typedef std::pair<const_iterator, const_iterator> const_range_t;
105 bool doService(Addr pc, ThreadContext *tc);
111 bool remove(PCEvent *event) override;
112 bool schedule(PCEvent *event) override;
113 bool service(Addr pc, ThreadContext *tc)
118 return doService(pc, tc);
121 range_t equal_range(Addr pc);
122 range_t equal_range(PCEvent *event) { return equal_range(event->pc()); }
129 PCEvent::PCEvent(PCEventScope *s, const std::string &desc, Addr pc)
130 : description(desc), scope(s), evpc(pc)
132 scope->schedule(this);
139 panic("cannot remove an uninitialized event;");
141 return scope->remove(this);
144 class BreakPCEvent : public PCEvent
150 BreakPCEvent(PCEventScope *s, const std::string &desc, Addr addr,
152 virtual void process(ThreadContext *tc);
155 class PanicPCEvent : public PCEvent
158 PanicPCEvent(PCEventScope *s, const std::string &desc, Addr pc);
159 virtual void process(ThreadContext *tc);
162 #endif // __PC_EVENT_HH__