18 #ifndef LIBCWD_DEBUGMALLOC_H 19 #define LIBCWD_DEBUGMALLOC_H 21 #ifndef LIBCWD_LIBRARIES_DEBUG_H 22 #error "Don't include <libcwd/debugmalloc.h> directly, include the appropriate \"debug.h\" instead." 25 #ifndef LIBCWD_CONFIG_H 28 #ifndef LIBCWD_MACRO_ALLOCTAG_H 38 #ifndef LIBCWD_CLASS_ALLOC_H 41 #ifndef LIBCW_LOCKABLE_AUTO_PTR_H 44 #ifndef LIBCWD_PRIVATE_SET_ALLOC_CHECKING_H 47 #ifndef LIBCWD_ENUM_MEMBLK_TYPES_H 50 #if CWDEBUG_MARKER && !defined(LIBCWD_CLASS_MARKER_H) 53 #ifndef LIBCWD_CLASS_ALLOC_FILTER_H 56 #ifndef LIBCW_SYS_TIME_H 57 #define LIBCW_SYS_TIME_H 88 int const max_frames = 16;
89 extern void (*backtrace_hook)(
void** buffer,
int frames LIBCWD_COMMA_TSD_PARAM);
91 #ifndef LIBCWD_DOXYGEN 140 extern void init_debugmalloc();
144 #else // !CWDEBUG_ALLOC 155 #endif // !CWDEBUG_ALLOC 158 #define LIBCWD_DEBUGM_CERR(x) DEBUGDEBUG_CERR(x) 159 #define LIBCWD_DEBUGM_ASSERT(expr) do { if (!(expr)) { FATALDEBUGDEBUG_CERR("CWDEBUG_DEBUGM: " __FILE__ ":" << __LINE__ << ": " << __PRETTY_FUNCTION__ << ": Assertion`" << LIBCWD_STRING(expr) << "' failed."); core_dump(); } } while(0) 161 #define LIBCWD_DEBUGM_CERR(x) do { } while(0) 162 #define LIBCWD_DEBUGM_ASSERT(x) do { } while(0) 170 #else // !CWDEBUG_ALLOC 172 #endif // !CWDEBUG_ALLOC 176 #ifndef LIBCWD_DEBUGMALLOC_INTERNAL 179 #ifndef LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC 183 #define malloc __libcwd_malloc 184 #define calloc __libcwd_calloc 185 #define realloc __libcwd_realloc 186 #define free __libcwd_free 189 #ifndef LIBCWD_HAVE_DLOPEN 191 #if defined(LIBCWD_HAVE_POSIX_MEMALIGN) || defined(LIBCWD_HAVE_ALIGNED_ALLOC) 195 #ifdef LIBCWD_HAVE_POSIX_MEMALIGN 196 #define posix_memalign __libcwd_posix_memalign 198 #ifdef LIBCWD_HAVE_ALIGNED_ALLOC 199 #define aligned_alloc __libcwd_aligned_alloc 202 #if defined(HAVE_MALLOC_H) && (defined(HAVE_MEMALIGN) || defined(HAVE_VALLOC)) 205 #if defined(HAVE_UNISTD_H) && defined(HAVE_VALLOC) 208 #ifdef LIBCWD_HAVE_MEMALIGN 209 #define memalign __libcwd_memalign 211 #ifdef LIBCWD_HAVE_VALLOC 212 #define valloc __libcwd_valloc 214 #endif // !LIBCWD_HAVE_DLOPEN 221 extern "C" void* malloc(
size_t size)
throw() __attribute__((__malloc__));
222 extern "C" void* calloc(
size_t nmemb,
size_t size)
throw() __attribute__((__malloc__));
223 extern "C" void* realloc(
void* ptr,
size_t size)
throw() __attribute__((__malloc__));
224 extern "C" void free(
void* ptr)
throw();
225 #ifdef LIBCWD_HAVE_POSIX_MEMALIGN 226 #ifdef posix_memalign // Due to declaration conflicts with cstdlib, lets not define this when this isn't our macro. 227 extern "C" int posix_memalign(
void** memptr,
size_t alignment,
size_t size)
throw() __attribute__((__nonnull__(1))) __wur;
230 #ifdef LIBCWD_HAVE_ALIGNED_ALLOC 231 extern "C" void* aligned_alloc(
size_t alignment,
size_t size)
throw() __attribute__((__malloc__)) __attribute__((__alloc_size__(2))) __wur;
233 #ifdef LIBCWD_HAVE_VALLOC 234 extern "C" void* valloc(
size_t size)
throw() __attribute__((__malloc__)) __wur;
236 #ifdef LIBCWD_HAVE_MEMALIGN 237 extern "C" void* memalign(
size_t boundary,
size_t size)
throw() __attribute__((__malloc__));
240 #ifndef LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC 242 #define strdup __libcwd_strdup 244 #define wcsdup __libcwd_wcsdup 249 __libcwd_strdup(
char const* str)
251 size_t size = strlen(str) + 1;
252 char* p = (
char*)malloc(size);
255 memcpy(p, str, size);
263 size_t wcslen(
wchar_t const*);
264 wchar_t* wmemcpy(
wchar_t*,
wchar_t const*,
size_t);
269 __libcwd_wcsdup(
wchar_t const* str)
271 size_t size = wcslen(str) + 1;
272 wchar_t* p = (
wchar_t*)malloc(size *
sizeof(
wchar_t));
275 wmemcpy(p, str, size);
280 #endif // HAVE_WMEMCPY 281 #endif // !LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC 283 #endif // CWDEBUG_ALLOC 284 #endif // !LIBCWD_DEBUGMALLOC_INTERNAL 286 #endif // LIBCWD_DEBUGMALLOC_H The Debug Object class, this object represents one output device (ostream).
Definition: class_debug.h:77
A memory allocation marker.
Definition: class_marker.h:33
An allocated-memory filter class.An object of this type can be passed to list_allocations_on containi...
Definition: class_alloc_filter.h:89
void make_invisible(void const *void_ptr)
Make allocation pointed to by ptr invisible.The allocation pointed to by ptr is made invisible; it wo...
Definition: debugmalloc.cc:3126
std::ostream & operator<<(std::ostream &os, memblk_types_nt memblk_type)
Allow writing a memblk_types_nt directly to an ostream.
Definition: debugmalloc.cc:688
void set_invisible_on()
Make all future allocations invisible.All following allocations are made invisible; they won't show u...
Definition: debugmalloc.h:127
void make_all_allocations_invisible_except(void const *ptr)
Make all current allocations invisible except the given pointer.All allocations, except the given poi...
Definition: debugmalloc.cc:3186
void move_outside(marker_ct *marker, void const *void_ptr)
Move memory allocation pointed to by ptr outside marker.
Definition: debugmalloc.cc:3454
void set_invisible_off()
Cancel a call to set_invisible_on.See set_invisible_on.
Definition: debugmalloc.h:134
An object of type alloc_ct contains information about one allocated memory block. ...
Definition: class_alloc.h:60
Writing the current number of allocated bytes and blocks to an ostream.
Definition: debugmalloc.h:84
namespace for libcwd.
Definition: debug.cc:87
bool test_delete(void const *void_ptr)
Test if a pointer points to the start of an allocated memory block.
Definition: debugmalloc.cc:2839
unsigned long mem_blocks()
Returns the total number of allocated memory blocks.
Definition: debugmalloc.cc:2900
void make_exit_function_list_invisible()
Make allocations done in libc.so:__new_exitfn invisible.This makes the allocation done in __new_exitf...
Definition: debugmalloc.cc:3229
size_t mem_size()
Returns the total number of allocated bytes.
Definition: debugmalloc.cc:2874
unsigned long list_allocations_on(debug_ct &debug_object)
List all current allocations to a given debug object.With CWDEBUG_ALLOC set to 1, it is possible to write the overview of allocated memory to a Debug Object.
Definition: debugmalloc.cc:2987
#define AllocTag(p, x)
Annotate type of p with a static description.
Definition: macro_AllocTag.h:166
alloc_ct const * find_alloc(void const *ptr)
Find information about a memory allocation.Given a pointer, which points to the start of or inside an...
Definition: debugmalloc.cc:3608
malloc_report_nt
Type of malloc_report.
Definition: debugmalloc.h:64