Skip to content
Permalink
Browse files

Merge pull request #592 from tomay3000/patch-1

Adjust stack walking for windows 64 bit architecture to fix build erros
  • Loading branch information
sodevel committed Mar 25, 2020
2 parents 006148d + 585e439 commit 4d526fb5b10660f4a8ec58023a5ac2e208166c33
Showing with 41 additions and 12 deletions.
  1. +28 −6 src/dbg_stack_trace/stack.cpp
  2. +13 −6 src/maingui.cpp
@@ -253,11 +253,18 @@ namespace
context = *fromContext;
}

frame.AddrPC.Offset = context.Eip;
#if defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) // 64-bit
frame.AddrPC.Offset = context.Rip;
frame.AddrStack.Offset = context.Rsp;
frame.AddrFrame.Offset = context.Rbp;
#elif defined(__i386__) || defined(_X86_) || defined(_M_IX86) // 32-bit
frame.AddrPC.Offset = context.Eip;
frame.AddrStack.Offset = context.Esp;
frame.AddrFrame.Offset = context.Ebp;
#endif

frame.AddrPC.Mode = AddrModeFlat;
frame.AddrStack.Offset = context.Esp;
frame.AddrStack.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context.Ebp;
frame.AddrFrame.Mode = AddrModeFlat;

HANDLE process = GetCurrentProcess();
@@ -283,7 +290,12 @@ namespace
symbol->SizeOfStruct = (sizeof *symbol) + 255;
symbol->MaxNameLength = 254;

DWORD module_base = SymGetModuleBase(process, frame.AddrPC.Offset);
#if defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) // 64-bit
DWORD64 module_base = SymGetModuleBase(process, frame.AddrPC.Offset);
#elif defined(__i386__) || defined(_X86_) || defined(_M_IX86) // 32-bit
DWORD module_base = SymGetModuleBase(process, frame.AddrPC.Offset);
#endif

std::string module_name = "[unknown module]";
if( module_base && GetModuleFileNameA(reinterpret_cast<HINSTANCE>(module_base), module_name_raw, MAX_PATH))
module_name = module_name_raw;
@@ -293,12 +305,22 @@ namespace

if (func.empty())
{
DWORD displacement = 0; // dummy variable
#if defined(__amd64__) || defined(__x86_64__) // 64-bit
DWORD64 displacement = 0; // dummy variable
#elif defined(__i386__) || defined(_X86_) // 32-bit
DWORD displacement = 0; // dummy variable
#endif

BOOL got_symbol = SymGetSymFromAddr(process, frame.AddrPC.Offset, &displacement, symbol);
func = got_symbol ? symbol->Name : "[unknown function]";
}
#else
DWORD displacement = 0; // dummy variable
#if defined(_M_AMD64) // 64-bit
DWORD64 displacement = 0; // dummy variable
#elif defined(_M_IX86) // 32-bit
DWORD displacement = 0; // dummy variable
#endif

BOOL got_symbol = SymGetSymFromAddr(process, frame.AddrPC.Offset, &displacement, symbol);
std::string func = got_symbol ? symbol->Name : "[unknown function]";
#endif
@@ -88,12 +88,19 @@ int MyApp::OnRun()
#if wxUSE_ON_FATAL_EXCEPTION && wxUSE_STACKWALKER
::wxHandleFatalExceptions( true );
#elif defined(_WIN32) && defined(__MINGW32__)
// Structured Exception handlers are stored in a linked list at FS:[0]
// THIS MUST BE A LOCAL VARIABLE - windows won't use an object outside of the thread's stack frame
EXCEPTION_REGISTRATION ex;
ex.handler = StructuredExceptionHandler;
asm volatile ("movl %%fs:0, %0" : "=r" (ex.prev));
asm volatile ("movl %0, %%fs:0" : : "r" (&ex));
// Structured Exception handlers are stored in a linked list at FS:[0] for 32-bit and GS:[0] for 64-bit
// https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L347
// THIS MUST BE A LOCAL VARIABLE - windows won't use an object outside of the thread's stack frame
EXCEPTION_REGISTRATION ex;
ex.handler = StructuredExceptionHandler;

#if defined(__amd64__) || defined(__x86_64__) // 64-bit
asm volatile ("movq %%gs:0, %0" : "=r" (ex.prev));
asm volatile ("movq %0, %%gs:0" : : "r" (&ex));
#elif defined(__i386__) || defined(_X86_) // 32-bit
asm volatile ("movl %%fs:0, %0" : "=r" (ex.prev));
asm volatile ("movl %0, %%fs:0" : : "r" (&ex));
#endif
#endif

// Using a space so the initial 'w' will not be capitalized in wxLogGUI dialogs

0 comments on commit 4d526fb

Please sign in to comment.
You can’t perform that action at this time.