Skip to content

Commit

Permalink
WIP: try to use regular libbacktrace API
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Jul 18, 2022
1 parent d8c57ee commit f10ac62
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1621,8 +1621,8 @@ ifdef OPEN_RETURNS_EINTR
endif
ifneq (,$(DEBUG_FILE_LOCKS))
BACKTRACE_SOURCES := $(patsubst %,compat/libbacktrace/%,atomic.c \
alloc.c dwarf.c state.c fileline.c posix.c pecoff.c sort.c \
read.c)
alloc.c backtrace.c dwarf.c state.c fileline.c posix.c \
pecoff.c sort.c read.c)
BACKTRACE_OBJS := $(patsubst %.c,%.o,$(BACKTRACE_SOURCES))
COMPAT_OBJS += $(BACKTRACE_OBJS)
$(BACKTRACE_OBJS): EXTRA_CPPFLAGS = -I compat/libbacktrace
Expand Down
4 changes: 2 additions & 2 deletions compat/libbacktrace/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ static int win32_unwind(struct backtrace_data *bdata)
HMODULE kernel32 =
LoadLibraryExW(L"kernel32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (kernel32)
RtlCaptureStackBackTrace =
(void *)GetProcAddress(kernel32, "RtlCaptureStackBackTrace");
RtlCaptureStackBackTrace = (USHORT (*)(ULONG, ULONG, PVOID*, PULONG))
(void (*)(void))GetProcAddress(kernel32, "RtlCaptureStackBackTrace");
initialized = 1;
if (!RtlCaptureStackBackTrace)
return -1;
Expand Down
26 changes: 26 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3624,6 +3624,31 @@ static int is_system32_path(const char *path)
return 1;
}

#include "libbacktrace/backtrace.h"
#include "libbacktrace/backtrace-supported.h"

static void bt_error_callback(void *data, const char *msg, int errnum)
{
error("%s (%d)", msg, errnum);
}

static struct backtrace_state *bt_state;

static int bt_full_callback(void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
{
fprintf(stderr, "%s:%d %s %p\n", filename, lineno, function, (void *)pc);

return 0;
}

static void printStacktraceWithLines(void)
{
if (!bt_state)
bt_state = backtrace_create_state(NULL, BACKTRACE_SUPPORTS_THREADS, bt_error_callback, NULL);
backtrace_full(bt_state, 1, bt_full_callback, bt_error_callback, NULL);
}


static void setup_windows_environment(void)
{
char *tmp = getenv("TMPDIR");
Expand All @@ -3638,6 +3663,7 @@ static void setup_windows_environment(void)
}
}

printStacktraceWithLines();
if (tmp) {
/*
* Convert all dir separators to forward slashes,
Expand Down

0 comments on commit f10ac62

Please sign in to comment.