📄 libmpatrol.3
字号:
Searches up to \fIsize\fP bytes in \fIptr\fP for the first occurrence of\fIbyte\fP and returns a pointer to it or \fBNULL\fP if no such byte occurs. If\fIsize\fP is \fB0\fP then no bytes will be searched. If the operation wouldaffect an existing memory allocation in the heap but would straddle thatallocation's boundaries then an error message will be generated in the log fileand no bytes will be searched..TP\fBmemmem\fPSearches up to \fIsize1\fP bytes in \fIptr1\fP for the first occurrence of\fIptr2\fP (which is exactly \fIsize2\fP bytes in length) and returns a pointerto it or \fBNULL\fP if no such sequence of bytes occur. If \fIsize1\fP or\fIsize2\fP is \fB0\fP then no bytes will be searched. If the operation wouldaffect an existing memory allocation in the heap but would straddle thatallocation's boundaries then an error message will be generated in the log fileand no bytes will be searched..PPThe following 42 functions are available as support routines for additionalcontrol and tracing in the mpatrol library. Although they are documented hereas being prefixed by \fB__mp_\fP, their equivalent functions that are prefixedby \fBmpatrol_\fP are also defined as aliases in the \fImpatrol.h\fP headerfile. To use these you should include the \fImpatrol.h\fP header file:.TP\fB__mp_atexit\fPInstalls a function to be called when the mpatrol library terminates. Up to 32such functions can be registered and will be called in reverse order ofregistration. Returns \fI1\fP on success or \fP0\fP if \fIfunc\fP could not beregistered..TP\fB__mp_setoption\fPSets the value of an mpatrol option after the library has been initialised.Options that require values are listed in \fImpatrol.h\fP prefixed with\fIMP_OPT_*\fP. The \fIopt\fP argument should be set to one of these macros,and the \fIval\fP argument should be set to the option value, cast to anunsigned integer. The return value will be \fI0\fP on success and \fI1\fP onfailure. Options that are flags are listed in \fImpatrol.h\fP prefixed with\fIMP_FLG_*\fP. Multiple flags can be set or unset at once using the\fIMP_OPT_SETFLAGS\fP and \fIMP_OPT_UNSETFLAGS\fP options respectively, with thenecessary flags specified in \fIval\fP. The return value will be \fI0\fP onsuccess and a combination of all of the flags that could not be set or unset onfailure..TP\fB__mp_getoption\fPGets the value of an mpatrol option after the library has been initialised.If \fIopt\fP is a valid option listed in \fImpatrol.h\fP then \fI1\fP will bereturned and the associated value will be returned in \fIval\fP and cast to anunsigned integer, otherwise \fI0\fP will be returned. If \fIopt\fP is\fIMP_OPT_SETFLAGS\fP then all of the mpatrol library flags that are set will bereturned in \fIval\fP. If \fIopt\fP is \fIMP_OPT_UNSETFLAGS\fP then all of thempatrol library flags that are not set will be returned in \fIval\fP..TP\fB__mp_libversion\fPReturns the version number of the mpatrol library. This can be useful forverifying that the version of the mpatrol library that a program is linked withis the one expected at compile-time..TP\fB__mp_strerror\fPReturns the error message corresponding to the error code \fIerr\fP or\fBNULL\fP if no such error code exists. The most recent error code recorded bythe mpatrol library can be obtained by examining \fB__mp_errno\fP..TP\fB__mp_function\fPReturns the name of the function corresponding to the allocation type \fIfunc\fPor \fBNULL\fP if no such allocation type exists..TP\fB__mp_setuser\fPSets the user data for the memory allocation containing \fIptr\fP. The contentsof \fIdata\fP are entirely application-specific as user data will never beexamined by the mpatrol library. Such data is associated with a memoryallocation for its entire lifetime unless overridden by a subsequent call to\fB__mp_setuser\fP. As such, the user data must be valid for the entirelifetime of the memory allocation, perhaps even after the allocation has beenfreed if the \fBNOFREE\fP option is being used. This function returns \fI1\fPif there is an allocated memory block containing \fIptr\fP, and \fI0\fPotherwise..TP\fB__mp_setmark\fPSets the marked flag for the memory allocation containing \fIptr\fP, indicatingthat the memory allocation cannot be freed (but can be reallocated) and thuswill not be listed as a memory leak. This function returns \fI1\fP if there isan allocated memory block containing \fIptr\fP, and \fI0\fP otherwise. Notethat a memory allocation made by \fBalloca\fP, \fBstrdupa\fP or \fBstrndupa\fPmay not be marked..TP\fB__mp_info\fPObtains information about a specific memory allocation by placing statisticsabout \fIptr\fP in \fIinfo\fP. If \fIptr\fP does not belong to a previouslyallocated memory allocation or free memory block then \fI0\fP will be returned,otherwise \fI1\fP will be returned and \fIinfo\fP will contain the followinginformation (note that a free memory block will only contain the \fIblock\fP and\fIsize\fP fields and can be identified by not having the \fIallocated\fP flagset):.TSl l.\fBField\fP \fBDescription\fP\fBblock\fP Pointer to first byte of alloc.\fBsize\fP Size of alloc in bytes.\fBtype\fP Type of function which allocated memory.\fBalloc\fP Allocation index.\fBrealloc\fP Number of times reallocated.\fBthread\fP Thread identifier.\fBevent\fP Event of last modification.\fBfunc\fP Function in which alloc took place.\fBfile\fP File in which alloc took place.\fBline\fP Line number at which alloc took place.\fBstack\fP Pointer to function call stack.\fBtypestr\fP Type stored in allocation.\fBtypesize\fP Size of type stored in allocation.\fBuserdata\fP User data associated with allocation.\fBallocated\fP Indicates if alloc was allocated.\fBfreed\fP Indicates if alloc has been freed.\fBmarked\fP Indicates if alloc has been marked.\fBprofiled\fP Indicates if alloc has been profiled.\fBtraced\fP Indicates if alloc has been traced.\fBinternal\fP Indicates if alloc is internal..TE.TP\fB__mp_syminfo\fPObtains symbolic information about a specific code address by placing statisticsabout \fIptr\fP in \fIinfo\fP. If \fIptr\fP does not belong to a functionsymbol then \fI0\fP will be returned, otherwise \fI1\fP will be returned and\fIinfo\fP will contain the following information:.TSl l.\fBField\fP \fBDescription\fP\fBname\fP Name of symbol.\fBobject\fP File containing symbol.\fBaddr\fP Start address of symbol.\fBsize\fP Size of symbol.\fBfile\fP Filename corresponding to address.\fBline\fP Line number corresponding to address..TE.TP\fB__mp_symbol\fPObtains the name of a function symbol containing the code address specified in\fIptr\fP. If \fIptr\fP does not belong to a function symbol then \fBNULL\fPwill be returned..TP\fB__mp_printinfo\fPDisplays information about a specific memory allocation containing \fIptr\fP tothe standard error file stream. If \fIptr\fP does not belong to a previouslyallocated memory allocation or free memory block then \fI0\fP will be returned,otherwise \fI1\fP will be returned. This function is intended to be called fromwithin a debugger..TP\fB__mp_snapshot\fPReturns the current event number, effectively taking a snapshot of the heap.This number can then be used in later calls to \fB__mp_iterate\fP..TP\fB__mp_iterate\fPIterates over all of the current allocated and freed memory allocations,calling \fIfunc\fP with the start address of every memory allocation that hasbeen modified since event number \fIevent\fP. If \fIfunc\fP is \fBNULL\fP then\fB__mp_printinfo\fP will be used as the callback function. If \fBevent\fP is\fI0\fP then \fIfunc\fP will be called with the start address of every memoryallocation. If \fIfunc\fP returns a negative number then the iteration processwill be stopped immediately. If \fIfunc\fP returns a positive number above zerothen \fB__mp_iterate\fP will return the number of times \fIfunc\fP returned anon-zero number after the iteration process has stopped. The \fIdata\fPargument is passed directly to \fIfunc\fP as its second argument and is notread by the mpatrol library..TP\fB__mp_iterateall\fPIterates over all of the current allocated and freed memory allocations and anyfree memory blocks, calling \fIfunc\fP with the start address of every memoryallocation or free block. If \fIfunc\fP is \fBNULL\fP then \fB__mp_printinfo\fPwill be used as the callback function. If \fIfunc\fP returns a negative numberthen the iteration process will be stopped immediately. If \fIfunc\fP returns apositive number above zero then \fB__mp_iterate\fP will return the number oftimes \fIfunc\fP returned a non-zero number after the iteration process hasstopped. The \fIdata\fP argument is passed directly to \fIfunc\fP as its secondargument and is not read by the mpatrol library. Note that unlike\fB__mp_iterate\fP, this function will also include internal memory allocationsmade by the mpatrol library and is intended for walking the entire heap..TP\fB__mp_addallocentry\fPAdds an entry representing an allocation of size \fIsize\fP to the leak table.The allocation will be associated with a source filename of \fIfile\fP and aline number of \fIline\fP if the former is non-\fBNULL\fP and the latter isnon-zero. If \fIfile\fP is non-\fBNULL\fP and \fIline\fP is \fI0\fP then\fIfile\fP represents the name of the function that made the allocation. If\fIfile\fP is \fBNULL\fP and \fIline\fP is non-zero then \fIline\fP representsthe code address at which the allocation was made. If \fIfile\fP is \fBNULL\fPand \fIline\fP is \fI0\fP then the location of the allocation is unknown.Returns \fI1\fP on success and \fI0\fP if there was no more memory available toadd another entry to the leak table..TP\fB__mp_addfreeentry\fPAdds an entry representing a deallocation of size \fIsize\fP to the leak table.The deallocation will be associated with a source filename of \fIfile\fP and aline number of \fIline\fP if the former is non-\fBNULL\fP and the latter isnon-zero. If \fIfile\fP is non-\fBNULL\fP and \fIline\fP is \fI0\fP then\fIfile\fP represents the name of the function that made the deallocation. If\fIfile\fP is \fBNULL\fP and \fIline\fP is non-zero then \fIline\fP representsthe code address at which the deallocation was made. If \fIfile\fP is\fBNULL\fP and \fIline\fP is \fI0\fP then the location of the deallocation isunknown. Returns \fI1\fP on success and \fI0\fP if there was no existingallocation from the same location in the leak table..TP\fB__mp_clearleaktable\fPDeletes all of the existing entries in the leak table, making it empty. Thiswill also affect the behaviour of the \fBLEAKTABLE\fP option since that optionwill then only be able to show a summary of the entries in the leak table thatwere collected after the last call to this function rather than from the startof program execution..TP\fB__mp_startleaktable\fPStarts the automatic logging of all memory allocations, reallocations anddeallocations to the leak table. Returns \fI1\fP if such logging was alreadybeing performed and \fI0\fP otherwise..TP\fB__mp_stopleaktable\fPStops the automatic logging of all memory allocations, reallocations anddeallocations to the leak table. Returns \fI1\fP if such logging was alreadybeing performed and \fI0\fP otherwise..TP\fB__mp_leaktable\fPDisplays a summary of up to \fIsize\fP entries from the leak table, or allentries if \fIsize\fP is \fI0\fP. If \fIopt\fP is \fIMP_LT_ALLOCATED\fP thenall allocated entries will be displayed, if \fIopt\fP is \fIMP_LT_FREED\fP thenall freed entries will be displayed and if \fIopt\fP is \fIMP_LT_UNFREED\fP thenall unfreed entries will be displayed. The summary is normally sorted indescending order of total bytes from each entry, but this can be changed bysetting \fIflags\fP to any combination of \fIMP_LT_COUNTS\fP (to sort by thenumber of occurrences in each entry) and \fIMP_LT_BOTTOM\fP (to sort inascending order)..TP\fB__mp_memorymap\fPIf \fIstats\fP is non-zero then the current statistics of the mpatrol librarywill be displayed. If the heap contains at least one allocated, freed or freeblock then a map of the current heap will also be displayed..TP\fB__mp_summary\fPDisplays information about the current state of the mpatrol library, includingits settings and any relevant statistics..TP\fB__mp_stats\fPObtains statistics about the current state of the heap and places them in\fIinfo\fP. If this information could not be determined then \fI0\fP will bereturned, otherwise \fI1\fP will be returned and \fIinfo\fP will contain the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -