proccontrol: Fix Coverity UNINIT_CTOR errors
[dyninst.git] / proccontrol / src / event.C
1 /*
2  * See the dyninst/COPYRIGHT file for copyright information.
3  * 
4  * We provide the Paradyn Tools (below described as "Paradyn")
5  * on an AS IS basis, and do not warrant its validity or performance.
6  * We reserve the right to update, modify, or discontinue this
7  * software at any time.  We shall have no obligation to supply such
8  * updates or modifications or any other form of support to you.
9  * 
10  * By your use of Paradyn, you understand and agree that we (or any
11  * other person or entity with proprietary rights in Paradyn) are
12  * under no obligation to provide either maintenance services,
13  * update services, notices of latent defects, or correction of
14  * defects for Paradyn.
15  * 
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  * 
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  * 
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29  */
30
31 #include "common/h/dyntypes.h"
32 #include "proccontrol/src/int_process.h"
33 #include "proccontrol/src/int_handler.h"
34 #include "proccontrol/src/int_event.h"
35 #include "proccontrol/src/procpool.h"
36 #include "proccontrol/src/irpc.h"
37 #include "proccontrol/h/Event.h"
38 #include "proccontrol/h/PCProcess.h"
39 #include "proccontrol/h/PCErrors.h"
40 #include "proccontrol/h/Generator.h"
41 #include <assert.h>
42 #include <stdlib.h>
43 #include <string.h>
44
45 using namespace std;
46
47 ArchEvent::ArchEvent(std::string name_) :
48    name(name_)
49 {
50 }
51
52 ArchEvent::~ArchEvent()
53 {
54 }
55
56 std::string ArchEvent::getName()
57 {
58    return name;
59 }
60
61 Event::Event(EventType etype_, Thread::ptr thread_) :
62    etype(etype_),
63    thread(thread_),
64    proc(thread_ ? thread_->getProcess() : Process::ptr()),
65    stype(unset),
66    master_event(Event::ptr()),
67    suppress_cb(false),
68    user_event(false),
69    handling_started(false),
70    noted_event(false)
71 {
72 }
73
74 EventType Event::getEventType() const {
75    return etype;
76 }
77
78 Thread::const_ptr Event::getThread() const {
79    return thread;
80 }
81
82 Process::const_ptr Event::getProcess() const {
83    return proc;
84 }
85
86 void Event::setThread(Thread::const_ptr t) {
87    thread = t;
88 }
89
90 void Event::setProcess(Process::const_ptr p) {
91         proc = p;
92 }
93
94 void Event::setUserEvent(bool b) {
95     user_event = b;
96 }
97
98 bool Event::userEvent() const {
99     return user_event;
100 }
101
102 bool Event::canFastHandle() const
103 {
104    return false;
105 }
106
107 void Event::setSyncType(SyncType s)
108 {
109    stype = s;
110 }
111
112 bool Event::suppressCB() const
113 {
114    return suppress_cb;
115 }
116
117 bool Event::triggersCB() const
118 {
119    HandleCallbacks *cbhandler = HandleCallbacks::getCB();
120    if (cbhandler->requiresCB(shared_from_this()))
121      return true;
122    std::vector<Event::ptr>::const_iterator i = subservient_events.begin();
123    for (; i != subservient_events.end(); ++i) {
124       if ((*i)->triggersCB())
125          return true;
126    }
127    return false;
128 }
129
130 void Event::setSuppressCB(bool b)
131 {
132   pthrd_printf("Setting callback suppress for %s\n", name().c_str());
133    suppress_cb = b;
134 }
135
136 Event::SyncType Event::getSyncType() const
137 {
138    return stype;
139 }
140
141 std::string Event::name() const
142 {
143    return etype.name();
144 }
145
146 Event::weak_ptr Event::subservientTo() const
147 {
148    return master_event;
149 }
150
151 void Event::addSubservientEvent(Event::ptr ev)
152 {
153    subservient_events.push_back(ev);
154    ev->master_event = shared_from_this();
155 }
156
157 std::string EventType::name() const
158 {
159    std::string prefix;
160    if (etime == Pre)
161       prefix = "pre-";
162    if (etime == Post)
163       prefix = "post-";
164
165 #define STR_CASE(ET) case ET: return prefix + std::string(#ET)
166    switch (ecode) {
167       STR_CASE(Error);
168       STR_CASE(Unset);
169       STR_CASE(Exit);
170       STR_CASE(Crash);
171       STR_CASE(Fork);
172       STR_CASE(Exec);
173       STR_CASE(ThreadCreate);
174       STR_CASE(UserThreadCreate);
175       STR_CASE(LWPCreate);
176       STR_CASE(ThreadDestroy);
177       STR_CASE(UserThreadDestroy);
178       STR_CASE(LWPDestroy);
179       STR_CASE(Stop);
180       STR_CASE(Signal);
181       STR_CASE(LibraryLoad);
182       STR_CASE(LibraryUnload);
183       STR_CASE(Bootstrap);
184       STR_CASE(Breakpoint);
185       STR_CASE(RPC);
186       STR_CASE(SingleStep);
187       STR_CASE(Library);
188       STR_CASE(BreakpointClear);
189       STR_CASE(BreakpointRestore);
190       STR_CASE(RPCLaunch);
191       STR_CASE(Async);
192       STR_CASE(ChangePCStop);
193       STR_CASE(Detach);
194       STR_CASE(IntBootstrap);
195       STR_CASE(ForceTerminate);
196       STR_CASE(PreBootstrap);
197       STR_CASE(Nop);
198       STR_CASE(ThreadDB);
199       STR_CASE(ThreadInfo);
200       STR_CASE(ControlAuthority);
201       STR_CASE(AsyncRead);
202       STR_CASE(AsyncWrite);
203       STR_CASE(AsyncReadAllRegs);
204       STR_CASE(AsyncSetAllRegs);
205       STR_CASE(AsyncFileRead);
206       STR_CASE(PostponedSyscall);
207       default: return prefix + std::string("Unknown");
208    }
209 }
210
211 bool Event::procStopper() const
212 {
213    return false;
214 }
215
216 Event::~Event()
217 {
218 }
219
220 void Event::setLastError(err_t ec, const char *es) {
221    if (proc) {
222       proc->setLastError(ec, es);
223    }
224 }
225
226 EventTerminate::EventTerminate(EventType type_) :
227    Event(type_)
228 {
229 }
230
231 EventTerminate::~EventTerminate()
232 {
233 }
234
235 EventExit::EventExit(EventType::Time eventtime, int exitcode_) :
236    EventTerminate(EventType(eventtime, EventType::Exit)),
237    exitcode(exitcode_)
238 {
239 }
240
241 int EventExit::getExitCode() const
242 {
243    return exitcode;
244 }
245
246 EventExit::~EventExit()
247 {
248 }
249
250 EventCrash::EventCrash(int termsig_) :
251    EventTerminate(EventType(EventType::None, EventType::Crash)),
252    termsig(termsig_)
253 {
254 }
255
256 int EventCrash::getTermSignal() const
257 {
258    return termsig;
259 }
260          
261 EventCrash::~EventCrash()
262 {
263 }
264
265 EventForceTerminate::EventForceTerminate(int termsig_) :
266     EventTerminate(EventType(EventType::Post, EventType::ForceTerminate)),
267     termsig(termsig_)
268 {
269 }
270
271 int EventForceTerminate::getTermSignal() const
272 {
273    return termsig;
274 }
275
276 EventForceTerminate::~EventForceTerminate()
277 {
278 }
279
280 EventExec::EventExec(EventType::Time etime_, std::string path) :
281    Event(EventType(etime_, EventType::Exec)),
282    execpath(path)
283 {
284 }
285
286 EventExec::~EventExec()
287 {
288 }
289
290 std::string EventExec::getExecPath() const
291 {
292    return execpath;
293 }
294
295 void EventExec::setExecPath(std::string e)
296 {
297    execpath = e;
298 }
299
300 EventStop::EventStop() :
301    Event(EventType(EventType::None, EventType::Stop))
302 {
303 }
304
305 EventStop::~EventStop()
306 {
307 }
308
309
310 EventBreakpoint::EventBreakpoint(int_eventBreakpoint *ibp_) :
311    Event(EventType(EventType::None, EventType::Breakpoint)),
312    int_bp(ibp_)
313 {
314 }
315
316 EventBreakpoint::~EventBreakpoint()
317 {
318    if (int_bp) {
319       delete int_bp;
320       int_bp = NULL;
321    }
322    
323 }
324
325 Dyninst::Address EventBreakpoint::getAddress() const
326 {
327    return int_bp->addr;
328 }
329
330 void EventBreakpoint::getBreakpoints(std::vector<Breakpoint::const_ptr> &bps) const
331 {
332    if (!int_bp)
333       return;
334    bp_instance *ibp = int_bp->lookupInstalledBreakpoint();
335    std::set<Breakpoint::ptr>::iterator i;
336    for (i = ibp->hl_bps.begin(); i != ibp->hl_bps.end(); ++i) {
337       bps.push_back(*i);
338    }
339 }
340
341 void EventBreakpoint::getBreakpoints(std::vector<Breakpoint::ptr> &bps)
342 {
343    if (!int_bp)
344       return;
345    bp_instance *ibp = int_bp->lookupInstalledBreakpoint();
346    std::set<Breakpoint::ptr>::iterator i;
347    for (i = ibp->hl_bps.begin(); i != ibp->hl_bps.end(); i++) {
348       bps.push_back(*i);
349    }
350 }
351
352 bool EventBreakpoint::suppressCB() const
353 {
354
355   if (Event::suppressCB()) {
356     pthrd_printf("Suppressing CB on EventBreakpoint: All event suppress\n");
357       return true;
358   }
359    bp_instance *ibp = int_bp->lookupInstalledBreakpoint();
360    if (!ibp) {
361      pthrd_printf("Suppressing CB on EventBreakpoint: no bp_instance\n");
362      return true;
363    }
364    if (ibp->hl_bps.empty()) {
365      pthrd_printf("Suppressing CB on EventBreakpoint:: no hl_bps in bp_instance\n");
366      return true;
367    }
368    for (bp_instance::iterator iter = ibp->begin();
369         iter != ibp->end(); ++iter) {
370      pthrd_printf("Suppressing CB on EventBreakpoint: checking for unsuppressed HL BP: %s\n",
371                   (*iter)->suppressCallbacks() ? "<suppress>" : "<no suppress>");
372      if (!(*iter)->suppressCallbacks()) return false;
373    }
374    pthrd_printf("Suppressing CB on EventBreakpoint: default case\n");
375    return true;
376 }
377
378 int_eventBreakpoint *EventBreakpoint::getInternal() const
379 {
380    return int_bp;
381 }
382
383 bool EventBreakpoint::procStopper() const
384 {
385    int num_proc_stoppers = 0;
386    bp_instance *bp = int_bp->lookupInstalledBreakpoint();
387    if (!bp) {
388       return false;
389    }
390
391    for (sw_breakpoint::iterator i = bp->begin(); i != bp->end(); i++) {
392       if (!(*i)->isProcessStopper())
393          continue;
394       if (isGeneratorThread()) {
395          //We can call this during decode--don't set the states then.
396          return true;
397       }
398       num_proc_stoppers++;
399    }
400
401    if (!handled_by.empty())
402       return false;
403
404    if (!num_proc_stoppers) {
405       //The breakpoint is not a proc stopper.
406       return false;
407    }
408
409    int_process *proc = getProcess()->llproc();
410    int_thread *thrd = getThread()->llthrd();
411    if (!int_bp->stopped_proc) {
412       //Move the BreakpointHold state of the process to be stopped.
413       thrd->getBreakpointHoldState().desyncStateProc(int_thread::stopped);
414       int_bp->stopped_proc = true;
415    }
416    
417    //We return true if the event isn't ready
418    return !proc->getProcStopManager().processStoppedTo(int_thread::BreakpointHoldStateID);
419 }
420
421 EventSignal::EventSignal(int sig_) :
422    Event(EventType(EventType::None, EventType::Signal)),
423    sig(sig_)
424 {
425 }
426
427 EventSignal::~EventSignal()
428 {
429 }
430
431 int EventSignal::getSignal() const
432 {
433    return sig;
434 }
435
436 void EventSignal::clearThreadSignal() const
437 {
438     int_thread *thr = getThread()->llthrd();
439     thr->setContSignal(0);
440 }
441
442 void EventSignal::setThreadSignal(int newSignal) const 
443 {
444     int_thread *thr = getThread()->llthrd();
445     thr->setContSignal(newSignal);
446 }
447
448 EventBootstrap::EventBootstrap() :
449    Event(EventType(EventType::None, EventType::Bootstrap))
450 {
451 }
452
453 EventBootstrap::~EventBootstrap()
454 {
455 }
456
457 EventPreBootstrap::EventPreBootstrap() :
458    Event(EventType(EventType::None, EventType::PreBootstrap))
459 {
460 }
461
462 EventPreBootstrap::~EventPreBootstrap()
463 {
464 }
465
466
467 EventNewThread::EventNewThread(EventType et) : 
468    Event(et)
469 {
470 }
471
472 EventNewThread::~EventNewThread()
473 {
474 }
475
476 EventNewUserThread::EventNewUserThread() :
477    EventNewThread(EventType(EventType::None, EventType::UserThreadCreate))
478 {
479    iev = new int_eventNewUserThread();
480 }
481
482 EventNewUserThread::~EventNewUserThread()
483 {
484    if (iev) 
485       delete iev;
486    iev = NULL;
487 }
488
489 Dyninst::LWP EventNewUserThread::getLWP() const
490 {
491    if (iev->lwp != NULL_LWP)
492       return iev->lwp;
493    return iev->thr ? iev->thr->getLWP() : NULL_LWP;
494 }
495
496 Thread::const_ptr EventNewUserThread::getNewThread() const
497 {
498    if (iev->thr)
499       return iev->thr->thread();
500    if (iev->lwp == NULL_LWP)
501       return Thread::const_ptr();
502
503    iev->thr = getProcess()->llproc()->threadPool()->findThreadByLWP(iev->lwp);
504    assert(iev->thr);
505    return iev->thr->thread();
506 }
507
508 int_eventNewUserThread *EventNewUserThread::getInternalEvent() const
509 {
510    return iev;
511 }
512
513 EventNewLWP::EventNewLWP(Dyninst::LWP lwp_, int attach_status) :
514    EventNewThread(EventType(EventType::None, EventType::LWPCreate)),
515    lwp(lwp_)
516 {
517    iev = new int_eventNewLWP();
518    iev->lwp = lwp;
519    iev->attach_status = (int_thread::attach_status_t) attach_status;
520 }
521
522 EventNewLWP::~EventNewLWP()
523 {
524    delete iev;
525 }
526
527 Dyninst::LWP EventNewLWP::getLWP() const
528 {
529    return iev->lwp;
530 }
531
532 Thread::const_ptr EventNewLWP::getNewThread() const
533 {
534    int_thread *thr = getProcess()->llproc()->threadPool()->findThreadByLWP(lwp);
535    assert(thr);
536    return thr->thread();
537 }
538
539 int_eventNewLWP *EventNewLWP::getInternalEvent()
540 {
541    return iev;
542 }
543
544 EventThreadDestroy::EventThreadDestroy(EventType et) :
545    Event(et)
546 {
547 }
548
549 EventThreadDestroy::~EventThreadDestroy()
550 {
551 }
552
553 EventUserThreadDestroy::EventUserThreadDestroy(EventType::Time time_) :
554    EventThreadDestroy(EventType(time_, EventType::UserThreadDestroy))
555 {
556 }
557
558 EventUserThreadDestroy::~EventUserThreadDestroy()
559 {
560 }
561
562 EventLWPDestroy::EventLWPDestroy(EventType::Time time_) :
563    EventThreadDestroy(EventType(time_, EventType::LWPDestroy))
564 {
565 }
566
567 EventLWPDestroy::~EventLWPDestroy()
568 {
569 }
570
571 EventFork::EventFork(EventType::Time time_, Dyninst::PID pid_) :
572    Event(EventType(time_, EventType::Fork)),
573    pid(pid_)
574 {
575 }
576
577 EventFork::~EventFork()
578 {
579 }
580
581 Dyninst::PID EventFork::getPID() const
582 {
583    return pid;
584 }
585
586 Process::const_ptr EventFork::getChildProcess() const
587 {
588    int_process *iproc = ProcPool()->findProcByPid(pid);
589    assert(iproc);
590    return iproc->proc();
591 }
592
593 EventRPC::EventRPC(rpc_wrapper *wrapper_) :
594    Event(EventType(EventType::None, EventType::RPC)),
595    wrapper(new rpc_wrapper(wrapper_))
596 {
597    int_rpc = new int_eventRPC();
598 }
599
600 EventRPC::~EventRPC()
601 {
602    delete wrapper;
603    wrapper = NULL;
604
605    if (int_rpc) {
606       delete int_rpc;
607       int_rpc = NULL;
608    }
609 }
610
611 IRPC::const_ptr EventRPC::getIRPC() const
612
613    return wrapper->rpc->getIRPC().lock();
614 }
615
616 bool EventRPC::suppressCB() const
617 {
618    if (Event::suppressCB()) return true;
619    return (wrapper->rpc->getIRPC().lock() == IRPC::ptr());
620 }
621
622 rpc_wrapper *EventRPC::getllRPC()
623 {
624    return wrapper;
625 }
626
627 int_eventRPC *EventRPC::getInternal() const
628 {
629    return int_rpc;
630 }
631
632 bool EventRPCLaunch::procStopper() const
633 {
634    int_process *proc = getProcess()->llproc();
635    int_thread *thrd = getThread()->llthrd();
636
637    if (!handled_by.empty())
638       return false;
639
640    int_iRPC::ptr rpc = thrd->nextPostedIRPC();
641    assert(rpc);
642
643    if (proc->plat_threadOpsNeedProcStop()) {
644       return !proc->getProcStopManager().processStoppedTo(int_thread::IRPCSetupStateID);
645    }
646    if (rpc->isProcStopRPC()) {
647       return !rpc->isRPCPrepped();
648    }
649    return !proc->getProcStopManager().threadStoppedTo(thrd, int_thread::IRPCSetupStateID);
650 }
651
652 EventRPCLaunch::EventRPCLaunch() :
653    Event(EventType(EventType::None, EventType::RPCLaunch))
654 {
655 }
656
657 EventRPCLaunch::~EventRPCLaunch()
658 {
659 }
660
661 EventSingleStep::EventSingleStep() :
662    Event(EventType(EventType::None, EventType::SingleStep))
663 {
664 }
665
666 EventSingleStep::~EventSingleStep()
667 {
668 }
669
670 EventBreakpointClear::EventBreakpointClear() :
671   Event(EventType(EventType::None, EventType::BreakpointClear))
672 {
673    int_bpc = new int_eventBreakpointClear();
674 }
675
676 EventBreakpointClear::~EventBreakpointClear()
677 {
678    assert(int_bpc);
679    delete int_bpc;
680    int_bpc = NULL;
681 }
682
683 int_eventBreakpointClear *EventBreakpointClear::getInternal() const
684 {
685    return int_bpc;
686 }
687
688 bool EventBreakpointClear::procStopper() const
689 {
690    if (!int_bpc->stopped_proc)
691       return false;
692
693    if (!handled_by.empty())
694       return false;
695
696    int_process *proc = getProcess()->llproc();
697    return !proc->getProcStopManager().processStoppedTo(int_thread::BreakpointStateID);
698 }
699
700 EventBreakpointRestore::EventBreakpointRestore(int_eventBreakpointRestore *iebpr) :
701    Event(EventType(EventType::None, EventType::BreakpointRestore)),
702    int_bpr(iebpr)
703 {
704 }
705
706 EventBreakpointRestore::~EventBreakpointRestore()
707 {
708    assert(int_bpr);
709    delete int_bpr;
710    int_bpr = NULL;
711 }
712
713 int_eventBreakpointRestore *EventBreakpointRestore::getInternal() const
714 {
715    return int_bpr;
716 }
717
718
719 EventLibrary::EventLibrary(const std::set<Library::ptr> &added_libs_,
720                            const std::set<Library::ptr> &rmd_libs_) :
721    Event(EventType(EventType::None, EventType::Library)),
722    added_libs(added_libs_),
723    rmd_libs(rmd_libs_)
724 {
725 }
726
727 EventLibrary::EventLibrary() :
728    Event(EventType(EventType::None, EventType::Library))
729 {
730 }
731
732 EventLibrary::~EventLibrary()
733 {
734 }
735
736 void EventLibrary::setLibs(const std::set<Library::ptr> &added_libs_,
737                            const std::set<Library::ptr> &rmd_libs_)
738 {
739    added_libs = added_libs_;
740    rmd_libs = rmd_libs_;
741 }
742
743 const std::set<Library::ptr> &EventLibrary::libsAdded() const
744 {
745    return added_libs;
746 }
747
748 const std::set<Library::ptr> &EventLibrary::libsRemoved() const
749 {
750    return rmd_libs;
751 }
752
753 EventAsync::EventAsync(int_eventAsync *ievent) :
754    Event(EventType(EventType::None, EventType::Async)),
755    internal(ievent)
756 {
757 }
758
759 EventAsync::~EventAsync()
760 {
761    if (internal) {
762       delete internal;
763       internal = NULL;
764    }
765 }
766
767 int_eventAsync *EventAsync::getInternal() const
768 {
769    return internal;
770 }
771
772 EventChangePCStop::EventChangePCStop() :
773    Event(EventType(EventType::None, EventType::ChangePCStop))
774 {
775 }
776
777 EventChangePCStop::~EventChangePCStop()
778 {
779 }
780
781 EventDetach::EventDetach() :
782    Event(EventType(EventType::None, EventType::Detach))
783 {
784    int_detach = new int_eventDetach();
785 }
786
787 EventDetach::~EventDetach()
788 {
789    if (int_detach)
790       delete int_detach;
791    int_detach = NULL;
792 }
793
794 int_eventDetach *EventDetach::getInternal() const
795 {
796    return int_detach;
797 }
798
799 bool EventDetach::procStopper() const
800 {
801    if (!handled_by.empty())
802       return false;
803
804    if (getInternal()->removed_bps)
805       return false;
806
807    int_process *proc = getProcess()->llproc();
808    return !proc->getProcStopManager().processStoppedTo(int_thread::DetachStateID);
809 }
810
811 EventIntBootstrap::EventIntBootstrap(void *d) :
812    Event(EventType(EventType::None, EventType::IntBootstrap)),
813    data(d)
814 {
815 }
816
817 EventIntBootstrap::~EventIntBootstrap()
818 {
819 }
820
821 void *EventIntBootstrap::getData() const
822 {
823    return data;
824 }
825
826 void EventIntBootstrap::setData(void *d)
827 {
828    data = d;
829 }
830
831 EventAsyncIO::EventAsyncIO(EventType et, int_eventAsyncIO *iev_) :
832    Event(et),
833    iev(iev_)
834 {
835 }
836
837 EventAsyncIO::~EventAsyncIO()
838 {
839    if (iev) {
840       delete iev;
841       iev = NULL;
842    }
843 }
844
845 bool EventAsyncIO::hadError() const
846 {
847    return iev->resp->hasError();
848 }
849
850 void *EventAsyncIO::getOpaqueVal() const
851 {
852    return iev->opaque_value;
853 }
854
855 int_eventAsyncIO *EventAsyncIO::getInternalEvent() const
856 {
857    return iev;
858 }
859
860 EventAsyncRead::EventAsyncRead(int_eventAsyncIO *iev_) :
861    EventAsyncIO(EventType(EventType::None, EventType::AsyncRead), iev_)
862 {
863 }
864
865 EventAsyncRead::~EventAsyncRead()
866 {
867 }
868
869 void *EventAsyncRead::getMemory() const
870 {
871    return iev->local_memory;
872 }
873
874 size_t EventAsyncRead::getSize() const
875 {
876    return iev->size;
877 }
878
879 Address EventAsyncRead::getAddress() const
880 {
881    return iev->remote_addr;
882 }
883
884 EventAsyncWrite::EventAsyncWrite(int_eventAsyncIO *iev_) :
885    EventAsyncIO(EventType(EventType::None, EventType::AsyncWrite), iev_)
886 {
887 }
888
889 EventAsyncWrite::~EventAsyncWrite()
890 {
891 }
892
893 size_t EventAsyncWrite::getSize() const
894 {
895    return iev->size;
896 }
897
898 Address EventAsyncWrite::getAddress() const
899 {
900    return iev->remote_addr;
901 }
902
903 EventAsyncReadAllRegs::EventAsyncReadAllRegs(int_eventAsyncIO *iev_) :
904    EventAsyncIO(EventType(EventType::None, EventType::AsyncReadAllRegs), iev_)
905 {
906 }
907
908 EventAsyncReadAllRegs::~EventAsyncReadAllRegs()
909 {
910 }
911
912 const RegisterPool &EventAsyncReadAllRegs::getRegisters() const
913 {
914    return *iev->rpool;
915 }
916
917 EventAsyncSetAllRegs::EventAsyncSetAllRegs(int_eventAsyncIO *iev_) :
918    EventAsyncIO(EventType(EventType::None, EventType::AsyncSetAllRegs), iev_)
919 {
920 }
921
922 EventAsyncSetAllRegs::~EventAsyncSetAllRegs()
923 {
924 }
925
926 EventNop::EventNop() :
927    Event(EventType(EventType::None, EventType::Nop))
928 {
929 }
930
931 EventNop::~EventNop()
932 {
933 }
934
935 EventThreadDB::EventThreadDB() :
936    Event(EventType(EventType::None, EventType::ThreadDB))
937 {
938    int_etdb = new int_eventThreadDB();
939 }
940
941 EventThreadDB::~EventThreadDB()
942 {
943    delete int_etdb;
944    int_etdb = NULL;
945 }
946
947 EventWinStopThreadDestroy::EventWinStopThreadDestroy(EventType::Time time_) :
948 EventThreadDestroy(EventType(time_, EventType::WinStopThreadDestroy)) {};
949
950 EventWinStopThreadDestroy::~EventWinStopThreadDestroy() {}
951
952 int_eventThreadDB *EventThreadDB::getInternal() const
953 {
954    return int_etdb;
955 }
956
957 bool EventThreadDB::triggersCB() const
958 {
959    EventType::Time ev_times[] = { EventType::None, EventType::Pre, EventType::Post };
960    int ev_types[] = { EventType::UserThreadCreate, EventType::UserThreadDestroy, 
961                       EventType::LWPCreate, EventType::LWPDestroy };
962    HandleCallbacks *cbhandler = HandleCallbacks::getCB();
963    for (unsigned i = 0; i < 3; i++)
964       for (unsigned j = 0; j < 4; j++)
965          if (cbhandler->hasCBs(EventType(ev_times[i], ev_types[j])))
966             return true;
967    return false;
968 }
969
970 EventControlAuthority::EventControlAuthority(EventType::Time t, int_eventControlAuthority *iev_) :
971    Event(EventType(t, EventType::ControlAuthority)),
972    iev(iev_)
973 {
974 }
975
976 EventControlAuthority::~EventControlAuthority()
977 {
978    if (iev && !iev->dont_delete) {
979       delete iev;
980    }
981    iev = NULL;
982 }
983
984 bool EventControlAuthority::procStopper() const
985 {
986    if (eventTrigger() == ControlUnset)
987       return false;
988    if (eventTrigger() == ControlGained)
989       return false;
990    if (iev->unset_desync)
991       return false;
992
993    int_process *proc = getProcess()->llproc();
994    int_thread *thr = getThread()->llthrd();
995
996    if (!iev->did_desync) {
997       pthrd_printf("Desyncing control authority state for EventControlAuthority\n");
998       thr->getControlAuthorityState().desyncStateProc(int_thread::stopped);
999       iev->did_desync = true;
1000    }
1001    return !proc->getProcStopManager().processStoppedTo(int_thread::ControlAuthorityStateID);
1002 }
1003
1004 std::string EventControlAuthority::otherToolName() const
1005 {
1006    return iev->toolname;
1007 }
1008  
1009 unsigned int EventControlAuthority::otherToolID() const
1010 {
1011    return iev->toolid;
1012 }
1013
1014 int EventControlAuthority::otherToolPriority() const
1015 {
1016    return iev->priority;
1017 }
1018
1019 EventControlAuthority::Trigger EventControlAuthority::eventTrigger() const
1020 {
1021    return iev->trigger;
1022 }
1023
1024 EventAsyncFileRead::EventAsyncFileRead(int_eventAsyncFileRead *iev_) :
1025    Event(EventType(EventType::None, EventType::AsyncFileRead)),
1026    iev(iev_)
1027 {
1028 }
1029
1030 EventAsyncFileRead::~EventAsyncFileRead()
1031 {
1032    delete iev;
1033 }
1034
1035 std::string EventAsyncFileRead::getFilename() const
1036 {
1037    return iev->filename;
1038 }
1039
1040 size_t EventAsyncFileRead::getReadSize() const
1041 {
1042    return iev->orig_size;
1043 }
1044
1045 Dyninst::Offset EventAsyncFileRead::getReadOffset() const
1046 {
1047    return iev->offset;
1048 }
1049
1050 void *EventAsyncFileRead::getBuffer() const
1051 {
1052    return iev->data;
1053 }
1054
1055 size_t EventAsyncFileRead::getBufferSize() const
1056 {
1057    return iev->size;
1058 }
1059
1060 bool EventAsyncFileRead::isEOF() const
1061 {
1062    return (iev->size != iev->orig_size);
1063 }
1064
1065 int EventAsyncFileRead::errorCode() const 
1066 {
1067    return iev->errorcode;
1068 }
1069
1070 int_eventAsyncFileRead *EventAsyncFileRead::getInternal()
1071 {
1072    return iev;
1073 }
1074
1075 int_eventControlAuthority *EventControlAuthority::getInternalEvent() const 
1076 {
1077    return iev;
1078 }
1079
1080 EventPostponedSyscall::EventPostponedSyscall() :
1081    Event(EventType(EventType::None, EventType::PostponedSyscall))
1082 {
1083 }
1084
1085 EventPostponedSyscall::~EventPostponedSyscall()
1086 {
1087 }
1088
1089 int_eventBreakpoint::int_eventBreakpoint(Address a, sw_breakpoint *, int_thread *thr) :
1090    addr(a),
1091    hwbp(NULL),
1092    thrd(thr),
1093    stopped_proc(false)
1094 {
1095 }
1096
1097 int_eventBreakpoint::int_eventBreakpoint(hw_breakpoint *i, int_thread *thr) :
1098    addr(i->getAddr()),
1099    hwbp(i),
1100    thrd(thr),
1101    stopped_proc(false)
1102 {
1103 }
1104
1105 int_eventBreakpoint::~int_eventBreakpoint()
1106 {
1107 }
1108
1109 bp_instance *int_eventBreakpoint::lookupInstalledBreakpoint()
1110 {
1111    if (hwbp)
1112       return static_cast<bp_instance *>(hwbp);
1113    else
1114       return static_cast<bp_instance *>(thrd->llproc()->getBreakpoint(addr));
1115 }
1116
1117 int_eventBreakpointClear::int_eventBreakpointClear() :
1118    started_bp_suspends(false),
1119    cached_bp_sets(false),
1120    set_singlestep(false),
1121    stopped_proc(false)
1122 {
1123 }
1124
1125 int_eventBreakpointClear::~int_eventBreakpointClear()
1126 {
1127 }
1128
1129 int_eventBreakpointRestore::int_eventBreakpointRestore(bp_instance *breakpoint_) :
1130    set_states(false),
1131    bp_resume_started(false),
1132    bp(breakpoint_)
1133 {
1134 }
1135
1136 int_eventBreakpointRestore::~int_eventBreakpointRestore()
1137 {
1138 }
1139
1140 int_eventNewLWP::int_eventNewLWP() :
1141    lwp(NULL_LWP),
1142    attach_status(int_thread::as_unknown)
1143 {
1144 }
1145
1146 int_eventNewLWP::~int_eventNewLWP()
1147 {
1148 }
1149
1150 int_eventRPC::int_eventRPC()
1151 {
1152 }
1153
1154 int_eventRPC::~int_eventRPC()
1155 {
1156 }
1157
1158 void int_eventRPC::getPendingAsyncs(std::set<response::ptr> &pending)
1159 {
1160    if (alloc_regresult && !alloc_regresult->isReady()) {
1161       pending.insert(alloc_regresult);
1162    }
1163    if (memrestore_response && !memrestore_response->isReady()) {
1164       pending.insert(memrestore_response);
1165    }
1166    if (regrestore_response && !regrestore_response->isReady()) {
1167       pending.insert(regrestore_response);
1168    }
1169 }
1170
1171 int_eventAsync::int_eventAsync(response::ptr r)
1172 {
1173    resp.insert(r);
1174 }
1175
1176 int_eventAsync::~int_eventAsync()
1177 {
1178 }
1179
1180 set<response::ptr> &int_eventAsync::getResponses()
1181 {
1182    return resp;
1183 }
1184
1185 void int_eventAsync::addResp(response::ptr r)
1186 {
1187    resp.insert(r);
1188 }
1189
1190 int_eventNewUserThread::int_eventNewUserThread() :
1191    thr(NULL),
1192    lwp(NULL_LWP),
1193    raw_data(NULL),
1194    needs_update(true)
1195 {   
1196 }
1197
1198 int_eventNewUserThread::~int_eventNewUserThread()
1199 {
1200    if (raw_data)
1201       free(raw_data);
1202 }
1203
1204 int_eventThreadDB::int_eventThreadDB() :
1205    completed_new_evs(false),
1206    completed_getmsgs(false)
1207 {
1208 }
1209
1210 int_eventThreadDB::~int_eventThreadDB()
1211 {
1212 }
1213
1214 int_eventDetach::int_eventDetach() :
1215    temporary_detach(false),
1216    leave_stopped(false),
1217    removed_bps(false),
1218    done(false),
1219    had_error(false)
1220 {
1221 }
1222
1223 int_eventDetach::~int_eventDetach()
1224 {
1225 }
1226
1227 int_eventControlAuthority::int_eventControlAuthority(string toolname_, unsigned int toolid_,
1228                                                      int priority_, EventControlAuthority::Trigger trigger_) :
1229    toolname(toolname_),
1230    toolid(toolid_),
1231    priority(priority_),
1232    trigger(trigger_),
1233    control_lost(false),
1234    handled_bps(false),
1235    took_ca(false),
1236    did_desync(false),
1237    unset_desync(false),
1238    dont_delete(false),
1239    waiting_on_stop(false)
1240 {
1241 }
1242
1243 int_eventControlAuthority::int_eventControlAuthority() :
1244    toolid(0),
1245    priority(0),
1246    trigger(EventControlAuthority::ControlUnset),
1247    control_lost(false),
1248    handled_bps(false),
1249    took_ca(false),
1250    did_desync(false),
1251    unset_desync(false),
1252    dont_delete(false),
1253    waiting_on_stop(false)
1254 {
1255 }
1256
1257 int_eventControlAuthority::~int_eventControlAuthority()
1258 {
1259 }
1260
1261 int_eventAsyncIO::int_eventAsyncIO(response::ptr resp_, asyncio_type iot_) : 
1262    resp(resp_),
1263    local_memory(NULL),
1264    remote_addr(0),
1265    size(0),
1266    opaque_value(NULL),
1267    iot(iot_),
1268    rpool(NULL)
1269 {
1270    pthrd_printf("Creating int_eventAsyncIO at %p\n", this);
1271 }
1272
1273 int_eventAsyncIO::~int_eventAsyncIO()
1274 {
1275    pthrd_printf("Deleting int_eventAsyncIO at %p\n", this);
1276 }
1277
1278 int_eventAsyncFileRead::int_eventAsyncFileRead() :
1279    data(NULL),
1280    size(0),
1281    orig_size(0),
1282    to_free(NULL),
1283    offset(0),
1284    errorcode(0),
1285    whole_file(false),
1286    resp(NULL)
1287 {
1288 }
1289
1290 int_eventAsyncFileRead::~int_eventAsyncFileRead()
1291 {
1292    if (to_free)
1293       free(to_free);
1294 }
1295
1296 bool int_eventAsyncFileRead::isComplete()
1297 {
1298    if (!whole_file)
1299       return true;
1300    return (size != orig_size);
1301 }
1302
1303 #define DEFN_EVENT_CAST(NAME, TYPE) \
1304    NAME::ptr Event::get ## NAME() {  \
1305      if (etype.code() != EventType::TYPE) return NAME::ptr();  \
1306      return boost::static_pointer_cast<NAME>(shared_from_this()); \
1307    } \
1308    NAME::const_ptr Event::get ## NAME() const { \
1309      if (etype.code() != EventType::TYPE) return NAME::const_ptr();  \
1310      return boost::static_pointer_cast<const NAME>(shared_from_this()); \
1311    }
1312
1313 #define DEFN_EVENT_CAST2(NAME, TYPE, TYPE2) \
1314    NAME::ptr Event::get ## NAME() {  \
1315      if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2) return NAME::ptr(); \
1316      return boost::static_pointer_cast<NAME>(shared_from_this()); \
1317    } \
1318    NAME::const_ptr Event::get ## NAME() const { \
1319      if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2) return NAME::const_ptr(); \
1320      return boost::static_pointer_cast<const NAME>(shared_from_this()); \
1321    }
1322
1323 #define DEFN_EVENT_CAST3(NAME, TYPE, TYPE2, TYPE3) \
1324    NAME::ptr Event::get ## NAME() {  \
1325      if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2 && etype.code() != EventType::TYPE3) return NAME::ptr(); \
1326      return boost::static_pointer_cast<NAME>(shared_from_this()); \
1327    } \
1328    NAME::const_ptr Event::get ## NAME() const { \
1329      if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2 && etype.code() != EventType::TYPE3) return NAME::const_ptr(); \
1330      return boost::static_pointer_cast<const NAME>(shared_from_this()); \
1331    }
1332
1333 #define DEFN_EVENT_CAST4(NAME, TYPE, TYPE2, TYPE3, TYPE4)   \
1334    NAME::ptr Event::get ## NAME() {  \
1335       if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2 && etype.code() != EventType::TYPE3 && etype.code() != EventType::TYPE4) return NAME::ptr(); \
1336      return boost::static_pointer_cast<NAME>(shared_from_this()); \
1337    } \
1338    NAME::const_ptr Event::get ## NAME() const { \
1339       if (etype.code() != EventType::TYPE && etype.code() != EventType::TYPE2 && etype.code() != EventType::TYPE3 && etype.code() != EventType::TYPE4) return NAME::const_ptr(); \
1340      return boost::static_pointer_cast<const NAME>(shared_from_this()); \
1341    }
1342
1343
1344 DEFN_EVENT_CAST4(EventAsyncIO, AsyncRead, AsyncWrite, AsyncReadAllRegs, AsyncSetAllRegs)
1345 DEFN_EVENT_CAST3(EventTerminate, Exit, Crash, ForceTerminate)
1346 DEFN_EVENT_CAST2(EventNewThread, UserThreadCreate, LWPCreate)
1347 DEFN_EVENT_CAST2(EventThreadDestroy, UserThreadDestroy, LWPDestroy)
1348 DEFN_EVENT_CAST(EventExit, Exit)
1349 DEFN_EVENT_CAST(EventCrash, Crash)
1350 DEFN_EVENT_CAST(EventForceTerminate, ForceTerminate)
1351 DEFN_EVENT_CAST(EventExec, Exec)
1352 DEFN_EVENT_CAST(EventStop, Stop)
1353 DEFN_EVENT_CAST(EventBreakpoint, Breakpoint)
1354 DEFN_EVENT_CAST(EventNewUserThread, UserThreadCreate)
1355 DEFN_EVENT_CAST(EventNewLWP, LWPCreate)
1356 DEFN_EVENT_CAST(EventUserThreadDestroy, UserThreadDestroy)
1357 DEFN_EVENT_CAST(EventLWPDestroy, LWPDestroy)
1358 DEFN_EVENT_CAST(EventFork, Fork)
1359 DEFN_EVENT_CAST(EventSignal, Signal)
1360 DEFN_EVENT_CAST(EventBootstrap, Bootstrap)
1361 DEFN_EVENT_CAST(EventRPC, RPC)
1362 DEFN_EVENT_CAST(EventSingleStep, SingleStep)
1363 DEFN_EVENT_CAST(EventBreakpointClear, BreakpointClear)
1364 DEFN_EVENT_CAST(EventBreakpointRestore, BreakpointRestore)
1365 DEFN_EVENT_CAST(EventLibrary, Library)
1366 DEFN_EVENT_CAST(EventRPCLaunch, RPCLaunch)
1367 DEFN_EVENT_CAST(EventAsync, Async)
1368 DEFN_EVENT_CAST(EventChangePCStop, ChangePCStop)
1369 DEFN_EVENT_CAST(EventPreBootstrap, PreBootstrap)
1370 DEFN_EVENT_CAST(EventDetach, Detach)
1371 DEFN_EVENT_CAST(EventIntBootstrap, IntBootstrap)
1372 DEFN_EVENT_CAST(EventNop, Nop)
1373 DEFN_EVENT_CAST(EventThreadDB, ThreadDB)
1374 DEFN_EVENT_CAST(EventWinStopThreadDestroy, WinStopThreadDestroy)
1375 DEFN_EVENT_CAST(EventControlAuthority, ControlAuthority)
1376 DEFN_EVENT_CAST(EventAsyncRead, AsyncRead)
1377 DEFN_EVENT_CAST(EventAsyncWrite, AsyncWrite)
1378 DEFN_EVENT_CAST(EventAsyncReadAllRegs, AsyncReadAllRegs)
1379 DEFN_EVENT_CAST(EventAsyncSetAllRegs, AsyncSetAllRegs)
1380 DEFN_EVENT_CAST(EventAsyncFileRead, AsyncFileRead)
1381 DEFN_EVENT_CAST(EventPostponedSyscall, PostponedSyscall)