2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* portable debugging helper functions specific to the STL.
|
2006-04-24 01:14:18 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_DEBUG_STL
|
|
|
|
#define INCLUDED_DEBUG_STL
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-22 15:19:40 +02:00
|
|
|
|
|
|
|
namespace ERR
|
|
|
|
{
|
|
|
|
const LibError STL_CNT_UNKNOWN = -100500;
|
|
|
|
// likely causes: not yet initialized or memory corruption.
|
|
|
|
const LibError STL_CNT_INVALID = -100501;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
/**
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
* @param buffer holding input symbol name; modified in-place.
|
|
|
|
* there is no length limit; must be large enough to hold typical STL
|
|
|
|
* strings. DBG_SYMBOL_LEN chars is a good measure.
|
|
|
|
* @return name for convenience.
|
|
|
|
**/
|
2009-11-03 22:46:35 +01:00
|
|
|
extern wchar_t* debug_stl_simplify_name(wchar_t* name);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
/**
|
|
|
|
* abstraction of all STL iterators used by debug_stl.
|
|
|
|
**/
|
2007-10-09 19:05:05 +02:00
|
|
|
typedef const u8* (*DebugStlIterator)(void* internal, size_t el_size);
|
2006-06-22 20:26:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* no STL iterator is larger than this; see below.
|
|
|
|
**/
|
2006-04-24 01:14:18 +02:00
|
|
|
const size_t DEBUG_STL_MAX_ITERATOR_SIZE = 64;
|
|
|
|
|
2006-06-22 20:26:08 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param type_name exact type of STL container (see example above)
|
|
|
|
* @param p raw memory holding the container
|
|
|
|
* @param size sizeof(container)
|
|
|
|
* @param el_size sizeof(value_type)
|
|
|
|
* @param el_count out; number of valid elements in container
|
|
|
|
* @param el_iterator out; callback function that acts as an iterator
|
|
|
|
* @param it_mem out; buffer holding the iterator state. must be
|
|
|
|
* at least DEBUG_STL_MAX_ITERATOR_SIZE bytes.
|
2006-09-22 15:19:40 +02:00
|
|
|
* @return LibError (ERR::STL_*)
|
2006-06-22 20:26:08 +02:00
|
|
|
**/
|
2009-11-03 22:46:35 +01:00
|
|
|
extern LibError debug_stl_get_container_info(const wchar_t* type_name, const u8* p, size_t size,
|
2007-10-09 19:05:05 +02:00
|
|
|
size_t el_size, size_t* el_count, DebugStlIterator* el_iterator, void* it_mem);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // #ifndef INCLUDED_DEBUG_STL
|