A first pass at implementing thread stop and continue on FreeBSD.
[dyninst.git] / proccontrol / h / Event.h
1 #if !defined(EVENT_H_)
2 #define EVENT_H_
3
4 #include <string>
5 #include <set>
6 #include "dyntypes.h"
7 #include "EventType.h"
8 #include "Process.h"
9
10 #include "dyn_detail/boost/shared_ptr.hpp"
11 #include "dyn_detail/boost/enable_shared_from_this.hpp"
12
13 class installed_breakpoint;
14 class HandlerPool;
15
16 namespace Dyninst {
17 namespace ProcControlAPI {
18
19 class ArchEvent
20 {
21 private:
22    std::string name;
23 public:
24    ArchEvent(std::string name_ = std::string(""));
25    virtual ~ArchEvent();
26    std::string getName(); 
27 };
28
29 class EventTerminate;
30 class EventExit;
31 class EventCrash;
32 class EventExec;
33 class EventBreakpoint;
34 class EventStop;
35 class EventContinue;
36 class EventNewThread;
37 class EventThreadDestroy;
38 class EventFork;
39 class EventSignal;
40 class EventBootstrap;
41 class EventRPC;
42 class EventSingleStep;
43 class EventBreakpointClear;
44 class EventLibrary;
45
46 class Event : public dyn_detail::boost::enable_shared_from_this<Event>
47 {
48    friend void dyn_detail::boost::checked_delete<Event>(Event *);
49    friend void dyn_detail::boost::checked_delete<const Event>(const Event *);
50    friend class ::HandlerPool;
51  public:
52    typedef dyn_detail::boost::shared_ptr<Event> ptr;
53    typedef dyn_detail::boost::shared_ptr<const Event> const_ptr;
54    typedef dyn_detail::boost::weak_ptr<Event> weak_ptr;
55
56    Event(EventType etype_, Thread::ptr thread_ = Thread::ptr());
57    virtual ~Event();
58
59    typedef enum {
60       unset,
61       async,
62       sync_thread,
63       sync_process
64    } SyncType;
65
66    EventType getEventType() const;
67    Thread::const_ptr getThread() const;
68    Process::const_ptr getProcess() const;
69    SyncType getSyncType() const;
70    std::string name() const;
71
72    void setThread(Thread::const_ptr t);
73    void setProcess(Process::const_ptr p);
74    void setSyncType(SyncType t);
75
76    virtual bool suppressCB() const;
77    virtual bool triggersCB() const;
78    virtual bool canFastHandle() const;
79    virtual bool procStopper() const;
80    Event::weak_ptr subservientTo() const;
81    void addSubservientEvent(Event::ptr ev);
82
83    dyn_detail::boost::shared_ptr<EventTerminate> getEventTerminate();
84    dyn_detail::boost::shared_ptr<const EventTerminate> getEventTerminate() const;
85
86    dyn_detail::boost::shared_ptr<EventExit> getEventExit();
87    dyn_detail::boost::shared_ptr<const EventExit> getEventExit() const;
88
89    dyn_detail::boost::shared_ptr<EventCrash> getEventCrash();
90    dyn_detail::boost::shared_ptr<const EventCrash> getEventCrash() const;
91
92    dyn_detail::boost::shared_ptr<EventExec> getEventExec();
93    dyn_detail::boost::shared_ptr<const EventExec> getEventExec() const;
94
95    dyn_detail::boost::shared_ptr<EventStop> getEventStop();
96    dyn_detail::boost::shared_ptr<const EventStop> getEventStop() const;
97
98    dyn_detail::boost::shared_ptr<EventContinue> getEventContinue();
99    dyn_detail::boost::shared_ptr<const EventContinue> getEventContinue() const;
100
101    dyn_detail::boost::shared_ptr<EventBreakpoint> getEventBreakpoint();
102    dyn_detail::boost::shared_ptr<const EventBreakpoint> getEventBreakpoint() const;
103
104    dyn_detail::boost::shared_ptr<EventNewThread> getEventNewThread();
105    dyn_detail::boost::shared_ptr<const EventNewThread> getEventNewThread() const;
106
107    dyn_detail::boost::shared_ptr<EventThreadDestroy> getEventThreadDestroy();
108    dyn_detail::boost::shared_ptr<const EventThreadDestroy> getEventThreadDestroy() const;
109
110    dyn_detail::boost::shared_ptr<EventFork> getEventFork();
111    dyn_detail::boost::shared_ptr<const EventFork> getEventFork() const;
112
113    dyn_detail::boost::shared_ptr<EventSignal> getEventSignal();
114    dyn_detail::boost::shared_ptr<const EventSignal> getEventSignal() const;
115
116    dyn_detail::boost::shared_ptr<EventBootstrap> getEventBootstrap();
117    dyn_detail::boost::shared_ptr<const EventBootstrap> getEventBootstrap() const;
118
119    dyn_detail::boost::shared_ptr<EventRPC> getEventRPC();
120    dyn_detail::boost::shared_ptr<const EventRPC> getEventRPC() const;
121
122    dyn_detail::boost::shared_ptr<EventSingleStep> getEventSingleStep();
123    dyn_detail::boost::shared_ptr<const EventSingleStep> getEventSingleStep() const;
124
125    dyn_detail::boost::shared_ptr<EventBreakpointClear> getEventBreakpointClear();
126    dyn_detail::boost::shared_ptr<const EventBreakpointClear> getEventBreakpointClear() const;
127
128    dyn_detail::boost::shared_ptr<EventLibrary> getEventLibrary();
129    dyn_detail::boost::shared_ptr<const EventLibrary> getEventLibrary() const;
130
131  protected:
132    EventType etype;
133    Thread::const_ptr thread;
134    Process::const_ptr proc;
135    SyncType stype;
136    std::vector<Event::ptr> subservient_events;
137    Event::weak_ptr master_event;
138 };
139
140 class EventTerminate : public Event
141 {
142    friend void dyn_detail::boost::checked_delete<EventTerminate>(EventTerminate *);
143    friend void dyn_detail::boost::checked_delete<const EventTerminate>(const EventTerminate *);
144  public:
145    typedef dyn_detail::boost::shared_ptr<EventTerminate> ptr;
146    typedef dyn_detail::boost::shared_ptr<const EventTerminate> const_ptr;
147    EventTerminate(EventType type_);
148    virtual ~EventTerminate();
149 };
150
151 class EventExit : public EventTerminate
152 {
153    friend void dyn_detail::boost::checked_delete<EventExit>(EventExit *);
154    friend void dyn_detail::boost::checked_delete<const EventExit>(const EventExit *);
155  private:
156    int exitcode;
157  public:
158    typedef dyn_detail::boost::shared_ptr<EventExit> ptr;
159    typedef dyn_detail::boost::shared_ptr<const EventExit> const_ptr;
160    int getExitCode() const;
161    EventExit(EventType::Time eventtime, int exitcode_);
162    virtual ~EventExit();
163 };
164
165 class EventCrash : public EventTerminate
166 {
167    friend void dyn_detail::boost::checked_delete<EventCrash>(EventCrash *);
168    friend void dyn_detail::boost::checked_delete<const EventCrash>(const EventCrash *);
169  private:
170    int termsig;
171  public:
172    typedef dyn_detail::boost::shared_ptr<EventCrash> ptr;
173    typedef dyn_detail::boost::shared_ptr<const EventCrash> const_ptr;
174    int getTermSignal() const;
175    EventCrash(int termsig);
176    virtual ~EventCrash();
177 };
178
179 class EventExec : public Event
180 {
181    friend void dyn_detail::boost::checked_delete<EventExec>(EventExec *);
182    friend void dyn_detail::boost::checked_delete<const EventExec>(const EventExec *);
183  private:
184    std::string execpath;
185  public:
186    typedef dyn_detail::boost::shared_ptr<EventExec> ptr;
187    typedef dyn_detail::boost::shared_ptr<const EventExec> const_ptr;
188    EventExec(EventType::Time etime_, std::string path = std::string(""));
189    virtual ~EventExec();
190
191    std::string getExecPath() const;
192    void setExecPath(std::string path_);
193 };
194
195 class EventStop : public Event
196 {
197    friend void dyn_detail::boost::checked_delete<EventStop>(EventStop *);
198    friend void dyn_detail::boost::checked_delete<const EventStop>(const EventStop *);
199  public:
200    typedef dyn_detail::boost::shared_ptr<EventStop> ptr;
201    typedef dyn_detail::boost::shared_ptr<const EventStop> const_ptr;
202    EventStop();
203    virtual ~EventStop();
204 };
205
206 class EventContinue : public Event
207 {
208    friend void dyn_detail::boost::checked_delete<EventContinue>(EventContinue *);
209    friend void dyn_detail::boost::checked_delete<const EventContinue>(const EventContinue *);
210  private:
211    int continueSignal;
212  public:
213    typedef dyn_detail::boost::shared_ptr<EventContinue> ptr;
214    typedef dyn_detail::boost::shared_ptr<const EventContinue> const_ptr;
215    int getContinueSignal() const;
216    EventContinue(int contsig);
217    virtual ~EventContinue();
218 };
219
220 class EventBreakpoint : public Event
221 {
222    friend void dyn_detail::boost::checked_delete<EventBreakpoint>(EventBreakpoint *);
223    friend void dyn_detail::boost::checked_delete<const EventBreakpoint>(const EventBreakpoint *);
224  private:
225    installed_breakpoint *ibp;
226    Dyninst::Address addr;
227  public:
228    typedef dyn_detail::boost::shared_ptr<EventBreakpoint> ptr;
229    typedef dyn_detail::boost::shared_ptr<const EventBreakpoint> const_ptr;
230    installed_breakpoint *installedbp() const;
231
232    EventBreakpoint(Dyninst::Address addr, installed_breakpoint *ibp_);
233    virtual ~EventBreakpoint();
234
235    Dyninst::Address getAddress() const;
236    void getBreakpoints(std::vector<Breakpoint::const_ptr> &bps) const;
237    virtual bool suppressCB() const;
238    virtual bool procStopper() const;
239 };
240
241 class EventNewThread : public Event
242 {
243    friend void dyn_detail::boost::checked_delete<EventNewThread>(EventNewThread *);
244    friend void dyn_detail::boost::checked_delete<const EventNewThread>(const EventNewThread *);
245  private:
246    Dyninst::LWP lwp;
247  public:
248    typedef dyn_detail::boost::shared_ptr<EventNewThread> ptr;
249    typedef dyn_detail::boost::shared_ptr<const EventNewThread> const_ptr;
250    EventNewThread(Dyninst::LWP lwp_);
251    ~EventNewThread();
252    Dyninst::LWP getLWP() const;
253    Thread::const_ptr getNewThread() const;
254 };
255
256 class EventThreadDestroy : public Event
257 {
258    friend void dyn_detail::boost::checked_delete<EventThreadDestroy>(EventThreadDestroy *);
259    friend void dyn_detail::boost::checked_delete<const EventThreadDestroy>(const EventThreadDestroy *);
260  public:
261    typedef dyn_detail::boost::shared_ptr<EventThreadDestroy> ptr;
262    typedef dyn_detail::boost::shared_ptr<const EventThreadDestroy> const_ptr;
263    EventThreadDestroy(EventType::Time time_);
264    virtual ~EventThreadDestroy();
265 };
266
267 class EventFork : public Event
268 {
269    friend void dyn_detail::boost::checked_delete<EventFork>(EventFork *);
270    friend void dyn_detail::boost::checked_delete<const EventFork>(const EventFork *);
271   private:
272    Dyninst::PID pid;
273   public:
274    typedef dyn_detail::boost::shared_ptr<EventFork> ptr;
275    typedef dyn_detail::boost::shared_ptr<const EventFork> const_ptr;
276    EventFork(Dyninst::PID pid_);
277    ~EventFork();
278    Dyninst::PID getPID() const;
279    Process::const_ptr getChildProcess() const;
280 };
281
282 class EventSignal : public Event
283 {
284    friend void dyn_detail::boost::checked_delete<EventSignal>(EventSignal *);
285    friend void dyn_detail::boost::checked_delete<const EventSignal>(const EventSignal *);
286  private:
287    int sig;
288  public:
289    typedef dyn_detail::boost::shared_ptr<EventSignal> ptr;
290    typedef dyn_detail::boost::shared_ptr<const EventSignal> const_ptr;
291    EventSignal(int sig);
292    virtual ~EventSignal();
293
294    int getSignal() const;
295 };
296
297 class EventBootstrap : public Event
298 {
299    friend void dyn_detail::boost::checked_delete<EventBootstrap>(EventBootstrap *);
300    friend void dyn_detail::boost::checked_delete<const EventBootstrap>(const EventBootstrap *);
301  public:
302    typedef dyn_detail::boost::shared_ptr<EventBootstrap> ptr;
303    typedef dyn_detail::boost::shared_ptr<const EventBootstrap> const_ptr;
304    EventBootstrap();
305    virtual ~EventBootstrap();
306 };
307
308 class EventRPC : public Event
309 {
310    friend void dyn_detail::boost::checked_delete<EventRPC>(EventRPC *);
311    friend void dyn_detail::boost::checked_delete<const EventRPC>(const EventRPC *);
312  private:
313    rpc_wrapper *wrapper;
314  public:
315    virtual bool suppressCB() const;
316    rpc_wrapper *getllRPC();
317    typedef dyn_detail::boost::shared_ptr<EventRPC> ptr;
318    typedef dyn_detail::boost::shared_ptr<const EventRPC> const_ptr;
319    EventRPC(rpc_wrapper *wrapper_);
320    virtual ~EventRPC();
321
322    IRPC::const_ptr getIRPC() const;
323 };
324
325 class EventSingleStep : public Event
326 {
327    friend void dyn_detail::boost::checked_delete<EventSingleStep>(EventSingleStep *);
328    friend void dyn_detail::boost::checked_delete<const EventSingleStep>(const EventSingleStep *);
329  public:
330    typedef dyn_detail::boost::shared_ptr<EventSingleStep> ptr;
331    typedef dyn_detail::boost::shared_ptr<const EventSingleStep> const_ptr;
332    EventSingleStep();
333    ~EventSingleStep();
334 };
335
336 class EventBreakpointClear : public Event
337 {
338    friend void dyn_detail::boost::checked_delete<EventBreakpointClear>(EventBreakpointClear *);
339    friend void dyn_detail::boost::checked_delete<const EventBreakpointClear>(const EventBreakpointClear *);
340   private:
341    installed_breakpoint *bp_;
342   public:
343    typedef dyn_detail::boost::shared_ptr<EventBreakpointClear> ptr;
344    typedef dyn_detail::boost::shared_ptr<const EventBreakpointClear> const_ptr;
345    EventBreakpointClear(installed_breakpoint *bp);
346    ~EventBreakpointClear();
347    
348    installed_breakpoint *bp();
349 };
350
351 class EventLibrary : public Event
352 {
353    friend void dyn_detail::boost::checked_delete<EventLibrary>(EventLibrary *);
354    friend void dyn_detail::boost::checked_delete<const EventLibrary>(const EventLibrary *);
355  private:
356    std::set<Library::ptr> added_libs;
357    std::set<Library::ptr> rmd_libs;
358  public:
359    typedef dyn_detail::boost::shared_ptr<EventLibrary> ptr;
360    typedef dyn_detail::boost::shared_ptr<const EventLibrary> const_ptr;
361    EventLibrary();
362    EventLibrary(const std::set<Library::ptr> &added_libs_,
363                 const std::set<Library::ptr> &rmd_libs_);
364    ~EventLibrary();
365
366    void setLibs(const std::set<Library::ptr> &added_libs_,
367                 const std::set<Library::ptr> &rmd_libs_);
368    const std::set<Library::ptr> &libsAdded() const;
369    const std::set<Library::ptr> &libsRemoved() const;
370 };
371
372 }
373 }
374 #endif