| 76 | } |
| 77 | |
| 78 | void |
| 79 | CoreFileExtractor::populateMaps() |
| 80 | { |
| 81 | LOG(DEBUG) << "Populating memory maps for core file"; |
| 82 | /* Check that we are working with a coredump. */ |
| 83 | GElf_Ehdr ehdr; |
| 84 | if (gelf_getehdr(d_analyzer->d_elf.get(), &ehdr) == nullptr || ehdr.e_type != ET_CORE) { |
| 85 | throw CoreAnalyzerError("The file is not a coredump!"); |
| 86 | } |
| 87 | |
| 88 | if (dwfl_getmodules(d_analyzer->d_dwfl.get(), module_callback, &d_module_info, 0) != 0) { |
| 89 | throw CoreAnalyzerError("Failed to fetch modules!"); |
| 90 | } |
| 91 | |
| 92 | std::for_each(d_module_info.begin(), d_module_info.end(), [this](auto& mod) { |
| 93 | std::string relocated_library = d_analyzer->locateLibrary(mod.filename); |
| 94 | LOG(DEBUG) << "Resolved library " << mod.filename << " to " << relocated_library; |
| 95 | mod.filename = relocated_library; |
| 96 | }); |
| 97 | |
| 98 | size_t nphdr; |
| 99 | if (elf_getphdrnum(d_analyzer->d_elf.get(), &nphdr) != 0) { |
| 100 | throw CoreAnalyzerError("Failed to get program headers"); |
| 101 | } |
| 102 | |
| 103 | std::vector<CoreVirtualMap> vmaps; |
| 104 | |
| 105 | LOG(DEBUG) << "Found " << nphdr << " program headers"; |
| 106 | LOG(DEBUG) << "Searching for PT_LOAD segments"; |
| 107 | |
| 108 | for (size_t i = 0; i < nphdr; i++) { |
| 109 | GElf_Phdr phdr; |
| 110 | if (gelf_getphdr(d_analyzer->d_elf.get(), i, &phdr) != &phdr) { |
| 111 | continue; |
| 112 | } |
| 113 | |
| 114 | if (phdr.p_type != PT_LOAD) { |
| 115 | continue; |
| 116 | } |
| 117 | |
| 118 | Dwarf_Addr start = phdr.p_vaddr; |
| 119 | Dwarf_Addr end = phdr.p_vaddr + phdr.p_memsz; |
| 120 | |
| 121 | auto it = std::find_if(d_module_info.cbegin(), d_module_info.cend(), [&](auto& module) { |
| 122 | return start >= module.start && end <= module.end; |
| 123 | }); |
| 124 | |
| 125 | std::string filename; |
| 126 | if (it != d_module_info.cend()) { |
| 127 | filename = it->filename; |
| 128 | } |
| 129 | LOG(DEBUG) << "Found PT_LOAD segment for module " << (filename.empty() ? "???" : filename) |
| 130 | << " spanning from " << std::hex << std::showbase << start << " to " << end; |
| 131 | |
| 132 | std::string build_id = getBuildId(filename); |
| 133 | |
| 134 | CoreVirtualMap vmap = { |
| 135 | start, |
nothing calls this directly
no test coverage detected