Attempt to fallback to dladdr if dladdr1 is not available
This commit is contained in:
parent
f8d28a6469
commit
7916f10278
@ -94,6 +94,9 @@ endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
check_support(HAS_DL_FIND_OBJECT has_dl_find_object.cpp "" "" "")
|
||||
if(NOT HAS_DL_FIND_OBJECT)
|
||||
check_support(HAS_DLADDR1 has_dladdr1.cpp "" "" "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# =============================================== Autoconfig unwinding ===============================================
|
||||
@ -316,6 +319,10 @@ if(HAS_DL_FIND_OBJECT)
|
||||
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DL_FIND_OBJECT)
|
||||
endif()
|
||||
|
||||
if(HAS_DLADDR1)
|
||||
target_compile_definitions(${target_name} PUBLIC CPPTRACE_HAS_DLADDR1)
|
||||
endif()
|
||||
|
||||
# Symbols
|
||||
if(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
|
||||
if(NOT HAS_BACKTRACE)
|
||||
|
||||
7
cmake/has_dladdr1.cpp
Normal file
7
cmake/has_dladdr1.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
int main() {
|
||||
Dl_info info;
|
||||
link_map* link_map_info;
|
||||
dladdr1(reinterpret_cast<void*>(&main), &info, reinterpret_cast<void**>(&link_map_info), RTLD_DL_LINKMAP);
|
||||
}
|
||||
@ -21,7 +21,8 @@
|
||||
|
||||
namespace cpptrace {
|
||||
namespace detail {
|
||||
#if IS_LINUX
|
||||
#if IS_LINUX || IS_APPLE
|
||||
#if defined(CPPTRACE_HAS_DL_FIND_OBJECT) || defined(HAS_DLADDR1)
|
||||
std::string resolve_l_name(const char* l_name) {
|
||||
if(l_name != nullptr && l_name[0] != 0) {
|
||||
return l_name;
|
||||
@ -37,6 +38,7 @@ namespace detail {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef CPPTRACE_HAS_DL_FIND_OBJECT // we don't even check for this on apple
|
||||
object_frame get_frame_object_info(frame_ptr address) {
|
||||
// Use _dl_find_object when we can, it's orders of magnitude faster
|
||||
@ -50,7 +52,7 @@ namespace detail {
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
#else
|
||||
#elif defined(HAS_DLADDR1)
|
||||
// dladdr queries are needed to get pre-ASLR addresses and targets to run addr2line on
|
||||
object_frame get_frame_object_info(frame_ptr address) {
|
||||
// reference: https://github.com/bminor/glibc/blob/master/debug/backtracesyms.c
|
||||
@ -76,8 +78,8 @@ namespace detail {
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
#endif
|
||||
#elif IS_APPLE
|
||||
#else
|
||||
// TODO: Try to verify this is correct in the context of bad argv[0]
|
||||
// macos doesn't have dladdr1 but it seems its dli_fname behaves more sensibly?
|
||||
// dladdr queries are needed to get pre-ASLR addresses and targets to run addr2line on
|
||||
object_frame get_frame_object_info(frame_ptr address) {
|
||||
@ -99,6 +101,7 @@ namespace detail {
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
std::string get_module_name(HMODULE handle) {
|
||||
static std::mutex mutex;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user