From 101f86b75942a5bedc290b4c5c60a2cd833873a0 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 16 Nov 2015 20:16:53 +0100 Subject: [PATCH 1/2] Add file and line support to backtrace generator on windows. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 --- dbus/dbus-sysdeps-win.c | 65 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index d24dead..c25a129 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -2468,7 +2468,12 @@ static BOOL (WINAPI *pSymGetModuleInfo)( static DWORD (WINAPI *pSymSetOptions)( DWORD SymOptions ); - +static BOOL (WINAPI *pSymGetLineFromAddr)( + HANDLE hProcess, + DWORD dwAddr, + PDWORD pdwDisplacement, + PIMAGEHLP_LINE Line +); static BOOL init_backtrace() { @@ -2541,9 +2546,14 @@ PTRANSLATE_ADDRESS_ROUTINE TranslateAddress pSymSetOptions = (DWORD (WINAPI *)( DWORD SymOptions ))GetProcAddress (hmodDbgHelp, FUNC(SymSetOptions)); + pSymGetLineFromAddr = (BOOL (WINAPI *)( + HANDLE hProcess, + DWORD dwAddr, + PDWORD pdwDisplacement, + PIMAGEHLP_LINE Line +))GetProcAddress (hmodDbgHelp, FUNC(SymGetLineFromAddr)); - - pSymSetOptions(SYMOPT_UNDNAME); + pSymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES); pSymInitialize(GetCurrentProcess(), NULL, TRUE); @@ -2610,37 +2620,50 @@ static void dump_backtrace_for_thread(HANDLE hThread) # error You need to fill in the STACKFRAME structure for your architecture #endif + /* + backtrace format +
[+offset] [ '[' ':' ']' ] [ 'in' ] + example: + 6 0xf75ade6b wine_switch_to_stack+0x2a [/usr/src/debug/wine-snapshot/libs/wine/port.c:59] in libwine.so.1 + */ while (pStackWalk(dwImageType, GetCurrentProcess(), hThread, &sf, &context, NULL, pSymFunctionTableAccess, pSymGetModuleBase, NULL)) - { + { BYTE buffer[256]; IMAGEHLP_SYMBOL * pSymbol = (IMAGEHLP_SYMBOL *)buffer; DWORD dwDisplacement; + IMAGEHLP_LINE line; + IMAGEHLP_MODULE moduleInfo; pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); pSymbol->MaxNameLength = sizeof(buffer) - sizeof(IMAGEHLP_SYMBOL) + 1; - if (!pSymGetSymFromAddr(GetCurrentProcess(), sf.AddrPC.Offset, - &dwDisplacement, pSymbol)) - { - IMAGEHLP_MODULE ModuleInfo; - ModuleInfo.SizeOfStruct = sizeof(ModuleInfo); - - if (!pSymGetModuleInfo(GetCurrentProcess(), sf.AddrPC.Offset, - &ModuleInfo)) - DPRINTF("%3d %p\n", i++, (void*)sf.AddrPC.Offset); + if (pSymGetSymFromAddr(GetCurrentProcess(), sf.AddrPC.Offset, + &dwDisplacement, pSymbol)) + { + if (dwDisplacement) + DPRINTF ("%3d %s+0x%lx", i++, pSymbol->Name, dwDisplacement); else - DPRINTF("%3d %s+0x%lx\n", i++, ModuleInfo.ImageName, - sf.AddrPC.Offset - ModuleInfo.BaseOfImage); - } - else if (dwDisplacement) - DPRINTF("%3d %s+0x%lx\n", i++, pSymbol->Name, dwDisplacement); + DPRINTF ("%3d %s", i++, pSymbol->Name); + } else - DPRINTF("%3d %s\n", i++, pSymbol->Name); - } + DPRINTF ("%3d 0x%lx", i++, sf.AddrPC.Offset); - ResumeThread(hThread); + line.SizeOfStruct = sizeof(IMAGEHLP_LINE); + if (pSymGetLineFromAddr(GetCurrentProcess(), sf.AddrPC.Offset, &dwDisplacement, &line) == TRUE) + { + DPRINTF (" [%s:%ld]", line.FileName, line.LineNumber); + } + + moduleInfo.SizeOfStruct = sizeof(moduleInfo); + if (pSymGetModuleInfo(GetCurrentProcess(), sf.AddrPC.Offset, &moduleInfo)) + { + DPRINTF (" in %s", moduleInfo.ModuleName); + } + DPRINTF ("\n"); + } + ResumeThread (hThread); } static DWORD WINAPI dump_thread_proc(LPVOID lpParameter) -- 1.8.4.5