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
92 extern std::ostream&
operator<<(std::ostream&, malloc_report_nt);
99 extern alloc_ct
const*
find_alloc(
void const* ptr);
127 inline void set_invisible_on() { LIBCWD_TSD_DECLARATION; _private_::set_invisible_on(LIBCWD_TSD); }
134 inline void set_invisible_off() { LIBCWD_TSD_DECLARATION; _private_::set_invisible_off(LIBCWD_TSD); }
140 extern void init_debugmalloc();
150 inline void set_invisible_on() { }
151 inline void set_invisible_off() { }
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)
168 extern unsigned long list_allocations_on(debug_ct& debug_object, alloc_filter_ct
const& format);
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
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
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);
256 AllocTag(p,
"strdup()");
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);
276 AllocTag(p,
"wcsdup()");
unsigned long mem_blocks()
Returns the total number of allocated memory blocks.
Definition: debugmalloc.cc:2933
bool test_delete(void const *void_ptr)
Test if a pointer points to the start of an allocated memory block.
Definition: debugmalloc.cc:2872
size_t mem_size()
Returns the total number of allocated bytes.
Definition: debugmalloc.cc:2907
channel_ct malloc
Definition: debug.cc:474
alloc_ct const * find_alloc(void const *ptr)
Find information about a memory allocation.
Definition: debugmalloc.cc:3641
void make_invisible(void const *void_ptr)
Make allocation pointed to by ptr invisible.
Definition: debugmalloc.cc:3159
void make_all_allocations_invisible_except(void const *ptr)
Make all current allocations invisible except the given pointer.
Definition: debugmalloc.cc:3219
void make_exit_function_list_invisible()
Make allocations done in libc.so:__new_exitfn invisible.
Definition: debugmalloc.cc:3262
void move_outside(marker_ct *marker, void const *void_ptr)
Move memory allocation pointed to by ptr outside marker.
Definition: debugmalloc.cc:3487
unsigned long list_allocations_on(debug_ct &debug_object)
List all current allocations to a given debug object.
Definition: debugmalloc.cc:3020
namespace for libcwd.
Definition: debug.cc:87
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