home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbmalloc.zip / README < prev    next >
Text File  |  1993-01-04  |  21KB  |  483 lines

  1. /*
  2.  * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (uunet!virtech!cpcahil).  
  3.  *
  4.  * This software may be distributed freely as long as the following conditions
  5.  * are met:
  6.  *         * the distribution, or any derivative thereof, may not be
  7.  *          included as part of a commercial product
  8.  *        * full source code is provided including this copyright
  9.  *        * there is no charge for the software itself (there may be
  10.  *          a minimal charge for the copying or distribution effort)
  11.  *        * this copyright notice is not modified or removed from any
  12.  *          source file
  13.  */
  14.  
  15. This package is a collection of routines which are a drop-in replacement
  16. for the malloc(3), memory(3), string(3), and bstring(3) library functions.
  17. These replacement modules are different from the original modules in that
  18. they provide a full set of debugging features which detect malloc 
  19. memory overruns and other types of misuse.
  20.  
  21. The software has been developed under ISC UNIX and ported to several other
  22. UNIX architectures including HP-UX, SunOS, and AIX.  You should be able 
  23. to get it to run out of the box on most UNIX systems.  If not, see the PROBLEMS
  24. file for some help.  
  25.  
  26. Virtual Technologies, Inc also supports a commercial version of the library 
  27. which includes more features, better error reporting, better performance,
  28. no need to recompile the code to be verified, professional documentation,
  29. and support.  The commercial version is available on a growing range of
  30. architectures and is reasonably priced.
  31.  
  32. If you would like more info on the commercial version, you can send email
  33. to info@virtech.vti.com.
  34.  
  35. --------------------------------------------------------------------------
  36. PORTING NOTES:
  37.  
  38. 0. Short cut:  just run "make runtests".  This will configure and compile
  39.    the library and compile and run all of the tests.  Otherwise, you can
  40.    follow the following steps:
  41.  
  42. 1. Edit the makefile and set the appropriate flags for the compilations
  43.    See note about configure and setting special flags in the next step.
  44.  
  45. 2. Type make malloc.h  - which will run the Configure script to generate
  46.    the appropriate entries in malloc.h file for this compiler/OS.
  47.    If the configure script has problems, then you will probably have to 
  48.    configure the malloc.h file by hand.  Look in the PROBLEMS file
  49.    for more info.
  50.  
  51.    NOTE: Configure looks around for all of the compilers you have on the
  52.    system and attempts to setup a single malloc.h that can be included by
  53.    any of them.  Configure assumes that the compilers can be called without
  54.    any special flags for a basic compile.  If this is not the case you
  55.    will have to modify the Config.flags file and add a line with the
  56.    compiler name and special flags. 
  57.  
  58.    For example, if you wanted to use the -Aa flag on HP/UX cc (strict 
  59.    ANSI mode - which also would require -D_POSIX_SOURCE to compile the
  60.    malloc library), you would have to add the line: "cc -Aa -D_POSIX_SOURCE"
  61.    to Config.flags (and add -Aa -D_POSIX_SOURCE to the CFLAGS definition
  62.    in the Makefile).
  63.  
  64.    REMEMBER, if you do this, you may get error message if the malloc.h
  65.    file is included in compiles that do not include the specified flags.
  66.    If you expect different compilation environments with the same compiler,
  67.    you might want to have different versions of the debugging malloc.h file
  68.    for each environment.
  69.  
  70.    NOTE: Configure will automatically generate two configurations for
  71.    gcc if it finds it (one for normal gcc and one for gcc -traditional)
  72.    so that the library can be used in either mode.
  73.  
  74.    NOTE: real programmers don't need any fancy Configure script, they can 
  75.    configure the utility by hand (and so bypass this step). :-}
  76.  
  77.    PROBLEMS: if you find a problem with the configure script, you can do
  78.    one of the following:
  79.  
  80.     1. give up
  81.     2. report problem and give up
  82.     3. fix problem, send fix to me and continue
  83.     4. bypass the automatic configuration (see the PROBLEMS file for
  84.        info on how to do this).
  85.  
  86.    Since I have ensured that this works on all the environments that I 
  87.    have access to, I will not be able to fix a problem that you have 
  88.    on your OS/compiler combination unless you give me extremely good 
  89.    details about the problem including:
  90.     
  91.     1. Hardware & OS
  92.     2. compiler
  93.     3. compilation environment (i.e. on suns you can run in a Sys V
  94.        environment or a BSD environment - this is important)
  95.     4. any flags used for compiling
  96.     5. output from "make runtests"
  97.     6. any pertinent files - which *should* include the following:
  98.     
  99.         /usr/include/memory.h (if it exists)
  100.         /usr/include/malloc.h
  101.         /usr/include/string.h
  102.         malloc.h (if it got generated)
  103.         .configure
  104.         .configure.s
  105.         
  106.  
  107.    With this info I will probably be able to *guess* at the source of
  108.    the problem and send you back a potential fix.  However, without access
  109.    to such an architecture, I may not be able to fix the problem. 
  110.  
  111. 3. Type make (See the PROBLEMS file if you have a problem compiling)
  112.  
  113. 4. Type make runtests to build and runt the tests (some of which will take
  114.    a long time and some which will abort).  See the notes below for 
  115.    more info on the tests and the expected output
  116.  
  117. 5. Install libdbmalloc.a and malloc.h somewhere where users can get
  118.    to them by using make install (make sure INSTDIR is set correctly
  119.    in the makefile)
  120.  
  121. 6. If the system memory routines are not compatible with the ones expected
  122.    by the malloclib (this is the case if the configure script doesn't create
  123.    a datam[cs].O file) and if you are good with assembly, and if you have
  124.    nothing better to do, you could put together an asm module for either, or
  125.    both of the functions (as I have done for the DataMC routine on 386 
  126.    systems).
  127.  
  128.    These two functions are typically the bottle neck when running the debugging
  129.    library and I have found that a few moments spent on carefully implementing
  130.    these routines will vastly increase the performance of the library.
  131.  
  132.    If you do start upon this mission, make sure that you maintain the 
  133.    functionality present in the portable versions of the routines.  This is
  134.    especially important with the DataMC routine, which must function like
  135.    memcpy plus handle overlapping moves (like memmove).
  136.  
  137.    Once you have it working (and it passes the tests) send it in and I will 
  138.    include it in the baseline.
  139.  
  140. --------------------------------------------------------------------------
  141. USAGE:
  142.  
  143. To use the library, include the malloc.h header included with this
  144. library ( this is not entirely necessary, but the identification of where
  145. the problems originated will be much better if it is), compile the 
  146. object files, and link with the libdbmalloc.a (make sure it is before
  147. the libc.a on the link command - this is the default if you don't specifically
  148. include libc.a on your link).
  149.  
  150. For more info on how to use the library, see the man page in
  151. malloc.3 ([nt]roff source) or malloc.man (already nroffed).
  152.  
  153. --------------------------------------------------------------------------
  154. TEST PROGRAMS
  155.  
  156. The library comes with several test programs that should be run before
  157. it is installed on the system.  The tests are run automatically by the
  158. Runtests shell (which is invoked by make runtests).  Runtests will attempt
  159. to automatically determine if the library passes all of the tests and
  160. will save all of its output in the file Runtests.out.  If a failure is 
  161. reported, you should look at Runtests.out for more info on where the failure
  162. occurred.
  163.  
  164. The following test are run by the script:
  165.  
  166. testmalloc - this program runs through zillions of mallocs/reallocs and frees
  167. in order to exercise the malloc system.  The output from this program will
  168. look something like the following (NOTE that if run from the Runtests script,
  169. it will only run for 50000 iterations):
  170.  
  171.     MAXITER 1000000 MAXOBJS 1000 BIGOBJ 90000, TINYOBJ 80, nbig/ntiny 1/100
  172.     Memory use at start: 20140 bytes
  173.     Starting the test...
  174.     0 iterations
  175.     10000 iterations
  176.     20000 iterations
  177.     ....(lots of iterations skipped)....
  178.     980000 iterations
  179.     990000 iterations
  180.  
  181.     Did 1000000 iterations, 999 objects, 515733 mallocs, 484267 reallocs
  182.     Memory use at end: 1617580 bytes
  183.     Memory use after free: 1617580 bytes
  184.  
  185.     ************************************************************...
  186.                      FREE     FREE                 ...
  187.       PTR      NEXT     PREV     NEXT     PREV      FLAGS     ...
  188.     -------- -------- -------- -------- -------- ---------- -...
  189.     0x403C30 0x407510 0x000000 0x000000 0x000000 0x00000000  ...
  190.     0x407510 0x407640 0x403C30 0x000000 0x000000 0x03156111  ...
  191.     0x407640 0x000000 0x407510 0x000000 0x000000 0x03156100  ...
  192.     Malloc start:      0x403C30
  193.     Malloc end:        0x407640
  194.     Malloc data start: 0x407510
  195.     Malloc data end:   0x58F510
  196.     Malloc free list:  0x407640
  197.  
  198.     startsize 20140 != endsize 1617580
  199.  
  200. This is normal output.  If it doesn't get to the expected number of 
  201. iterations (50000 if run by runtest, or 1000000 if run from the command
  202. line with no other arguments) or if there are any allocations still in
  203. effect that were initiated by testmalloc.c, something went wrong (the
  204. library didn't pass the test).  Don't worry about having exact matches with
  205. the numbers listed above and don't worry that startsize != endsize.
  206.  
  207. Note that there may be several entries in the malloc chain if the C startup
  208. function has allocated data before the main gets called.  The key is that
  209. there are no allocated entries (those with the 1 bit on in the flags field)
  210. left that are identified as being allocated within the testmalloc.c file.
  211. In the example above, the middle entry does in fact have the 1 bit on, but
  212. in the info that was cut-off, there was no indication that it was allocated
  213. within testmalloc.c, therefore it must have been allocated somewhere else.
  214. The last line in the chain will usually say it was allocated within
  215. testmalloc.c; however, as in this case, it will also indicate that it is
  216. not in use (the 1 bit will be off in the flags field).
  217.  
  218. Most likely, if the program ran to completion (processed 1000000 iterations),
  219. the test was successful.
  220.  
  221. Also note that this program performs many small and large allocations and
  222. may take a long time to run.  The run time for various architectures (all
  223. done under fairly quiet system utilization):
  224.  
  225.     486/33 with cc under ISC UNIX 3.0:        1:17 (1 minute, 17 secs)
  226.     HP9000/857 with cc under HP/UX 8.0:        0:59
  227.     RS6000/320 with cc under AIX ?3.1?:        3:47
  228.     ATT 3B2/600 with cc under SVR4.1ES:           16:59
  229.  
  230. If this test takes too long for you, you can speed it up by setting 
  231. MALLOC_FILLAREA equal to zero.  This has the following effects on the 
  232. time it takes to run the tests:
  233.  
  234.     486/33 with cc under ISC UNIX 3.0:        0:45.8 (45 seconds)
  235.     HP9000/857 with cc under HP/UX 8.0:        0:33.4
  236.     RS6000/320 with cc under AIX ?3.1?:        3:47
  237.     ATT 3B2/600 with cc under SVR4.1ES:            7:04.2
  238.  
  239. If it is still too slow, you can add an argument to the program specifying
  240. the number of iterations.  The default is 1,000,000. 
  241.  
  242. One thing to think about before making a change to increase the performance
  243. of this test is that maintaining dynamic memory (along wit the additional
  244. debugging code that has been added) is a somewhat complex piece of software.
  245. It should be well tested before you place it into a user environment.
  246.  
  247. testmem - this program tests many of the string and memory functions to verify
  248. that they work as they are supposed to.  You should get no output from this
  249. test.  If you do, something is wrong.
  250.  
  251. testerr - this program tests several malloc related program errors (to make
  252. sure that the library is correctly identifying the problems).  The output
  253. from the test goes to stderr and should be similar to the following (although
  254. because of machine architectures the error messages may be slightly different):
  255.  
  256.     -------------------------------------
  257.     Error from strcpy() - out of bounds
  258.     MALLOC Warning from strncpy() (called from testerr.c line 33):
  259.     Pointer within malloc region, but outside of malloc data bounds
  260.     This error is *probably* associated with the following allocation:
  261.  
  262.         A call to malloc for 10 bytes in testerr.c on line 29.
  263.         This was the 2nd call to malloc.
  264.  
  265.     -------------------------------------
  266.     Error from memset() - out of bounds
  267.     MALLOC Warning from memset() (called from testerr.c line 37):
  268.     Pointer within malloc region, but outside of malloc data bounds
  269.     This error is *probably* associated with the following allocation:
  270.  
  271.         A call to malloc for 20 bytes in testerr.c on line 27.
  272.         This was the 1st call to malloc.
  273.  
  274.     -------------------------------------
  275.     Error from free() - overrun
  276.     MALLOC Warning from free() (called from testerr.c line 41):
  277.     Data has overrun beyond requested number of bytes
  278.     This error is *probably* associated with the following allocation:
  279.  
  280.         A call to malloc for 20 bytes in testerr.c on line 27.
  281.         This was the 1st call to malloc.
  282.  
  283.     MALLOC Warning from free() (called from testerr.c line 41):
  284.     Data has overrun beyond requested number of bytes
  285.     This error is *probably* associated with the following allocation:
  286.  
  287.         A call to malloc for 20 bytes in testerr.c on line 27.
  288.         This was the 1st call to malloc.
  289.  
  290.     -------------------------------------
  291.     Error from free() - double free
  292.     MALLOC Warning from free() (called from testerr.c line 45):
  293.     Data area is not in use (can't be freed or realloced)
  294.     This error is *probably* associated with the following allocation:
  295.  
  296.         A call to malloc for 20 bytes in testerr.c on line 27.
  297.         This was the 1st call to malloc.
  298.  
  299.         This block was freed on the 1st call to free()
  300.         in testerr.c on line 41.
  301.  
  302.     -------------------------------------
  303.     NO error from bzero
  304.     -------------------------------------
  305.     Error from bzero() - out of bounds
  306.     MALLOC Warning from bzero() (called from testerr.c line 53):
  307.     Pointer within malloc region, but outside of malloc data bounds
  308.     This error is *probably* associated with the following allocation:
  309.  
  310.         A call to malloc for 10 bytes in testerr.c on line 29.
  311.         This was the 2nd call to malloc.
  312.  
  313.     -------------------------------------
  314.     Error from free() - overrun
  315.     MALLOC Warning from free() (called from testerr.c line 57):
  316.     Data has overrun beyond requested number of bytes
  317.     This error is *probably* associated with the following allocation:
  318.  
  319.         A call to malloc for 10 bytes in testerr.c on line 29.
  320.         This was the 2nd call to malloc.
  321.  
  322.     MALLOC Warning from free() (called from testerr.c line 57):
  323.     Data has overrun beyond requested number of bytes
  324.     This error is *probably* associated with the following allocation:
  325.  
  326.         A call to malloc for 10 bytes in testerr.c on line 29.
  327.         This was the 2nd call to malloc.
  328.  
  329.     -------------------------------------
  330.     Error from free() - invalid magic
  331.     MALLOC Warning from free() (called from testerr.c line 61):
  332.     Malloc region does not have valid magic number in header
  333.     -------------------------------------
  334.     Error from memset() - out of bounds
  335.     MALLOC Warning from memset() (called from testerr.c line 68):
  336.     Pointer within malloc region, but outside of malloc data bounds
  337.     This error is *probably* associated with the following allocation:
  338.  
  339.         A call to malloc for 10 bytes in testerr.c on line 63.
  340.         This was the 3rd call to malloc.
  341.  
  342.     -------------------------------------
  343.     Error from malloc() - chain broken
  344.     MALLOC Warning from malloc() (called from testerr.c line 72):
  345.     Pointers between this segment and adjoining segments are invalid
  346.     This error is *probably* associated with the following allocation:
  347.  
  348.         A call to malloc for 10 bytes in testerr.c on line 63.
  349.         This was the 3rd call to malloc.
  350.  
  351.     MALLOC Warning from malloc() (called from testerr.c line 72):
  352.     Malloc region does not have valid magic number in header
  353.     MALLOC Fatal error from malloc() (called from testerr.c line 72):
  354.     Pointer is not within malloc area
  355.  
  356. abort-core dumped (or something about SIGIOT) can be expected at the end
  357. of the test because of a purposeful overwrite of memory.  Depending upon the
  358. architecture, the purposeful overwrite may actually cause some other form
  359. of core dump.  If it dumps somewhere in the last error, you can *probably*
  360. consider it normal.
  361.  
  362. teststack - this test verifies that the stack tracking mechanism still works.
  363. The program just uses the malloc_enter and malloc_leave macros to record a
  364. stack while allocating variables and then dumping the list.  The output
  365. should look something like the following:
  366.  
  367.     MALLOC Warning from strcpy() (called from teststack.c line 84):
  368.     Pointer within malloc region, but outside of malloc data bounds
  369.     This error is *probably* associated with the following allocation:
  370.  
  371.         A call to malloc for 1 bytes in teststack.c on line 82.
  372.         This was the 5th call to malloc.
  373.         Stack from where allocated:
  374.          -> sub3() in teststack.c(80)
  375.          -> sub2() in teststack.c(65)
  376.          -> sub1() in teststack.c(46)
  377.          -> main() in teststack.c(27)
  378.  
  379.     MALLOC Warning from strcpy() (called from teststack.c line 84):
  380.     Pointer within malloc region, but outside of malloc data bounds
  381.     This error is *probably* associated with the following allocation:
  382.  
  383.         A call to malloc for 1 bytes in teststack.c on line 82.
  384.         This was the 7th call to malloc.
  385.         Stack from where allocated:
  386.          -> sub3() in teststack.c(80)
  387.          -> sub1() in teststack.c(46)
  388.          -> main() in teststack.c(27)
  389.  
  390.     MALLOC Warning from strcpy() (called from teststack.c line 84):
  391.     Pointer within malloc region, but outside of malloc data bounds
  392.     This error is *probably* associated with the following allocation:
  393.  
  394.         A call to malloc for 1 bytes in teststack.c on line 82.
  395.         This was the 9th call to malloc.
  396.         Stack from where allocated:
  397.          -> sub3() in teststack.c(80)
  398.          -> sub2() in teststack.c(65)
  399.          -> sub1() in teststack.c(46)
  400.          -> main() in teststack.c(27)
  401.  
  402.     MALLOC Warning from strcpy() (called from teststack.c line 84):
  403.     Pointer within malloc region, but outside of malloc data bounds
  404.     This error is *probably* associated with the following allocation:
  405.  
  406.         A call to malloc for 1 bytes in teststack.c on line 82.
  407.         This was the 13th call to malloc.
  408.         Stack from where allocated:
  409.          -> sub3() in teststack.c(80)
  410.          -> sub2() in teststack.c(65)
  411.          -> main() in teststack.c(27)
  412.  
  413.     MALLOC Warning from strcpy() (called from teststack.c line 84):
  414.     Pointer within malloc region, but outside of malloc data bounds
  415.     This error is *probably* associated with the following allocation:
  416.  
  417.         A call to malloc for 1 bytes in teststack.c on line 82.
  418.         This was the 15th call to malloc.
  419.         Stack from where allocated:
  420.          -> sub3() in teststack.c(80)
  421.          -> main() in teststack.c(27)
  422.  
  423.     ************************** Dump of Malloc Chain ******************...
  424.     POINTER     FILE  WHERE         LINE      ALLOC        DATA     HE...
  425.     TO DATA      ALLOCATED         NUMBER     FUNCT       LENGTH  OF B...
  426.     -------- -------------------- ------- -------------- ------- -----...
  427.     0x404D94 teststack.c               29 malloc(2)           10 01010...
  428.          -> main() in teststack.c(27)
  429.     0x404DE8 teststack.c               48 malloc(3)            0        
  430.          -> sub1() in teststack.c(46)
  431.          -> main() in teststack.c(27)
  432.     0x404E34 teststack.c               67 malloc(4)            0       
  433.          -> sub2() in teststack.c(65)
  434.          -> sub1() in teststack.c(46)
  435.          -> main() in teststack.c(27)
  436.     0x404E80 teststack.c               82 malloc(5)            1 31   
  437.          -> sub3() in teststack.c(80)
  438.          -> sub2() in teststack.c(65)
  439.          -> sub1() in teststack.c(46)
  440.          -> main() in teststack.c(27)
  441.     0x404ECC teststack.c               71 malloc(6)           10 01010...
  442.          -> sub2() in teststack.c(65)
  443.          -> sub1() in teststack.c(46)
  444.          -> main() in teststack.c(27)
  445.     0x404F20 teststack.c               82 malloc(7)            1 31  
  446.          -> sub3() in teststack.c(80)
  447.          -> sub1() in teststack.c(46)
  448.          -> main() in teststack.c(27)
  449.     0x404F6C teststack.c               67 malloc(8)            0    
  450.          -> sub2() in teststack.c(65)
  451.          -> sub1() in teststack.c(46)
  452.          -> main() in teststack.c(27)
  453.     0x404FB8 teststack.c               82 malloc(9)            1 31
  454.          -> sub3() in teststack.c(80)
  455.          -> sub2() in teststack.c(65)
  456.          -> sub1() in teststack.c(46)
  457.          -> main() in teststack.c(27)
  458.     0x405004 teststack.c               71 malloc(10)          10 01010...
  459.          -> sub2() in teststack.c(65)
  460.          -> sub1() in teststack.c(46)
  461.          -> main() in teststack.c(27)
  462.     0x405058 teststack.c               56 malloc(11)          10 01010...
  463.          -> sub1() in teststack.c(46)
  464.          -> main() in teststack.c(27)
  465.     0x4050AC teststack.c               67 malloc(12)           0   
  466.          -> sub2() in teststack.c(65)
  467.          -> main() in teststack.c(27)
  468.     0x4050F8 teststack.c               82 malloc(13)           1 31 
  469.          -> sub3() in teststack.c(80)
  470.          -> sub2() in teststack.c(65)
  471.          -> main() in teststack.c(27)
  472.     0x405144 teststack.c               71 malloc(14)          10 01010...
  473.          -> sub2() in teststack.c(65)
  474.          -> main() in teststack.c(27)
  475.     0x405198 teststack.c               82 malloc(15)           1 31
  476.          -> sub3() in teststack.c(80)
  477.          -> main() in teststack.c(27)
  478.  
  479.  
  480. The item of importance is the presence of the stack information on the
  481. lines with the arrows (->).
  482.  
  483.