1
0
mirror of synced 2024-11-13 18:50:53 +01:00

fix: Stack trace printing on Windows not working right

This commit is contained in:
WerWolv 2023-06-22 15:15:06 +02:00
parent cb3b71e2f3
commit ae06954771
2 changed files with 10 additions and 14 deletions

View File

@ -601,13 +601,12 @@ function(generatePDBs)
COMMAND COMMAND
(${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb && (${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb &&
${cv2pdb_SOURCE_DIR}/cv2pdb64.exe ${cv2pdb_SOURCE_DIR}/cv2pdb64.exe
$<TARGET_FILE:${PDB}> $<TARGET_FILE:${PDB}>) || (exit 0)
${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb) || (exit 0)
DEPENDS $<TARGET_FILE:${PDB}> DEPENDS $<TARGET_FILE:${PDB}>
COMMAND_EXPAND_LISTS) COMMAND_EXPAND_LISTS)
target_sources(imhex_all PRIVATE ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb) target_sources(imhex_all PRIVATE ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb)
install(FILES ${CMAKE_BINARY_DIR}/${GENERATED_PDB}.pdb DESTINATION ".") install(FILES $<TARGET_FILE_DIR:${PDB}>/${GENERATED_PDB}.pdb DESTINATION ".")
endforeach () endforeach ()

View File

@ -1,5 +1,4 @@
#include <hex/helpers/stacktrace.hpp> #include <hex/helpers/stacktrace.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
@ -41,25 +40,24 @@
stackFrame.AddrStack.Mode = AddrModeFlat; stackFrame.AddrStack.Mode = AddrModeFlat;
while (true) { while (true) {
if (StackWalk64(
if (!StackWalk64(
image, process, thread, image, process, thread,
&stackFrame, &context, nullptr, &stackFrame, &context, nullptr,
SymFunctionTableAccess64, SymGetModuleBase64, nullptr)) SymFunctionTableAccess64, SymGetModuleBase64, nullptr) == FALSE)
break; break;
if (stackFrame.AddrReturn.Offset == stackFrame.AddrPC.Offset) if (stackFrame.AddrReturn.Offset == stackFrame.AddrPC.Offset)
break; break;
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; std::array<char, sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)> buffer = {};
auto symbol = (PSYMBOL_INFO)buffer; auto symbol = (PSYMBOL_INFO)buffer.data();
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME; symbol->MaxNameLen = MAX_SYM_NAME;
DWORD64 displacementSymbol = 0; DWORD64 displacementSymbol = 0;
std::string symbolName; const char *symbolName;
if (SymFromAddr(process, stackFrame.AddrPC.Offset, &displacementSymbol, symbol) == TRUE) { if (SymFromAddr(process, stackFrame.AddrPC.Offset, &displacementSymbol, symbol) == TRUE) {
symbolName = hex::format("{} (0x{:X})", symbol->Name, symbol->Address); symbolName = symbol->Name;
} else { } else {
symbolName = "??"; symbolName = "??";
} }
@ -70,9 +68,9 @@
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
DWORD displacementLine = 0; DWORD displacementLine = 0;
u32 lineNumber;
std::string fileName;
u32 lineNumber;
const char *fileName;
if (SymGetLineFromAddr64(process, stackFrame.AddrPC.Offset, &displacementLine, &line) == TRUE) { if (SymGetLineFromAddr64(process, stackFrame.AddrPC.Offset, &displacementLine, &line) == TRUE) {
lineNumber = line.LineNumber; lineNumber = line.LineNumber;
fileName = line.FileName; fileName = line.FileName;
@ -90,7 +88,6 @@
demangledName = symbolName; demangledName = symbolName;
stackTrace.push_back(StackFrame { fileName, demangledName, lineNumber }); stackTrace.push_back(StackFrame { fileName, demangledName, lineNumber });
} }
SymCleanup(process); SymCleanup(process);