char* buffer[BACKTRACE_BUFFER_SIZE];
int nptrs = backtrace(reinterpret_cast<void**>(buffer),
BACKTRACE_BUFFER_SIZE);
- _ERR("backtrace() returned %d addresses", nptrs - 4);
-
- // To print numbers, we use backtrace_symbols() instead of backtrace_symbols_fd().
- // If there is an issues related to the memory, we cannot use backtrace_symbols().
- // backtrace_symbols_fd(buffer, nptrs, STDERR_FILENO);
- char** strings = backtrace_symbols(reinterpret_cast<void**>(buffer), nptrs);
- if (strings == nullptr) {
- perror("backtrace_symbols");
- return;
- }
+ _ERR("backtrace() returned %d addresses", nptrs);
- Dl_info info;
- for (int i = 4; i < nptrs; ++i) {
- dladdr(buffer[i], &info);
- _ERR("[%3d] %s %s",
- i - 4, info.dli_sname ? info.dli_sname : "?", strings[i]);
- }
- free(strings);
+ backtrace_symbols_fd(reinterpret_cast<void**>(buffer), nptrs, STDERR_FILENO);
}
class ExitHandler {