bool PCProcess::getExecFileDescriptor(std::string filename, bool waitForTrap, fileDescriptor &desc) { Address mainFileBase = 0; Dyninst::ProcControlAPI::ExecFileInfo* efi = pcProc_->getExecutableInfo(); desc = fileDescriptor(filename, efi->fileBase, efi->fileBase, false); desc.setHandles(efi->processHandle, efi->fileHandle); delete efi; return true; }
NZMQT_INLINE SocketNotifierZMQSocket::SocketNotifierZMQSocket(ZMQContext* context_, Type type_) : super(context_, type_) , socketNotifyRead_(0) , socketNotifyWrite_(0) { qintptr fd = fileDescriptor(); socketNotifyRead_ = new QSocketNotifier(fd, QSocketNotifier::Read, this); QObject::connect(socketNotifyRead_, &QSocketNotifier::activated, this, &SocketNotifierZMQSocket::socketReadActivity); socketNotifyWrite_ = new QSocketNotifier(fd, QSocketNotifier::Write, this); QObject::connect(socketNotifyWrite_, &QSocketNotifier::activated, this, &SocketNotifierZMQSocket::socketWriteActivity); }
// processLinkMaps: get a list of all loaded objects in fileDescriptor form. bool dynamic_linking::processLinkMaps(pdvector<fileDescriptor> &descs) { int proc_fd = proc->getRepresentativeLWP()->get_fd(); if(!proc_fd){ return false;} // step 2: get the runtime loader table from the process Address ldr_base_addr; ldr_context first; ldr_module module; assert(proc->readDataSpace((const void*)LDR_BASE_ADDR,sizeof(Address), &ldr_base_addr, true)); assert(proc->readDataSpace((const void*)ldr_base_addr,sizeof(ldr_context), &first, true)); assert(proc->readDataSpace((const void *) first.head,sizeof(ldr_module), &module, true)); while (module.next != first.head) { if (module.nregions == 0) { assert(proc->readDataSpace((const void *) module.next,sizeof(ldr_module), &module,true)); continue; } pdstring obj_name = pdstring(readDataString(proc, module.name)); ldr_region *regions; regions = (ldr_region *) malloc(module.nregions * sizeof(ldr_region)); assert(proc->readDataSpace((const void *) module.regions, sizeof(ldr_region)*module.nregions, regions, true)); long offset = regions[0].mapaddr - regions[0].vaddr; #ifdef notdef if (offset) { bperr("*** shared lib at non-default offset **: "); bperr(" %s\n", obj_name.c_str()); bperr(" offset = %ld\n", offset); } else { bperr("*** shared lib **: "); bperr(" %s\n", obj_name.c_str()); bperr(" at = %ld\n", regions[0].mapaddr); } #endif for (int i=0; i < module.nregions; i++) { long newoffset = regions[i].mapaddr - regions[i].vaddr; if (newoffset != offset) { bperr( "shared lib regions have different offsets\n"); } regions[i].name = (long unsigned) readDataString(proc, (void *) regions[i].name); // bperr(" region %d (%s) ", i, regions[i].name); // bperr("addr = %lx, ", regions[i].vaddr); // bperr("mapped at = %lx, ", regions[i].mapaddr); // bperr("size = %x\n", regions[i].size); } descs.push_back(fileDescriptor(obj_name, offset, offset, true)); free(regions); assert(proc->readDataSpace((const void *) module.next,sizeof(ldr_module), &module,true)); } return true; }
// processLinkMaps: This routine is called by getSharedObjects to // process all shared objects that have been mapped into the process's // address space. This routine reads the link maps from the application // process to find the shared object file base mappings. It returns 0 on error. bool dynamic_linking::processLinkMaps(pdvector<fileDescriptor> &descs) { r_debug debug_elm; if(!proc->readDataSpace((caddr_t)(r_debug_addr), sizeof(r_debug),(caddr_t)&(debug_elm),true)) { // bperr("read d_ptr_addr failed r_debug_addr = 0x%lx\n",r_debug_addr); return 0; } // get each link_map object Link_map *next_link_map = debug_elm.r_map; Address next_addr = (Address)next_link_map; while(next_addr != 0){ Link_map link_elm; if(!proc->readDataSpace((caddr_t)(next_addr), sizeof(Link_map),(caddr_t)&(link_elm),true)) { logLine("read next_link_map failed\n"); return 0; } // get file name char f_name[256]; // assume no file names greater than 256 chars // check to see if reading 256 chars will go out of bounds // of data segment u_int f_amount = 256; bool done = false; for(u_int i=0; (i<256) && (!done); i++){ if(!proc->readDataSpace((caddr_t)((u_int)(link_elm.l_name)+i), sizeof(char),(caddr_t)(&(f_name[i])),true)){ } if(f_name[i] == '\0'){ done = true; f_amount = i+1; } } f_name[f_amount-1] = '\0'; pdstring obj_name = pdstring(f_name); parsing_cerr << "dynamicLinking::processLinkMaps(): file name of next shared obj=" << obj_name << endl; // create a mapped_object and add it to the list // kludge: ignore the entry if it has the same name as the // executable file...this seems to be the first link-map entry // VG(09/25/01): also ignore if address is 65536 or name is (unknown) if(obj_name != proc->getAOut()->fileName() && obj_name != proc->getAOut()->fullName() && link_elm.l_addr != 65536 && obj_name != "(unknown)" //strncmp(obj_name.c_str(), "(unknown)", 10) ) { fileDescriptor desc = fileDescriptor(obj_name, link_elm.l_addr, link_elm.l_addr, true); descs.push_back(desc); } next_addr = (Address)link_elm.l_next; } return true; }