Skip to content

Commit f10ac62

Browse files
committed
WIP: try to use regular libbacktrace API
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d8c57ee commit f10ac62

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Diff for: Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,8 @@ ifdef OPEN_RETURNS_EINTR
16211621
endif
16221622
ifneq (,$(DEBUG_FILE_LOCKS))
16231623
BACKTRACE_SOURCES := $(patsubst %,compat/libbacktrace/%,atomic.c \
1624-
alloc.c dwarf.c state.c fileline.c posix.c pecoff.c sort.c \
1625-
read.c)
1624+
alloc.c backtrace.c dwarf.c state.c fileline.c posix.c \
1625+
pecoff.c sort.c read.c)
16261626
BACKTRACE_OBJS := $(patsubst %.c,%.o,$(BACKTRACE_SOURCES))
16271627
COMPAT_OBJS += $(BACKTRACE_OBJS)
16281628
$(BACKTRACE_OBJS): EXTRA_CPPFLAGS = -I compat/libbacktrace

Diff for: compat/libbacktrace/backtrace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ static int win32_unwind(struct backtrace_data *bdata)
108108
HMODULE kernel32 =
109109
LoadLibraryExW(L"kernel32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
110110
if (kernel32)
111-
RtlCaptureStackBackTrace =
112-
(void *)GetProcAddress(kernel32, "RtlCaptureStackBackTrace");
111+
RtlCaptureStackBackTrace = (USHORT (*)(ULONG, ULONG, PVOID*, PULONG))
112+
(void (*)(void))GetProcAddress(kernel32, "RtlCaptureStackBackTrace");
113113
initialized = 1;
114114
if (!RtlCaptureStackBackTrace)
115115
return -1;

Diff for: compat/mingw.c

+26
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,31 @@ static int is_system32_path(const char *path)
36243624
return 1;
36253625
}
36263626

3627+
#include "libbacktrace/backtrace.h"
3628+
#include "libbacktrace/backtrace-supported.h"
3629+
3630+
static void bt_error_callback(void *data, const char *msg, int errnum)
3631+
{
3632+
error("%s (%d)", msg, errnum);
3633+
}
3634+
3635+
static struct backtrace_state *bt_state;
3636+
3637+
static int bt_full_callback(void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
3638+
{
3639+
fprintf(stderr, "%s:%d %s %p\n", filename, lineno, function, (void *)pc);
3640+
3641+
return 0;
3642+
}
3643+
3644+
static void printStacktraceWithLines(void)
3645+
{
3646+
if (!bt_state)
3647+
bt_state = backtrace_create_state(NULL, BACKTRACE_SUPPORTS_THREADS, bt_error_callback, NULL);
3648+
backtrace_full(bt_state, 1, bt_full_callback, bt_error_callback, NULL);
3649+
}
3650+
3651+
36273652
static void setup_windows_environment(void)
36283653
{
36293654
char *tmp = getenv("TMPDIR");
@@ -3638,6 +3663,7 @@ static void setup_windows_environment(void)
36383663
}
36393664
}
36403665

3666+
printStacktraceWithLines();
36413667
if (tmp) {
36423668
/*
36433669
* Convert all dir separators to forward slashes,

0 commit comments

Comments
 (0)