File mtrace.icn |
Read the output log from the GCC mtrace facility (man mtrace)
and produce a summary of problems that have been found.
Maps problems back to source file and line where possible.
Three types of errors can be detected and reported:
-- cases where memory is allocated, but not freed
-- cases where an attempt is made to free already freed memory
-- cases where an attempt is made to free memory that was never allocated
For example, here is the output from this program when run on a test program:
Allocation that is not freed: 0x8831f90[ 1024 bytes] <- test.c:[197] 0x88337c0[ 1024 bytes] <- test.c:[197] 0x8832fb0[ 1024 bytes] <- test.c:[197] 0x8831780[ 1024 bytes] <- test.c:[197] 0x88327a0[ 1024 bytes] <- test.c:[197] 0x88333d8[ 50 bytes] <- test.c:[159] Duplicated free: 0x98c1378[ 1024 bytes] <- test.c:[209] <test.c[197]> 0x98c1b88[ 1024 bytes] <- test.c:[209] <test.c[197]> 0x98c2398[ 1024 bytes] <- test.c:[209] <test.c[197]> 0x98c2ba8[ 1024 bytes] <- test.c:[209] <test.c[197]> 0x98c33b8[ 1024 bytes] <- test.c:[209] <test.c[197]>(There were no attempts to free unallocated memory in this example) The first field of each record is the memory address of the region that is being allocated/freed, the second (when present) is the size of that allocation, the third is the source code file and the fourth is the line number in that file where the allocation/free took place. Note that the report on each duplicate free provides the location where the free was attempted and also the location where the allocation took place as a fifth field.
This file is part of the (main) package.
Source code.Details |
Procedures: |
getFileAndLine(fName, codeLoc)
Produces a list containing the source file name and source line number (in order), given the object file name and byte offset into the code.
mkFreeRec(fName, codeLoc, alloLoc, tr)
Construct a record of a duplicated free. Includes both the source location of the free, but also of the original allocation.
mkRec(fName, codeLoc, alloLoc, alloSize)
fName | -- name of executable unit involved |
codeLoc | -- hexadecimal address within that unit |
Construct a report line from the information parsed from the gcc mtrace log. This includes determining the source file name and line number within that source file where the allocation/free took place that caused this record to exist. <[ram alloSize -- size (if known) of the allocation
Process the lines in a gcc mtrace log file.
This procedure builds up three lists of information based
on the contents of that log file:
-- a list of those malloc()s that don't have associated
frees (global variable noFree)
-- a list of those free()s that attempt to free memory
that was never allocated (noMalloc)
-- a list of those free()s that attempt to free memory
that as already be freed (dupFree)
prompt | -- header line identifying the trace category |
A | -- list of trace records |
Displays all the record lines for a specific category.
Records: |
traceRecord(fName, size, memAddr, alloAddr, freeAddr)
traceRecords are used within the process procedure to track the allocation/free cycles for memory requests.
Global variables: |