1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/debughlp.h
3 // Purpose: wraps dbghelp.h standard file
4 // Author: Vadim Zeitlin
6 // Created: 2005-01-08 (extracted from msw/crashrpt.cpp)
8 // Copyright: (c) 2003-2005 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSW_DEBUGHLPH_H_
13 #define _WX_MSW_DEBUGHLPH_H_
15 #include "wx/dynlib.h"
17 #include "wx/msw/wrapwin.h"
21 #include "wx/msw/private.h"
23 // we need to determine whether we have the declarations for the function in
24 // debughlp.dll version 5.81 (at least) and we check for DBHLPAPI to test this
27 // - VC6 version of imagehlp.h doesn't define it
29 // - testing for compiler version doesn't work as you can install and use
30 // the new SDK headers with VC6
32 // in any case, the user may override by defining wxUSE_DBGHELP himself
35 #define wxUSE_DBGHELP 1
37 #define wxUSE_DBGHELP 0
43 // ----------------------------------------------------------------------------
44 // wxDbgHelpDLL: dynamically load dbghelp.dll functions
45 // ----------------------------------------------------------------------------
47 // wrapper for some functions from dbghelp.dll
49 // MT note: this class is not MT safe and should be only used from a single
50 // thread at a time (this is so because dbghelp.dll is not MT-safe
55 // some useful constants not present in debughlp.h (stolen from DIA SDK)
69 BASICTYPE_CURRENCY
= 25,
71 BASICTYPE_VARIANT
= 27,
72 BASICTYPE_COMPLEX
= 28,
75 BASICTYPE_HRESULT
= 31,
84 SYMBOL_TAG_COMPILAND_DETAILS
,
85 SYMBOL_TAG_COMPILAND_ENV
,
89 SYMBOL_TAG_ANNOTATION
,
91 SYMBOL_TAG_PUBLIC_SYMBOL
,
94 SYMBOL_TAG_FUNCTION_TYPE
,
95 SYMBOL_TAG_POINTER_TYPE
,
96 SYMBOL_TAG_ARRAY_TYPE
,
99 SYMBOL_TAG_BASE_CLASS
,
101 SYMBOL_TAG_FUNCTION_ARG_TYPE
,
102 SYMBOL_TAG_FUNC_DEBUG_START
,
103 SYMBOL_TAG_FUNC_DEBUG_END
,
104 SYMBOL_TAG_USING_NAMESPACE
,
105 SYMBOL_TAG_VTABLE_SHAPE
,
109 SYMBOL_TAG_CUSTOM_TYPE
,
110 SYMBOL_TAG_MANAGED_TYPE
,
111 SYMBOL_TAG_DIMENSION
,
121 DATA_OBJECT_PTR
, // "this" pointer
140 typedef DWORD (WINAPI
*SymGetOptions_t
)();
141 typedef DWORD (WINAPI
*SymSetOptions_t
)(DWORD
);
142 typedef BOOL (WINAPI
*SymInitialize_t
)(HANDLE
, LPSTR
, BOOL
);
143 typedef BOOL (WINAPI
*StackWalk_t
)(DWORD
, HANDLE
, HANDLE
, LPSTACKFRAME
,
144 LPVOID
, PREAD_PROCESS_MEMORY_ROUTINE
,
145 PFUNCTION_TABLE_ACCESS_ROUTINE
,
146 PGET_MODULE_BASE_ROUTINE
,
147 PTRANSLATE_ADDRESS_ROUTINE
);
148 typedef BOOL (WINAPI
*SymFromAddr_t
)(HANDLE
, DWORD64
, PDWORD64
, PSYMBOL_INFO
);
149 typedef LPVOID (WINAPI
*SymFunctionTableAccess_t
)(HANDLE
, DWORD_PTR
);
150 typedef DWORD_PTR (WINAPI
*SymGetModuleBase_t
)(HANDLE
, DWORD_PTR
);
151 typedef BOOL (WINAPI
*SymGetLineFromAddr_t
)(HANDLE
, DWORD_PTR
,
152 PDWORD
, PIMAGEHLP_LINE
);
153 typedef BOOL (WINAPI
*SymSetContext_t
)(HANDLE
, PIMAGEHLP_STACK_FRAME
,
155 typedef BOOL (WINAPI
*SymEnumSymbols_t
)(HANDLE
, ULONG64
, PCSTR
,
156 PSYM_ENUMERATESYMBOLS_CALLBACK
, PVOID
);
157 typedef BOOL (WINAPI
*SymGetTypeInfo_t
)(HANDLE
, DWORD64
, ULONG
,
158 IMAGEHLP_SYMBOL_TYPE_INFO
, PVOID
);
159 typedef BOOL (WINAPI
*SymCleanup_t
)(HANDLE
);
160 typedef BOOL (WINAPI
*EnumerateLoadedModules_t
)(HANDLE
, PENUMLOADED_MODULES_CALLBACK
, PVOID
);
161 typedef BOOL (WINAPI
*MiniDumpWriteDump_t
)(HANDLE
, DWORD
, HANDLE
,
163 CONST PMINIDUMP_EXCEPTION_INFORMATION
,
164 CONST PMINIDUMP_USER_STREAM_INFORMATION
,
165 CONST PMINIDUMP_CALLBACK_INFORMATION
);
167 // The macro called by wxDO_FOR_ALL_SYM_FUNCS() below takes 2 arguments:
168 // the name of the function in the program code, which never has "64"
169 // suffix, and the name of the function in the DLL which can have "64"
170 // suffix in some cases. These 2 helper macros call the macro with the
171 // correct arguments in both cases.
172 #define wxSYM_CALL(what, name) what(name, name)
173 #if defined(_M_AMD64)
174 #define wxSYM_CALL_64(what, name) what(name, name ## 64)
176 // Also undo all the "helpful" definitions done by imagehlp.h that map 32
177 // bit functions to 64 bit ones, we don't need this as we do it ourselves.
179 #undef SymFunctionTableAccess
180 #undef SymGetModuleBase
181 #undef SymGetLineFromAddr
182 #undef EnumerateLoadedModules
184 #define wxSYM_CALL_64(what, name) what(name, name)
187 #define wxDO_FOR_ALL_SYM_FUNCS(what) \
188 wxSYM_CALL_64(what, StackWalk); \
189 wxSYM_CALL_64(what, SymFunctionTableAccess); \
190 wxSYM_CALL_64(what, SymGetModuleBase); \
191 wxSYM_CALL_64(what, SymGetLineFromAddr); \
192 wxSYM_CALL_64(what, EnumerateLoadedModules); \
194 wxSYM_CALL(what, SymGetOptions); \
195 wxSYM_CALL(what, SymSetOptions); \
196 wxSYM_CALL(what, SymInitialize); \
197 wxSYM_CALL(what, SymFromAddr); \
198 wxSYM_CALL(what, SymSetContext); \
199 wxSYM_CALL(what, SymEnumSymbols); \
200 wxSYM_CALL(what, SymGetTypeInfo); \
201 wxSYM_CALL(what, SymCleanup); \
202 wxSYM_CALL(what, MiniDumpWriteDump)
204 #define wxDECLARE_SYM_FUNCTION(func, name) static func ## _t func
206 wxDO_FOR_ALL_SYM_FUNCS(wxDECLARE_SYM_FUNCTION
);
208 #undef wxDECLARE_SYM_FUNCTION
210 // load all functions from DLL, return true if ok
213 // return the string with the error message explaining why Init() failed
214 static const wxString
& GetErrorMessage();
216 // log error returned by the given function to debug output
217 static void LogError(const wxChar
*func
);
219 // return textual representation of the value of given symbol
220 static wxString
DumpSymbol(PSYMBOL_INFO pSymInfo
, void *pVariable
);
222 // return the name of the symbol with given type index
223 static wxString
GetSymbolName(PSYMBOL_INFO pSymInfo
);
226 // dereference the given symbol, i.e. return symbol which is not a
227 // pointer/reference any more
229 // if ppData != NULL, dereference the pointer as many times as we
230 // dereferenced the symbol
232 // return the tag of the dereferenced symbol
233 static SymbolTag
DereferenceSymbol(PSYMBOL_INFO pSymInfo
, void **ppData
);
235 static wxString
DumpField(PSYMBOL_INFO pSymInfo
,
239 static wxString
DumpBaseType(BasicType bt
, DWORD64 length
, void *pVariable
);
241 static wxString
DumpUDT(PSYMBOL_INFO pSymInfo
,
246 #endif // wxUSE_DBGHELP
248 #endif // _WX_MSW_DEBUGHLPH_H_