Pyrogenesis  trunk
debug_stl.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 Wildfire Games.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * portable debugging helper functions specific to the STL.
25  */
26 
27 #ifndef INCLUDED_DEBUG_STL
28 #define INCLUDED_DEBUG_STL
29 
30 
31 namespace ERR
32 {
33  const Status STL_CNT_UNKNOWN = -100500;
34  const Status STL_CNT_UNSUPPORTED = -100501;
35  // likely causes: not yet initialized or memory corruption.
36  const Status STL_CNT_INVALID = -100502;
37 }
38 
39 
40 /**
41  * reduce complicated STL symbol names to human-readable form.
42  *
43  * algorithm: remove/replace undesired substrings in one pass (fast).
44  * example: "std::basic_string<char, char_traits<char>,
45  * std::allocator<char> >" => "string".
46  *
47  * @param name Buffer holding input symbol name; modified in-place.
48  * There is no length limit; must be large enough to hold typical STL
49  * strings. DEBUG_SYMBOL_CHARS chars is a good measure.
50  * @return name for convenience.
51  **/
52 extern wchar_t* debug_stl_simplify_name(wchar_t* name);
53 
54 
55 /**
56  * abstraction of all STL iterators used by debug_stl.
57  **/
58 typedef const u8* (*DebugStlIterator)(void* internal, size_t el_size);
59 
60 /**
61  * no STL iterator is larger than this; see below.
62  **/
63 const size_t DEBUG_STL_MAX_ITERATOR_SIZE = 64;
64 
65 /**
66  * prepare to enumerate the elements of arbitrarily typed STL containers.
67  *
68  * works by retrieving element count&size via debug information and hiding
69  * the container's iterator implementation behind a common interface.
70  * a basic sanity check is performed to see if the container memory is
71  * valid and appears to be initialized.
72  *
73  * @param type_name exact type of STL container (see example above)
74  * @param p raw memory holding the container
75  * @param size sizeof(container)
76  * @param el_size sizeof(value_type)
77  * @param el_count out; number of valid elements in container
78  * @param el_iterator out; callback function that acts as an iterator
79  * @param it_mem out; buffer holding the iterator state. must be
80  * at least DEBUG_STL_MAX_ITERATOR_SIZE bytes.
81  * @return Status (ERR::STL_*)
82  **/
83 extern Status debug_stl_get_container_info(const wchar_t* type_name, const u8* p, size_t size,
84  size_t el_size, size_t* el_count, DebugStlIterator* el_iterator, void* it_mem);
85 
86 #endif // #ifndef INCLUDED_DEBUG_STL
const Status STL_CNT_UNSUPPORTED
Definition: debug_stl.h:34
const Status STL_CNT_INVALID
Definition: debug_stl.h:36
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.
Definition: debug_stl.cpp:550
uint8_t u8
Definition: types.h:37
i64 Status
Error handling system.
Definition: status.h:169
const size_t DEBUG_STL_MAX_ITERATOR_SIZE
no STL iterator is larger than this; see below.
Definition: debug_stl.h:63
Introduction
Definition: debug.h:407
wchar_t * debug_stl_simplify_name(wchar_t *name)
reduce complicated STL symbol names to human-readable form.
Definition: debug_stl.cpp:81
const Status STL_CNT_UNKNOWN
Definition: debug_stl.h:33
const u8 *(* DebugStlIterator)(void *internal, size_t el_size)
abstraction of all STL iterators used by debug_stl.
Definition: debug_stl.h:58