Project

General

Profile

Feature #17638 » ruby-libbacktrace-using-backtrace.patch

xtkoba (Tee KOBAYASHI), 02/27/2021 10:44 PM

View differences:

vm_dump.c
}
#endif
#if defined(USE_LIBBACKTRACE)
void
libbacktrace_cb_error(void *data, const char *msg, int errnum)
{
fprintf(stderr, "libbacktrace error: msg: %s, errnum: %d\n", msg, errnum);
}
void
libbacktrace_cb_syminfo(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize)
{
if (symname != NULL) {
fprintf(stderr, "[0x%"PRIxPTR"] %s+0x%"PRIxPTR"\n", pc, symname, pc-symval);
} else {
fprintf(stderr, "[0x%"PRIxPTR"]\n", pc);
}
}
int
libbacktrace_cb_pcinfo(void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
{
if (filename != NULL) {
fprintf(stderr, "\t%s:%d\n", filename, lineno);
}
return 0;
}
#endif
void
rb_print_backtrace(void)
{
#if defined(USE_LIBBACKTRACE)
struct backtrace_state *state = backtrace_create_state(NULL, 0, NULL, NULL);
backtrace_print(state, 0, stderr);
#elif HAVE_BACKTRACE
#endif
#if HAVE_BACKTRACE
#define MAX_NATIVE_TRACE 1024
static void *trace[MAX_NATIVE_TRACE];
int n = (int)backtrace(trace, MAX_NATIVE_TRACE);
#if (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) && defined(HAVE_DLADDR) && !defined(__sparc)
int i;
#if defined(USE_LIBBACKTRACE)
for (i = 0; i < n; i++) {
#if defined(__arm__)
uintptr_t pc = ((uintptr_t)trace[i] & (~1)) - 1;
#else
uintptr_t pc = (uintptr_t)trace[i] - 1;
#endif
backtrace_syminfo(state, pc, libbacktrace_cb_syminfo, libbacktrace_cb_error, NULL);
backtrace_pcinfo(state, pc, libbacktrace_cb_pcinfo, libbacktrace_cb_error, NULL);
}
#elif (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) && defined(HAVE_DLADDR) && !defined(__sparc)
rb_dump_backtrace_with_lines(n, trace);
#elif defined(HAVE_EXECINFO_H)
char **syms = backtrace_symbols(trace, n);
......
free(syms);
}
#endif
#elif defined(USE_LIBBACKTRACE)
backtrace_print(state, 0, stderr);
#elif defined(_WIN32)
DWORD tid = GetCurrentThreadId();
HANDLE th = (HANDLE)_beginthread(dump_thread, 0, &tid);
(2-2/3)