diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-08-04 21:22:50 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-08-04 21:22:50 +1000 |
commit | cb547d0bc62220dba9c61544f6ab190be88d2b17 (patch) | |
tree | bfd13ff2db8fc636e774c00e19aca4e39aab4840 /source/core/StarException_windows.cpp | |
parent | 9b3bf5ae822f0080f72f5149f50bc79455fcdfeb (diff) |
Improve Windows stack output
Diffstat (limited to 'source/core/StarException_windows.cpp')
-rw-r--r-- | source/core/StarException_windows.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/source/core/StarException_windows.cpp b/source/core/StarException_windows.cpp index 159cf3d..ae9d8d9 100644 --- a/source/core/StarException_windows.cpp +++ b/source/core/StarException_windows.cpp @@ -10,6 +10,8 @@ namespace Star { struct WindowsSymInitializer { WindowsSymInitializer() { + DWORD options = SymGetOptions(); + SymSetOptions(options | SYMOPT_LOAD_LINES); if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) fatalError("SymInitialize failed", false); } @@ -126,9 +128,19 @@ OutputProxy outputStack(StackCapture stack) { symbol->SizeOfStruct = sizeof(SYMBOL_INFO); symbol->MaxNameLen = MAX_SYM_NAME; - DWORD64 displacement = 0; - format(os, "[{}] {}", i, (void*)stack.first[i]); - if (SymFromAddr(process, stack.first[i], &displacement, symbol)) + format(os, "[{:0{}}] {}", i, (int)log10(stack.second) + 1, (void*)stack.first[i]); + IMAGEHLP_LINE64 line{}; + DWORD displacement = 0; + line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); + if (SymGetLineFromAddr64(process, stack.first[i], &displacement, &line) && *line.FileName) { + char* file = line.FileName; + for (char* i = file; *i; ++i) { + if (*i == '\\' || *i == '/') + file = i; + } + format(os, " ({}:{})", ++file, line.LineNumber); + } + if (SymFromAddr(process, stack.first[i], NULL, symbol)) format(os, " {}", symbol->Name); if (i + 1 < stack.second) |