📄 mpatrol.txt
字号:
This file documents mpatrol, a library for controlling and tracingdynamic memory allocations. Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com> This is edition 2.13 of the mpatrol manual for version 1.4.8, 8thJanuary, 2002. Permission is granted to make and distribute verbatim copies of thismanual provided the copyright notice and this permission notice arepreserved on all copies. Permission is granted to copy and distribute modified versions ofthis manual under the conditions for verbatim copying, provided thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one. Permission is granted to copy and distribute translations of thismanual into another language, under the above conditions for modifiedversions, except that this permission notice may be stated in atranslation approved by the Free Software Foundation. All product names mentioned in the documentation and source code forthis library are the trademarks of their respective owners....Table of Contents...mpatrol******* _ _ | | | | ____ ___ _____ _____ _| |_ _____ ____ | || _ ~ _ \ | __ \ / __ | |_ _| | ___| / __ \ | || | | | | | | | | | | | | | | | | | | | | | | || | | | | | | |__| | | |__| | | | | | | |__| | | ||_| |_| |_| | ___/ \_____| |_| |_| \____/ |_| | | |_| This document describes mpatrol, a library for controlling andtracing dynamic memory allocations. This is edition 2.13 of the mpatrol manual for version 1.4.8, 8thJanuary, 2002.Foreword******** I first started writing this library a few years ago when thecompany I work for sent me out to a customer who had reported a memoryleak, which he expected was coming from the code generated by our C++compiler. A few years on and the library has changed dramatically fromits first beginnings, but I thought I'd release it publicly in caseanyone else found it useful. When writing the library, I placed more emphasis on the quantity andquality of information about allocated memory rather than the speed andefficiency of allocating the actual memory. This means that thelibrary will use dramatically more memory than normal dynamic memoryallocation libraries and can slow down to a crawl depending on whichoptions you use. However, the end results are likely to be accurateand reliable, and in most cases the library will run quite happily at asane speed. The mpatrol library is by no means the only library of its kind.Solaris has no less that 6 different malloc libraries, and there areplenty available as freeware or as commercial products. Try to keep inmind that mpatrol comes with absolutely no warranty and so if itdoesn't work for you and you need a fast solution, try some of theother libraries or products available. I have listed some of the mostpopular at the end of this manual (*note Related software::). This manual is arranged so that complete reference material on thempatrol library can be found in the appendices, while introductory andbackground material can be found in the preceding chapters andsections. For readers who wish to delve right in and use the library,the Installation (*note Installation::) and Examples (*note Examples::)chapters should be enough to get started in combination with the quickreference card. Otherwise, this manual should be read from beginningto end in order to get the most out of the software it describes. Notethat all of the output shown from the examples was produced on 32-bitenvironments, although mpatrol can be built to support 64-bitenvironments as well. Due to their very nature, problems with dynamic memory allocationsare notoriously difficult to reproduce and debug, and this is likely tobe the case if you find a bug in the mpatrol library as it might beextremely hard to reproduce on another system. Details on how toreport bugs are given elsewhere in this document (*note Notes::), butit would be very useful if you could try to provide as much informationas possible when reporting a problem, and that includes having a lookin the library source code to see if it's obvious what is wrong.However, please try to read the frequently asked questions (*noteFrequently asked questions::) first in case your question or problem iscovered there since they are usually updated every time I receive aquestion about mpatrol. The latest version of the mpatrol library and this manual can alwaysbe found at `http://www.cbmamiga.demon.co.uk/mpatrol/', and anycorrespondence relating to mpatrol (bug reports, enhancement requests,compliments, etc.) should be sent to <mpatrol@cbmamiga.demon.co.uk>.I'd be very interested in hearing any success stories with usingmpatrol to debug programs, since I get very little feedback apart fromthe occasional bug report. The mpatrol library is also registered atFreshMeat (`http://freshmeat.net/projects/mpatrol/') and SourceForge(`http://sourceforge.net/projects/mpatrol/') and several other softwaresites so you can receive notification of updates there as well. Inormally only check my e-mail about once or twice a week, so don'texpect an immediate response. I can also be reached at<graeme.roy@analog.com> but that is my work e-mail address. There isalso a discussion group at `http://groups.yahoo.com/group/mpatrol/'where you can post mpatrol-related questions but you must firstsubscribe to the group before you can send mail to it. Finally, I'd like to thank Stephan Springl (<springl@bfw-online.de>)for his help on reading debugging information from object files via theGNU BFD library, and Adam Zell (<zell@best.com>) for helping withpatching the dynamic linker support functions for loading sharedlibraries. Both Alexander Barton (<abarton@innotrac.com>) and DaveGibson (<david.gibson@analog.com>) helped to make mpatrol thread-safe.Roger Keane (<rgr@bcs-inc.com>) provided the perl code in the `mpsym'command and also the idea for the `MP_USE_ATEXIT' feature macro. SteveMcIntyre (<smcintyre@allstor-sw.co.uk>) helped by diagnosing the`fork()' problem and provided example code on how to fix it. PeterZijlstra (<peter@xlnt-software.com>) contributed code to enhance stacktraces for errors. Boris Makushkin (<oberon@antibiotic.ru>) requested, helped with, andprovided initial testing for the FreeBSD port, and Ivan Finch(<i.finch@rl.ac.uk>), Gerrit Bruchhaeuser (<gbruchhaeuser@orga.com>)and Andreas Schallenberg(<andreas.schallenberg@informatik.uni-oldenburg.de>) did the same forthe Tru64 and SuSE ports. Both Aleksandar Donev (<donev@pa.msu.edu>)and Van Snyder (<vsnyder@math.jpl.nasa.gov>) provided suggestions andcode for using mpatrol with FORTRAN. Michael Anthony (<m@xyzfind.com>)wrote the profdiff tool and Jerome Marant (<jerome@debian.org>) did theDebian GNU/Linux port. In addition, after spending well over 2000 hours designing andprogramming mpatrol, my sanity would not have been preserved in thestate it is in today were it not for the music of The ChemicalBrothers, The Manic Street Preachers, Orbital and The Prodigy. You cannow argue how sane I am depending on your musical tastes! Oh, and always remember to do final release builds without thempatrol library as the library is much slower than normal mallocimplementations and uses much more memory. Happy debugging! Graeme Roy, 11th October, 1999. Edinburgh, Scotland.1 Overview********** The mpatrol library is yet another link library that attempts todiagnose run-time errors that are caused by the wrong use ofdynamically allocated memory. If you don't know what the `malloc()'function or `operator new[]' do then this library is probably not foryou. You have to have a certain amount of programming expertise and aknowledge of how to run a command line compiler and linker before youshould attempt to use this. Along with providing a comprehensive and configurable log of alldynamic memory operations that occurred during the lifetime of aprogram, the mpatrol library performs extensive checking to detect anymisuse of dynamically allocated memory. All of this functionality canbe integrated into existing code through the inclusion of a singleheader file at compile-time. On UNIX and Windows platforms (andAmigaOS when using `gcc') this may not even be necessary as the mpatrollibrary can be linked with existing object files at link-time or, onsome platforms, even dynamically linked with existing programs atrun-time. All logging and tracing output from the mpatrol library is sent to aseparate log file in order to keep its diagnostics separate from anythat the program being tested might generate. A wide variety oflibrary settings can also be changed at run-time via an environmentvariable, thus removing the need to recompile or relink in order tochange the library's behaviour. A file containing a summary of the memory allocation profilingstatistics for a particular program can be produced by the mpatrollibrary. This file can then be read by a profiling tool which willdisplay a set of tables based upon the accumulated data. The profilinginformation includes summaries of all of the memory allocations listedby size and the function that allocated them and a list of memory leakswith the call stack of the allocating function. It also includes agraph of all memory allocations listed in tabular form, and an optionalgraph specification file for later processing by the `dot' graphvisualisation package. A file containing a concise encoded trace of all memory allocations,reallocations and deallocations made by a program can also be producedby the mpatrol library. This file can then be read by a tracing toolwhich will decode the trace and display the events in tabular orgraphical form, and also display any relevant statistics that could becalculated. The mpatrol library has been designed with the intention ofreplacing calls to existing C and C++ memory allocation functions asseamlessly as possible, but in many cases that may not be possible andslight code modifications may be required. However, a preprocessormacro containing the version of the mpatrol library is provided for thepurposes of conditional compilation so that release builds and debugbuilds can be easily automated.2 Features********** An overall list of features contained in the mpatrol library isgiven below. This is not intended to be exhaustive since the best wayto see what the library does is to read the documentation and try itout. * Written for 32-bit and 64-bit UNIX, AmigaOS, Windows and Netware platforms. Contains direct support for (and takes advantage of most of the features of) AIX, DG/UX, DRS/NX, DYNIX/ptx, FreeBSD, HP/UX, IRIX, Linux, LynxOS, NetBSD, OpenBSD, SINIX, Solaris, SunOS, Tru64 and UnixWare. Also contains target-specific code to take advantage of Alpha, Intel 80x86, Motorola 680x0 and 88xx0, MIPS, HP PA/RISC, IBM RS/6000, PowerPC and SPARC processors. * Has the ability to read symbols from executable files and shared libraries in the `a.out', COFF, XCOFF, ELF32, ELF64 and Windows Portable Executable file formats, and if the GNU BFD library is available then the mpatrol library can read symbols from all of the file formats that it has support for as well. Can also liase with AIX, BSD-based, HP/UX, IRIX, OSF, SVR4-based and Windows dynamic linkers in order to find out information about shared libraries. * Can be built to allocate memory from a fixed-sized static array rather than using heap memory from the system. * Can be built as archive, shared and/or thread-safe libraries on systems that support them, or even as one large object file. A lint library can also be built from the mpatrol library on UNIX platforms. * A release version of the mpatrol library is provided, which has the same functional interface, but does not contain any of mpatrol's debugging, tracing or profiling features. It is intended to be used to quickly remove the mpatrol library. * Details of memory allocations and free memory are stored internally as a tree structure for speed and also to allow the best fit allocation algorithm to be used. This also enables the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -