Changeset View
Changeset View
Standalone View
Standalone View
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | #undef DBGHELP_IMPORT | ||||
CHECK_NE(last_bslash, 0); | CHECK_NE(last_bslash, 0); | ||||
*last_bslash = L'\0'; | *last_bslash = L'\0'; | ||||
if (!SymSetSearchPathW(GetCurrentProcess(), path_buffer)) { | if (!SymSetSearchPathW(GetCurrentProcess(), path_buffer)) { | ||||
Report("*** WARNING: Failed to SymSetSearchPathW\n"); | Report("*** WARNING: Failed to SymSetSearchPathW\n"); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
#ifdef __clang__ | |||||
#pragma clang diagnostic push | |||||
#pragma clang diagnostic ignored "-Wframe-larger-than=" | |||||
#endif | |||||
bool WinSymbolizerTool::SymbolizePC(uptr addr, SymbolizedStack *frame) { | bool WinSymbolizerTool::SymbolizePC(uptr addr, SymbolizedStack *frame) { | ||||
InitializeDbgHelpIfNeeded(); | InitializeDbgHelpIfNeeded(); | ||||
// See http://msdn.microsoft.com/en-us/library/ms680578(VS.85).aspx | // See https://docs.microsoft.com/en-us/windows/win32/debug/retrieving-symbol-information-by-address | ||||
amccarth: URL update in case the redirect goes bad in the future. | |||||
Sure, will add that change. mstorsjo: Sure, will add that change. | |||||
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(CHAR)]; | char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(CHAR)]; | ||||
Not Done ReplyInline Actions
amccarth: 1. The sample code used `sizeof(TCHAR)` not `CHAR`. So I'm guessing this is a potential stack… | |||||
mstorsjo: 1. In https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/ns-dbghelp-symbol_info it… | |||||
Not Done ReplyInline Actions
Unlike other Win32 APIs, the "wide" versions seem to be enabled by DBGHELP_TRANSLATE_TCHAR rather than UNICODE. LLVM doesn't seem to use that, so I guess this works for now. Using sizeof(TCHAR) now might ease a future transition, but I'll leave it up to you. amccarth: 1. Well, there is a wide version called `SYMBOL_INFOW` for use with `SymFromAddrW`, see https… | |||||
I'd hold off of such further refactorings as part of this commit, and just stick to silencing warnings, but thanks for the pointers! mstorsjo: I'd hold off of such further refactorings as part of this commit, and just stick to silencing… | |||||
PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer; | PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer; | ||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); | symbol->SizeOfStruct = sizeof(SYMBOL_INFO); | ||||
symbol->MaxNameLen = MAX_SYM_NAME; | symbol->MaxNameLen = MAX_SYM_NAME; | ||||
DWORD64 offset = 0; | DWORD64 offset = 0; | ||||
BOOL got_objname = SymFromAddr(GetCurrentProcess(), | BOOL got_objname = SymFromAddr(GetCurrentProcess(), | ||||
(DWORD64)addr, &offset, symbol); | (DWORD64)addr, &offset, symbol); | ||||
if (!got_objname) | if (!got_objname) | ||||
return false; | return false; | ||||
DWORD unused; | DWORD unused; | ||||
IMAGEHLP_LINE64 line_info; | IMAGEHLP_LINE64 line_info; | ||||
line_info.SizeOfStruct = sizeof(IMAGEHLP_LINE64); | line_info.SizeOfStruct = sizeof(IMAGEHLP_LINE64); | ||||
BOOL got_fileline = SymGetLineFromAddr64(GetCurrentProcess(), (DWORD64)addr, | BOOL got_fileline = SymGetLineFromAddr64(GetCurrentProcess(), (DWORD64)addr, | ||||
&unused, &line_info); | &unused, &line_info); | ||||
frame->info.function = internal_strdup(symbol->Name); | frame->info.function = internal_strdup(symbol->Name); | ||||
frame->info.function_offset = (uptr)offset; | frame->info.function_offset = (uptr)offset; | ||||
if (got_fileline) { | if (got_fileline) { | ||||
frame->info.file = internal_strdup(line_info.FileName); | frame->info.file = internal_strdup(line_info.FileName); | ||||
frame->info.line = line_info.LineNumber; | frame->info.line = line_info.LineNumber; | ||||
} | } | ||||
// Only consider this a successful symbolization attempt if we got file info. | // Only consider this a successful symbolization attempt if we got file info. | ||||
// Otherwise, try llvm-symbolizer. | // Otherwise, try llvm-symbolizer. | ||||
return got_fileline; | return got_fileline; | ||||
} | } | ||||
#ifdef __clang__ | |||||
#pragma clang diagnostic pop | |||||
#endif | |||||
const char *WinSymbolizerTool::Demangle(const char *name) { | const char *WinSymbolizerTool::Demangle(const char *name) { | ||||
CHECK(is_dbghelp_initialized); | CHECK(is_dbghelp_initialized); | ||||
static char demangle_buffer[1000]; | static char demangle_buffer[1000]; | ||||
if (name[0] == '\01' && | if (name[0] == '\01' && | ||||
UnDecorateSymbolName(name + 1, demangle_buffer, sizeof(demangle_buffer), | UnDecorateSymbolName(name + 1, demangle_buffer, sizeof(demangle_buffer), | ||||
UNDNAME_NAME_ONLY)) | UNDNAME_NAME_ONLY)) | ||||
return demangle_buffer; | return demangle_buffer; | ||||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |
URL update in case the redirect goes bad in the future.