📄 mpatrol.html
字号:
<html lang="en"><head><title>mpatrol</title><meta http-equiv="Content-Type" content="text/html"><meta name=description content="mpatrol"><meta name=generator content="makeinfo 4.0"><link href="http://texinfo.org/" rel=generator-home></head><body><h1>Table of Contents</h1><ul><li><a href="#Top">mpatrol</a><li><a href="#Foreword">Foreword</a><li><a href="#Overview">1 Overview</a><li><a href="#Features">2 Features</a><li><a href="#Installation">3 Installation</a><li><a href="#Integration">4 Integration</a><ul><li><a href="#Adding%20mpatrol">4.1 Adding mpatrol</a><li><a href="#Removing%20mpatrol">4.2 Removing mpatrol</a></ul><li><a href="#Memory%20allocations">5 Memory allocations</a><ul><li><a href="#Static%20memory%20allocations">5.1 Static memory allocations</a><li><a href="#Stack%20memory%20allocations">5.2 Stack memory allocations</a><li><a href="#Dynamic%20memory%20allocations">5.3 Dynamic memory allocations</a></ul><li><a href="#Operating%20system%20support">6 Operating system support</a><ul><li><a href="#Virtual%20memory">6.1 Virtual memory</a><li><a href="#Call%20stacks%20and%20symbol%20tables">6.2 Call stacks and symbol tables</a><li><a href="#Threads">6.3 Threads</a></ul><li><a href="#Using%20mpatrol">7 Using mpatrol</a><ul><li><a href="#Library%20behaviour">7.1 Library behaviour</a><li><a href="#Logging%20and%20tracing">7.2 Logging and tracing</a><li><a href="#General%20errors">7.3 General errors</a><li><a href="#Overwrites%20and%20underwrites">7.4 Overwrites and underwrites</a><li><a href="#Using%20with%20a%20debugger">7.5 Using with a debugger</a><li><a href="#Testing">7.6 Testing</a><li><a href="#Library%20functions">7.7 Library functions</a><li><a href="#Leak%20table">7.8 Leak table</a></ul><li><a href="#Tools">8 Tools</a><ul><li><a href="#dbmalloc">8.1 Dbmalloc-compatible functions</a><li><a href="#dmalloc">8.2 Dmalloc-compatible functions</a><li><a href="#heapdiff">8.3 Determining heap differences</a><li><a href="#mgauge">8.4 Memory allocation gauge</a><li><a href="#mtrace">8.5 Memory allocation tracing</a></ul><li><a href="#Utilities">9 Utilities</a><ul><li><a href="#The%20mpatrol%20command">9.1 The <code>mpatrol</code> command</a><li><a href="#The%20mleak%20command">9.2 The <code>mleak</code> command</a><li><a href="#The%20mpsym%20command">9.3 The <code>mpsym</code> command</a><li><a href="#The%20mpedit%20command">9.4 The <code>mpedit</code> command</a><li><a href="#The%20hexwords%20command">9.5 The <code>hexwords</code> command</a></ul><li><a href="#Profiling">10 Profiling</a><li><a href="#Tracing">11 Tracing</a><li><a href="#Heap%20corruption">12 Heap corruption</a><li><a href="#Memory%20leaks">13 Memory leaks</a><li><a href="#Improving%20performance">14 Improving performance</a><li><a href="#How%20it%20works">15 How it works</a><li><a href="#Examples">16 Examples</a><ul><li><a href="#Example%201">16.1 Getting started</a><li><a href="#Example%202">16.2 Detecting incorrect reuse of freed memory</a><li><a href="#Example%203">16.3 Detecting use of free memory</a><li><a href="#Example%204">16.4 Using overflow buffers</a><li><a href="#Example%205">16.5 Checking memory accesses</a><li><a href="#Example%206">16.6 Bad memory operations</a><li><a href="#Example%207">16.7 Incompatible function calls</a><li><a href="#Example%208">16.8 The <code>alloca()</code> functions</a><li><a href="#Example%209">16.9 The <code>MP_MALLOC()</code> functions</a><li><a href="#Example%2010">16.10 Additional useful information</a></ul><li><a href="#Tutorial">17 Tutorial</a><li><a href="#Functions">Appendix A Functions</a><ul><li><a href="#Functions%201">A.1 C dynamic memory allocation functions</a><li><a href="#Functions%202">A.2 C dynamic memory extension functions</a><li><a href="#Functions%203">A.3 C dynamic memory alternative functions</a><li><a href="#Functions%204">A.4 C++ dynamic memory allocation functions</a><li><a href="#Functions%205">A.5 C memory operation functions</a><li><a href="#Functions%206">A.6 mpatrol library functions</a></ul><li><a href="#Environment">Appendix B Environment</a><li><a href="#Options">Appendix C Options</a><li><a href="#Diagnostic%20messages">Appendix D Diagnostic messages</a><li><a href="#Library%20performance">Appendix E Library performance</a><li><a href="#File%20formats">Appendix F File formats</a><ul><li><a href="#Profiling%20file%20format">F.1 Profiling file format</a><li><a href="#Tracing%20file%20format">F.2 Tracing file format</a></ul><li><a href="#Supported%20systems">Appendix G Supported systems</a><li><a href="#Porting">Appendix H Porting</a><li><a href="#Notes">Appendix I Notes</a><ul><li><a href="#Generic%20notes">I.1 Notes for all platforms</a><li><a href="#UNIX%20notes">I.2 Notes for UNIX platforms</a><li><a href="#Amiga%20notes">I.3 Notes for Amiga platforms</a><li><a href="#Windows%20notes">I.4 Notes for Windows platforms</a><li><a href="#Netware%20notes">I.5 Notes for Netware platforms</a></ul><li><a href="#Frequently%20asked%20questions">Appendix J Frequently asked questions</a><ul><li><a href="#Documentation">J.1 Documentation</a><li><a href="#Building">J.2 Building</a><li><a href="#Linking">J.3 Linking</a><li><a href="#Running">J.4 Running</a><li><a href="#Files">J.5 Files</a></ul><li><a href="#Related%20software">Appendix K Related software</a><li><a href="#References">Appendix L References</a><li><a href="#About%20the%20author">Appendix M About the author</a><li><a href="#Copying">Appendix N Copying</a><li><a href="#Function%20index">Function index</a><li><a href="#Index">Index</a></ul><p><hr>Node:<a name="Top">Top</a>,Next:<a rel=next href="#Foreword">Foreword</a>,Up:<a rel=up href="#(dir)">(dir)</a><br><h1>mpatrol</h1><img src="images/mpatrol.jpg" alt="images/mpatrol.jpg"><p>This document describes mpatrol, a library for controlling and tracing dynamicmemory allocations.<p>This is edition 2.13 of the mpatrol manual for version1.4.8, 8th January, 2002.<ul><li><a href="#Foreword">Foreword</a>: Motivation and feedback. <li><a href="#Overview">Overview</a>: Overview of mpatrol. <li><a href="#Features">Features</a>: Features of mpatrol. <li><a href="#Installation">Installation</a>: Building and installing. <li><a href="#Integration">Integration</a>: Debugging existing programs. <li><a href="#Memory%20allocations">Memory allocations</a>: Background. <li><a href="#Operating%20system%20support">Operating system support</a>: Additional background. <li><a href="#Using%20mpatrol">Using mpatrol</a>: Using the library. <li><a href="#Tools">Tools</a>: Additional tools. <li><a href="#Utilities">Utilities</a>: External programs. <li><a href="#Profiling">Profiling</a>: Memory allocation profiling. <li><a href="#Tracing">Tracing</a>: Memory allocation tracing. <li><a href="#Heap%20corruption">Heap corruption</a>: Squashing those errors. <li><a href="#Memory%20leaks">Memory leaks</a>: Detection and identification. <li><a href="#Improving%20performance">Improving performance</a>: Life beyond mpatrol. <li><a href="#How%20it%20works">How it works</a>: Implementation details. <li><a href="#Examples">Examples</a>: Examples of usage. <li><a href="#Tutorial">Tutorial</a>: Complete example. <li><a href="#Functions">Functions</a>: Library functions. <li><a href="#Environment">Environment</a>: Library run-time options. <li><a href="#Options">Options</a>: Command line options. <li><a href="#Diagnostic%20messages">Diagnostic messages</a>: Warnings and errors. <li><a href="#Library%20performance">Library performance</a>: Comparitive timings. <li><a href="#File%20formats">File formats</a>: Output file layouts. <li><a href="#Supported%20systems">Supported systems</a>: Known platforms that mpatrol runs on. <li><a href="#Porting">Porting</a>: How to port mpatrol to a new system. <li><a href="#Notes">Notes</a>: Known bugs and future enhancements. <li><a href="#Frequently%20asked%20questions">Frequently asked questions</a>: For answering specific problems. <li><a href="#Related%20software">Related software</a>: Similar programs. <li><a href="#References">References</a>: Additional information. <li><a href="#About%20the%20author">About the author</a>: Information about me. <li><a href="#Copying">Copying</a>: GNU Library General Public License. <li><a href="#Function%20index">Function index</a>: Library functions. <li><a href="#Index">Index</a>: Main index. </ul><p><hr>Node:<a name="Foreword">Foreword</a>,Next:<a rel=next href="#Overview">Overview</a>,Previous:<a rel=previous href="#Top">Top</a>,Up:<a rel=up href="#Top">Top</a><br><h1>Foreword</h1><p>I first started writing this library a few years ago when the company I work forsent me out to a customer who had reported a memory leak, which he expected wascoming from the code generated by our C++ compiler. A few years on and thelibrary has changed dramatically from its first beginnings, but I thought I'drelease it publicly in case anyone else found it useful.<p>When writing the library, I placed more emphasis on the quantity and quality ofinformation about allocated memory rather than the speed and efficiency ofallocating the actual memory. This means that the library will use dramaticallymore memory than normal dynamic memory allocation libraries and can slow down toa crawl depending on which options you use. However, the end results are likelyto be accurate and reliable, and in most cases the library will run quitehappily at a sane speed.<p>The mpatrol library is by no means the only library of its kind. Solaris hasno less that 6 different malloc libraries, and there are plenty available asfreeware or as commercial products. Try to keep in mind that mpatrol comes withabsolutely no warranty and so if it doesn't work for you and you need a fastsolution, try some of the other libraries or products available. I have listedsome of the most popular at the end of this manual (see <a href="#Related%20software">Related software</a>).<p>This manual is arranged so that complete reference material on the mpatrollibrary can be found in the appendices, while introductory and backgroundmaterial can be found in the preceding chapters and sections. For readers whowish to delve right in and use the library, the Installation(see <a href="#Installation">Installation</a>) and Examples (see <a href="#Examples">Examples</a>) chapters should be enoughto get started in combination with the quick reference card. Otherwise, thismanual should be read from beginning to end in order to get the most out of thesoftware it describes. Note that all of the output shown from the examples wasproduced on 32-bit environments, although mpatrol can be built to support 64-bitenvironments as well.<p>Due to their very nature, problems with dynamic memory allocations arenotoriously difficult to reproduce and debug, and this is likely to be the caseif you find a bug in the mpatrol library as it might be extremely hard toreproduce on another system. Details on how to report bugs are given elsewherein this document (see <a href="#Notes">Notes</a>), but it would be very useful if you could tryto provide as much information as possible when reporting a problem, and thatincludes having a look in the library source code to see if it's obvious what iswrong. However, please try to read the frequently asked questions(see <a href="#Frequently%20asked%20questions">Frequently asked questions</a>) first in case your question or problem iscovered there since they are usually updated every time I receive a questionabout mpatrol.<p>The latest version of the mpatrol library and this manual can always be found at<a href="http://www.cbmamiga.demon.co.uk/mpatrol/">http://www.cbmamiga.demon.co.uk/mpatrol/</a>, and any correspondence relatingto mpatrol (bug reports, enhancement requests, compliments, etc.) should besent to <a href="mailto:mpatrol@cbmamiga.demon.co.uk">mpatrol@cbmamiga.demon.co.uk</a>. I'd be very interested inhearing any success stories with using mpatrol to debug programs, since I getvery little feedback apart from the occasional bug report. The mpatrol libraryis also registered at FreshMeat (<a href="http://freshmeat.net/projects/mpatrol/">http://freshmeat.net/projects/mpatrol/</a>)and SourceForge (<a href="http://sourceforge.net/projects/mpatrol/">http://sourceforge.net/projects/mpatrol/</a>) and severalother software sites so you can receive notification of updates there as well. I normally only check my e-mail about once or twice a week, so don't expect animmediate response. I can also be reached at <a href="mailto:graeme.roy@analog.com">graeme.roy@analog.com</a> butthat is my work e-mail address. There is also a discussion group at<a href="http://groups.yahoo.com/group/mpatrol/">http://groups.yahoo.com/group/mpatrol/</a> where you can post mpatrol-relatedquestions but you must first subscribe to the group before you can send mail to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -