Process::cb_ret_t Backend::handleTimeEvent() { // Get all subscribed events set<Event*>& events = Time::getTimeSubscribers(); set<Event*>::iterator eventIter = events.begin(); for(;eventIter != events.end(); eventIter++) { Event* event = *eventIter; ProcessSet::ptr procset = ((Time *)event)->getProcset(); ProcessSet::iterator procIter = procset->begin(); if(procset->size() == 0) continue; if(!event || !event->isEnabled(*procIter)) continue; // this is to avoid a race condition where a time event occurs in the middle of iterating through the processes DYSECTVERBOSE(true, "Time event with timeout %d detected on %d processes", ((Time *)event)->getTimeout(), procset->size()); for(;procIter != procset->end(); procIter++) { Process::ptr procPtr = *procIter; if(event && event->isEnabled(procPtr)) { Thread::ptr threadPtr = procPtr->threads().getInitialThread(); Walker *proc = (Walker *)procPtr->getData(); handleEvent(procPtr, threadPtr, event); } } if(event->getOwner()->getLifeSpan() == fireOnce) event->disable(); } return Process::cbDefault; }
bool Location::disable(ProcessSet::ptr lprocset) { assert(owner != 0); if(codeLocations.empty()) { return Err::verbose(true, "No code locations"); } if(!lprocset) { return Err::warn(false, "Process set not present"); } ProcessSet::iterator procIter = lprocset->begin(); for(;procIter != lprocset->end(); procIter++) { Process::ptr procPtr = *procIter; Walker* proc = (Walker*)procPtr->getData(); vector<DysectAPI::CodeLocation*>::iterator locationIter = codeLocations.begin(); for(;locationIter != codeLocations.end(); locationIter++) { DysectAPI::CodeLocation* location = *locationIter; if(!location->addProcLib(proc)) { return Err::warn(false, "Symbol not found in process"); } vector<Dyninst::Address> addrs; if(!location->getAddrs(proc, addrs) || addrs.empty()) { return Err::warn(false, "Addresses for symbol could not be determined"); } // Breakpoint locations at hand for(int i = 0; i < addrs.size() ; i++) { Dyninst::Address addr = addrs[i]; if(!procPtr->rmBreakpoint(addr, bp)) { Err::verbose(false, "Breakpoint not removed! %s", ProcControlAPI::getLastErrorMsg()); } } } } return true; }
ProcessSet::ptr ProcessMgr::filterExited(ProcessSet::ptr inSet) { if(!inSet) return inSet; if(inSet->empty()) return inSet; ProcessSet::ptr procs = ProcessSet::newProcessSet(); // Filter out exited processes ProcessSet::iterator procIter = inSet->begin(); for(; procIter != inSet->end(); procIter++) { Process::ptr process = *procIter; if(process->isTerminated() || process->isExited() || process->isCrashed() || process->isDetached()) { continue; } procs->insert(process); } return procs; }
bool Location::enable(ProcessSet::ptr lprocset) { assert(owner != 0); if(codeLocations.empty()) { return Err::verbose(true, "No code locations"); } if(!lprocset) { return Err::warn(false, "Process set not present"); } ProcessSet::iterator procIter = lprocset->begin(); AddressSet::ptr addrset = AddressSet::newAddressSet(); if(lprocset->size() <= 0) { return Err::info(true, "Process set empty!"); } // Find library location for target processes for(;procIter != lprocset->end(); procIter++) { Process::ptr procPtr = *procIter; Walker* proc = (Walker*)procPtr->getData(); vector<DysectAPI::CodeLocation*>::iterator locationIter = codeLocations.begin(); for(;locationIter != codeLocations.end(); locationIter++) { DysectAPI::CodeLocation* location = *locationIter; if(!location->addProcLib(proc)) { return Err::warn(false, "Symbol not found in process"); } vector<Dyninst::Address> addrs; if(!location->getAddrs(proc, addrs) || addrs.empty()) { return Err::warn(false, "Addresses for symbol could not be determined"); } // Breakpoint locations at hand for(int i = 0; i < addrs.size() ; i++) { Dyninst::Address addr = addrs[i]; if(!procPtr->addBreakpoint(addr, bp)) { return Err::verbose(false, "Breakpoint not installed: %s", ProcControlAPI::getLastErrorMsg()); } else { Err::verbose(true, "Breakpoint installed at %lx", addr); } //addrset->insert(addr, procPtr); } //if(addrs.empty()) { // Err::verbose(true, "No addresses"); //} } } //if(addrset->size() <= 0) { // return Err::verbose(true, "Empty address set"); //} //if(!lprocset->addBreakpoint(addrset, nbp)) { // return Err::warn(false, "Could not insert breakpoints!"); //} else { // Err::info(true, "%d breakpoints inserted in %d processes", addrset->size(), lprocset->size()); //} return true; }