1. Edd Dawson
  2. stack_trace
Issue #1 resolved

Windows 64bit support

Anonymous created an issue

Hi I use this lib in my project and have made some changes in it. See: https://tora.svn.sourceforge.net/svnroot/tora/branches/tora3/extlibs/stack

--- /cygdrive/d/DEVEL/stack.cpp 2012-05-07 19:18:12.739675600 +0200 +++ stack.cpp 2012-05-07 18:59:46.172794400 +0200 @@ -264,13 +263,21 @@ void (WINAPI RtlCaptureContext_)(CONTEXT) = kernel32.function("RtlCaptureContext");

     RtlCaptureContext_(&context);

- +#ifdef _WIN64 + frame.AddrPC.Offset = context.Rip; + frame.AddrPC.Mode = AddrModeFlat; + frame.AddrStack.Offset = context.Rsp; + frame.AddrStack.Mode = AddrModeFlat; + frame.AddrFrame.Offset = context.Rbp; + frame.AddrFrame.Mode = AddrModeFlat; +#else frame.AddrPC.Offset = context.Eip; frame.AddrPC.Mode = AddrModeFlat; frame.AddrStack.Offset = context.Esp; frame.AddrStack.Mode = AddrModeFlat; frame.AddrFrame.Offset = context.Ebp; frame.AddrFrame.Mode = AddrModeFlat; +#endif

     HANDLE process = GetCurrentProcess();
     HANDLE thread = GetCurrentThread();

@@ -280,7 +287,11 @@ char symbol_buffer[sizeof(IMAGEHLP_SYMBOL) + 255]; char module_name_raw[MAX_PATH];

+#ifdef _WIN64 + while(StackWalk(IMAGE_FILE_MACHINE_AMD64, process, thread, &frame, &context, 0, SymFunctionTableAccess, SymGetModuleBase, 0)) +#else while(StackWalk(IMAGE_FILE_MACHINE_I386, process, thread, &frame, &context, 0, SymFunctionTableAccess, SymGetModuleBase, 0)) +#endif { if (skip) { @@ -294,7 +305,11 @@ symbol->SizeOfStruct = (sizeof *symbol) + 255; symbol->MaxNameLength = 254;

+#ifdef _WIN64 + DWORD64 module_base = SymGetModuleBase(process, frame.AddrPC.Offset); +#else 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; @@ -309,7 +324,11 @@ func = got_symbol ? symbol->Name : "[unknown function]"; } #else +#ifdef _WIN64 + DWORD64 dummy = 0; +#else DWORD dummy = 0; +#endif BOOL got_symbol = SymGetSymFromAddr(process, frame.AddrPC.Offset, &dummy, symbol); std::string func = got_symbol ? symbol->Name : "[unknown function]"; #endif

And also fixed a segfault, when a library (like Qt) contains hidden symbols. @@ -24,25 +23,25 @@ #endif

#elif defined(GNUC) + #include <string.h> #include <dlfcn.h> #include <cxxabi.h> #endif

namespace { + #if defined(GNUC) std::string demangle(const char *name) { + //this just does not work - some QT's private symbols cannot be resolved + //if (!name) throws std::runtime_error then "use -rdynamic"; + if(!name) return "uknown symbol";

Ivan

Comments (2)

  1. Log in to comment