Previous: Functions 5, Up: Functions
The following 42 functions are available as support routines for additional control and tracing in the mpatrol library. Although they are documented here as being prefixed by `__mp_', their equivalent functions that are prefixed by `mpatrol_' are also defined as aliases in the mpatrol.h header file. To use these you should include the mpatrol.h header file.
int __mp_atexit(void (*func)(void))
unsigned long __mp_setoption(long opt, unsigned long val)
MP_OPT_SETFLAGS
and MP_OPT_UNSETFLAGS
options respectively, with
the necessary flags specified in val. The return value will be `0'
on success and a combination of all of the flags that could not be set or unset
on failure.
int __mp_getoption(long opt, unsigned long *val)
MP_OPT_SETFLAGS
then all of the mpatrol library flags that are set will
be returned in val. If opt is MP_OPT_UNSETFLAGS
then all of
the mpatrol library flags that are not set will be returned in val.
unsigned long __mp_libversion(void)
const char *__mp_strerror(__mp_errortype err)
__mp_errno
.
const char *__mp_function(__mp_alloctype func)
int __mp_setuser(const void *ptr, const void *data)
__mp_setuser()
. As such, the user data must be valid for the entire
lifetime of the memory allocation, perhaps even after the allocation has been
freed if the NOFREE option is being used. This function returns
`1' if there is an allocated memory block containing ptr, and
`0' otherwise.
int __mp_setmark(const void *ptr)
alloca()
, strdupa()
or
strndupa()
may not be marked.
int __mp_info(const void *ptr, __mp_allocinfo *info)
block
and size
fields and can be identified by not having the allocated
flag set):
Field | Description
|
block
| Pointer to first byte of allocation.
|
size
| Size of allocation in bytes.
|
type
| Type of function which allocated memory.
|
alloc
| Allocation index.
|
realloc
| Number of times reallocated.
|
thread
| Thread identifier.
|
event
| Event of last modification.
|
func
| Function in which allocation took place.
|
file
| File in which allocation took place.
|
line
| Line number at which allocation took place.
|
stack
| Pointer to function call stack.
|
typestr
| Type stored in allocation.
|
typesize
| Size of type stored in allocation.
|
userdata
| User data associated with allocation.
|
allocated
| Indicates if allocation was allocated.
|
freed
| Indicates if allocation has been freed.
|
marked
| Indicates if allocation has been marked.
|
profiled
| Indicates if allocation has been profiled.
|
traced
| Indicates if allocation has been traced.
|
internal
| Indicates if allocation is internal.
|
int __mp_syminfo(const void *ptr, __mp_symbolinfo *info)
Field | Description
|
name
| Name of symbol.
|
object
| File containing symbol.
|
addr
| Start address of symbol.
|
size
| Size of symbol.
|
file
| Filename corresponding to address.
|
line
| Line number corresponding to address.
|
const char *__mp_symbol(const void *ptr)
int __mp_printinfo(const void *ptr)
unsigned long __mp_snapshot(void)
__mp_iterate()
.
size_t __mp_iterate(int (*func)(const void *, void *), void *data, unsigned long event)
__mp_printinfo()
will be used as the callback function. If event
is `0' then func will be called with the start address of every
memory allocation. If func returns a negative number then the iteration
process will be stopped immediately. If func returns a positive number
above zero then __mp_iterate()
will return the number of times func
returned a non-zero number after the iteration process has stopped. The
data argument is passed directly to func as its second argument and
is not read by the mpatrol library.
size_t __mp_iterateall(int (*func)(const void *, void *), void *data)
__mp_printinfo()
will be used as the callback function. If func
returns a negative number then the iteration process will be stopped
immediately. If func returns a positive number above zero then
__mp_iterate()
will return the number of times func returned a
non-zero number after the iteration process has stopped. The data
argument is passed directly to func as its second argument and is not read
by the mpatrol library. Note that unlike __mp_iterate()
, this function
will also include internal memory allocations made by the mpatrol library and is
intended for walking the entire heap.
int __mp_addallocentry(const char *file, unsigned long line, size_t size)
int __mp_addfreeentry(const char *file, unsigned long line, size_t size)
void __mp_clearleaktable(void)
int __mp_startleaktable(void)
int __mp_stopleaktable(void)
void __mp_leaktable(size_t size, int opt, unsigned char flags)
MP_LT_ALLOCATED
then
all allocated entries will be displayed, if opt is MP_LT_FREED
then
all freed entries will be displayed and if opt is MP_LT_UNFREED
then all unfreed entries will be displayed. The summary is normally sorted in
descending order of total bytes from each entry, but this can be changed by
setting flags to any combination of MP_LT_COUNTS
(to sort by the
number of occurrences in each entry) and MP_LT_BOTTOM
(to sort in
ascending order).
void __mp_memorymap(int stats)
void __mp_summary(void)
int __mp_stats(__mp_heapinfo *info)
Field | Description
|
acount
| Total number of allocated blocks.
|
atotal
| Total size of allocated blocks.
|
fcount
| Total number of free blocks.
|
ftotal
| Total size of free blocks.
|
gcount
| Total number of freed blocks.
|
gtotal
| Total size of freed blocks.
|
icount
| Total number of internal blocks.
|
itotal
| Total size of internal blocks.
|
mcount
| Total number of marked blocks.
|
mtotal
| Total size of marked blocks.
|
void __mp_check(void)
alloca()
family of
functions are out of scope then this function will also cause them to be freed.
__mp_prologuehandler __mp_prologue(const __mp_prologuehandler func)
Argument 1 | Argument 2 | Argument 3 | Called by
|
-1
| size | align | malloc() , etc.
|
ptr | size | align | realloc() , etc.
|
ptr | -1
| 0
| free() , etc.
|
ptr | -2
| 1
| strdup() , etc.
|
__mp_epiloguehandler __mp_epilogue(const __mp_epiloguehandler func)
Argument | Called by
|
ptr | malloc() , realloc() , strdup() , etc.
|
-1
| free() , etc.
|
__mp_nomemoryhandler __mp_nomemory(const __mp_nomemoryhandler func)
set_new_handler()
and will replace the handler installed by that function.
int __mp_printf(const char *fmt, ...)
int __mp_vprintf(const char *fmt, va_list args)
void __mp_locprintf(const char *fmt, ...)
void __mp_vlocprintf(const char *fmt, va_list args)
void __mp_logmemory(const void *ptr, size_t size)
int __mp_logstack(size_t frames)
int __mp_logaddr(const void *ptr)
int __mp_edit(const char *file, unsigned long line)
int __mp_list(const char *file, unsigned long line)
int __mp_view(const char *file, unsigned long line)
int __mp_readcontents(const char *file, void *ptr)
int __mp_writecontents(const char *file, const void *ptr)
long __mp_cmpcontents(const char *file, const void *ptr)
int __mp_remcontents(const char *file, const void *ptr)