Resolve symbol names in Cygwin Backtrace::desc implementation

This commit is contained in:
Maxime Coste 2015-06-16 18:49:56 +01:00
parent d8e2e9e043
commit 7417c5e9e2
2 changed files with 23 additions and 4 deletions

View File

@ -15,6 +15,9 @@ os := $(shell uname)
ifeq ($(os),Darwin) ifeq ($(os),Darwin)
LIBS += -lncurses -lboost_regex-mt LIBS += -lncurses -lboost_regex-mt
else ifneq (,$(findstring CYGWIN,$(os)))
LIBS += -lncursesw -lboost_regex -ldbghelp
LDFLAGS += -rdynamic
else else
LIBS += -lncursesw -lboost_regex LIBS += -lncursesw -lboost_regex
LDFLAGS += -rdynamic LDFLAGS += -rdynamic

View File

@ -7,6 +7,7 @@
# include <stdlib.h> # include <stdlib.h>
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
# include <windows.h> # include <windows.h>
# include <dbghelp.h>
# include <stdio.h> # include <stdio.h>
#endif #endif
@ -39,12 +40,27 @@ String Backtrace::desc() const
free(symbols); free(symbols);
return res; return res;
#elif defined(__CYGWIN__) #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*>(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) for (int i = 0; i < num_frames; ++i)
{ {
char addr[20]; SymFromAddr(process, (DWORD64)stackframes[i], 0, symbol_info);
snprintf(addr, 20, "0x%p\n", stackframes[i]); char desc[276];
res += addr; snprintf(desc, 276, "0x%0llx (%s)\n", symbol_info->Address, symbol_info->Name);
res += desc;
} }
return res; return res;
#else #else