X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Flogbacktrace_win.cpp;h=d465b466a15b6b06feb6044164eda115544e3204;hp=f6d922bd246ef2406edb75c5bd98b4701ec7f1b9;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/common/logbacktrace_win.cpp b/src/common/logbacktrace_win.cpp index f6d922bd..d465b466 100644 --- a/src/common/logbacktrace_win.cpp +++ b/src/common/logbacktrace_win.cpp @@ -18,51 +18,51 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "quassel.h" +#include #include #include -#include -// #include #include #include -void loadHelpStackFrame(IMAGEHLP_STACK_FRAME &ihsf, const STACKFRAME64 &stackFrame) +#include "quassel.h" + +void loadHelpStackFrame(IMAGEHLP_STACK_FRAME& ihsf, const STACKFRAME64& stackFrame) { ZeroMemory(&ihsf, sizeof(IMAGEHLP_STACK_FRAME)); ihsf.InstructionOffset = stackFrame.AddrPC.Offset; ihsf.FrameOffset = stackFrame.AddrFrame.Offset; } - BOOL CALLBACK EnumSymbolsCB(PSYMBOL_INFO symInfo, ULONG size, PVOID user) { Q_UNUSED(size) - QStringList *params = (QStringList *)user; + QStringList* params = (QStringList*)user; if (symInfo->Flags & SYMFLAG_PARAMETER) { params->append(symInfo->Name); } return TRUE; } - -struct EnumModulesContext { +struct EnumModulesContext +{ HANDLE hProcess; - QTextStream &stream; - EnumModulesContext(HANDLE hProcess, QTextStream &stream) : hProcess(hProcess), stream(stream) {} + QTextStream& stream; + EnumModulesContext(HANDLE hProcess, QTextStream& stream) + : hProcess(hProcess) + , stream(stream) + {} }; BOOL CALLBACK EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext) { Q_UNUSED(ModuleName) IMAGEHLP_MODULE64 mod; - EnumModulesContext *context = (EnumModulesContext *)UserContext; + EnumModulesContext* context = (EnumModulesContext*)UserContext; mod.SizeOfStruct = sizeof(IMAGEHLP_MODULE64); if (SymGetModuleInfo64(context->hProcess, BaseOfDll, &mod)) { - QString line = QString("%1 0x%2 Image: %3").arg(mod.ModuleName, -14) - .arg(BaseOfDll, 8, 16, QLatin1Char('0')) - .arg(mod.LoadedImageName); + QString line = QString("%1 0x%2 Image: %3").arg(mod.ModuleName, -14).arg(BaseOfDll, 8, 16, QLatin1Char('0')).arg(mod.LoadedImageName); // qDebug() << qPrintable(line); context->stream << line << '\n'; @@ -76,16 +76,15 @@ BOOL CALLBACK EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserCont return TRUE; } - #if defined(_M_IX86) && defined(Q_CC_MSVC) // Disable global optimization and ignore /GS waning caused by // inline assembly. // not needed with mingw cause we can tell mingw which registers we use - #pragma optimize("g", off) - #pragma warning(push) - #pragma warning(disable : 4748) +# pragma optimize("g", off) +# pragma warning(push) +# pragma warning(disable : 4748) #endif -void Quassel::logBacktrace(const QString &filename) +void Quassel::logBacktrace(const QString& filename) { DWORD MachineType; CONTEXT Context; @@ -95,16 +94,16 @@ void Quassel::logBacktrace(const QString &filename) ZeroMemory(&Context, sizeof(CONTEXT)); Context.ContextFlags = CONTEXT_CONTROL; -#ifdef __MINGW32__ - asm ("Label:\n\t" - "movl %%ebp,%0;\n\t" - "movl %%esp,%1;\n\t" - "movl $Label,%%eax;\n\t" - "movl %%eax,%2;\n\t" - : "=r" (Context.Ebp), "=r" (Context.Esp), "=r" (Context.Eip) - : //no input - : "eax"); -#else +# ifdef __MINGW32__ + asm("Label:\n\t" + "movl %%ebp,%0;\n\t" + "movl %%esp,%1;\n\t" + "movl $Label,%%eax;\n\t" + "movl %%eax,%2;\n\t" + : "=r"(Context.Ebp), "=r"(Context.Esp), "=r"(Context.Eip) + : // no input + : "eax"); +# else _asm { Label: mov[Context.Ebp], ebp; @@ -112,43 +111,43 @@ Label: mov eax, [Label]; mov[Context.Eip], eax; } -#endif +# endif #else RtlCaptureContext(&Context); #endif ZeroMemory(&StackFrame, sizeof(STACKFRAME64)); #ifdef _M_IX86 - MachineType = IMAGE_FILE_MACHINE_I386; - StackFrame.AddrPC.Offset = Context.Eip; - StackFrame.AddrPC.Mode = AddrModeFlat; + MachineType = IMAGE_FILE_MACHINE_I386; + StackFrame.AddrPC.Offset = Context.Eip; + StackFrame.AddrPC.Mode = AddrModeFlat; StackFrame.AddrFrame.Offset = Context.Ebp; - StackFrame.AddrFrame.Mode = AddrModeFlat; + StackFrame.AddrFrame.Mode = AddrModeFlat; StackFrame.AddrStack.Offset = Context.Esp; - StackFrame.AddrStack.Mode = AddrModeFlat; + StackFrame.AddrStack.Mode = AddrModeFlat; #elif defined(_M_X64) - MachineType = IMAGE_FILE_MACHINE_AMD64; - StackFrame.AddrPC.Offset = Context.Rip; - StackFrame.AddrPC.Mode = AddrModeFlat; + MachineType = IMAGE_FILE_MACHINE_AMD64; + StackFrame.AddrPC.Offset = Context.Rip; + StackFrame.AddrPC.Mode = AddrModeFlat; StackFrame.AddrFrame.Offset = Context.Rsp; - StackFrame.AddrFrame.Mode = AddrModeFlat; + StackFrame.AddrFrame.Mode = AddrModeFlat; StackFrame.AddrStack.Offset = Context.Rsp; - StackFrame.AddrStack.Mode = AddrModeFlat; + StackFrame.AddrStack.Mode = AddrModeFlat; #elif defined(_M_IA64) - MachineType = IMAGE_FILE_MACHINE_IA64; - StackFrame.AddrPC.Offset = Context.StIIP; - StackFrame.AddrPC.Mode = AddrModeFlat; + MachineType = IMAGE_FILE_MACHINE_IA64; + StackFrame.AddrPC.Offset = Context.StIIP; + StackFrame.AddrPC.Mode = AddrModeFlat; StackFrame.AddrFrame.Offset = Context.IntSp; - StackFrame.AddrFrame.Mode = AddrModeFlat; + StackFrame.AddrFrame.Mode = AddrModeFlat; StackFrame.AddrBStore.Offset = Context.RsBSP; - StackFrame.AddrBStore.Mode = AddrModeFlat; + StackFrame.AddrBStore.Mode = AddrModeFlat; StackFrame.AddrStack.Offset = Context.IntSp; - StackFrame.AddrStack.Mode = AddrModeFlat; + StackFrame.AddrStack.Mode = AddrModeFlat; #else - #error "Unsupported platform" +# error "Unsupported platform" #endif - //EnterCriticalSection(&DbgHelpLock); + // EnterCriticalSection(&DbgHelpLock); QFile logFile(filename); logFile.open(QIODevice::Append); @@ -160,9 +159,7 @@ Label: DWORD64 dwDisplacement; - ULONG64 buffer[(sizeof(SYMBOL_INFO) + - MAX_SYM_NAME*sizeof(TCHAR) + - sizeof(ULONG64) - 1) / sizeof(ULONG64)]; + ULONG64 buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + sizeof(ULONG64) - 1) / sizeof(ULONG64)]; PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); pSymbol->MaxNameLen = MAX_SYM_NAME; @@ -179,7 +176,7 @@ Label: break; loadHelpStackFrame(ihsf, StackFrame); - if (StackFrame.AddrPC.Offset != 0) { // Valid frame. + if (StackFrame.AddrPC.Offset != 0) { // Valid frame. QString fileName("???"); if (SymGetModuleInfo64(hProcess, ihsf.InstructionOffset, &mod)) { fileName = QString(mod.ImageName); @@ -198,17 +195,18 @@ Label: SymSetContext(hProcess, &ihsf, NULL); SymEnumSymbols(hProcess, 0, NULL, EnumSymbolsCB, (PVOID)¶ms); - QString debugLine = QString("#%1 %2 0x%3 %4(%5)").arg(i, 3, 10) - .arg(fileName, -20) - .arg(ihsf.InstructionOffset, 8, 16, QLatin1Char('0')) - .arg(funcName) - .arg(params.join(", ")); + QString debugLine = QString("#%1 %2 0x%3 %4(%5)") + .arg(i, 3, 10) + .arg(fileName, -20) + .arg(ihsf.InstructionOffset, 8, 16, QLatin1Char('0')) + .arg(funcName) + .arg(params.join(", ")); // qDebug() << qPrintable(debugLine); logStream << debugLine << '\n'; i++; } else { - break; // we're at the end. + break; // we're at the end. } } @@ -220,8 +218,7 @@ Label: logFile.close(); } - #if defined(_M_IX86) && defined(Q_CC_MSVC) - #pragma warning(pop) - #pragma optimize("g", on) +# pragma warning(pop) +# pragma optimize("g", on) #endif