⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpatrol.html

📁 debug source code under unix platform.
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<br></tr></table><li>Contains 10 replacement C memory operation functions:<p><table><tr align="left"><td><code>memset()</code><td>ANSI<td>Fills memory with a specific byte. <br></tr><tr align="left"><td><code>bzero()</code><td>UNIX<td>Fills memory with the zero byte. <br></tr><tr align="left"><td><code>memccpy()</code><td>UNIX<td>Copies memory up to a specific byte. <br></tr><tr align="left"><td><code>memcpy()</code><td>ANSI<td>Copies non-overlapping memory. <br></tr><tr align="left"><td><code>memmove()</code><td>ANSI<td>Copies possibly-overlapping memory. <br></tr><tr align="left"><td><code>bcopy()</code><td>UNIX<td>Copies possibly-overlapping memory. <br></tr><tr align="left"><td><code>memcmp()</code><td>ANSI<td>Compares two blocks of memory. <br></tr><tr align="left"><td><code>bcmp()</code><td>UNIX<td>Compares two blocks of memory. <br></tr><tr align="left"><td><code>memchr()</code><td>ANSI<td>Searches memory for a specific byte. <br></tr><tr align="left"><td><code>memmem()</code><td>UNIX<td>Searches memory for specific bytes.<br></tr></table><li>All of the above functions can also be defined with an additional underscoreprepended to their external name in order to catch all uses of these functionsin the system and third-party libraries.<li>Contains support for a user-defined low-memory handler function, including areplacement for the C++ function, <code>set_new_handler()</code>.<li>The C++ dynamic memory allocation operators make use of the preprocessor inorder to obtain source-level information.  If this causes problems thenreplacement operator names may be used so that the existing operators will stillwork.<li>Contains support for automatically registering any functions whose names beginwith <code>__mp_init_</code> and <code>__mp_fini_</code> to be called when the mpatrollibrary is initialised and terminated respectively.  A function is also providedto register additional functions to be called when the mpatrol libraryterminates.<li>Contains support for user-defined prologue and epilogue callback functions,which get called before and after every memory allocation, reallocation ordeallocation.<li>A function is provided to return as much information as possible about a givenmemory allocation or free block, and can be called at any time during programexecution.  A similar function is also provided for calling from within adebugger and an example command file is provided for use with <code>gdb</code>.<li>A function is provided to display library settings and heap usage statistics,including peak memory usage.  This information is also displayed at programtermination, and can also be placed into a data structure at run-time viaanother function.<li>The library reads any user-controllable options at run-time from an environmentvariable, but this does not have to be set as defaults will then be used.  Thisprevents having to recompile anything in order to change any library settings. An option exists to display a quick-reference summary of all of the recognisedoptions to the standard error file stream.  Library settings can also be set andread from within user code after the library has been initialised by calling twointernal functions.<li>All diagnostics and logging are sent to a file in the current directory, butthis can be overridden, including forcing the log file to be the standard outputor standard error file streams.  An environment variable specifying a defaultdirectory in which to place log files can also be set.<li>Options exist to log details of every memory allocation, reallocation ordeallocation when they occur.  A function exists to log the details of anymemory allocation to the mpatrol log file.<li>Options exist to halt the program at a specific memory allocation, reallocationor deallocation when running the program within a debugger.  These options haveno effect when running the program without a debugger.<li>An option exists to enable memory allocation profiling, which forces a summaryof all memory allocation statistics to be written to a specified file for lateruse by a profiling command.  The profiling file can also be written at aspecified frequency.  An environment variable specifying a default directory inwhich to place profiling output files can also be set.<li>A profiling command is provided which reads a profiling output file produced bythe mpatrol library and displays a set of tables based on the accumulated data. The profiling information includes summaries of all of the memory allocationslisted by size and the function that allocated them and a list of memory leakswith the call stack of the allocating function.  It also includes a graph of allmemory allocations listed in tabular form, and an optional graph specificationfile for later processing by the <code>dot</code> graph visualisation package.<li>An option exists to enable memory allocation tracing, which forces certaindetails for every memory allocation event to be written to a specified file forlater use by a tracing command.  The tracing file is written in a conciseencoded form so as to keep the size of the file down.  An environment variablespecifying a default directory in which to place tracing output files can alsobe set.<li>A tracing command is provided which reads a tracing output file produced by thempatrol library and displays the memory allocation events in tabular orgraphical form.  It also displays any relevant statistics that could becalculated, and has options to write out the trace in HATF format or write outa trace-driven memory allocation simulation program as C source code.<li>On UNIX platforms, the <code>mmap()</code> function can optionally be used to allocateuser memory instead of the <code>sbrk()</code> function, but only if the systemsupports it.  If <code>mmap()</code> is supported then internal mpatrol library memoryis normally allocated with this function in order to segregate it from usermemory but this behaviour can be swapped around.<li>On non-UNIX platforms where the mpatrol library overrides <code>malloc()</code>without requiring the inclusion of <code>mpatrol.h</code>, versions of the UNIXfunctions <code>brk()</code> and <code>sbrk()</code> are provided for compatibility withcertain libraries.  These should <em>not</em> be called by user code as they haveonly limited functionality.<li>All newly-allocated memory that is not allocated by the <code>calloc()</code> or<code>recalloc()</code> functions will be pre-filled with a non-zero value in order tocatch out programs that wrongly assume that all newly-allocated memory iszeroed.  This value can be modified at run-time.<li>Can automatically check to see if there have been any illegal writes to byteslocated just before and after every memory allocation through the use ofoverflow buffers.  The size of such overflow buffers and the value to pre-fillthem with can be modified at run-time.  The checks will be performed beforeevery memory allocation call to ensure that nothing has overwritten theoverflow buffers, but a function is also provided to perform additional checksunder the programmer's control and an option exists to specify a range andfrequency in which checks will be performed.<li>On systems that support them, watch point areas can be used instead of overflowbuffers so that every read and write to memory is checked to ensure that it isnot within an overflow buffer.<li>Supports the <code>-fcheck-memory-usage</code> option of <code>gcc</code> to check allheap memory accesses in programs that were compiled with that option.  Currentlythis only supports checking that memory accesses do not overflow heapallocations or access free memory, rather than keeping records of individualmemory accesses that GNU Checker does.<li>Can automatically check to see if there have been any illegal writes to freememory blocks.  The value to pre-fill free memory blocks with can be modifiedat run-time.  The check will be performed before every memory allocation callto ensure that nothing has overwritten the free memory block, but a function isalso provided to perform additional checks under the programmer's control andan option exists to specify a range in which checks will be performed.<li>On systems that support memory protection, every memory allocation canoptionally be allocated at least one page of memory.  That way, any free memoryblocks can be made read and write protected so that nothing can access freememory on the heap.  An option is provided to specify whether all memoryallocations should be allocated at the start or at the end of such pages, andthe bytes left over within the pages become overflow buffers.<li>All freed memory allocations can optionally be prevented from being returned tothe free memory pool.  This is useful for detecting if use is being made offreed memory just after a memory allocation has been freed.  The contents ofthe memory allocation can either be preserved or can be pre-filled with a valuein order to detect illegal writes to the freed memory allocation.  In addition,only a specified number of recently-freed memory allocations can be preventedfrom being returned to the free memory pool.  Any older freed memory allocationswill then eventually be reused.<li>The <code>alloca()</code>, <code>strdupa()</code> and <code>strndupa()</code> functions areimplemented so that the temporary stack-based allocations that they wouldnormally make are now temporary heap-based allocations that can be traced bympatrol.  Such allocations will be implicitly freed when the function thatallocated them returns, but a function also exists to explicitly free them aswell.<li>Calls to memory operation functions (such as <code>memset()</code> or <code>memcpy()</code>)have their arguments checked to ensure that they do not pass null pointers orattempt to read or write memory straddling the boundary of a previouslyallocated memory block, although an option exists to turn such an error into awarning so that the operation can still be performed.  Tracing from all suchfunctions can also optionally be written to the log file.<li>The internal data structures used by the library are kept separate from therest of the memory allocations.  On systems that support memory protection, allof these internal data structures will be write-protected in order to preventcorruption by the calling program.  This feature can be overridden at run-timeas it can slow the program down.<li>Certain signals can be saved and restored on entry to each library function and<code>errno</code> is set to <code>ENOMEM</code> if memory cannot be allocated, except forthe ANSI C++ operators which throw the <code>std::bad_alloc</code> exception instead.<li>On systems that support memory protection, the library attempts to detect anyillegal memory accesses and display as much information as it can obtain aboutthe address in question and where the illegal memory access occurred.<li>A call stack traceback from any function performing a memory allocation isstored if the library supports this feature on the system it is being run on. This information can then be displayed when information about a specific memoryallocation is required.  Many different call stack traceback implementations areprovided for different platforms.  A function is also provided to write thecurrent call stack to the mpatrol log file.<li>Symbol table details from executable files and shared libraries areautomatically read on systems that support this feature in order to make thecall stack tracebacks more meaningful.  An option also exists to display acomplete list of the symbols that were read by the library at programtermination.  A function is also provided to return symbolic information aboutany code address.<li>Compiler-generated line number tables from any debugging sections that existin executable files and shared libraries can also be used by the mpatrol libraryin order to provide more meaningful information in call stack tracebacks.  Anexternal command is also provided to make use of a debugger to get suchinformation if one is available.<li>If the library is unable to automatically determine a program's executablefilename to read symbols from then an option exists to specify the full path tothe program's executable file.<li>Options are provided to edit and list a source file at a specific line numberwhen a warning or error occurs due to that source line.  An external commandwhich provides this functionality outwith the mpatrol library is included, andfunctions are provided to do this from within user code.<li>An option exists to change the default alignment used for general-purpose memoryallocations.<li>Contains support for a user-defined limit to available memory which can beuseful for stress-testing a program in simulated low memory conditions.<li>Contains a feature to randomly fail a specific frequency of memory allocationswhich can be useful for stress-testing error recovery code in a program.<li>An option exists to display a complete memory map of the heap at programtermination.  A function to do this is also available to call at any pointduring program execution.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -