Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ldbg.cpp File Reference
#include "precompiled.h"
#include "lib/sysdep/sysdep.h"
#include "lib/debug.h"
#include <algorithm>
#include <cstring>
#include <sys/syscall.h>
#include <execinfo.h>
Include dependency graph for ldbg.cpp:

Functions

void * debug_GetCaller (void *context, const wchar_t *lastFuncToSkip)
 return the caller of a certain function on the call stack. More...
 
Status debug_DumpStack (wchar_t *buf, size_t max_chars, void *context, const wchar_t *lastFuncToSkip)
 write a complete stack trace (including values of local variables) into the specified buffer. More...
 
Status debug_ResolveSymbol (void *ptr_of_interest, wchar_t *sym_name, wchar_t *file, int *line)
 read and return symbol information for the given address. More...
 
void debug_SetThreadName (const char *name)
 inform the debugger of the current thread's name. More...
 

Function Documentation

◆ debug_DumpStack()

Status debug_DumpStack ( wchar_t *  buf,
size_t  maxChars,
void *  context,
const wchar_t *  lastFuncToSkip 
)

write a complete stack trace (including values of local variables) into the specified buffer.

Parameters
bufTarget buffer.
maxCharsMax chars of buffer (should be several thousand).
contextPlatform-specific representation of execution state (e.g. Win32 CONTEXT). either specify an SEH exception's context record or use debug_CaptureContext to retrieve the current state. Rationale: intermediates such as debug_DisplayError change the context, so it should be captured as soon as possible.
lastFuncToSkipIs used for omitting error-reporting functions like debug_OnAssertionFailure from the stack trace. It is either 0 (skip nothing) or a substring of a function's name (this allows platform-independent matching of stdcall-decorated names). Rationale: this is safer than specifying a fixed number of frames, which can be incorrect due to inlining.
Returns
Status; ERR::REENTERED if reentered via recursion or multithreading (not allowed since static data is used).

◆ debug_GetCaller()

void * debug_GetCaller ( void *  context,
const wchar_t *  lastFuncToSkip 
)

return the caller of a certain function on the call stack.

this function is useful for recording (partial) stack traces for memory allocation tracking, etc.

Parameters
context,lastFuncToSkip- see debug_DumpStack
Returns
address of the caller

◆ debug_ResolveSymbol()

Status debug_ResolveSymbol ( void *  ptr_of_interest,
wchar_t *  sym_name,
wchar_t *  file,
int *  line 
)

read and return symbol information for the given address.

NOTE: the PDB implementation is rather slow (~500 us).

Parameters
ptr_of_interestaddress of symbol (e.g. function, variable)
sym_nameoptional out; holds at least DEBUG_SYMBOL_CHARS; receives symbol name returned via debug info.
fileoptional out; holds at least DEBUG_FILE_CHARS; receives base name only (no path; see rationale in wdbg_sym) of source file containing the symbol.
lineoptional out; receives source file line number of symbol.

note: all of the output parameters are optional; we pass back as much information as is available and desired.

Returns
Status; INFO::OK iff any information was successfully retrieved and stored.

◆ debug_SetThreadName()

void debug_SetThreadName ( const char *  name)

inform the debugger of the current thread's name.

(threads are easier to keep apart when they are identified by name rather than TID.)