Pyrogenesis  trunk
Classes | Macros | Functions | Variables
debug_stl.cpp File Reference
#include "precompiled.h"
#include "lib/debug_stl.h"
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <list>
#include "lib/regex.h"
Include dependency graph for debug_stl.cpp:

Classes

struct  ContainerBase< Container >
 
struct  Any_deque
 
struct  Any_list
 
struct  Any_vector
 
struct  Any_queue
 
struct  Any_stack
 

Macros

#define REPLACE(what, with)
 
#define STRIP(what)
 
#define STRIP_NESTED(what)
 
#define CONTAINER(name, type_name_pattern)
 
#define STD_CONTAINER(name)   CONTAINER(name, L"std::" WIDEN(#name) L"<*>")
 
#define STRINGIZE2(id)   # id
 
#define STRINGIZE(id)   STRINGIZE2(id)
 

Functions

 STATUS_ADD_DEFINITIONS (debugStlStatusDefinitions)
 
wchar_tdebug_stl_simplify_name (wchar_t *name)
 reduce complicated STL symbol names to human-readable form. More...
 
template<class T >
const u8stl_iterator (void *it_mem, size_t el_size)
 
template<class T >
static bool IsContainerValid (const T &t, size_t el_count)
 
template<class T >
bool get_container_info (const T &t, size_t size, size_t el_size, size_t &el_count, DebugStlIterator &el_iterator, void *it_mem)
 
Status debug_stl_get_container_info (const wchar_t *type_name, const u8 *p, size_t size, size_t el_size, size_t *el_count, DebugStlIterator *el_iterator, void *it_mem)
 prepare to enumerate the elements of arbitrarily typed STL containers. More...
 

Variables

static const StatusDefinition debugStlStatusDefinitions []
 

Macro Definition Documentation

#define CONTAINER (   name,
  type_name_pattern 
)
Value:
else if(match_wildcard(type_name, type_name_pattern))\
{\
handled = true;\
IsValid = get_container_info<Any_##name>(*(Any_##name*)p, size, el_size, *el_count, *el_iterator, it_mem);\
}
int match_wildcard(const wchar_t *s, const wchar_t *w)
see if string matches pattern.
Definition: regex.cpp:28
#define REPLACE (   what,
  with 
)
Value:
else if(!wcsncmp(src, (what), ARRAY_SIZE(what)-1))\
{\
src += ARRAY_SIZE(what)-1-1; /* see preincrement rationale*/\
wcscpy_s(dst, ARRAY_SIZE(with), (with));\
dst += ARRAY_SIZE(with)-1;\
}
#define ARRAY_SIZE(name)
Definition: code_annotation.h:336
int wcscpy_s(wchar_t *dst, size_t max_dst_chars, const wchar_t *src)
#define STD_CONTAINER (   name)    CONTAINER(name, L"std::" WIDEN(#name) L"<*>")
#define STRINGIZE (   id)    STRINGIZE2(id)
#define STRINGIZE2 (   id)    # id
#define STRIP (   what)
Value:
else if(!wcsncmp(src, (what), ARRAY_SIZE(what)-1))\
{\
src += ARRAY_SIZE(what)-1-1;/* see preincrement rationale*/\
}
#define ARRAY_SIZE(name)
Definition: code_annotation.h:336
#define STRIP_NESTED (   what)
Value:
else if(!wcsncmp(src, (what), ARRAY_SIZE(what)-1))\
{\
/* remove preceding comma (if present) */\
if(src != name && src[-1] == ',')\
dst--;\
src += ARRAY_SIZE(what)-1;\
/* strip everything until trailing > is matched */\
ENSURE(nesting == 0);\
nesting = 1;\
}
#define ARRAY_SIZE(name)
Definition: code_annotation.h:336
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:287

Function Documentation

Status debug_stl_get_container_info ( const wchar_t type_name,
const u8 p,
size_t  size,
size_t  el_size,
size_t *  el_count,
DebugStlIterator el_iterator,
void *  it_mem 
)

prepare to enumerate the elements of arbitrarily typed STL containers.

works by retrieving element count&size via debug information and hiding the container's iterator implementation behind a common interface. a basic sanity check is performed to see if the container memory is valid and appears to be initialized.

Parameters
type_nameexact type of STL container (see example above)
praw memory holding the container
sizesizeof(container)
el_sizesizeof(value_type)
el_countout; number of valid elements in container
el_iteratorout; callback function that acts as an iterator
it_memout; buffer holding the iterator state. must be at least DEBUG_STL_MAX_ITERATOR_SIZE bytes.
Returns
Status (ERR::STL_*)
wchar_t* debug_stl_simplify_name ( wchar_t name)

reduce complicated STL symbol names to human-readable form.

algorithm: remove/replace undesired substrings in one pass (fast). example: "std::basic_string\<char, char_traits\<char\>, std::allocator\<char\> \>" => "string".

Parameters
nameBuffer holding input symbol name; modified in-place. There is no length limit; must be large enough to hold typical STL strings. DEBUG_SYMBOL_CHARS chars is a good measure.
Returns
name for convenience.
template<class T >
bool get_container_info ( const T t,
size_t  size,
size_t  el_size,
size_t &  el_count,
DebugStlIterator el_iterator,
void *  it_mem 
)
template<class T >
static bool IsContainerValid ( const T t,
size_t  el_count 
)
static
STATUS_ADD_DEFINITIONS ( debugStlStatusDefinitions  )
template<class T >
const u8* stl_iterator ( void *  it_mem,
size_t  el_size 
)

Variable Documentation

const StatusDefinition debugStlStatusDefinitions[]
static
Initial value:
= {
{ ERR::STL_CNT_UNKNOWN, L"Unknown STL container type_name" },
{ ERR::STL_CNT_UNSUPPORTED, L"Unsupported STL container" },
{ ERR::STL_CNT_INVALID, L"Container type is known but contents are invalid" }
}
const Status STL_CNT_UNSUPPORTED
Definition: debug_stl.h:34
const Status STL_CNT_INVALID
Definition: debug_stl.h:36
const Status STL_CNT_UNKNOWN
Definition: debug_stl.h:33