home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / dev / c / debug / mnemosyn.spk / !Mnemosyne / !Help < prev    next >
Text File  |  1991-04-24  |  5KB  |  113 lines

  1.  
  2.         This is a set of tools designed to help find memory leaks in
  3. programs, and to locate memory-hogging functions. It's implemented as
  4. a wrapper library that goes around malloc/free/etc, and an include file
  5. that "intercepts" calls to malloc/free/etc and makes them call the
  6. wrappers. Thus, you can get extensive memory profiling and leak
  7. detection by just adding one #include directive at the top of your
  8. file and recompiling/linking.
  9.  
  10.         Unlike some similar tools I've seen in the past, this makes
  11. sure that it keeps its on-disk data current, so that if the program
  12. is crashed or interrupted, the results still have some validity. The
  13. on-disk data is as compacted as I could make it, to give a chance of
  14. this being useable in debugging big memory pigs. It adds some cost
  15. in performance and memory size (since it keeps its own in-memory
  16. symbol tables) but since it's only a debugging tool, I think the
  17. cost is worth the benefit. This library can also be used to track
  18. only allocations in a single module, or set of modules, and doesn't
  19. interfere with calls to the "real" malloc() that are made in other
  20. library routines.
  21.  
  22.         Every effort has been made to ensure that the code is
  23. portable and won't interfere with running code - it should just
  24. plug in or out. The biggest hindrances are forward declarations of
  25. malloc() [which the preprocessor gleefully turns into syntax errors
  26. for you] and structure elements named "free". The code has been
  27. tested under Ultrix on DEC Risc and VAX systems, and under SunOS
  28. on a Motorola platform.  Please send patches, suggestions, etc,
  29. to the author, who will probably not have time to do anything with
  30. them.
  31.  
  32. Compiling and building:
  33.         You may wish to edit the Makefile and glance at mnemconf.h,
  34. then simply type "make". "make mtest" will build a simple test program
  35. that will give you an idea of how things work. "make runmtest" will
  36. run the test and do analysis on it.
  37.  
  38. Marcus J. Ranum
  39. mjr@decuac.dec.com
  40.  
  41. =====
  42.  
  43. This copy which you have was hacked by Graham Toal <gtoal@ed.ac.uk>
  44. primarily for the archimedes, although I have also made it DOS portable.
  45.  
  46. If compiling on the Archimedes, you will get extensions which the
  47. normal package doesn't offer.
  48.  
  49. The first is that *all* you have to do to your source is
  50.  
  51.                   #include <mnemosyn.h>
  52.  
  53. at the top after the system include files.  You don't have to call a
  54. procedure to save the symbol table, because I use the Ansi atexit() function
  55. to do that for you.
  56.  
  57. The most useful additions however are 'tombstones' -- markers at each end of
  58. every array which can be checked periodically; these help detect errors
  59. caused by writing past the end of arrays.  They don't detect gross errors;
  60. just the more common off-by-one error where the very next location has been
  61. accessed by accident.  (eg char *a = malloc(10); a[10] = 0;)
  62.  
  63. Also, this tombstone checking is normally done automatically for *all* areas
  64. you have allocated (even ones you've lost all pointers to :-)), rather than
  65. just the one you are currently freeing or reallocing.  This helps you find
  66. these errors much earlier than you would normally.
  67.  
  68. Most of the other things I've added have to do with improved diagnostics; on
  69. the Archimedes I can tell whether a variable is in the heap, or somewhere in
  70. code/constant space.
  71.  
  72. The diags also include the name of the procedure which called malloc -- this
  73. relies on poking around in the object file, so can be disabled if need be.
  74. You have to compile -gf to make sure suitable info is stored in your object.
  75. (if you don't, some of the names may be wrong due to the compiler optimising
  76. code and moving it around.  If you don't want to use -gf, make sure mnemosyn
  77. has been compiled *without* -DCALLER)
  78.  
  79. I've used the Ansi stringizing operator to pass the name of the variable in
  80. to free() and realloc().
  81.  
  82. If you step a pointer past the value returned by malloc (eg accidentally
  83. having moved a string past some prefix, then decided to free the string) we
  84. can find out which malloc area you were in and tell you where it was
  85. allocated.
  86.  
  87.  
  88. These additions are very much *hacks* to Marcus Ranum's excellent code; all
  89. bugs introduced are down to me; all credit for the original excellent design
  90. is down to Marcus.  It was so easy to port to both the Archimedes and Dos;
  91. portable code is normally the exception on usenet.  I've tried to maintain
  92. that original portability as best as I can, so most of these extensions can
  93. be ifdef'd out if they cause problems.
  94.  
  95. Thanks again to Marcus Ranum.  An excellent piece of work.  Saved me weeks
  96. of debugging.
  97.  
  98. Graham Toal, 18/04/91
  99. gtoal@ed.ac.uk
  100.  
  101. PS because code errors sometimes cause mnemosyne's internal structures to
  102. become corrupt, with the result that I can't find the information about some
  103. malloc, I've added a parameter to the mnemalyse program which prints out a
  104. single entry from the mnem.dat file.  Use this if you get a message such as
  105. "(see map entry 10 in mnem.dat)"
  106.  
  107. On the Archimedes, mnemalyse is provided on an icon (!Mnemo) (onto which you
  108. normally drop mnem.dat).  To use this extension, menu on the icon and select
  109. "Set Options". Change "mnemosyne " to "mnemosyne 10", press return, then
  110. drop mnem-dat on it as normal.
  111.  
  112. PPS You'll need PMoore's <utils> library.  I'll include my copy...
  113.