Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
#include "precompiled.h"
#include "lib/sysdep/os/win/wdbg_sym.h"
#include <cstdlib>
#include <cstdio>
#include <set>
#include "lib/byte_order.h"
#include "lib/module_init.h"
#include "lib/debug_stl.h"
#include "lib/app_hooks.h"
#include "lib/external_libraries/dbghelp.h"
#include "lib/sysdep/os/win/wdbg.h"
#include "lib/sysdep/os/win/wutil.h"
#include <atomic>
Classes | |
struct | SYMBOL_INFO_PACKAGEW2 |
struct | TI_FINDCHILDREN_PARAMS2 |
struct | DumpState |
Macros | |
#define | INDENT STMT(for(size_t i__ = 0; i__ <= state.level; i__++) out(L" ");) |
#define | UNINDENT STMT(out_erase((state.level+1)*4);) |
#define | SUPPRESS_HANDLE(name) if(!wcscmp(type_name, L#name L"__")) return true; |
Typedefs | |
typedef Status(* | DumpFunc) (DWORD typeId, const u8 *p, DumpState &state) |
Enumerations | |
enum | CV_HREG_e { CV_REG_EBP = 22 , CV_AMD64_RBP = 334 } |
Functions | |
static Status | InitDbghelp () |
static void | sym_init () |
static STACKFRAME64 | PopulateStackFrame (CONTEXT &context) |
static IMAGEHLP_STACK_FRAME | PopulateImageStackFrame (const STACKFRAME64 &sf) |
static Status | ResolveSymbol_lk (void *ptr_of_interest, wchar_t *sym_name, wchar_t *file, int *line) |
Status | debug_ResolveSymbol (void *ptr_of_interest, wchar_t *sym_name, wchar_t *file, int *line) |
read and return symbol information for the given address. More... | |
Status | debug_CaptureContext (void *pcontext) |
static Status | CallStackWalk (STACKFRAME64 &sf, CONTEXT &context) |
Status | wdbg_sym_WalkStack (StackFrameCallback cb, uintptr_t cbData, CONTEXT &context, const wchar_t *lastFuncToSkip) |
Iterate over a call stack, invoking a callback for each frame encountered. More... | |
void * | debug_GetCaller (void *pcontext, const wchar_t *lastFuncToSkip) |
return the caller of a certain function on the call stack. More... | |
static void | out_init (wchar_t *buf, size_t max_chars) |
static void | out (const wchar_t *fmt,...) |
static void | out_erase (size_t num_chars) |
static void | out_latch_pos () |
static Status | out_check_limit () |
static bool | is_string (const u8 *p, size_t stride) |
static Status | dump_sym (DWORD id, const u8 *p, DumpState &state) |
static void | dump_error (Status err) |
static Status | dump_string (const u8 *p, size_t el_size) |
static void | seq_determine_formatting (size_t el_size, size_t el_count, bool *fits_on_one_line, size_t *num_elements_to_show) |
static Status | dump_sequence (DebugStlIterator el_iterator, void *internal, size_t el_count, DWORD el_type_id, size_t el_size, DumpState &state) |
static const u8 * | array_iterator (void *internal, size_t el_size) |
static Status | dump_array (const u8 *p, size_t el_count, DWORD el_type_id, size_t el_size, DumpState &state) |
static Status | CanHandleDataKind (DWORD dataKind) |
static bool | IsRelativeToFramePointer (DWORD flags, DWORD reg) |
static bool | IsUnretrievable (DWORD flags) |
static Status | DetermineSymbolAddress (DWORD id, const SYMBOL_INFOW *sym, const DumpState &state, const u8 **pp) |
static Status | dump_sym_array (DWORD type_id, const u8 *p, DumpState &state) |
static void | AppendCharacterIfPrintable (u64 data) |
static Status | dump_sym_base_type (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_base_class (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_data (DWORD id, const u8 *p, DumpState &state) |
static Status | dump_sym_enum (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_function (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_function_type (DWORD type_id, const u8 *p, DumpState &state) |
static void | ptr_reset_visited () |
static bool | ptr_already_visited (const u8 *p) |
static Status | dump_sym_pointer (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_typedef (DWORD type_id, const u8 *p, DumpState &state) |
static Status | udt_get_child_type (const wchar_t *child_name, ULONG numChildren, const DWORD *children, const DumpState &state, DWORD *el_type_id, size_t *el_size) |
static Status | udt_dump_std (const wchar_t *type_name, const u8 *p, size_t size, DumpState &state, ULONG numChildren, const DWORD *children) |
static bool | udt_should_suppress (const wchar_t *type_name) |
static Status | udt_dump_suppressed (const wchar_t *type_name, const u8 *p, size_t size, DumpState state, ULONG numChildren, const DWORD *children) |
static bool | udt_fits_on_one_line (const wchar_t *type_name, size_t child_count, size_t total_size) |
static Status | udt_dump_normal (const wchar_t *type_name, const u8 *p, size_t size, DumpState state, ULONG numChildren, const DWORD *children) |
static Status | dump_sym_udt (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_vtable (DWORD type_id, const u8 *p, DumpState &state) |
static Status | dump_sym_unknown (DWORD type_id, const u8 *p, DumpState &state) |
static DumpFunc | DumpFuncFromTypeTag (DWORD typeTag) |
static bool | ShouldSkipSymbol (const wchar_t *name) |
static BOOL CALLBACK | dump_sym_cb (SYMBOL_INFOW *sym, ULONG size, PVOID userContext) |
static Status | dump_frame_cb (const STACKFRAME64 *sf, uintptr_t userContext) |
Status | debug_DumpStack (wchar_t *buf, size_t maxChars, void *pcontext, const wchar_t *lastFuncToSkip) |
write a complete stack trace (including values of local variables) into the specified buffer. More... | |
void | wdbg_sym_WriteMinidump (EXCEPTION_POINTERS *exception_pointers) |
Variables | |
static HANDLE | hProcess |
static WORD | machine |
static const size_t | maxIndirection = 255 |
static const size_t | maxLevel = 255 |
static size_t | out_chars_left |
static wchar_t * | out_pos |
static bool | out_have_warned_of_overflow |
static wchar_t * | out_latched_pos |
static bool | out_have_warned_of_limit |
static const size_t | maxVisited = 1000 |
static const u8 * | visited [maxVisited] |
static size_t | numVisited |
#define SUPPRESS_HANDLE | ( | name | ) | if(!wcscmp(type_name, L#name L"__")) return true; |
enum CV_HREG_e |
|
static |
|
static |
|
static |
|
static |
Status debug_CaptureContext | ( | void * | context | ) |
context | must point to an instance of the platform-specific type (e.g. CONTEXT) or CACHE_ALIGNED storage of DEBUG_CONTEXT_SIZE bytes. |
Status debug_DumpStack | ( | wchar_t * | buf, |
size_t | maxChars, | ||
void * | context, | ||
const wchar_t * | lastFuncToSkip | ||
) |
write a complete stack trace (including values of local variables) into the specified buffer.
buf | Target buffer. |
maxChars | Max chars of buffer (should be several thousand). |
context | Platform-specific representation of execution state (e.g. Win32 CONTEXT). either specify an SEH exception's context record or use debug_CaptureContext to retrieve the current state. Rationale: intermediates such as debug_DisplayError change the context, so it should be captured as soon as possible. |
lastFuncToSkip | Is used for omitting error-reporting functions like debug_OnAssertionFailure from the stack trace. It is either 0 (skip nothing) or a substring of a function's name (this allows platform-independent matching of stdcall-decorated names). Rationale: this is safer than specifying a fixed number of frames, which can be incorrect due to inlining. |
void * debug_GetCaller | ( | void * | context, |
const wchar_t * | lastFuncToSkip | ||
) |
return the caller of a certain function on the call stack.
this function is useful for recording (partial) stack traces for memory allocation tracking, etc.
context,lastFuncToSkip | - see debug_DumpStack |
Status debug_ResolveSymbol | ( | void * | ptr_of_interest, |
wchar_t * | sym_name, | ||
wchar_t * | file, | ||
int * | line | ||
) |
read and return symbol information for the given address.
NOTE: the PDB implementation is rather slow (~500 us).
ptr_of_interest | address of symbol (e.g. function, variable) |
sym_name | optional out; holds at least DEBUG_SYMBOL_CHARS; receives symbol name returned via debug info. |
file | optional out; holds at least DEBUG_FILE_CHARS; receives base name only (no path; see rationale in wdbg_sym) of source file containing the symbol. |
line | optional out; receives source file line number of symbol. |
note: all of the output parameters are optional; we pass back as much information as is available and desired.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Status wdbg_sym_WalkStack | ( | StackFrameCallback | cb, |
uintptr_t | cbData, | ||
CONTEXT & | context, | ||
const wchar_t * | lastFuncToSkip = 0 |
||
) |
Iterate over a call stack, invoking a callback for each frame encountered.
cb | |
cbData | |
context | Processor context from which to start (taken from an exception record or debug_CaptureContext). |
lastFuncToSkip |
void wdbg_sym_WriteMinidump | ( | EXCEPTION_POINTERS * | exception_pointers | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |