MCPcopy Create free account
hub / github.com/WayfireWM/wayfire / locate_source_file

Function locate_source_file

src/debug.cpp:210–244  ·  view source on GitHub ↗

* 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)". */

Source from the content-addressed store, hash-verified

208 * an string "unknown location(address)".
209 */
210addr2line_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
247extern "C"

Callers 1

print_traceMethod · 0.85

Calls 5

locate_executableFunction · 0.85
try_addr2lineFunction · 0.85
valid_addr2line_returnFunction · 0.85
hex_to_ptrFunction · 0.85
emptyMethod · 0.80

Tested by

no test coverage detected