|
Man Page discover.1NAME
discover - Sun Memory Error Discovery Tool
SYNOPSIS
discover
[-?] [-h] [-k] [-o file] [-s] [-v] [-w file] [-D dir]
[-H] [-K] [-L] [-N lib] [-T] [-V] target
DESCRIPTION
Sun Memory Error Discovery Tool (Discover) is a tool used by
software developers to detect programming errors related to
the allocation and use of program memory at runtime.
Examples of errors detected by Discover include:
* Accessing uninitialized memory.
* Reads from and writes to unallocated memory.
* Accessing memory beyond allocated array bounds.
* Use of freed memory.
* Freeing wrong memory blocks.
* Memory leaks.
Here is a simple example of preparing, instrumenting, and
running an executable:
% cc -g -O2 -xbinopt=prepare test.c -o test.prep
% discover -o test.prep.disc test.prep
% test.prep.disc
ERROR (UAW): writing to unallocated memory at address 0x50014 (4 bytes) at:
main() + 0x58 [test.prep.disc:0x30058]
<test.c:5>:
2: int main()
3: {
4: int *p = (int*) malloc(sizeof(int));
5:=> *(p+1) = 1;
6: return 0;
7: }
_start() + 0x108 [test.prep.disc:0x107b4]
DISCOVER SUMMARY:
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
The compiler options "-xbinopt=prepare" and "-O1" or greater
are required to prepare a binary for Discover. Also using
"-g" allows Discover to produce more informative messages.
MESSAGES
Discover may produce the following error messages:
ERROR (UAR) reading from unallocated memory
ERROR (UAW) writing to unallocated memory
ERROR (FMR) reading from freed memory
ERROR (FMW) writing to freed memory
ERROR (UMR) accessing uninitialized data
ERROR (PIR) accessing partially initialized data
ERROR (ABR) reading memory beyond array bounds
ERROR (ABW) writing to memory beyond array bounds
ERROR (DFM) double freeing memory
ERROR (BFM) freeing wrong memory block
ERROR (BRP) bad address parameter for realloc
ERROR (SBR) read is beyond current stack bounds
ERROR (SBW) write is beyond current stack bounds
ERROR (IMR) read from invalid memory address
ERROR (IMW) write to invalid memory address
ERROR (FRP) freed pointer passed to realloc
ERROR (AZS) allocating zero size memory block
OPTIONS
The following options are supported:
-? -h
Print help message.
-k Force reinstrumentation.
-o file
Instrumented output filename.
-s OK if dependent libraries are not instrumentable.
-v Verbose.
-w file
Write Discover analysis to file
-D dir
Cache Directory. The default is $HOME/SUNW_Bit_Cache.
-H Output analysis in HTML format.
-K Do not read the bit.rc initialization files.
-L Enable Memory leak detection.
-N lib
Ignore lib.
-T Do not instrument libraries at run time.
-V Print version.
EXIT STATUS
The following exit values are returned:
0 All input files were output successfully.
1 An error occurred.
ENVIRONMENT VARIABLES
Discover supports a number of environment variables that
begin with the characters "DISCOVER_". These environment
variables must be set before the target program is run, and
they allow the user to control Discover behavior at runtime.
For example the name of the report file can be changed at
runtime by setting environment variable DISCOVER_OUTPUT to a
new file name.
The list of environment variables together with explanations
is provided below:
DISCOVER_GUARD_SIZE
Integer value determines the size of array guard
blocks.
DISCOVER_HTML
If set to 1 will set the report format to HTML. If set
to 0 - the output format will be ASCII (default).
DISCOVER_LEAK_STACK_DEPTH
The number of function on top of the stack counted to
disambiguate memory leak locations. When set to 0 whole
stack is counted. Default value is 5.
DISCOVER_MEMORY_LEAKS
If set to 1 will enable memory leak detection. When
set to 0 value will disable memory leak detection
(default).
DISCOVER_OUTPUT
Sets the name of the Discover report file. Default is
not set.
DISCOVER_QUOTE_LINES
Sets the number of source lines included in the report.
Default value is 7.
DISCOVER_STRONG_FREE
When set to 1 will allow application to reuse freed
memory (default). When set to 0 makes freed memory una-
vailable for the following allocation. Note that 0
value can significantly increase memory consumption of
the application.
DISCOVER_WWW
If set to the name of the HTML browser program (e.g.
"mozilla"), it will force generation of the HTML report
and will launch the browser with the report. Default -
not set.
SUNW_BIT_CACHE_DIR
This environment variable, if set, specifies the root
directory for the cache where Discover stores instru-
mented shared libraries. Its setting overrides the
value specified by the -D cachedir flag, and the
default, which is $HOME/SUNW_Bit_Cache.
EXAMPLES
EXAMPLE #1
This example examines a program that contains a use of unin-
itialized data:
% cat dtest_1.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char s[10];
printf("s[1] = %d0,s[1]);
return 0;
}
% cc -g -O1 -o dtest_1 dtest_1.c
% dtest_1
s[1] = 5
% cc -g -O1 -xbinopt=prepare -o dtest_1.prep dtest_1.c
% dtest_1.prep
s[1] = 5
% discover -o dtest_1.prep.discover dtest_1.prep
% dtest_1.prep.discover
ERROR (UMR): accessing uninitialized data from address 0xffbff023 (1 byte) at:
main() + 0x4c [dtest_1.prep.discover:0x3004c]
<dtest_1.c:7>:
4: int main(int argc, char *argv[])
5: {
6: char s[10];
7:=> printf("s[1] = %d0,s[1]);
8: return 0;
9: }
10:
_start() + 0x108 [dtest_1.prep.discover:0x107cc]
s[1] = 5
DISCOVER SUMMARY:
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
EXAMPLE #2
This example examines a program that attempts to write
beyond array bounds:
% cat dtest_2.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *cp;
cp = (char *)malloc(10);
cp[11] = 't';
return 0;
}
% cc -g -O1 -xbinopt=prepare -o dtest_2.prep dtest_2.c
% discover -o dtest_2.prep.discover dtest_2.prep
% dtest_2.prep.discover
ERROR (ABW): writing to memory beyond array bounds at address 0x50013 (1 byte) at:
main() + 0x138 [dtest_2.prep.discover:0x30138]
<dtest_2.c:8>:
5: {
6: char *cp;
7: cp = (char *)malloc(10);
8:=> cp[11] = 't';
9: return 0;
10: }
11:
_start() + 0x108 [dtest_2.prep.discover:0x107cc]
block at 0x50008 (10 bytes long) was allocated at:
malloc() + 0x144 [libdiscover.so:0xe11c]
main() + 0x90 [dtest_2.prep.discover:0x30090]
<dtest_2.c:7>:
4: int main(int argc, char *argv[])
5: {
6: char *cp;
7:=> cp = (char *)malloc(10);
8: cp[11] = 't';
9: return 0;
10: }
_start() + 0x108 [dtest_2.prep.discover:0x107cc]
DISCOVER SUMMARY:
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
EXAMPLE #3
This example uses the Discover -H option to send the Dis-
cover output to an HTML file (using the same example code as
Example #2 above).
% cc -g -O1 -xbinopt=prepare -o dtest_2.prep dtest_2.c
% discover -o dtest_2.prep.discover dtest_2.prep
% dtest_2.prep.discover
% ls
dtest_2.c
dtest_2.prep*
dtest_2.prep.disc*
dtest_2.prep.disc.html
Notice that Discover did not print messages but generated an
HTML file that provides a summary and an easy-to-use click-
for-details interface.
REQUIREMENTS
Operating System Requirements
The Discover software works only on Solaris versions 9
and 10. Correct results on newer versions of Solaris is
not guaranteed.
Patches
To run Discover-instrumented binaries on Solaris 9 sys-
tems earlier than S9U7, linker patch 112963-14 must be
installed.
Single-threaded Applications
The current release of the Discover software will work
only for single-threaded applications. Future releases
will support multi-threaded applications.
Preparation of Input Binary for Discover
The Discover software will work only with binaries com-
piled with Sun Studio 12 compiler or GCC for SPARC Sys-
tems 4.0.4 compiler. To use Discover on a binary, it
needs to be compiled and linked with optimizations (-O
or -xO[n] for Studio compiler and -O[n] for gcc for
SPARC systems) AND a special compiler flag
-xbinopt=prepare . When this is done, additional infor-
mation is added to the binary to help Discover
correctly instrument the binary. If the user tries to
run Discover on a binary which is not compiled and
linked with an optimization flag and -xbinopt=prepare,
Discover will issue an error and will not instrument
the binary. We also strongly recommend using the -g
flag while building the binary. If -g flag is not used,
Discover will not display source code and line number
information while reporting errors and warnings.
Instead it will just display program counters(PCs) of
the corresponding machine level instructions, which may
not be as helpful to the user. Also, using -g will help
the Discover software produce more accurate results.
FILES
DISCOVER AND BIT .rc FILES
Discover initializes its state by reading a series of .rc
files at startup. A system file,
<compiler_area>/prod/lib/postopt/bit.rc, provides default
values for certain variables. Discover reads this file
first, then $HOME/.bit.rc, if it exists, then `pwd`/.bit.rc,
if it exists.
The .rc files contain commands to set, append to, and remove
from variables. Whenever a set command is seen, the previous
value of the variable (if any) is discarded. An append com-
mand will cause its argument to be appended (after a colon
separator) to the existing value of the variable. A remove
command will cause its argument to be removed (along with a
colon separator) from the existing value of the variable.
The variables set in the .rc files include the list of
libraries to ignore while instrumenting, and lists of func-
tions or function prefixes to ignore when computing the per-
centage of nonannotated code in a binary.
For more information, see the header in the system .rc file.
SEE ALSO
bit(1), CC(1), cc(1), f77(1), f90(1), f95(1), gcc(1).
Man(1) output converted with man2html |
|
![]() |
By any use of this Website, you agree to be bound by these Policies and Terms of Use. |