2006-04-11 16:59:08 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* =========================================================================
|
|
|
|
|
|
* File : wdbg_sym.cpp
|
|
|
|
|
|
* Project : 0 A.D.
|
|
|
|
|
|
* Description : Win32 stack trace and symbol engine.
|
|
|
|
|
|
* =========================================================================
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
|
// license: GPL; see lib/license.txt
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
2007-05-21 16:24:56 -07:00
|
|
|
|
#include "wdbg_sym.h"
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <stdio.h>
|
2006-04-18 22:30:02 -07:00
|
|
|
|
#include <set>
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2007-05-09 14:01:11 -07:00
|
|
|
|
#include "lib/byte_order.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
|
#include "lib/sysdep/cpu.h"
|
2007-01-01 13:25:47 -08:00
|
|
|
|
|
2006-06-01 19:10:27 -07:00
|
|
|
|
#include "lib/debug_stl.h"
|
|
|
|
|
|
#include "lib/app_hooks.h"
|
2008-01-07 12:03:19 -08:00
|
|
|
|
#include "lib/os_path.h"
|
2006-04-22 09:26:16 -07:00
|
|
|
|
#include "lib/path_util.h"
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#if ARCH_IA32
|
2008-06-30 10:34:18 -07:00
|
|
|
|
# include "lib/sysdep/arch/ia32/ia32.h"
|
|
|
|
|
|
# include "lib/sysdep/arch/ia32/ia32_asm.h"
|
2005-10-23 17:06:08 -07:00
|
|
|
|
#endif
|
2008-04-19 11:10:00 -07:00
|
|
|
|
#include "lib/external_libraries/dbghelp.h"
|
|
|
|
|
|
#include "winit.h"
|
2007-05-04 10:30:32 -07:00
|
|
|
|
#include "wutil.h"
|
2007-01-01 13:25:47 -08:00
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2008-04-19 11:10:00 -07:00
|
|
|
|
WINIT_REGISTER_CRITICAL_INIT(wdbg_sym_Init);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
// dbghelp
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// passed to all dbghelp symbol query functions. we're not interested in
|
|
|
|
|
|
// resolving symbols in other processes; the purpose here is only to
|
|
|
|
|
|
// generate a stack trace. if that changes, we need to init a local copy
|
|
|
|
|
|
// of these in dump_sym_cb and pass them to all subsequent dump_*.
|
|
|
|
|
|
static HANDLE hProcess;
|
2008-05-01 08:41:42 -07:00
|
|
|
|
static uintptr_t mod_base;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// for StackWalk64; taken from PE header by wdbg_init.
|
|
|
|
|
|
static WORD machine;
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// call on-demand (allows handling exceptions raised before winit.cpp
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// init functions are called); no effect if already initialized.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError sym_init()
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
// bail if already initialized (there's nothing to do).
|
2005-10-11 21:22:44 -07:00
|
|
|
|
// don't use pthread_once because we need to return success/error code.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
static uintptr_t already_initialized = 0;
|
2007-09-23 08:36:29 -07:00
|
|
|
|
if(!cpu_CAS(&already_initialized, 0, 1))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
hProcess = GetCurrentProcess();
|
|
|
|
|
|
|
2005-09-27 08:20:56 -07:00
|
|
|
|
// set options
|
|
|
|
|
|
// notes:
|
|
|
|
|
|
// - can be done before SymInitialize; we do so in case
|
|
|
|
|
|
// any of the options affect it.
|
|
|
|
|
|
// - do not set directly - that would zero any existing flags.
|
|
|
|
|
|
DWORD opts = SymGetOptions();
|
|
|
|
|
|
opts |= SYMOPT_DEFERRED_LOADS; // the "fastest, most efficient way"
|
|
|
|
|
|
//opts |= SYMOPT_DEBUG; // lots of debug spew in output window
|
2008-02-25 13:19:52 -08:00
|
|
|
|
opts |= SYMOPT_UNDNAME;
|
2005-09-27 08:20:56 -07:00
|
|
|
|
SymSetOptions(opts);
|
|
|
|
|
|
|
|
|
|
|
|
// initialize dbghelp.
|
|
|
|
|
|
// .. request symbols from all currently active modules be loaded.
|
|
|
|
|
|
const BOOL fInvadeProcess = TRUE;
|
|
|
|
|
|
// .. use default *symbol* search path. we don't use this to locate
|
|
|
|
|
|
// our PDB file because its absolute path is stored inside the EXE.
|
2005-12-06 19:38:39 -08:00
|
|
|
|
PCSTR UserSearchPath = 0;
|
2005-09-27 08:20:56 -07:00
|
|
|
|
BOOL ok = SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
|
|
|
|
|
|
WARN_IF_FALSE(ok);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
mod_base = SymGetModuleBase64(hProcess, (u64)&sym_init);
|
2008-05-01 08:41:42 -07:00
|
|
|
|
IMAGE_NT_HEADERS* header = ImageNtHeader((void*)(uintptr_t)mod_base);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
machine = header->FileHeader.Machine;
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
struct SYMBOL_INFO_PACKAGEW2 : public SYMBOL_INFO_PACKAGEW
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-22 16:41:43 -07:00
|
|
|
|
SYMBOL_INFO_PACKAGEW2()
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
si.SizeOfStruct = sizeof(si);
|
|
|
|
|
|
si.MaxNameLen = MAX_SYM_NAME;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
// note: we can't derive from TI_FINDCHILDREN_PARAMS because its members
|
|
|
|
|
|
// aren't guaranteed to precede ours (although they do in practice).
|
|
|
|
|
|
struct TI_FINDCHILDREN_PARAMS2
|
|
|
|
|
|
{
|
|
|
|
|
|
TI_FINDCHILDREN_PARAMS2(DWORD num_children)
|
|
|
|
|
|
{
|
|
|
|
|
|
p.Start = 0;
|
2007-05-09 14:01:11 -07:00
|
|
|
|
p.Count = std::min(num_children, MAX_CHILDREN);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-05-09 14:01:11 -07:00
|
|
|
|
static const DWORD MAX_CHILDREN = 400;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
TI_FINDCHILDREN_PARAMS p;
|
|
|
|
|
|
DWORD additional_children[MAX_CHILDREN-1];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-06 18:22:23 -07:00
|
|
|
|
// actual implementation; made available so that functions already under
|
|
|
|
|
|
// the lock don't have to unlock (slow) to avoid recursive locking.
|
|
|
|
|
|
static LibError debug_resolve_symbol_lk(void* ptr_of_interest, char* sym_name, char* file, int* line)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
sym_init();
|
|
|
|
|
|
|
|
|
|
|
|
const DWORD64 addr = (DWORD64)ptr_of_interest;
|
|
|
|
|
|
int successes = 0;
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// get symbol name (if requested)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(sym_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
sym_name[0] = '\0';
|
2005-10-29 15:29:55 -07:00
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
SYMBOL_INFO_PACKAGEW2 sp;
|
|
|
|
|
|
SYMBOL_INFOW* sym = &sp.si;
|
|
|
|
|
|
if(SymFromAddrW(hProcess, addr, 0, sym))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
wsprintfA(sym_name, "%ws", sym->Name);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
successes++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// get source file and/or line number (if requested)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(file || line)
|
|
|
|
|
|
{
|
2005-10-29 15:29:55 -07:00
|
|
|
|
file[0] = '\0';
|
|
|
|
|
|
*line = 0;
|
|
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
IMAGEHLP_LINE64 line_info = { sizeof(IMAGEHLP_LINE64) };
|
|
|
|
|
|
DWORD displacement; // unused but required by SymGetLineFromAddr64!
|
|
|
|
|
|
if(SymGetLineFromAddr64(hProcess, addr, &displacement, &line_info))
|
2005-07-09 13:17:58 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(file)
|
|
|
|
|
|
{
|
|
|
|
|
|
// strip full path down to base name only.
|
|
|
|
|
|
// this loses information, but that isn't expected to be a
|
|
|
|
|
|
// problem and is balanced by not having to do this from every
|
|
|
|
|
|
// call site (full path is too long to display nicely).
|
2006-04-22 09:26:16 -07:00
|
|
|
|
const char* base_name = path_name_only(line_info.FileName);
|
2008-02-25 13:19:52 -08:00
|
|
|
|
wsprintf(file, "%s", base_name);
|
2005-07-09 13:17:58 -07:00
|
|
|
|
successes++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(line)
|
|
|
|
|
|
{
|
|
|
|
|
|
*line = line_info.LineNumber;
|
|
|
|
|
|
successes++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return (successes != 0)? INFO::OK : ERR::FAIL;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-07-06 18:22:23 -07:00
|
|
|
|
// read and return symbol information for the given address. all of the
|
|
|
|
|
|
// output parameters are optional; we pass back as much information as is
|
|
|
|
|
|
// available and desired. return 0 iff any information was successfully
|
|
|
|
|
|
// retrieved and stored.
|
|
|
|
|
|
// sym_name and file must hold at least the number of chars above;
|
|
|
|
|
|
// file is the base name only, not path (see rationale in wdbg_sym).
|
|
|
|
|
|
// the PDB implementation is rather slow (~500<30>s).
|
|
|
|
|
|
LibError debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file, int* line)
|
|
|
|
|
|
{
|
2008-01-19 03:33:11 -08:00
|
|
|
|
WinScopedLock lock(WDBG_SYM_CS);
|
|
|
|
|
|
return debug_resolve_symbol_lk(ptr_of_interest, sym_name, file, line);
|
2006-07-06 18:22:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2005-10-28 19:32:36 -07:00
|
|
|
|
// stack walk
|
2005-06-21 09:39:40 -07:00
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
2005-10-28 19:32:36 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Subroutine linkage example code:
|
|
|
|
|
|
|
|
|
|
|
|
push param2
|
|
|
|
|
|
push param1
|
|
|
|
|
|
call func
|
|
|
|
|
|
ret_addr:
|
|
|
|
|
|
[..]
|
|
|
|
|
|
|
|
|
|
|
|
func:
|
|
|
|
|
|
push ebp
|
|
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
sub esp, local_size
|
|
|
|
|
|
[..]
|
|
|
|
|
|
|
|
|
|
|
|
Stack contents (down = decreasing address)
|
|
|
|
|
|
[param2]
|
|
|
|
|
|
[param1]
|
|
|
|
|
|
ret_addr
|
|
|
|
|
|
prev_ebp (<- current ebp points at this value)
|
|
|
|
|
|
[local_variables]
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
call func1
|
|
|
|
|
|
ret1:
|
|
|
|
|
|
|
|
|
|
|
|
func1:
|
|
|
|
|
|
push ebp
|
|
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
call func2
|
|
|
|
|
|
ret2:
|
|
|
|
|
|
|
|
|
|
|
|
func2:
|
|
|
|
|
|
push ebp
|
|
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
STARTHERE
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#if ARCH_IA32 && !CONFIG_OMIT_FP
|
2005-10-29 15:29:55 -07:00
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
static LibError ia32_walk_stack(_tagSTACKFRAME64* sf)
|
2005-10-28 19:32:36 -07:00
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// read previous values from _tagSTACKFRAME64
|
2008-05-01 08:41:42 -07:00
|
|
|
|
void* prev_fp = (void*)(uintptr_t)sf->AddrFrame .Offset;
|
|
|
|
|
|
void* prev_ip = (void*)(uintptr_t)sf->AddrPC .Offset;
|
|
|
|
|
|
void* prev_ret = (void*)(uintptr_t)sf->AddrReturn.Offset;
|
2005-10-28 19:32:36 -07:00
|
|
|
|
if(!debug_is_stack_ptr(prev_fp))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::_11);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
if(prev_ip && !debug_is_code_ptr(prev_ip))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::_12);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
if(prev_ret && !debug_is_code_ptr(prev_ret))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::_13);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
|
|
|
|
|
|
// read stack frame
|
|
|
|
|
|
void* fp = ((void**)prev_fp)[0];
|
|
|
|
|
|
void* ret_addr = ((void**)prev_fp)[1];
|
2006-05-17 07:48:18 -07:00
|
|
|
|
if(!fp)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::ALL_COMPLETE;
|
2005-10-28 19:32:36 -07:00
|
|
|
|
if(!debug_is_stack_ptr(fp))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::_14);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
if(!debug_is_code_ptr(ret_addr))
|
2008-03-29 11:29:26 -07:00
|
|
|
|
return ERR::FAIL; // NOWARN (invalid address)
|
2005-10-28 19:32:36 -07:00
|
|
|
|
|
|
|
|
|
|
void* target;
|
2007-05-02 05:07:08 -07:00
|
|
|
|
LibError err = ia32_GetCallTarget(ret_addr, &target);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
RETURN_ERR(err);
|
2005-12-11 14:23:55 -08:00
|
|
|
|
if(target) // were able to determine it from the call instruction
|
2008-02-25 13:19:52 -08:00
|
|
|
|
{
|
|
|
|
|
|
if(!debug_is_code_ptr(target))
|
|
|
|
|
|
return ERR::FAIL; // NOWARN (invalid address)
|
|
|
|
|
|
}
|
2005-10-28 19:32:36 -07:00
|
|
|
|
|
|
|
|
|
|
sf->AddrFrame .Offset = (DWORD64)fp;
|
|
|
|
|
|
sf->AddrPC .Offset = (DWORD64)target;
|
|
|
|
|
|
sf->AddrReturn.Offset = (DWORD64)ret_addr;
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-10-28 19:32:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#endif // #if ARCH_IA32 && !CONFIG_OMIT_FP
|
2005-10-28 19:32:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
static void skip_this_frame(size_t& skip, void* context)
|
2006-07-06 18:22:23 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(!context)
|
|
|
|
|
|
skip++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-04-19 11:10:00 -07:00
|
|
|
|
|
|
|
|
|
|
typedef VOID (*PRtlCaptureContext)(PCONTEXT);
|
|
|
|
|
|
static PRtlCaptureContext s_RtlCaptureContext;
|
|
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
LibError wdbg_sym_WalkStack(StackFrameCallback cb, uintptr_t cbData, size_t skip, const CONTEXT* pcontext)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-10-23 17:06:08 -07:00
|
|
|
|
// to function properly, StackWalk64 requires a CONTEXT on
|
|
|
|
|
|
// non-x86 systems (documented) or when in release mode (observed).
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// exception handlers can call wdbg_sym_WalkStack with their context record;
|
2005-10-23 17:06:08 -07:00
|
|
|
|
// otherwise (e.g. dump_stack from debug_assert), we need to query it.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
CONTEXT context;
|
|
|
|
|
|
// .. caller knows the context (most likely from an exception);
|
|
|
|
|
|
// since StackWalk64 may modify it, copy to a local variable.
|
|
|
|
|
|
if(pcontext)
|
|
|
|
|
|
context = *pcontext;
|
|
|
|
|
|
// .. need to determine context ourselves.
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2006-07-06 18:22:23 -07:00
|
|
|
|
skip_this_frame(skip, (void*)pcontext);
|
2005-10-23 17:06:08 -07:00
|
|
|
|
|
|
|
|
|
|
// there are 4 ways to do so, in order of preference:
|
|
|
|
|
|
// - asm (easy to use but currently only implemented on IA32)
|
|
|
|
|
|
// - RtlCaptureContext (only available on WinXP or above)
|
|
|
|
|
|
// - intentionally raise an SEH exception and capture its context
|
|
|
|
|
|
// (spams us with "first chance exception")
|
|
|
|
|
|
// - GetThreadContext while suspended* (a bit tricky + slow).
|
|
|
|
|
|
//
|
|
|
|
|
|
// * it used to be common practice to query the current thread's context,
|
|
|
|
|
|
// but WinXP SP2 and above require it be suspended.
|
|
|
|
|
|
//
|
|
|
|
|
|
// this MUST be done inline and not in an external function because
|
|
|
|
|
|
// compiler-generated prolog code trashes some registers.
|
|
|
|
|
|
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#if ARCH_IA32
|
2007-05-02 05:07:08 -07:00
|
|
|
|
ia32_asm_GetCurrentContext(&context);
|
2005-10-23 17:06:08 -07:00
|
|
|
|
#else
|
2008-04-19 11:10:00 -07:00
|
|
|
|
// we no longer bother supporting stack walks on pre-WinXP systems
|
|
|
|
|
|
// that lack RtlCaptureContext. at least importing dynamically does
|
|
|
|
|
|
// allow the application to run on such systems.
|
|
|
|
|
|
// (note: the RaiseException method is annoying due to output in
|
|
|
|
|
|
// the debugger window and interaction with WinScopedLock's dtor)
|
|
|
|
|
|
if(!s_RtlCaptureContext)
|
|
|
|
|
|
return ERR::SYM_UNSUPPORTED; // NOWARN
|
|
|
|
|
|
s_RtlCaptureContext(&context);
|
2005-10-23 17:06:08 -07:00
|
|
|
|
#endif
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
pcontext = &context;
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
_tagSTACKFRAME64 sf;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
memset(&sf, 0, sizeof(sf));
|
|
|
|
|
|
sf.AddrPC.Mode = AddrModeFlat;
|
|
|
|
|
|
sf.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
|
|
sf.AddrStack.Mode = AddrModeFlat;
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#if ARCH_AMD64
|
2007-09-23 08:36:29 -07:00
|
|
|
|
sf.AddrPC.Offset = pcontext->Rip;
|
|
|
|
|
|
sf.AddrFrame.Offset = pcontext->Rbp;
|
|
|
|
|
|
sf.AddrStack.Offset = pcontext->Rsp;
|
|
|
|
|
|
#else
|
|
|
|
|
|
sf.AddrPC.Offset = pcontext->Eip;
|
|
|
|
|
|
sf.AddrFrame.Offset = pcontext->Ebp;
|
|
|
|
|
|
sf.AddrStack.Offset = pcontext->Esp;
|
|
|
|
|
|
#endif
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// for each stack frame found:
|
2006-09-22 06:19:40 -07:00
|
|
|
|
LibError ret = ERR::SYM_NO_STACK_FRAMES_FOUND;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
for(;;)
|
|
|
|
|
|
{
|
2005-10-28 19:32:36 -07:00
|
|
|
|
// rationale:
|
|
|
|
|
|
// - provide a separate ia32 implementation so that simple
|
|
|
|
|
|
// stack walks (e.g. to determine callers of malloc) do not
|
|
|
|
|
|
// require firing up dbghelp. that takes tens of seconds when
|
|
|
|
|
|
// OS symbols are installed (because symserv is wanting to access
|
|
|
|
|
|
// inet), which is entirely unacceptable.
|
|
|
|
|
|
// - VC7.1 sometimes generates stack frames despite /Oy ;
|
|
|
|
|
|
// ia32_walk_stack may appear to work, but it isn't reliable in
|
|
|
|
|
|
// this case and therefore must not be used!
|
|
|
|
|
|
// - don't switch between ia32_stack_walk and StackWalk64 when one
|
|
|
|
|
|
// of them fails: this needlessly complicates things. the ia32
|
|
|
|
|
|
// code is authoritative provided its prerequisite (FP not omitted)
|
|
|
|
|
|
// is met, otherwise totally unusable.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError err;
|
2007-12-20 12:09:19 -08:00
|
|
|
|
#if ARCH_IA32 && !CONFIG_OMIT_FP
|
2005-10-28 19:32:36 -07:00
|
|
|
|
err = ia32_walk_stack(&sf);
|
|
|
|
|
|
#else
|
2008-02-25 13:19:52 -08:00
|
|
|
|
WinScopedLock lock(WDBG_SYM_CS);
|
2005-10-28 19:32:36 -07:00
|
|
|
|
sym_init();
|
|
|
|
|
|
// note: unfortunately StackWalk64 doesn't always SetLastError,
|
|
|
|
|
|
// so we have to reset it and check for 0. *sigh*
|
|
|
|
|
|
SetLastError(0);
|
2005-10-30 17:15:49 -08:00
|
|
|
|
const HANDLE hThread = GetCurrentThread();
|
2007-12-20 12:09:19 -08:00
|
|
|
|
BOOL ok = StackWalk64(machine, hProcess, hThread, &sf, (PVOID)pcontext, 0, SymFunctionTableAccess64, SymGetModuleBase64, 0);
|
2006-04-02 18:00:45 -07:00
|
|
|
|
// note: don't use LibError_from_win32 because it raises a warning,
|
|
|
|
|
|
// and this "fails" commonly (when no stack frames are left).
|
2006-09-22 06:19:40 -07:00
|
|
|
|
err = ok? INFO::OK : ERR::FAIL;
|
2005-10-28 19:32:36 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// no more frames found - abort. note: also test FP because
|
|
|
|
|
|
// StackWalk64 sometimes erroneously reports success.
|
2006-07-06 18:22:23 -07:00
|
|
|
|
void* fp = (void*)(uintptr_t)sf.AddrFrame.Offset;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err != INFO::OK || !fp)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
return ret;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
if(skip)
|
|
|
|
|
|
{
|
|
|
|
|
|
skip--;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
ret = cb(&sf, cbData);
|
2006-07-06 18:22:23 -07:00
|
|
|
|
// callback is allowing us to continue
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret == INFO::CB_CONTINUE)
|
2008-02-25 13:19:52 -08:00
|
|
|
|
ret = INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// callback reports it's done; stop calling it and return that value.
|
2006-04-23 22:20:14 -07:00
|
|
|
|
// (can be either success or failure)
|
2006-07-06 18:22:23 -07:00
|
|
|
|
else
|
2005-12-11 14:23:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
debug_assert(ret <= 0); // shouldn't return > 0
|
2005-06-21 09:39:40 -07:00
|
|
|
|
return ret;
|
2005-12-11 14:23:55 -08:00
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// get address of Nth function above us on the call stack (uses wdbg_sym_WalkStack)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
//
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// called by wdbg_sym_WalkStack for each stack frame
|
|
|
|
|
|
static LibError nth_caller_cb(const _tagSTACKFRAME64* sf, uintptr_t cbData)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
void** pfunc = (void**)cbData;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// return its address
|
2008-05-01 08:41:42 -07:00
|
|
|
|
*pfunc = (void*)(uintptr_t)sf->AddrPC.Offset;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
void* debug_get_nth_caller(size_t skip, void* pcontext)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-07-09 13:17:58 -07:00
|
|
|
|
void* func;
|
2006-07-06 18:22:23 -07:00
|
|
|
|
skip_this_frame(skip, pcontext);
|
2008-02-25 13:19:52 -08:00
|
|
|
|
LibError ret = wdbg_sym_WalkStack(nth_caller_cb, (uintptr_t)&func, skip, (const CONTEXT*)pcontext);
|
2008-01-19 03:33:11 -08:00
|
|
|
|
return (ret == INFO::OK)? func : 0;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
|
2008-01-19 03:33:11 -08:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// helper routines for symbol value dump
|
2008-01-19 03:33:11 -08:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-27 21:12:50 -07:00
|
|
|
|
// overflow is impossible in practice, but check for robustness.
|
|
|
|
|
|
// keep in sync with DumpState.
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
static const size_t MAX_INDIRECTION = 255;
|
|
|
|
|
|
static const size_t MAX_LEVEL = 255;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
struct DumpState
|
|
|
|
|
|
{
|
|
|
|
|
|
// keep in sync with MAX_* above
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
size_t level : 8;
|
|
|
|
|
|
size_t indirection : 8;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
DumpState()
|
|
|
|
|
|
{
|
|
|
|
|
|
level = 0;
|
|
|
|
|
|
indirection = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
//----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
static size_t out_chars_left;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
static bool out_have_warned_of_overflow;
|
|
|
|
|
|
// only do so once until next out_init to avoid flood of messages.
|
2005-07-04 10:09:28 -07:00
|
|
|
|
static wchar_t* out_pos;
|
|
|
|
|
|
|
|
|
|
|
|
// some top-level (*) symbols cause tons of output - so much that they may
|
|
|
|
|
|
// single-handedly overflow the buffer (e.g. pointer to a tree of huge UDTs).
|
|
|
|
|
|
// we can't have that, so there is a limit in place as to how much a
|
|
|
|
|
|
// single top-level symbol can output. after that is reached, dumping is
|
|
|
|
|
|
// aborted for that symbol but continues for the subsequent top-level symbols.
|
|
|
|
|
|
//
|
|
|
|
|
|
// this is implemented as follows: dump_sym_cb latches the current output
|
|
|
|
|
|
// position; each dump_sym (through which all symbols go) checks if the
|
|
|
|
|
|
// new position exceeds the limit and aborts if so.
|
|
|
|
|
|
// slight wrinkle: since we don't want each level of UDTs to successively
|
|
|
|
|
|
// realize the limit has been hit and display the error message, we
|
2006-09-22 06:19:40 -07:00
|
|
|
|
// return ERR::SYM_SINGLE_SYMBOL_LIMIT once and thereafter INFO::SYM_SUPPRESS_OUTPUT.
|
2005-07-04 10:09:28 -07:00
|
|
|
|
//
|
|
|
|
|
|
// * example: local variables, as opposed to child symbols in a UDT.
|
|
|
|
|
|
static wchar_t* out_latched_pos;
|
|
|
|
|
|
static bool out_have_warned_of_limit;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
static void out_init(wchar_t* buf, size_t max_chars)
|
|
|
|
|
|
{
|
|
|
|
|
|
out_pos = buf;
|
2005-07-09 13:17:58 -07:00
|
|
|
|
out_chars_left = max_chars;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
out_have_warned_of_overflow = false;
|
2005-07-09 13:17:58 -07:00
|
|
|
|
out_have_warned_of_limit = false;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void out(const wchar_t* fmt, ...)
|
|
|
|
|
|
{
|
|
|
|
|
|
va_list args;
|
|
|
|
|
|
va_start(args, fmt);
|
2007-01-31 17:34:17 -08:00
|
|
|
|
int len = vswprintf(out_pos, out_chars_left, fmt, args);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// success
|
|
|
|
|
|
if(len >= 0)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-07-09 13:17:58 -07:00
|
|
|
|
out_pos += len;
|
|
|
|
|
|
// make sure out_chars_left remains nonnegative
|
|
|
|
|
|
if((size_t)len > out_chars_left)
|
|
|
|
|
|
{
|
2007-12-20 12:09:19 -08:00
|
|
|
|
debug_assert(0); // apparently wrote more than out_chars_left
|
2005-07-09 13:17:58 -07:00
|
|
|
|
len = (int)out_chars_left;
|
|
|
|
|
|
}
|
|
|
|
|
|
out_chars_left -= len;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// no more room left
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// the buffer really is full yet out_chars_left may not be 0
|
2007-01-31 17:34:17 -08:00
|
|
|
|
// (since it isn't updated if vswprintf returns -1).
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// must be set so subsequent calls don't try to squeeze stuff in.
|
|
|
|
|
|
out_chars_left = 0;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// write a warning into the output buffer (once) so it isn't
|
|
|
|
|
|
// abruptly cut off (which looks like an error)
|
|
|
|
|
|
if(!out_have_warned_of_overflow)
|
|
|
|
|
|
{
|
|
|
|
|
|
out_have_warned_of_overflow = true;
|
|
|
|
|
|
|
|
|
|
|
|
// with the current out_pos / out_chars_left variables, there's
|
|
|
|
|
|
// no way of knowing where the buffer actually ends. no matter;
|
|
|
|
|
|
// we'll just put the warning before out_pos and eat into the
|
|
|
|
|
|
// second newest text.
|
|
|
|
|
|
const wchar_t text[] = L"(no more room in buffer)";
|
|
|
|
|
|
wcscpy(out_pos-ARRAY_SIZE(text), text); // safe
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void out_erase(size_t num_chars)
|
|
|
|
|
|
{
|
2005-07-09 13:17:58 -07:00
|
|
|
|
// don't do anything if end of buffer was hit (prevents repeatedly
|
|
|
|
|
|
// scribbling over the last few bytes).
|
|
|
|
|
|
if(out_have_warned_of_overflow)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out_chars_left += (ssize_t)num_chars;
|
|
|
|
|
|
out_pos -= num_chars;
|
|
|
|
|
|
*out_pos = '\0';
|
|
|
|
|
|
// make sure it's 0-terminated in case there is no further output.
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-04 10:09:28 -07:00
|
|
|
|
// (see above)
|
|
|
|
|
|
static void out_latch_pos()
|
|
|
|
|
|
{
|
|
|
|
|
|
out_have_warned_of_limit = false;
|
|
|
|
|
|
out_latched_pos = out_pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (see above)
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError out_check_limit()
|
2005-07-04 10:09:28 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(out_have_warned_of_limit)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::SYM_SUPPRESS_OUTPUT;
|
2005-07-04 10:09:28 -07:00
|
|
|
|
if(out_pos - out_latched_pos > 3000) // ~30 lines
|
|
|
|
|
|
{
|
|
|
|
|
|
out_have_warned_of_limit = true;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_SINGLE_SYMBOL_LIMIT; // NOWARN
|
2005-07-04 10:09:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// no limit hit, proceed normally
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-07-04 10:09:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
//----------------------------------------------------------------------------
|
2005-07-04 10:09:28 -07:00
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
#define INDENT STMT(for(size_t i = 0; i <= state.level; i++) out(L" ");)
|
2005-06-26 17:28:50 -07:00
|
|
|
|
#define UNINDENT STMT(out_erase((state.level+1)*4);)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// does it look like an ASCII string is located at <addr>?
|
|
|
|
|
|
// set <stride> to 2 to search for WCS-2 strings (of western characters!).
|
|
|
|
|
|
// called by dump_sequence for its string special-case.
|
|
|
|
|
|
//
|
|
|
|
|
|
// algorithm: scan the "string" and count # text chars vs. garbage.
|
|
|
|
|
|
static bool is_string(const u8* p, size_t stride)
|
|
|
|
|
|
{
|
|
|
|
|
|
// note: access violations are caught by dump_sym; output is "?".
|
|
|
|
|
|
int score = 0;
|
|
|
|
|
|
for(;;)
|
|
|
|
|
|
{
|
|
|
|
|
|
// current character is:
|
|
|
|
|
|
const int c = *p & 0xff; // prevent sign extension
|
|
|
|
|
|
p += stride;
|
|
|
|
|
|
// .. text
|
|
|
|
|
|
if(isalnum(c))
|
|
|
|
|
|
score += 5;
|
|
|
|
|
|
// .. end of string
|
|
|
|
|
|
else if(!c)
|
|
|
|
|
|
break;
|
|
|
|
|
|
// .. garbage
|
|
|
|
|
|
else if(!isprint(c))
|
|
|
|
|
|
score -= 4;
|
|
|
|
|
|
|
|
|
|
|
|
// got enough information either way => done.
|
|
|
|
|
|
// (we don't want to unnecessarily scan huge binary arrays)
|
|
|
|
|
|
if(abs(score) >= 10)
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (score > 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// forward decl; called by dump_sequence and some of dump_sym_*.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym(DWORD id, const u8* p, DumpState state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// from cvconst.h
|
|
|
|
|
|
//
|
|
|
|
|
|
// rationale: we don't provide a get_register routine, since only the
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// value of FP is known to dump_frame_cb (via _tagSTACKFRAME64).
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// displaying variables stored in registers is out of the question;
|
|
|
|
|
|
// all we can do is display FP-relative variables.
|
|
|
|
|
|
enum CV_HREG_e
|
|
|
|
|
|
{
|
|
|
|
|
|
CV_REG_EAX = 17,
|
|
|
|
|
|
CV_REG_ECX = 18,
|
|
|
|
|
|
CV_REG_EDX = 19,
|
|
|
|
|
|
CV_REG_EBX = 20,
|
|
|
|
|
|
CV_REG_ESP = 21,
|
|
|
|
|
|
CV_REG_EBP = 22,
|
|
|
|
|
|
CV_REG_ESI = 23,
|
|
|
|
|
|
CV_REG_EDI = 24
|
|
|
|
|
|
};
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
static const wchar_t* string_for_register(CV_HREG_e reg)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
switch(reg)
|
|
|
|
|
|
{
|
|
|
|
|
|
case CV_REG_EAX:
|
|
|
|
|
|
return L"eax";
|
|
|
|
|
|
case CV_REG_ECX:
|
|
|
|
|
|
return L"ecx";
|
|
|
|
|
|
case CV_REG_EDX:
|
|
|
|
|
|
return L"edx";
|
|
|
|
|
|
case CV_REG_EBX:
|
|
|
|
|
|
return L"ebx";
|
|
|
|
|
|
case CV_REG_ESP:
|
|
|
|
|
|
return L"esp";
|
|
|
|
|
|
case CV_REG_EBP:
|
|
|
|
|
|
return L"ebp";
|
|
|
|
|
|
case CV_REG_ESI:
|
|
|
|
|
|
return L"esi";
|
|
|
|
|
|
case CV_REG_EDI:
|
|
|
|
|
|
return L"edi";
|
|
|
|
|
|
default:
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
static wchar_t buf[19];
|
|
|
|
|
|
swprintf(buf, ARRAY_SIZE(buf), L"0x%x", reg);
|
|
|
|
|
|
return buf;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static void dump_error(LibError err, const u8* p)
|
2005-06-26 17:28:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
switch(err)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
// no error => no output
|
|
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case ERR::SYM_SINGLE_SYMBOL_LIMIT:
|
2005-07-04 10:09:28 -07:00
|
|
|
|
out(L"(too much output; skipping to next top-level symbol)");
|
|
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case ERR::SYM_UNRETRIEVABLE_STATIC:
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out(L"(unavailable - located in another module)");
|
|
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case ERR::SYM_UNRETRIEVABLE_REG:
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out(L"(unavailable - stored in register %s)", string_for_register((CV_HREG_e)(uintptr_t)p));
|
|
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case ERR::SYM_TYPE_INFO_UNAVAILABLE:
|
2005-07-03 13:48:47 -07:00
|
|
|
|
out(L"(unavailable - type info request failed (GLE=%d))", GetLastError());
|
2005-06-26 17:28:50 -07:00
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case ERR::SYM_INTERNAL_ERROR:
|
2005-07-03 13:48:47 -07:00
|
|
|
|
out(L"(unavailable - internal error)\r\n");
|
2005-06-26 17:28:50 -07:00
|
|
|
|
break;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
case INFO::SYM_SUPPRESS_OUTPUT:
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// not an error; do not output anything. handled by caller.
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2005-07-03 13:48:47 -07:00
|
|
|
|
out(L"(unavailable - unspecified error 0x%X (%d))", err, err);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// split out of dump_sequence.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_string(const u8* p, size_t el_size)
|
2005-06-26 17:28:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
// not char or wchar_t string
|
|
|
|
|
|
if(el_size != sizeof(char) && el_size != sizeof(wchar_t))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CANNOT_HANDLE;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// not text
|
|
|
|
|
|
if(!is_string(p, el_size))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CANNOT_HANDLE;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
wchar_t buf[512];
|
|
|
|
|
|
if(el_size == sizeof(wchar_t))
|
|
|
|
|
|
wcscpy_s(buf, ARRAY_SIZE(buf), (const wchar_t*)p);
|
2005-12-11 14:23:55 -08:00
|
|
|
|
// convert to wchar_t
|
2005-06-26 17:28:50 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
for(i = 0; i < ARRAY_SIZE(buf)-1; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
buf[i] = (wchar_t)p[i];
|
|
|
|
|
|
if(buf[i] == '\0')
|
|
|
|
|
|
break;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
2005-06-26 17:28:50 -07:00
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out(L"\"%s\"", buf);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-03 15:36:24 -07:00
|
|
|
|
// split out of dump_sequence.
|
|
|
|
|
|
static void seq_determine_formatting(size_t el_size, size_t el_count,
|
|
|
|
|
|
bool* fits_on_one_line, size_t* num_elements_to_show)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(el_size == sizeof(char))
|
|
|
|
|
|
{
|
|
|
|
|
|
*fits_on_one_line = el_count <= 16;
|
2008-04-19 11:10:00 -07:00
|
|
|
|
*num_elements_to_show = std::min((size_t)16u, el_count);
|
2005-07-03 15:36:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if(el_size <= sizeof(int))
|
|
|
|
|
|
{
|
|
|
|
|
|
*fits_on_one_line = el_count <= 8;
|
2008-04-19 11:10:00 -07:00
|
|
|
|
*num_elements_to_show = std::min((size_t)12u, el_count);
|
2005-07-03 15:36:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
*fits_on_one_line = false;
|
2008-04-19 11:10:00 -07:00
|
|
|
|
*num_elements_to_show = std::min((size_t)8u, el_count);
|
2005-07-03 15:36:24 -07:00
|
|
|
|
}
|
2005-07-03 18:00:22 -07:00
|
|
|
|
|
|
|
|
|
|
// make sure empty containers are displayed with [0] {}, otherwise
|
|
|
|
|
|
// the lack of output looks like an error.
|
|
|
|
|
|
if(!el_count)
|
|
|
|
|
|
*fits_on_one_line = true;
|
2005-07-03 15:36:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-09 10:05:05 -07:00
|
|
|
|
static LibError dump_sequence(DebugStlIterator el_iterator, void* internal,
|
2005-06-26 17:28:50 -07:00
|
|
|
|
size_t el_count, DWORD el_type_id, size_t el_size, DumpState state)
|
|
|
|
|
|
{
|
2005-08-09 09:23:19 -07:00
|
|
|
|
const u8* el_p = 0; // avoid "uninitialized" warning
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
// special case: display as a string if the sequence looks to be text.
|
2005-07-03 13:48:47 -07:00
|
|
|
|
// do this only if container isn't empty because the otherwise the
|
|
|
|
|
|
// iterator may crash.
|
|
|
|
|
|
if(el_count)
|
|
|
|
|
|
{
|
|
|
|
|
|
el_p = el_iterator(internal, el_size);
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError ret = dump_string(el_p, el_size);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret == INFO::OK)
|
2005-07-03 13:48:47 -07:00
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-03 13:48:47 -07:00
|
|
|
|
// choose formatting based on element size and count
|
2005-06-27 21:12:50 -07:00
|
|
|
|
bool fits_on_one_line;
|
|
|
|
|
|
size_t num_elements_to_show;
|
2005-07-03 15:36:24 -07:00
|
|
|
|
seq_determine_formatting(el_size, el_count, &fits_on_one_line, &num_elements_to_show);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-03 15:36:24 -07:00
|
|
|
|
out(L"[%d] ", el_count);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
state.level++;
|
|
|
|
|
|
out(fits_on_one_line? L"{ " : L"\r\n");
|
|
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
for(size_t i = 0; i < num_elements_to_show; i++)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(!fits_on_one_line)
|
|
|
|
|
|
INDENT;
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError err = dump_sym(el_type_id, el_p, state);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
el_p = el_iterator(internal, el_size);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-04 10:09:28 -07:00
|
|
|
|
// there was no output for this child; undo its indentation (if any),
|
|
|
|
|
|
// skip everything below and proceed with the next child.
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == INFO::SYM_SUPPRESS_OUTPUT)
|
2005-06-26 17:28:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(!fits_on_one_line)
|
|
|
|
|
|
UNINDENT;
|
2005-07-04 10:09:28 -07:00
|
|
|
|
continue;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
}
|
2005-07-04 10:09:28 -07:00
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
dump_error(err, el_p); // nop if err == INFO::OK
|
2005-07-04 10:09:28 -07:00
|
|
|
|
// add separator unless this is the last element (can't just
|
|
|
|
|
|
// erase below due to additional "...").
|
|
|
|
|
|
if(i != num_elements_to_show-1)
|
|
|
|
|
|
out(fits_on_one_line? L", " : L"\r\n");
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == ERR::SYM_SINGLE_SYMBOL_LIMIT)
|
2005-07-04 10:09:28 -07:00
|
|
|
|
break;
|
|
|
|
|
|
} // for each child
|
|
|
|
|
|
|
|
|
|
|
|
// indicate some elements were skipped
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(el_count != num_elements_to_show)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L" ...");
|
|
|
|
|
|
|
2005-07-04 10:09:28 -07:00
|
|
|
|
state.level--;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(fits_on_one_line)
|
|
|
|
|
|
out(L" }");
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
static const u8* array_iterator(void* internal, size_t el_size)
|
|
|
|
|
|
{
|
|
|
|
|
|
const u8*& pos = *(const u8**)internal;
|
|
|
|
|
|
const u8* cur_pos = pos;
|
|
|
|
|
|
pos += el_size;
|
|
|
|
|
|
return cur_pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_array(const u8* p,
|
2005-06-25 00:47:33 -07:00
|
|
|
|
size_t el_count, DWORD el_type_id, size_t el_size, DumpState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
const u8* iterator_internal_pos = p;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
return dump_sequence(array_iterator, &iterator_internal_pos,
|
2005-06-25 00:47:33 -07:00
|
|
|
|
el_count, el_type_id, el_size, state);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
static const _tagSTACKFRAME64* current_stackframe64;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError determine_symbol_address(DWORD id, DWORD UNUSED(type_id), const u8** pp)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
const _tagSTACKFRAME64* sf = current_stackframe64;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
DWORD data_kind;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, id, TI_GET_DATAKIND, &data_kind))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
switch(data_kind)
|
|
|
|
|
|
{
|
|
|
|
|
|
// SymFromIndex will fail
|
|
|
|
|
|
case DataIsMember:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// pp is already correct (udt_dump_normal retrieved the offset;
|
|
|
|
|
|
// we do it that way so we can check it against the total
|
|
|
|
|
|
// UDT size for safety).
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// this symbol is defined as static in another module =>
|
|
|
|
|
|
// there's nothing we can do.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case DataIsStaticMember:
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_UNRETRIEVABLE_STATIC; // NOWARN
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// ok; will handle below
|
|
|
|
|
|
case DataIsLocal:
|
|
|
|
|
|
case DataIsStaticLocal:
|
|
|
|
|
|
case DataIsParam:
|
|
|
|
|
|
case DataIsObjectPtr:
|
|
|
|
|
|
case DataIsFileStatic:
|
|
|
|
|
|
case DataIsGlobal:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2007-12-20 12:09:19 -08:00
|
|
|
|
NODEFAULT;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// get SYMBOL_INFO (we need .Flags)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
SYMBOL_INFO_PACKAGEW2 sp;
|
|
|
|
|
|
SYMBOL_INFOW* sym = &sp.si;
|
|
|
|
|
|
if(!SymFromIndexW(hProcess, mod_base, id, sym))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
DWORD addrofs = 0;
|
|
|
|
|
|
ULONG64 addr2 = 0;
|
|
|
|
|
|
DWORD ofs2 = 0;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
SymGetTypeInfo(hProcess, mod_base, id, TI_GET_ADDRESSOFFSET, &addrofs);
|
|
|
|
|
|
SymGetTypeInfo(hProcess, mod_base, id, TI_GET_ADDRESS, &addr2);
|
|
|
|
|
|
SymGetTypeInfo(hProcess, mod_base, id, TI_GET_OFFSET, &ofs2);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get address
|
2008-05-01 08:41:42 -07:00
|
|
|
|
uintptr_t addr = sym->Address;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// .. relative to a register
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// note: we only have the FP (not SP)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(sym->Flags & SYMFLAG_REGREL)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sym->Register == CV_REG_EBP)
|
2005-06-25 00:47:33 -07:00
|
|
|
|
goto fp_rel;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
else
|
|
|
|
|
|
goto in_register;
|
|
|
|
|
|
}
|
|
|
|
|
|
// .. relative to FP (appears to be obsolete)
|
|
|
|
|
|
else if(sym->Flags & SYMFLAG_FRAMEREL)
|
2005-06-25 00:47:33 -07:00
|
|
|
|
{
|
|
|
|
|
|
fp_rel:
|
2005-06-21 09:39:40 -07:00
|
|
|
|
addr += sf->AddrFrame.Offset;
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// HACK: reg-relative symbols (params and locals, but not
|
|
|
|
|
|
// static) appear to be off by 4 bytes in release builds.
|
|
|
|
|
|
// no idea as to the cause, but this "fixes" it.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
#ifdef NDEBUG
|
2005-06-25 00:47:33 -07:00
|
|
|
|
addr += sizeof(void*);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
#endif
|
2005-06-25 00:47:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
// .. in register (this happens when optimization is enabled,
|
|
|
|
|
|
// but we can't do anything; see SymbolInfoRegister)
|
|
|
|
|
|
else if(sym->Flags & SYMFLAG_REGISTER)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-25 00:47:33 -07:00
|
|
|
|
in_register:
|
|
|
|
|
|
*pp = (const u8*)(uintptr_t)sym->Register;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_UNRETRIEVABLE_REG; // NOWARN
|
2005-06-25 00:47:33 -07:00
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2008-05-01 08:41:42 -07:00
|
|
|
|
*pp = (const u8*)(uintptr_t)addr;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-10-27 09:53:41 -07:00
|
|
|
|
debug_printf("SYM| %ws at %p flags=%X dk=%d sym->addr=%I64X addrofs=%X addr2=%I64X ofs2=%X\n", sym->Name, *pp, sym->Flags, data_kind, sym->Address, addrofs, addr2, ofs2);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// dump routines for each dbghelp symbol type
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// these functions return != 0 if they're not able to produce any
|
|
|
|
|
|
// reasonable output at all; the caller (dump_sym_data, dump_sequence, etc.)
|
|
|
|
|
|
// will display the appropriate error message via dump_error.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// called by dump_sym; lock is held.
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_array(DWORD type_id, const u8* p, DumpState state)
|
2005-06-25 00:47:33 -07:00
|
|
|
|
{
|
2005-06-21 09:39:40 -07:00
|
|
|
|
ULONG64 size_ = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_LENGTH, &size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
const size_t size = (size_t)size_;
|
|
|
|
|
|
|
|
|
|
|
|
// get element count and size
|
2005-06-25 00:47:33 -07:00
|
|
|
|
DWORD el_type_id = 0;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_TYPEID, &el_type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// .. workaround: TI_GET_COUNT returns total struct size for
|
|
|
|
|
|
// arrays-of-struct. therefore, calculate as size / el_size.
|
|
|
|
|
|
ULONG64 el_size_;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, el_type_id, TI_GET_LENGTH, &el_size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
const size_t el_size = (size_t)el_size_;
|
2005-06-27 21:12:50 -07:00
|
|
|
|
debug_assert(el_size != 0);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
const size_t num_elements = size/el_size;
|
2005-06-27 21:12:50 -07:00
|
|
|
|
debug_assert(num_elements != 0);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
|
|
|
|
|
|
return dump_array(p, num_elements, el_type_id, el_size, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_base_type(DWORD type_id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
DWORD base_type;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_BASETYPE, &base_type))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
ULONG64 size_ = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_LENGTH, &size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
const size_t size = (size_t)size_;
|
|
|
|
|
|
|
2005-08-09 09:23:19 -07:00
|
|
|
|
// single out() call. note: we pass a single u64 for all sizes,
|
|
|
|
|
|
// which will only work on little-endian systems.
|
|
|
|
|
|
// must be declared before goto to avoid W4 warning.
|
|
|
|
|
|
const wchar_t* fmt = L"";
|
|
|
|
|
|
|
2007-05-09 14:01:11 -07:00
|
|
|
|
u64 data = movzx_le64(p, size);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// if value is 0xCC..CC (uninitialized mem), we display as hex.
|
|
|
|
|
|
// the output would otherwise be garbage; this makes it obvious.
|
|
|
|
|
|
// note: be very careful to correctly handle size=0 (e.g. void*).
|
|
|
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(p[i] != 0xCC)
|
|
|
|
|
|
break;
|
|
|
|
|
|
if(i == size-1)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
goto display_as_hex;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(base_type)
|
|
|
|
|
|
{
|
|
|
|
|
|
// boolean
|
|
|
|
|
|
case btBool:
|
2005-06-27 21:12:50 -07:00
|
|
|
|
debug_assert(size == sizeof(bool));
|
2005-06-21 09:39:40 -07:00
|
|
|
|
fmt = L"%hs";
|
|
|
|
|
|
data = (u64)(data? "true " : "false");
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// floating-point
|
|
|
|
|
|
case btFloat:
|
2005-07-03 13:48:47 -07:00
|
|
|
|
// C calling convention casts float params to doubles, so printf
|
|
|
|
|
|
// expects one when we indicate %g. there are no width flags,
|
|
|
|
|
|
// so we have to manually convert the float data to double.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(size == sizeof(float))
|
2005-07-03 13:48:47 -07:00
|
|
|
|
*(double*)&data = (double)*(float*)&data;
|
|
|
|
|
|
else if(size != sizeof(double))
|
2007-12-20 12:09:19 -08:00
|
|
|
|
debug_assert(0); // invalid float size
|
2005-07-03 13:48:47 -07:00
|
|
|
|
fmt = L"%g";
|
2005-06-21 09:39:40 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// signed integers (displayed as decimal)
|
|
|
|
|
|
case btInt:
|
|
|
|
|
|
case btLong:
|
2005-07-03 18:00:22 -07:00
|
|
|
|
if(size != 1 && size != 2 && size != 4 && size != 8)
|
2007-12-20 12:09:19 -08:00
|
|
|
|
debug_assert(0); // invalid int size
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// need to re-load and sign-extend, because we output 64 bits.
|
2007-05-09 14:01:11 -07:00
|
|
|
|
data = movsx_le64(p, size);
|
2005-07-03 18:00:22 -07:00
|
|
|
|
fmt = L"%I64d";
|
2005-06-21 09:39:40 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// unsigned integers (displayed as hex)
|
|
|
|
|
|
// note: 0x00000000 can get annoying (0 would be nicer),
|
|
|
|
|
|
// but it indicates the variable size and makes for consistently
|
|
|
|
|
|
// formatted structs/arrays. (0x1234 0 0x5678 is ugly)
|
|
|
|
|
|
case btUInt:
|
|
|
|
|
|
case btULong:
|
2005-06-22 16:41:43 -07:00
|
|
|
|
display_as_hex:
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(size == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
// _TUCHAR
|
|
|
|
|
|
if(state.indirection)
|
|
|
|
|
|
{
|
|
|
|
|
|
state.indirection = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_array(p, 8, type_id, size, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
fmt = L"0x%02X";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(size == 2)
|
|
|
|
|
|
fmt = L"0x%04X";
|
|
|
|
|
|
else if(size == 4)
|
|
|
|
|
|
fmt = L"0x%08X";
|
|
|
|
|
|
else if(size == 8)
|
|
|
|
|
|
fmt = L"0x%016I64X";
|
|
|
|
|
|
else
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
debug_assert(0); // invalid size_t size
|
2005-06-21 09:39:40 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// character
|
|
|
|
|
|
case btChar:
|
|
|
|
|
|
case btWChar:
|
2005-06-27 21:12:50 -07:00
|
|
|
|
debug_assert(size == sizeof(char) || size == sizeof(wchar_t));
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// char*, wchar_t*
|
|
|
|
|
|
if(state.indirection)
|
|
|
|
|
|
{
|
|
|
|
|
|
state.indirection = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_array(p, 8, type_id, size, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
// either integer or character;
|
|
|
|
|
|
// if printable, the character will be appended below.
|
|
|
|
|
|
fmt = L"%d";
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// note: void* is sometimes indicated as (pointer, btNoType).
|
|
|
|
|
|
case btVoid:
|
|
|
|
|
|
case btNoType:
|
|
|
|
|
|
// void* - cannot display what it's pointing to (type unknown).
|
|
|
|
|
|
if(state.indirection)
|
|
|
|
|
|
{
|
|
|
|
|
|
out_erase(4); // " -> "
|
|
|
|
|
|
fmt = L"";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2007-12-20 12:09:19 -08:00
|
|
|
|
debug_assert(0); // non-pointer btVoid or btNoType
|
2005-06-21 09:39:40 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
debug_warn("dump_sym_base_type: unknown type");
|
|
|
|
|
|
//-fallthrough
|
|
|
|
|
|
|
|
|
|
|
|
// unsupported complex types
|
|
|
|
|
|
case btBCD:
|
|
|
|
|
|
case btCurrency:
|
|
|
|
|
|
case btDate:
|
|
|
|
|
|
case btVariant:
|
|
|
|
|
|
case btComplex:
|
|
|
|
|
|
case btBit:
|
|
|
|
|
|
case btBSTR:
|
|
|
|
|
|
case btHresult:
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_UNSUPPORTED; // NOWARN
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out(fmt, data);
|
|
|
|
|
|
|
|
|
|
|
|
// if the current value is a printable character, display in that form.
|
|
|
|
|
|
// this isn't only done in btChar because sometimes ints store characters.
|
|
|
|
|
|
if(data < 0x100)
|
|
|
|
|
|
{
|
|
|
|
|
|
int c = (int)data;
|
|
|
|
|
|
if(isprint(c))
|
|
|
|
|
|
out(L" ('%hc')", c);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_base_class(DWORD type_id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
DWORD base_class_type_id;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_TYPEID, &base_class_type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
2005-08-09 09:23:19 -07:00
|
|
|
|
// this is a virtual base class. we can't display those because it'd
|
|
|
|
|
|
// require reading the VTbl, which is difficult given lack of documentation
|
|
|
|
|
|
// and just not worth it.
|
|
|
|
|
|
DWORD vptr_ofs;
|
|
|
|
|
|
if(SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_VIRTUALBASEPOINTEROFFSET, &vptr_ofs))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_UNSUPPORTED; // NOWARN
|
2005-08-09 09:23:19 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
return dump_sym(base_class_type_id, p, state);
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_data(DWORD id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// display name (of variable/member)
|
|
|
|
|
|
const wchar_t* name;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, id, TI_GET_SYMNAME, &name))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L"%s = ", name);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
LocalFree((HLOCAL)name);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
__try
|
|
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// get type_id and address
|
|
|
|
|
|
DWORD type_id;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, id, TI_GET_TYPEID, &type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2006-07-06 18:22:23 -07:00
|
|
|
|
RETURN_ERR(determine_symbol_address(id, type_id, &p));
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
// display value recursively
|
|
|
|
|
|
return dump_sym(type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
|
{
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_INTERNAL_ERROR; // NOWARN
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_enum(DWORD type_id, const u8* p, DumpState UNUSED(state))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
ULONG64 size_ = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_LENGTH, &size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
const size_t size = (size_t)size_;
|
|
|
|
|
|
|
2007-05-09 14:01:11 -07:00
|
|
|
|
const i64 enum_value = movsx_le64(p, size);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// get array of child symbols (enumerants).
|
2005-06-21 09:39:40 -07:00
|
|
|
|
DWORD num_children;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_CHILDRENCOUNT, &num_children))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
TI_FINDCHILDREN_PARAMS2 fcp(num_children);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_FINDCHILDREN, &fcp))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
num_children = fcp.p.Count; // was truncated to MAX_CHILDREN
|
|
|
|
|
|
const DWORD* children = fcp.p.ChildId;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// for each child (enumerant):
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
for(size_t i = 0; i < num_children; i++)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
DWORD child_data_id = children[i];
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// get this enumerant's value. we can't make any assumptions about
|
|
|
|
|
|
// the variant's type or size - no restriction is documented.
|
|
|
|
|
|
// rationale: VariantChangeType is much less tedious than doing
|
|
|
|
|
|
// it manually and guarantees we cover everything. the OLE DLL is
|
|
|
|
|
|
// already pulled in by e.g. OpenGL anyway.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
VARIANT v;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_data_id, TI_GET_VALUE, &v))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(VariantChangeType(&v, &v, 0, VT_I8) != S_OK)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// it's the one we want - output its name.
|
|
|
|
|
|
if(enum_value == v.llVal)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const wchar_t* name;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_data_id, TI_GET_SYMNAME, &name))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L"%s", name);
|
2005-06-26 17:28:50 -07:00
|
|
|
|
LocalFree((HLOCAL)name);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// we weren't able to retrieve a matching enum value, but can still
|
|
|
|
|
|
// produce reasonable output (the numeric value).
|
|
|
|
|
|
// note: could goto here after a SGTI fails, but we fail instead
|
|
|
|
|
|
// to make sure those errors are noticed.
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out(L"%I64d", enum_value);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_function(DWORD UNUSED(type_id), const u8* UNUSED(p),
|
2005-08-09 09:23:19 -07:00
|
|
|
|
DumpState UNUSED(state))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::SYM_SUPPRESS_OUTPUT;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_function_type(DWORD UNUSED(type_id), const u8* p, DumpState UNUSED(state))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
// this symbol gives class parent, return type, and parameter count.
|
|
|
|
|
|
// unfortunately the one thing we care about, its name,
|
|
|
|
|
|
// isn't exposed via TI_GET_SYMNAME, so we resolve it ourselves.
|
|
|
|
|
|
|
|
|
|
|
|
char name[DBG_SYMBOL_LEN];
|
2006-07-06 18:22:23 -07:00
|
|
|
|
LibError err = debug_resolve_symbol_lk((void*)p, name, 0, 0);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
out(L"0x%p", p);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == INFO::OK)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L" (%hs)", name);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// do not follow pointers that we have already displayed. this reduces
|
|
|
|
|
|
// clutter a bit and prevents infinite recursion for cyclical references
|
|
|
|
|
|
// (e.g. via struct S { S* p; } s; s.p = &s;)
|
|
|
|
|
|
|
2008-07-04 11:02:54 -07:00
|
|
|
|
// note: allocating memory dynamically would cause trouble if dumping
|
|
|
|
|
|
// the stack from within memory-related code (the allocation hook would
|
|
|
|
|
|
// be reentered, which is not permissible).
|
|
|
|
|
|
|
|
|
|
|
|
static const size_t maxVisited = 1000;
|
|
|
|
|
|
static const u8* visited[maxVisited];
|
|
|
|
|
|
static size_t numVisited;
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
static void ptr_reset_visited()
|
|
|
|
|
|
{
|
2008-07-04 11:02:54 -07:00
|
|
|
|
numVisited = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool ptr_already_visited(const u8* p)
|
|
|
|
|
|
{
|
2008-07-04 11:02:54 -07:00
|
|
|
|
for(size_t i = 0; i < numVisited; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(visited[i] == p)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(numVisited < maxVisited)
|
|
|
|
|
|
{
|
|
|
|
|
|
visited[numVisited] = p;
|
|
|
|
|
|
numVisited++;
|
|
|
|
|
|
}
|
|
|
|
|
|
// capacity exceeded
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// warn user - but only once (we can't use the regular
|
|
|
|
|
|
// debug_display_error and wdbg_assert doesn't have a
|
|
|
|
|
|
// suppress mechanism)
|
|
|
|
|
|
static bool haveComplained;
|
|
|
|
|
|
if(!haveComplained)
|
|
|
|
|
|
{
|
|
|
|
|
|
debug_printf("WARNING: ptr_already_visited: capacity exceeded, increase maxVisited\n");
|
|
|
|
|
|
debug_break();
|
|
|
|
|
|
haveComplained = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-06-25 00:47:33 -07:00
|
|
|
|
|
2008-07-04 11:02:54 -07:00
|
|
|
|
return false;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_pointer(DWORD type_id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
ULONG64 size_ = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_LENGTH, &size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
const size_t size = (size_t)size_;
|
|
|
|
|
|
|
|
|
|
|
|
// read+output pointer's value.
|
2008-05-01 08:41:42 -07:00
|
|
|
|
p = (const u8*)(uintptr_t)movzx_le64(p, size);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L"0x%p", p);
|
|
|
|
|
|
|
|
|
|
|
|
// bail if it's obvious the pointer is bogus
|
|
|
|
|
|
// (=> can't display what it's pointing to)
|
2005-08-09 09:23:19 -07:00
|
|
|
|
if(debug_is_pointer_bogus(p))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// avoid duplicates and circular references
|
|
|
|
|
|
if(ptr_already_visited(p))
|
|
|
|
|
|
{
|
|
|
|
|
|
out(L" (see above)");
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// display what the pointer is pointing to.
|
|
|
|
|
|
// if the pointer is invalid (despite "bogus" check above),
|
|
|
|
|
|
// dump_data_sym recovers via SEH and prints an error message.
|
|
|
|
|
|
// if the pointed-to value turns out to uninteresting (e.g. void*),
|
|
|
|
|
|
// the responsible dump_sym* will erase "->", leaving only address.
|
|
|
|
|
|
out(L" -> ");
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_TYPEID, &type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-27 21:12:50 -07:00
|
|
|
|
|
|
|
|
|
|
// prevent infinite recursion just to be safe (shouldn't happen)
|
|
|
|
|
|
if(state.indirection >= MAX_INDIRECTION)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_NESTING_LIMIT);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
state.indirection++;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym(type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_typedef(DWORD type_id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_TYPEID, &type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym(type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// determine type and size of the given child in a UDT.
|
|
|
|
|
|
// useful for UDTs that contain typedefs describing their contents,
|
|
|
|
|
|
// e.g. value_type in STL containers.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError udt_get_child_type(const wchar_t* child_name,
|
2005-06-26 17:28:50 -07:00
|
|
|
|
ULONG num_children, const DWORD* children,
|
2005-06-22 16:41:43 -07:00
|
|
|
|
DWORD* el_type_id, size_t* el_size)
|
|
|
|
|
|
{
|
|
|
|
|
|
*el_type_id = 0;
|
|
|
|
|
|
*el_size = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for(ULONG i = 0; i < num_children; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DWORD child_id = children[i];
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// find the desired child
|
|
|
|
|
|
wchar_t* this_child_name;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_id, TI_GET_SYMNAME, &this_child_name))
|
2005-06-22 16:41:43 -07:00
|
|
|
|
continue;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const bool found_it = !wcscmp(this_child_name, child_name);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
LocalFree(this_child_name);
|
|
|
|
|
|
if(!found_it)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// .. its type information is what we want.
|
|
|
|
|
|
DWORD type_id;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_id, TI_GET_TYPEID, &type_id))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
|
|
|
|
|
ULONG64 size;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_id, TI_GET_LENGTH, &size))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
|
|
|
|
|
*el_type_id = type_id;
|
|
|
|
|
|
*el_size = (size_t)size;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
// (happens if called for containers that are treated as STL but are not)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::SYM_CHILD_NOT_FOUND; // NOWARN
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError udt_dump_std(const wchar_t* wtype_name, const u8* p, size_t size, DumpState state,
|
2005-06-25 00:47:33 -07:00
|
|
|
|
ULONG num_children, const DWORD* children)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
{
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError err;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-07-16 10:49:38 -07:00
|
|
|
|
// not a C++ standard library object; can't handle it.
|
|
|
|
|
|
if(wcsncmp(wtype_name, L"std::", 5) != 0)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CANNOT_HANDLE;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
|
2005-07-16 10:49:38 -07:00
|
|
|
|
// check for C++ objects that should be displayed via udt_dump_normal.
|
|
|
|
|
|
// STL containers are special-cased and the rest (apart from those here)
|
|
|
|
|
|
// are ignored, because for the most part they are spew.
|
|
|
|
|
|
if(!wcsncmp(wtype_name, L"std::pair", 9))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CANNOT_HANDLE;
|
2005-07-16 10:49:38 -07:00
|
|
|
|
|
|
|
|
|
|
// convert to char since debug_stl doesn't support wchar_t.
|
2005-07-03 15:36:24 -07:00
|
|
|
|
char ctype_name[DBG_SYMBOL_LEN];
|
2008-01-19 03:33:11 -08:00
|
|
|
|
sprintf_s(ctype_name, ARRAY_SIZE(ctype_name), "%ws", wtype_name);
|
2005-07-03 15:36:24 -07:00
|
|
|
|
|
2005-07-16 10:49:38 -07:00
|
|
|
|
// display contents of STL containers
|
|
|
|
|
|
// .. get element type
|
|
|
|
|
|
DWORD el_type_id;
|
|
|
|
|
|
size_t el_size;
|
|
|
|
|
|
err = udt_get_child_type(L"value_type", num_children, children, &el_type_id, &el_size);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err != INFO::OK)
|
2005-07-16 10:49:38 -07:00
|
|
|
|
goto not_valid_container;
|
|
|
|
|
|
// .. get iterator and # elements
|
2005-06-25 00:47:33 -07:00
|
|
|
|
size_t el_count;
|
2007-10-09 10:05:05 -07:00
|
|
|
|
DebugStlIterator el_iterator;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
u8 it_mem[DEBUG_STL_MAX_ITERATOR_SIZE];
|
2006-06-22 11:26:08 -07:00
|
|
|
|
err = debug_stl_get_container_info(ctype_name, p, size, el_size, &el_count, &el_iterator, it_mem);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err != INFO::OK)
|
2005-07-16 10:49:38 -07:00
|
|
|
|
goto not_valid_container;
|
|
|
|
|
|
return dump_sequence(el_iterator, it_mem, el_count, el_type_id, el_size, state);
|
|
|
|
|
|
not_valid_container:
|
|
|
|
|
|
|
|
|
|
|
|
// build and display detailed "error" message.
|
|
|
|
|
|
char buf[100];
|
2005-12-11 14:23:55 -08:00
|
|
|
|
const char* text;
|
|
|
|
|
|
// .. object named std::* but doesn't include a "value_type" child =>
|
|
|
|
|
|
// it's a non-STL C++ stdlib object. wasn't handled by the
|
|
|
|
|
|
// special case above, so we just display its simplified type name
|
|
|
|
|
|
// (the contents are usually spew).
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == ERR::SYM_CHILD_NOT_FOUND)
|
2005-07-16 10:49:38 -07:00
|
|
|
|
text = "";
|
2005-12-11 14:23:55 -08:00
|
|
|
|
// .. not one of the containers we can analyse.
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == ERR::STL_CNT_UNKNOWN)
|
2005-12-11 14:23:55 -08:00
|
|
|
|
text = "unsupported ";
|
|
|
|
|
|
// .. container of a known type but contents are invalid.
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == ERR::STL_CNT_INVALID)
|
2005-07-16 10:49:38 -07:00
|
|
|
|
text = "uninitialized/invalid ";
|
|
|
|
|
|
// .. some other error encountered
|
2005-07-03 13:48:47 -07:00
|
|
|
|
else
|
2005-12-11 14:23:55 -08:00
|
|
|
|
{
|
2008-01-19 03:33:11 -08:00
|
|
|
|
sprintf_s(buf, ARRAY_SIZE(buf), "error %d while analyzing ", err);
|
2005-12-11 14:23:55 -08:00
|
|
|
|
text = buf;
|
|
|
|
|
|
}
|
2006-06-22 11:26:08 -07:00
|
|
|
|
out(L"(%hs%hs)", text, debug_stl_simplify_name(ctype_name));
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
static bool udt_should_suppress(const wchar_t* type_name)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
{
|
|
|
|
|
|
// specialized HANDLEs are defined as pointers to structs by
|
|
|
|
|
|
// DECLARE_HANDLE. we only want the numerical value (pointer address),
|
|
|
|
|
|
// so prevent these structs from being displayed.
|
|
|
|
|
|
// note: no need to check for indirection; these are only found in
|
|
|
|
|
|
// HANDLEs (which are pointers).
|
|
|
|
|
|
// removed obsolete defs: HEVENT, HFILE, HUMPD
|
|
|
|
|
|
if(type_name[0] != 'H')
|
|
|
|
|
|
goto not_handle;
|
|
|
|
|
|
#define SUPPRESS_HANDLE(name) if(!wcscmp(type_name, L#name L"__")) return true;
|
|
|
|
|
|
SUPPRESS_HANDLE(HACCEL);
|
|
|
|
|
|
SUPPRESS_HANDLE(HBITMAP);
|
|
|
|
|
|
SUPPRESS_HANDLE(HBRUSH);
|
|
|
|
|
|
SUPPRESS_HANDLE(HCOLORSPACE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HCURSOR);
|
|
|
|
|
|
SUPPRESS_HANDLE(HDC);
|
|
|
|
|
|
SUPPRESS_HANDLE(HENHMETAFILE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HFONT);
|
|
|
|
|
|
SUPPRESS_HANDLE(HGDIOBJ);
|
|
|
|
|
|
SUPPRESS_HANDLE(HGLOBAL);
|
|
|
|
|
|
SUPPRESS_HANDLE(HGLRC);
|
|
|
|
|
|
SUPPRESS_HANDLE(HHOOK);
|
|
|
|
|
|
SUPPRESS_HANDLE(HICON);
|
|
|
|
|
|
SUPPRESS_HANDLE(HIMAGELIST);
|
|
|
|
|
|
SUPPRESS_HANDLE(HIMC);
|
|
|
|
|
|
SUPPRESS_HANDLE(HINSTANCE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HKEY);
|
|
|
|
|
|
SUPPRESS_HANDLE(HKL);
|
|
|
|
|
|
SUPPRESS_HANDLE(HKLOCAL);
|
|
|
|
|
|
SUPPRESS_HANDLE(HMENU);
|
|
|
|
|
|
SUPPRESS_HANDLE(HMETAFILE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HMODULE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HMONITOR);
|
|
|
|
|
|
SUPPRESS_HANDLE(HPALETTE);
|
|
|
|
|
|
SUPPRESS_HANDLE(HPEN);
|
|
|
|
|
|
SUPPRESS_HANDLE(HRGN);
|
|
|
|
|
|
SUPPRESS_HANDLE(HRSRC);
|
|
|
|
|
|
SUPPRESS_HANDLE(HSTR);
|
|
|
|
|
|
SUPPRESS_HANDLE(HTASK);
|
|
|
|
|
|
SUPPRESS_HANDLE(HWINEVENTHOOK);
|
|
|
|
|
|
SUPPRESS_HANDLE(HWINSTA);
|
|
|
|
|
|
SUPPRESS_HANDLE(HWND);
|
|
|
|
|
|
not_handle:
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError udt_dump_suppressed(const wchar_t* type_name, const u8* UNUSED(p), size_t UNUSED(size),
|
2005-08-09 09:23:19 -07:00
|
|
|
|
DumpState state, ULONG UNUSED(num_children), const DWORD* UNUSED(children))
|
2005-06-22 16:41:43 -07:00
|
|
|
|
{
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!udt_should_suppress(type_name))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CANNOT_HANDLE;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
|
|
|
|
|
// the data symbol is pointer-to-UDT. since we won't display its
|
|
|
|
|
|
// contents, leave only the pointer's value.
|
|
|
|
|
|
if(state.indirection)
|
|
|
|
|
|
out_erase(4); // " -> "
|
|
|
|
|
|
|
|
|
|
|
|
// indicate something was deliberately left out
|
|
|
|
|
|
// (otherwise, lack of output may be taken for an error)
|
|
|
|
|
|
out(L" (..)");
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// (by now) non-trivial heuristic to determine if a UDT should be
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// displayed on one line or several. split out of udt_dump_normal.
|
2005-06-26 17:28:50 -07:00
|
|
|
|
static bool udt_fits_on_one_line(const wchar_t* type_name, size_t child_count, size_t total_size)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// special case: always put CStr* on one line
|
|
|
|
|
|
// (std::*string are displayed directly, but these go through
|
|
|
|
|
|
// udt_dump_normal. we want to avoid the ensuing 3-line output)
|
|
|
|
|
|
if(!wcscmp(type_name, L"CStr") || !wcscmp(type_name, L"CStr8") || !wcscmp(type_name, L"CStrW"))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// try to get actual number of relevant children
|
|
|
|
|
|
// (typedefs etc. are never displayed, but are included in child_count.
|
|
|
|
|
|
// we have to balance that vs. tons of static members, which aren't
|
|
|
|
|
|
// reflected in total_size).
|
|
|
|
|
|
// .. prevent division by 0.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(child_count == 0)
|
|
|
|
|
|
child_count = 1;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// special-case a few types that would otherwise be classified incorrectly
|
|
|
|
|
|
// (due to having more or less than expected relevant children)
|
|
|
|
|
|
if(!wcsncmp(type_name, L"std::pair", 9))
|
|
|
|
|
|
child_count = 2;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const size_t avg_size = total_size / child_count;
|
|
|
|
|
|
// (if 0, no worries - child_count will probably be large and
|
|
|
|
|
|
// we return false, which is a safe default)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// small UDT with a few (small) members: fits on one line.
|
2005-06-26 17:28:50 -07:00
|
|
|
|
if(child_count <= 3 && avg_size <= sizeof(int))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError udt_dump_normal(const wchar_t* type_name, const u8* p, size_t size,
|
2005-06-26 17:28:50 -07:00
|
|
|
|
DumpState state, ULONG num_children, const DWORD* children)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const bool fits_on_one_line = udt_fits_on_one_line(type_name, num_children, size);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-27 21:12:50 -07:00
|
|
|
|
// prevent infinite recursion just to be safe (shouldn't happen)
|
|
|
|
|
|
if(state.level >= MAX_LEVEL)
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_NESTING_LIMIT);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
state.level++;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(fits_on_one_line? L"{ " : L"\r\n");
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
bool displayed_anything = false;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
for(ULONG i = 0; i < num_children; i++)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-22 16:41:43 -07:00
|
|
|
|
const DWORD child_id = children[i];
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
// get offset. if not available, skip this child
|
|
|
|
|
|
// (we only display data here, not e.g. typedefs)
|
2005-06-25 00:47:33 -07:00
|
|
|
|
DWORD ofs = 0;
|
|
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, child_id, TI_GET_OFFSET, &ofs))
|
2005-06-26 17:28:50 -07:00
|
|
|
|
continue;
|
2005-06-27 21:12:50 -07:00
|
|
|
|
debug_assert(ofs < size);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(!fits_on_one_line)
|
|
|
|
|
|
INDENT;
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const u8* el_p = p+ofs;
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError err = dump_sym(child_id, el_p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-04 10:09:28 -07:00
|
|
|
|
// there was no output for this child; undo its indentation (if any),
|
|
|
|
|
|
// skip everything below and proceed with the next child.
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == INFO::SYM_SUPPRESS_OUTPUT)
|
2005-06-26 17:28:50 -07:00
|
|
|
|
{
|
|
|
|
|
|
if(!fits_on_one_line)
|
|
|
|
|
|
UNINDENT;
|
2005-07-04 10:09:28 -07:00
|
|
|
|
continue;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
}
|
2005-07-04 10:09:28 -07:00
|
|
|
|
|
|
|
|
|
|
displayed_anything = true;
|
2006-09-22 06:19:40 -07:00
|
|
|
|
dump_error(err, el_p); // nop if err == INFO::OK
|
2005-07-04 10:09:28 -07:00
|
|
|
|
out(fits_on_one_line? L", " : L"\r\n");
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(err == ERR::SYM_SINGLE_SYMBOL_LIMIT)
|
2005-07-04 10:09:28 -07:00
|
|
|
|
break;
|
|
|
|
|
|
} // for each child
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
state.level--;
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
if(!displayed_anything)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out_erase(2); // "{ " or "\r\n"
|
|
|
|
|
|
out(L"(%s)", type_name);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
2005-06-26 17:28:50 -07:00
|
|
|
|
|
|
|
|
|
|
// remove trailing comma separator
|
|
|
|
|
|
// note: we can't avoid writing it by checking if i == num_children-1:
|
|
|
|
|
|
// each child might be the last valid data member.
|
|
|
|
|
|
if(fits_on_one_line)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out_erase(2); // ", "
|
|
|
|
|
|
out(L" }");
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_udt(DWORD type_id, const u8* p, DumpState state)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
{
|
|
|
|
|
|
ULONG64 size_ = 0;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_LENGTH, &size_))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
const size_t size = (size_t)size_;
|
|
|
|
|
|
|
|
|
|
|
|
// get array of child symbols (members/functions/base classes).
|
|
|
|
|
|
DWORD num_children;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_CHILDRENCOUNT, &num_children))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
TI_FINDCHILDREN_PARAMS2 fcp(num_children);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_FINDCHILDREN, &fcp))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
num_children = fcp.p.Count; // was truncated to MAX_CHILDREN
|
|
|
|
|
|
const DWORD* children = fcp.p.ChildId;
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
const wchar_t* type_name;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_SYMNAME, &type_name))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
LibError ret;
|
2005-07-03 13:48:47 -07:00
|
|
|
|
// note: order is important (e.g. STL special-case must come before
|
|
|
|
|
|
// suppressing UDTs, which tosses out most other C++ stdlib classes)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-07-16 10:49:38 -07:00
|
|
|
|
ret = udt_dump_std (type_name, p, size, state, num_children, children);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret != INFO::CANNOT_HANDLE)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
goto done;
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
ret = udt_dump_suppressed(type_name, p, size, state, num_children, children);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret != INFO::CANNOT_HANDLE)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
goto done;
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
ret = udt_dump_normal (type_name, p, size, state, num_children, children);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret != INFO::CANNOT_HANDLE)
|
2005-06-22 16:41:43 -07:00
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
|
|
done:
|
2005-06-26 17:28:50 -07:00
|
|
|
|
LocalFree((HLOCAL)type_name);
|
2005-06-22 16:41:43 -07:00
|
|
|
|
return ret;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_vtable(DWORD UNUSED(type_id), const u8* UNUSED(p), DumpState UNUSED(state))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
// unsupported (vtable internals are undocumented; too much work).
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::SYM_SUPPRESS_OUTPUT;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym_unknown(DWORD type_id, const u8* UNUSED(p), DumpState UNUSED(state))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
// redundant (already done in dump_sym), but this is rare.
|
|
|
|
|
|
DWORD type_tag;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_SYMTAG, &type_tag))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-10-27 09:53:41 -07:00
|
|
|
|
debug_printf("SYM| unknown tag: %d\n", type_tag);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
out(L"(unknown symbol type)");
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
2005-06-25 00:47:33 -07:00
|
|
|
|
// write name and value of the symbol <type_id> to the output buffer.
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// delegates to dump_sym_* depending on the symbol's tag.
|
2005-12-11 14:23:55 -08:00
|
|
|
|
static LibError dump_sym(DWORD type_id, const u8* p, DumpState state)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-10-23 17:06:08 -07:00
|
|
|
|
RETURN_ERR(out_check_limit());
|
2005-07-04 10:09:28 -07:00
|
|
|
|
|
2005-06-21 09:39:40 -07:00
|
|
|
|
DWORD type_tag;
|
2005-06-25 00:47:33 -07:00
|
|
|
|
if(!SymGetTypeInfo(hProcess, mod_base, type_id, TI_GET_SYMTAG, &type_tag))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
switch(type_tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SymTagArrayType:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_array (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagBaseType:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_base_type (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagBaseClass:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_base_class (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagData:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_data (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagEnum:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_enum (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagFunction:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_function (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagFunctionType:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_function_type (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagPointerType:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_pointer (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagTypedef:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_typedef (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagUDT:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_udt (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
case SymTagVTable:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_vtable (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
default:
|
2005-06-25 00:47:33 -07:00
|
|
|
|
return dump_sym_unknown (type_id, p, state);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-19 03:33:11 -08:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
// stack trace
|
2008-01-19 03:33:11 -08:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
struct IMAGEHLP_STACK_FRAME2 : public IMAGEHLP_STACK_FRAME
|
|
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
IMAGEHLP_STACK_FRAME2(const _tagSTACKFRAME64* sf)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
// apparently only PC, FP and SP are necessary, but
|
|
|
|
|
|
// we go whole-hog to be safe.
|
|
|
|
|
|
memset(this, 0, sizeof(IMAGEHLP_STACK_FRAME2));
|
|
|
|
|
|
InstructionOffset = sf->AddrPC.Offset;
|
|
|
|
|
|
ReturnOffset = sf->AddrReturn.Offset;
|
|
|
|
|
|
FrameOffset = sf->AddrFrame.Offset;
|
|
|
|
|
|
StackOffset = sf->AddrStack.Offset;
|
|
|
|
|
|
BackingStoreOffset = sf->AddrBStore.Offset;
|
|
|
|
|
|
FuncTableEntry = (ULONG64)sf->FuncTableEntry;
|
|
|
|
|
|
Virtual = sf->Virtual;
|
|
|
|
|
|
// (note: array of different types, can't copy directly)
|
|
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
|
|
Params[i] = sf->Params[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2008-01-19 03:33:11 -08:00
|
|
|
|
// output the symbol's name and value via dump_sym*.
|
|
|
|
|
|
// called from dump_frame_cb for each local symbol; lock is held.
|
|
|
|
|
|
static BOOL CALLBACK dump_sym_cb(SYMBOL_INFO* sym, ULONG UNUSED(size), void* UNUSED(ctx))
|
|
|
|
|
|
{
|
|
|
|
|
|
out_latch_pos(); // see decl
|
|
|
|
|
|
mod_base = sym->ModBase;
|
2008-05-01 08:41:42 -07:00
|
|
|
|
const u8* p = (const u8*)(uintptr_t)sym->Address;
|
2008-01-19 03:33:11 -08:00
|
|
|
|
DumpState state;
|
|
|
|
|
|
|
|
|
|
|
|
INDENT;
|
|
|
|
|
|
LibError err = dump_sym(sym->Index, p, state);
|
|
|
|
|
|
dump_error(err, p);
|
|
|
|
|
|
if(err == INFO::SYM_SUPPRESS_OUTPUT)
|
|
|
|
|
|
UNINDENT;
|
|
|
|
|
|
else
|
|
|
|
|
|
out(L"\r\n");
|
|
|
|
|
|
|
|
|
|
|
|
return TRUE; // continue
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
// called by wdbg_sym_WalkStack for each stack frame
|
|
|
|
|
|
static LibError dump_frame_cb(const _tagSTACKFRAME64* sf, uintptr_t UNUSED(cbData))
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
current_stackframe64 = sf;
|
2008-05-01 08:41:42 -07:00
|
|
|
|
void* func = (void*)(uintptr_t)sf->AddrPC.Offset;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
char func_name[DBG_SYMBOL_LEN]; char file[DBG_FILE_LEN]; int line;
|
2006-07-06 18:22:23 -07:00
|
|
|
|
LibError ret = debug_resolve_symbol_lk(func, func_name, file, &line);
|
2006-09-22 06:19:40 -07:00
|
|
|
|
if(ret == INFO::OK)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2005-06-22 16:41:43 -07:00
|
|
|
|
// don't trace back further than the app's entry point
|
2006-07-06 18:22:23 -07:00
|
|
|
|
// (no one wants to see this frame). checking for the
|
2005-06-22 16:41:43 -07:00
|
|
|
|
// function name isn't future-proof, but not stopping is no big deal.
|
|
|
|
|
|
// an alternative would be to check if module=kernel32, but
|
|
|
|
|
|
// that would cut off callbacks as well.
|
|
|
|
|
|
if(!strcmp(func_name, "_BaseProcessStart@4"))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::OK;
|
2005-06-22 16:41:43 -07:00
|
|
|
|
|
2005-07-09 13:17:58 -07:00
|
|
|
|
out(L"%hs (%hs:%d)\r\n", func_name, file, line);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
out(L"%p\r\n", func);
|
|
|
|
|
|
|
|
|
|
|
|
// only enumerate symbols for this stack frame
|
|
|
|
|
|
// (i.e. its locals and parameters)
|
|
|
|
|
|
// problem: debug info is scope-aware, so we won't see any variables
|
|
|
|
|
|
// declared in sub-blocks. we'd have to pass an address in that block,
|
|
|
|
|
|
// which isn't worth the trouble. since
|
|
|
|
|
|
IMAGEHLP_STACK_FRAME2 imghlp_frame(sf);
|
|
|
|
|
|
SymSetContext(hProcess, &imghlp_frame, 0); // last param is ignored
|
|
|
|
|
|
|
2008-02-25 13:19:52 -08:00
|
|
|
|
const ULONG64 base = 0; const char* const mask = 0; // use scope set by SymSetContext
|
|
|
|
|
|
SymEnumSymbols(hProcess, base, mask, dump_sym_cb, 0);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
out(L"\r\n");
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return INFO::CB_CONTINUE;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 11:48:32 -07:00
|
|
|
|
LibError debug_dump_stack(wchar_t* buf, size_t max_chars, size_t skip, void* pcontext)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2006-07-06 18:22:23 -07:00
|
|
|
|
static uintptr_t already_in_progress;
|
2007-09-23 08:36:29 -07:00
|
|
|
|
if(!cpu_CAS(&already_in_progress, 0, 1))
|
2006-09-22 06:19:40 -07:00
|
|
|
|
return ERR::REENTERED; // NOWARN
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2005-06-26 17:28:50 -07:00
|
|
|
|
out_init(buf, max_chars);
|
2005-06-25 00:47:33 -07:00
|
|
|
|
ptr_reset_visited();
|
|
|
|
|
|
|
2006-07-06 18:22:23 -07:00
|
|
|
|
skip_this_frame(skip, pcontext);
|
2008-02-25 13:19:52 -08:00
|
|
|
|
LibError ret = wdbg_sym_WalkStack(dump_frame_cb, 0, skip, (const CONTEXT*)pcontext);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2006-07-06 18:22:23 -07:00
|
|
|
|
already_in_progress = 0;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2006-07-06 18:22:23 -07:00
|
|
|
|
return ret;
|
2005-06-21 09:39:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-19 03:33:11 -08:00
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
// write out a "minidump" containing register and stack state; this enables
|
|
|
|
|
|
// examining the crash in a debugger. called by wdbg_exception_filter.
|
|
|
|
|
|
// heavily modified from http://www.codeproject.com/debug/XCrashReportPt3.asp
|
|
|
|
|
|
// lock must be held.
|
2008-02-25 13:19:52 -08:00
|
|
|
|
void wdbg_sym_WriteMinidump(EXCEPTION_POINTERS* exception_pointers)
|
2005-06-21 09:39:40 -07:00
|
|
|
|
{
|
2008-01-19 03:33:11 -08:00
|
|
|
|
WinScopedLock lock(WDBG_SYM_CS);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
2008-01-07 12:03:19 -08:00
|
|
|
|
OsPath path = OsPath(ah_get_log_dir())/"crashlog.dmp";
|
|
|
|
|
|
HANDLE hFile = CreateFile(path.string().c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
|
2005-06-21 09:39:40 -07:00
|
|
|
|
if(hFile == INVALID_HANDLE_VALUE)
|
2008-01-19 03:33:11 -08:00
|
|
|
|
{
|
2008-02-25 13:19:52 -08:00
|
|
|
|
DEBUG_DISPLAY_ERROR(L"wdbg_sym_WriteMinidump: unable to create crashlog.dmp.");
|
2008-01-19 03:33:11 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION mei;
|
|
|
|
|
|
mei.ThreadId = GetCurrentThreadId();
|
|
|
|
|
|
mei.ExceptionPointers = exception_pointers;
|
|
|
|
|
|
mei.ClientPointers = FALSE;
|
|
|
|
|
|
// exception_pointers is not in our address space.
|
|
|
|
|
|
|
|
|
|
|
|
// note: we don't store other crashlog info within the dump file
|
|
|
|
|
|
// (UserStreamParam), since we will need to generate a plain text file on
|
|
|
|
|
|
// non-Windows platforms. users will just have to send us both files.
|
|
|
|
|
|
|
|
|
|
|
|
HANDLE hProcess = GetCurrentProcess(); DWORD pid = GetCurrentProcessId();
|
|
|
|
|
|
if(!MiniDumpWriteDump(hProcess, pid, hFile, MiniDumpNormal, &mei, 0, 0))
|
2008-02-25 13:19:52 -08:00
|
|
|
|
DEBUG_DISPLAY_ERROR(L"wdbg_sym_WriteMinidump: unable to generate minidump.");
|
2005-06-21 09:39:40 -07:00
|
|
|
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
}
|
2008-04-19 11:10:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
static LibError wdbg_sym_Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
HMODULE hKernel32Dll = GetModuleHandle("kernel32.dll");
|
|
|
|
|
|
s_RtlCaptureContext = (PRtlCaptureContext)GetProcAddress(hKernel32Dll, "RtlCaptureContext");
|
|
|
|
|
|
|
|
|
|
|
|
return INFO::OK;
|
|
|
|
|
|
}
|