//------------------------------------------------------------------------------ // Name: attach // Desc: //------------------------------------------------------------------------------ bool DebuggerCore::attach(edb::pid_t pid) { detach(); // create this, so the threads created can refer to it process_ = new PlatformProcess(this, pid); bool attached; do { attached = false; QDir proc_directory(QString("/proc/%1/task/").arg(pid)); for(const QString &s: proc_directory.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) { // this can get tricky if the threads decide to spawn new threads // when we are attaching. I wish that linux had an atomic way to do this // all in one shot const edb::tid_t tid = s.toUInt(); if(!threads_.contains(tid) && attach_thread(tid)) { attached = true; } } } while(attached); if(!threads_.empty()) { pid_ = pid; active_thread_ = pid; binary_info_ = edb::v1::get_binary_info(edb::v1::primary_code_region()); detectDebuggeeBitness(); return true; } else { delete process_; process_ = nullptr; } return false; }
//------------------------------------------------------------------------------ // Name: enumerate_processes // Desc: //------------------------------------------------------------------------------ QMap<edb::pid_t, IProcess::pointer> DebuggerCore::enumerate_processes() const { QMap<edb::pid_t, IProcess::pointer> ret; QDir proc_directory("/proc/"); QFileInfoList entries = proc_directory.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for(const QFileInfo &info: entries) { const QString filename = info.fileName(); if(is_numeric(filename)) { const edb::pid_t pid = filename.toULong(); // NOTE(eteran): the const_cast is reasonable here. // While we don't want THIS function to mutate the DebuggerCore object // we do want the associated PlatformProcess to be able to trigger // non-const operations in the future, at least hypothetically. ret.insert(pid, std::make_shared<PlatformProcess>(const_cast<DebuggerCore*>(this), pid)); } } return ret; }
int rom1394_get_directory(raw1394handle_t handle, nodeid_t node, rom1394_directory *dir) { octlet_t offset; int i, j; char *p; int result = 0; NODECHECK(handle, node); dir->node_capabilities = 0; dir->vendor_id = 0; dir->unit_spec_id = 0; dir->unit_sw_version = 0; dir->model_id = 0; dir->max_textual_leafs = dir->nr_textual_leafs = 0; dir->label = NULL; dir->textual_leafs = NULL; offset = CSR_REGISTER_BASE + CSR_CONFIG_ROM + ROM1394_ROOT_DIRECTORY; if ( ( result = proc_directory (handle, node, offset, dir) ) != -1 ) { /* Calculate label */ if (dir->nr_textual_leafs != 0 && dir->textual_leafs[0]) { for (i = 0, j = 0; i < dir->nr_textual_leafs; i++) if (dir->textual_leafs[i]) j += (strlen(dir->textual_leafs[i]) + 1); if ( (dir->label = (char *) malloc(j)) ) { for (i = 0, p = dir->label; i < dir->nr_textual_leafs; i++, p++) { if (dir->textual_leafs[i]) { strcpy ( p, dir->textual_leafs[i]); p += strlen(dir->textual_leafs[i]); if (i < dir->nr_textual_leafs-1) p[0] = ' '; } } } } } return result; }