| 159 | } |
| 160 | |
| 161 | void |
| 162 | CoreFileAnalyzer::resolveLibraries() |
| 163 | { |
| 164 | struct RemappedModule |
| 165 | { |
| 166 | std::string modname; |
| 167 | std::string path; |
| 168 | GElf_Addr addr; |
| 169 | }; |
| 170 | std::vector<RemappedModule> remapped_modules; |
| 171 | |
| 172 | LOG(DEBUG) << "Searching for missing and mismapped modules"; |
| 173 | removeModuleIf([this, &remapped_modules](Dwfl_Module* mod) -> bool { |
| 174 | Dwarf_Addr start, end; |
| 175 | const char* path; |
| 176 | const char* modname = |
| 177 | dwfl_module_info(mod, nullptr, &start, &end, nullptr, nullptr, &path, nullptr); |
| 178 | if (!path) { |
| 179 | path = modname; |
| 180 | } |
| 181 | |
| 182 | std::string located_path; |
| 183 | bool searched; |
| 184 | if (!d_executable || !d_lib_search_path) { |
| 185 | located_path = path; |
| 186 | searched = false; |
| 187 | } else { |
| 188 | located_path = locateLibrary(path); |
| 189 | searched = true; |
| 190 | } |
| 191 | bool const located_path_exists = fs::exists(located_path); |
| 192 | |
| 193 | if (!located_path_exists) { |
| 194 | LOG(DEBUG) << "Adding " << path << " as a missing module " |
| 195 | << (searched ? "despite" : "without") << " a search"; |
| 196 | d_missing_modules.emplace_back(located_path); |
| 197 | } |
| 198 | |
| 199 | if (located_path_exists && located_path != path) { |
| 200 | std::string const filename = std::filesystem::path(located_path).filename().string(); |
| 201 | remapped_modules.push_back({filename, located_path, start}); |
| 202 | LOG(DEBUG) << "Dropping module " << path << " spanning from " << std::hex << std::showbase |
| 203 | << start << " to " << end << " so that it can be remapped from " << located_path; |
| 204 | return true; |
| 205 | } else { |
| 206 | LOG(DEBUG) << "Retaining module " << path << " spanning from " << std::hex << std::showbase |
| 207 | << start << " to " << end; |
| 208 | return false; |
| 209 | } |
| 210 | }); |
| 211 | |
| 212 | LOG(DEBUG) << "Re-adding " << remapped_modules.size() |
| 213 | << " mismapped modules with corrected locations"; |
| 214 | for (const auto& module : remapped_modules) { |
| 215 | if (!dwfl_report_elf( |
| 216 | d_dwfl.get(), |
| 217 | module.modname.c_str(), |
| 218 | module.path.c_str(), |
nothing calls this directly
no test coverage detected