Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
debug_stl.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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#include "lib/status.h"
31
32#include <cstddef>
33
34namespace ERR
35{
36 const Status STL_CNT_UNKNOWN = -100500;
37 const Status STL_CNT_UNSUPPORTED = -100501;
38 // likely causes: not yet initialized or memory corruption.
39 const Status STL_CNT_INVALID = -100502;
40}
41
42
43/**
44 * reduce complicated STL symbol names to human-readable form.
45 *
46 * algorithm: remove/replace undesired substrings in one pass (fast).
47 * example: "std::basic_string<char, char_traits<char>,
48 * std::allocator<char> >" => "string".
49 *
50 * @param name Buffer holding input symbol name; modified in-place.
51 * There is no length limit; must be large enough to hold typical STL
52 * strings. DEBUG_SYMBOL_CHARS chars is a good measure.
53 * @return name for convenience.
54 **/
55extern wchar_t* debug_stl_simplify_name(wchar_t* name);
56
57
58/**
59 * abstraction of all STL iterators used by debug_stl.
60 **/
61typedef const std::uint8_t* (*DebugStlIterator)(void* internal, size_t el_size);
62
63/**
64 * no STL iterator is larger than this; see below.
65 **/
67
68/**
69 * prepare to enumerate the elements of arbitrarily typed STL containers.
70 *
71 * works by retrieving element count&size via debug information and hiding
72 * the container's iterator implementation behind a common interface.
73 * a basic sanity check is performed to see if the container memory is
74 * valid and appears to be initialized.
75 *
76 * @param type_name exact type of STL container (see example above)
77 * @param p raw memory holding the container
78 * @param size sizeof(container)
79 * @param el_size sizeof(value_type)
80 * @param el_count out; number of valid elements in container
81 * @param el_iterator out; callback function that acts as an iterator
82 * @param it_mem out; buffer holding the iterator state. must be
83 * at least DEBUG_STL_MAX_ITERATOR_SIZE bytes.
84 * @return Status (ERR::STL_*)
85 **/
86extern Status debug_stl_get_container_info(const wchar_t* type_name, const std::uint8_t* p, size_t size,
87 size_t el_size, size_t* el_count, DebugStlIterator* el_iterator, void* it_mem);
88
89#endif // #ifndef INCLUDED_DEBUG_STL
wchar_t * debug_stl_simplify_name(wchar_t *name)
reduce complicated STL symbol names to human-readable form.
Definition: debug_stl.cpp:86
const std::uint8_t *(* DebugStlIterator)(void *internal, size_t el_size)
abstraction of all STL iterators used by debug_stl.
Definition: debug_stl.h:61
Status debug_stl_get_container_info(const wchar_t *type_name, const std::uint8_t *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:556
const size_t DEBUG_STL_MAX_ITERATOR_SIZE
no STL iterator is larger than this; see below.
Definition: debug_stl.h:66
Definition: debug.h:340
const Status STL_CNT_UNKNOWN
Definition: debug_stl.h:36
const Status STL_CNT_UNSUPPORTED
Definition: debug_stl.h:37
const Status STL_CNT_INVALID
Definition: debug_stl.h:39
std::int64_t Status
Error handling system.
Definition: status.h:174