28#include "dbus-internals.h"
29#include "dbus-sysdeps.h"
31#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_ENABLE_EMBEDDED_TESTS)
33#if defined(_MSC_VER) || defined(DBUS_WINCE)
42#include "dbus-sysdeps-win.h"
48#define DPRINTF(fmt, ...) fprintf (stderr, fmt, ##__VA_ARGS__)
56static void dump_backtrace_for_thread (HANDLE hThread)
64 SymSetOptions (SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
65 SymInitialize (GetCurrentProcess (),
NULL,
TRUE);
70 if (hThread == GetCurrentThread())
73 DPRINTF (
"Backtrace:\n");
77 context.ContextFlags = CONTEXT_FULL;
79 SuspendThread (hThread);
81 if (!GetThreadContext (hThread, &context))
83 DPRINTF (
"Couldn't get thread context (error %ld)\n", GetLastError ());
84 ResumeThread (hThread);
91 dwImageType = IMAGE_FILE_MACHINE_I386;
92 sf.AddrFrame.Offset = context.Ebp;
93 sf.AddrFrame.Mode = AddrModeFlat;
94 sf.AddrPC.Offset = context.Eip;
95 sf.AddrPC.Mode = AddrModeFlat;
97 dwImageType = IMAGE_FILE_MACHINE_AMD64;
98 sf.AddrPC.Offset = context.Rip;
99 sf.AddrPC.Mode = AddrModeFlat;
100 sf.AddrFrame.Offset = context.Rsp;
101 sf.AddrFrame.Mode = AddrModeFlat;
102 sf.AddrStack.Offset = context.Rsp;
103 sf.AddrStack.Mode = AddrModeFlat;
104#elif defined(_M_IA64)
105 dwImageType = IMAGE_FILE_MACHINE_IA64;
106 sf.AddrPC.Offset = context.StIIP;
107 sf.AddrPC.Mode = AddrModeFlat;
108 sf.AddrFrame.Offset = context.IntSp;
109 sf.AddrFrame.Mode = AddrModeFlat;
110 sf.AddrBStore.Offset= context.RsBSP;
111 sf.AddrBStore.Mode = AddrModeFlat;
112 sf.AddrStack.Offset = context.IntSp;
113 sf.AddrStack.Mode = AddrModeFlat;
115# error You need to fill in the STACKFRAME structure for your architecture
124 while (StackWalk (dwImageType, GetCurrentProcess (),
125 hThread, &sf, &context,
NULL, SymFunctionTableAccess,
126 SymGetModuleBase,
NULL))
128 char buffer[
sizeof(SYMBOL_INFO) + MAX_SYM_NAME *
sizeof(
char)];
129 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
130 DWORD64 displacement;
132 DWORD dwDisplacement;
133 IMAGEHLP_MODULE moduleInfo;
141 if (old_address.Offset == sf.AddrPC.Offset)
147 pSymbol->SizeOfStruct =
sizeof(SYMBOL_INFO);
148 pSymbol->MaxNameLen = MAX_SYM_NAME;
150 if (SymFromAddr (GetCurrentProcess (), sf.AddrPC.Offset, &displacement, pSymbol))
153 DPRINTF (
"%3d %s+0x%I64x", i++, pSymbol->Name, displacement);
155 DPRINTF (
"%3d %s", i++, pSymbol->Name);
158 DPRINTF (
"%3d 0x%Ix", i++, sf.AddrPC.Offset);
160 line.SizeOfStruct =
sizeof(IMAGEHLP_LINE);
161 if (SymGetLineFromAddr (GetCurrentProcess (), sf.AddrPC.Offset, &dwDisplacement, &line))
163 DPRINTF (
" [%s:%ld]", line.FileName, line.LineNumber);
166 moduleInfo.SizeOfStruct =
sizeof(moduleInfo);
167 if (SymGetModuleInfo (GetCurrentProcess (), sf.AddrPC.Offset, &moduleInfo))
169 DPRINTF (
" in %s", moduleInfo.ModuleName);
172 old_address = sf.AddrPC;
174 ResumeThread (hThread);
177static DWORD WINAPI dump_thread_proc (LPVOID lpParameter)
179 dump_backtrace_for_thread ((HANDLE) lpParameter);
188 HANDLE hCurrentThread;
191 DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
192 GetCurrentProcess (), &hCurrentThread,
193 0,
FALSE, DUPLICATE_SAME_ACCESS);
194 hThread = CreateThread (
NULL, 0, dump_thread_proc, (LPVOID)hCurrentThread,
196 WaitForSingleObject (hThread, INFINITE);
197 CloseHandle (hThread);
198 CloseHandle (hCurrentThread);
204void _dbus_print_backtrace (
void)
209void _dbus_print_backtrace (
void)
211 _dbus_verbose (
" D-Bus not compiled with backtrace support\n");
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".