Oracle® Solaris Studio 12.4: Overview

Exit Print View

Updated: December 2014
 
 

discover Tool for Detecting Memory Errors

The Memory Error Discovery Tool (discover) is an advanced development tool for detecting memory access errors in your programs. Compiling a binary with –g enables discover to display source code and line number information while reporting errors and warnings.

The discover utility is simple to use. After compiling your binary with the–g option, you run the discover command on the binary to instrument it. Then you run the instrumented binary to create a discover report. You can request the discover report in HTML format, text format, or both. The report shows memory errors, warnings, and memory leaks, and you can display the source code and stack trace for each error or warning.

The following example from the discover(1) man page shows how to prepare, instrument, and run an executable to generate a discover report for detecting memory access errors. The –w option on the discover command line indicates the report should be written as text and the –o option indicates that the output should go to the screen.

% cc -g -O2 test.c -o test.prep
% discover -w - -o test.disc test.prep
% ./test.disc
ERROR (UMR): accessing uninitialized data from address 0x5000c (4 bytes) at:
     foo() + 0xdc  <ui.c:6>
          3:    int *t;
          4:    foo() {
          5:     t = malloc(5*sizeof(int));
          6:=>   printf("%d0, t[1]);
          7:    }
          8:
          9:    main()
     main() + 0x1c
     _start() + 0x108
    block at 0x50008 (20 bytes long) was allocated at:
     malloc() + 0x260
     foo() + 0x24  <ui.c:5>
          2:
          3:    int *t;
          4:    foo() {
          5:=>   t = malloc(5*sizeof(int));
          6:     printf("%d0, t[1]);
          7:    }
          8:
     main() + 0x1c
     _start() + 0x108

     ***************** Discover Memory Report *****************

1 block at 1 location left allocated on heap with a total size of 20 bytes

    1 block with total size of 20 bytes
     malloc() + 0x260
     foo() + 0x24  <ui.c:5>
          2:
          3:    int *t;
          4:    foo() {
          5:=>   t = malloc(5*sizeof(int));
          6:     printf("%d0, t[1]);
          7:    }
          8:
     main() + 0x1c
     _start() + 0x108

For more information, see the discover(1) man page and Oracle Solaris Studio 12.4: Discover and Uncover User’s Guide .