diff --git a/src/Makefile b/src/Makefile index 2945e536..9107794c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,6 +15,9 @@ os := $(shell uname) ifeq ($(os),Darwin) LIBS += -lncurses -lboost_regex-mt +else ifneq (,$(findstring CYGWIN,$(os))) + LIBS += -lncursesw -lboost_regex -ldbghelp + LDFLAGS += -rdynamic else LIBS += -lncursesw -lboost_regex LDFLAGS += -rdynamic diff --git a/src/backtrace.cc b/src/backtrace.cc index 7c195f67..adeb9301 100644 --- a/src/backtrace.cc +++ b/src/backtrace.cc @@ -7,6 +7,7 @@ # include #elif defined(__CYGWIN__) # include +# include # include #endif @@ -39,12 +40,27 @@ String Backtrace::desc() const free(symbols); return res; #elif defined(__CYGWIN__) - String res; res.reserve(num_frames * 20); + HANDLE process = GetCurrentProcess(); + + static bool symbols_initialized = false; + if (not symbols_initialized) + { + SymInitialize(process, nullptr, true); + symbols_initialized = true; + } + + alignas(SYMBOL_INFO) char symbol_info_buffer[sizeof(SYMBOL_INFO) + 256]; + SYMBOL_INFO* symbol_info = reinterpret_cast(symbol_info_buffer); + symbol_info->MaxNameLen = 255; + symbol_info->SizeOfStruct = sizeof(SYMBOL_INFO); + + String res; // res.reserve(num_frames * 276); for (int i = 0; i < num_frames; ++i) { - char addr[20]; - snprintf(addr, 20, "0x%p\n", stackframes[i]); - res += addr; + SymFromAddr(process, (DWORD64)stackframes[i], 0, symbol_info); + char desc[276]; + snprintf(desc, 276, "0x%0llx (%s)\n", symbol_info->Address, symbol_info->Name); + res += desc; } return res; #else