void CBrowseDlg::AddPathItems(HTREEITEM hParent, CString strPath) { WIN32_FIND_DATA fd; CString mask; mask.Format(_T("%s*.*"), strPath); HANDLE hFind = FindFirstFile(mask, &fd); if (hFind != INVALID_HANDLE_VALUE) { do { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { HTREEITEM hItem = AddDirItem(hParent, fd.cFileName, ICON_DIR, FALSE); // add one child, to display the plus sing CString strSubDir = strPath + fd.cFileName + _T("\\"); AddPossibleChild(hItem, strSubDir); } else if (m_bFiles) { CString strFileName = CString(fd.cFileName); if (HasExt(strFileName)) { CString strFilePath = strPath + strFileName; SHFILEINFO sfi = { 0 }; SHGetFileInfo(strFilePath, 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SMALLICON); // | SHGFI_SYSICONINDEX); int nIdx = m_oImageList.Add(sfi.hIcon); if (nIdx == -1) nIdx = ICON_FILE; HTREEITEM hItem = AddDirItem(hParent, strFileName, nIdx, FALSE); DeleteObject(sfi.hIcon); } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); // Sort the items in the tree control using my callback procedure. TVSORTCB tvs; tvs.hParent = hParent; tvs.lpfnCompare = DirFileCompareProc; tvs.lParam = (LPARAM) &m_ctlDirs; m_ctlDirs.SortChildrenCB(&tvs); } }
void CBrowseDlg::AddPossibleChild(HTREEITEM hParent, CString strPath) { WIN32_FIND_DATA fd; CString mask; mask.Format(_T("%s*.*"), strPath); HANDLE hFind = FindFirstFile(mask, &fd); if (hFind != INVALID_HANDLE_VALUE) { do { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { AddDirItem(hParent, fd.cFileName, ICON_DIR, FALSE); break; } else if (m_bFiles) { CString strFileName = CString(fd.cFileName); if (HasExt(strFileName)) { AddDirItem(hParent, fd.cFileName, ICON_FILE, FALSE); break; } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); } }
int InsertExternalFile(char *name) { char buf[260], *p; if (HasExt(name, ".asm") || HasExt(name,".nas")) { InsertFile(&objlist, name, ".o"); InsertFile(&asmlist, name, 0); return 1; /* compiler shouldn't process it*/ } else if (HasExt(name, ".l")) { InsertFile(&liblist, name, 0); return 1; } else if (HasExt(name, ".rc")) { InsertFile(&reslist, name, ".res"); InsertFile(&rclist, name, 0); return 1; } else if (HasExt(name, ".res")) { InsertFile(&reslist, name, 0); return 1; } else if (HasExt(name, ".o")) { InsertFile(&objlist, name, 0); return 1; } p = strrchr(name, '\\'); if (!p) p = name; else p++; strcpy(buf, p); InsertFile(&objlist, buf, ".o"); // compiling via assembly if (cparams.prm_asmfile && !cparams.prm_compileonly) { InsertFile(&asmlist, buf, ".asm"); } return 0; /* compiler should process it*/ }
int InsertExternalFile(char *name) { if (HasExt(name, ".ASM") || HasExt(name,".NAS")) { InsertFile(&objlist, name, ".o"); InsertFile(&asmlist, name, 0); return 1; /* compiler shouldn't process it*/ } else if (HasExt(name, ".L")) { InsertFile(&liblist, name, 0); return 1; } else if (HasExt(name, ".RC")) { InsertFile(&reslist, name, ".RES"); InsertFile(&rclist, name, 0); return 1; } else if (HasExt(name, ".RES")) { InsertFile(&reslist, name, 0); return 1; } else if (HasExt(name, ".o")) { InsertFile(&objlist, name, 0); return 1; } InsertFile(&objlist, name, ".O"); // compiling via assembly if (cparams.prm_asmfile && !cparams.prm_compileonly) { InsertFile(&asmlist, name, ".ASM"); } return 0; /* compiler should process it*/ }
static void LoadSymbols() { butil::Timer tm; tm.start(); butil::ScopedFILE fp(fopen("/proc/self/maps", "r")); if (fp == NULL) { return; } char* line = NULL; size_t line_len = 0; ssize_t nr = 0; while ((nr = getline(&line, &line_len, fp.get())) != -1) { butil::StringSplitter sp(line, line + line_len, ' '); if (sp == NULL) { continue; } char* endptr; uintptr_t start_addr = strtoull(sp.field(), &endptr, 16); if (*endptr != '-') { continue; } ++endptr; uintptr_t end_addr = strtoull(endptr, &endptr, 16); if (*endptr != ' ') { continue; } ++sp; // ..x. must be executable if (sp == NULL || sp.length() != 4 || sp.field()[2] != 'x') { continue; } ++sp; if (sp == NULL) { continue; } size_t offset = strtoull(sp.field(), &endptr, 16); if (*endptr != ' ') { continue; } //skip $4~$5 for (int i = 0; i < 3; ++i) { ++sp; } if (sp == NULL) { continue; } size_t n = sp.length(); if (sp.field()[n-1] == '\n') { --n; } std::string path(sp.field(), n); if (!HasExt(path, ".so") && !HasExt(path, ".dll") && !HasExt(path, ".dylib") && !HasExt(path, ".bundle")) { continue; } LibInfo info; info.start_addr = start_addr; info.end_addr = end_addr; info.offset = offset; info.path = path; ExtractSymbolsFromBinary(symbol_map, info); } free(line); LibInfo info; info.start_addr = 0; info.end_addr = std::numeric_limits<uintptr_t>::max(); info.offset = 0; info.path = program_invocation_name; ExtractSymbolsFromBinary(symbol_map, info); butil::Timer tm2; tm2.start(); size_t num_removed = 0; bool last_is_empty = false; for (SymbolMap::iterator it = symbol_map.begin(); it != symbol_map.end();) { if (it->second.empty()) { if (last_is_empty) { symbol_map.erase(it++); ++num_removed; } else { ++it; } last_is_empty = true; } else { ++it; } } tm2.stop(); RPC_VLOG_IF(num_removed) << "Removed " << num_removed << " entries in " << tm2.m_elapsed() << "ms"; tm.stop(); RPC_VLOG << "Loaded all symbols in " << tm.m_elapsed() << "ms"; }