* Try to locate the source file for the given address. * If addr2line is not available on the system, the operation simply returns * an string "unknown location(address)". */
| 208 | * an string "unknown location(address)". |
| 209 | */ |
| 210 | addr2line_result locate_source_file(const demangling_result& dr) |
| 211 | { |
| 212 | auto executable = locate_executable(dr.executable); |
| 213 | |
| 214 | if (executable.empty() || dr.address.empty()) |
| 215 | { |
| 216 | return {"", ""}; |
| 217 | } |
| 218 | |
| 219 | // First, try to check a symbol in the executable |
| 220 | auto in_executable = try_addr2line(executable, dr.address); |
| 221 | if (valid_addr2line_return(in_executable)) |
| 222 | { |
| 223 | auto function_name = try_addr2line(executable, dr.address, "-Cf"); |
| 224 | |
| 225 | return {function_name, in_executable}; |
| 226 | } |
| 227 | |
| 228 | // Second, try to check a symbol in a library |
| 229 | // We need the base address inside the library. |
| 230 | Dl_info info; |
| 231 | dladdr(hex_to_ptr(dr.address), &info); |
| 232 | |
| 233 | void *position_inside_lib = reinterpret_cast<void*>( |
| 234 | (char*)hex_to_ptr(dr.address) - (char*)info.dli_fbase); |
| 235 | |
| 236 | std::ostringstream out; |
| 237 | out << std::hex << position_inside_lib; |
| 238 | std::string real_address = out.str(); |
| 239 | |
| 240 | return { |
| 241 | try_addr2line(executable, real_address, "-Cf"), |
| 242 | try_addr2line(executable, real_address), |
| 243 | }; |
| 244 | } |
| 245 | |
| 246 | #if HAS_ASAN |
| 247 | extern "C" |
no test coverage detected