2. Sun Memory Error Discovery Tool (Discover)
Requirements for Using Discover
Binaries Must Be Prepared Correctly
Binaries That Use Preloading or Auditing Cannot Be Used
Binaries That Redefine Standard Memory Allocation Functions Can Be Used
Instrumenting a Prepared Binary
Instrumenting Shared Libraries
SUNW_DISCOVER_OPTIONS Environment Variable
SUNW_DISCOVER_FOLLOW_FORK_MODE Environment Variable
Running an Instrumented Binary
Memory Access Errors and Warnings
Interpreting Discover Error Messages
Limitations When Using Discover
Only Annotated Code is Instrumented
Machine Instruction Might Differ From Source Code
Compiler Options Affect the Generated Code
System Libraries Can Affect the Errors Reported
Custom Memory Management Can Affect the Accuracy of the Data
Out of Bounds Errors for Static and Automatic Arrays Cannot Be Detected
The following is an example of preparing a program, instrumenting it with Discover, and then running it and producing a report on the detected memory access errors. This example uses a simple program that accesses uninitialized data.
% cat test_UMR.c #include <stdio.h> #include <stdlib.h> int main() { // UMR: accessing uninitialized data int *p = (int*) malloc(sizeof(int)); printf("*p = %d\n", *p); free(p); } % cc -g -02 test_UMR.c % a.out *p = 131464 % discover -w - a.out % a.out ERROR (UMR): accessing uninitialized data from address 0x50010 (4 bytes) at: main() + 0x54 <test_UMR.c:7> 4: { 5: // UMR: accessing uninitialized data 6: int *p = (int*) malloc(sizeof(int)); 7:=> printf(**p = %d\n", *p); 8: free(p); 9: } _start() + 0x108 block at 0x50010 (4 bytes long) was allocated at: malloc() + 0x220 main() + 0x1c <test_UMR.c:6> 3: int main() 4: { 5: // UMR: accessing uninitialized data 6:=> int *p = (int*) malloc(sizeof(int)); 7: printf(**p = %d\n", *p); 8: free(p); 9: } _start() + 0x108 *p = 327704 **************** Discover Memory Report ***************** No allocated memory left on program exit. DISCOVER SUMMARY: unique errors : 1 (1 total, 0 filtered) unique warnings : 0 (0 total, 0 filtered) FILTERS: type=ML:func=_rt_boot:depth=*; type=*:func__f90_esfw:depth=*; type=ML:func=__f90_ssfw:depth=*;
The Discover output shows where the uninitialized memory was used and where it was allocated, along with summary of results.