Tool Mentor: Detecting
Run-time Errors Using Rational Purify and Rational PurifyPlus (Windows)
Purpose
This tool mentor provides an overview of how to use Rational Purify to
find run-time errors in Visual C/C++ programs. This tool mentor is
applicable for use with systems running Microsoft Windows.
PurifyPlus is a Rational product that includes Purify functionality.
To learn more about Purify,
read the Getting Started manual for the PurifyPlus product family
(Windows version).
For step-by-step information about using Purify, see the Purify online Help.
Related Rational Unified Process information:
Overview
Purify detects run-time errors, including memory leaks, both in your own
code and in the components your software uses, even when you don't have the
source code. It reports memory errors such as array bounds errors, access
through dangling pointers, uninitialized memory reads, memory allocation errors,
and memory leaks, so that you can resolve them before they do any damage. If you
have Rational PureCoverage on your system, Purify can also report how thoroughly
you have tested your code for errors.
Tool Steps
To test a program using Purify:
- Run the program with Purify to collect
error data and (optionally) coverage data
- Analyze the Purify error data
- Correct the errors and rerun the program
If you collected coverage data, take one more step to ensure that you've
Purify'd your entire program:
- Analyze the Purify coverage data to find untested code
1. Run the program with Purify to
collect error data and (optionally) coverage data
The first step in Purify'ing your code is to run your program under Purify.
If you are working in Microsoft Visual Studio, first select the Visual Studio
menu item Purify > Engage Purify Integration. If you have
PureCoverage on your system, select Purify > Collect Coverage Dataset
as well, instructing Purify to monitor code coverage. Then run your program in
Visual Studio as usual.
If you are using Purify as a standalone program, not integrated with Visual
Studio, run your program in the Purify user interface by selecting File >
Run.
Purify instruments a copy of your program and associated modules, inserting
instructions for detecting errors and monitoring coverage, and then starts your
program. As you exercise the program, Purify displays a Data Browser window with
an Error View tab that contains detailed diagnostics about the run-time
errors it detects.
When you exit the program, Purify reports memory leaks. You can specify
additional settings to have Purify also report memory and handles in use at
exit.
Purify uses a default level of instrumentation for each component, but you
can override the default settings to focus on specific parts of your code. You
can also set options to control how Purify handles error data. For example, you
can increase the length of call stacks recorded for errors and allocations in
order to pinpoint errors more easily.
Tip: In addition to using Purify interactively, you can incorporate
Purify into your test scripts, makefiles, and batch files for automated testing.
For more
information, look up the following topics in the Purify online Help
index:
- instrumenting
- running programs
- powercheck
- scripts
2. Analyze the Purify error data
The second step in Purify'ing your code is to analyze the Purify error data.
By default, the error view initially displays only the first line of each
message. This condensed outline format makes it easy to scan the messages,
quickly identify critical errors, and assess the state of the program. You can
expand the outline to see more detailed diagnostic information.
Using this error view information, you can identify, understand, and
eliminate hard-to-find memory access errors and memory leaks. You can also
examine the source code, if debug and relocation data were available when the
program was instrumented. Because Purify detects access errors at the point
where they occur, you can easily track and eliminate these errors.
A large program can generate hundreds of error messages. For this reason,
Purify provides filters to hide messages so that you can focus quickly on the
most critical errors.
Tip: If you have incorporated Purify into your test scripts,
makefiles, and batch files, you can automatically save error messages to an
ASCII text file.
For more information, look up the
following topics in the Purify online Help index:
- scripts
- error messages
- error view
- filters
3. Correct the errors and rerun the program
The third step in Purify'ing your code is to correct the errors and rerun the
program.
To correct errors, double-click the line where the error occurs. Purify opens
your source code in your editor at the exact location of the error, ready for
correction.
After you correct and rebuild the program, you can verify your correction by
rerunning the updated program and comparing the new results to the previous run.
Repeat the cycle of instrumenting and running, analyzing, and correcting until
your program runs clean.
You can use the Navigator window to switch between runs, and keep track of
all the runs you're working with. You can also save error view data as a Purify
data file, to share with colleagues who have Purify.
For more information, look up the following topics in the Purify online
Help index:
4. Analyze the Purify coverage data to find untested
code
If you collected coverage data for the program runs, you can also find the
parts of your code that you have not Purify'd. Use this information to improve
your testing coverage so that you find all of the errors in your program,
wherever they occur.
When you exit your program, Purify displays the coverage data in the Module
View, File View, and Function List View tabs of the Data
Browser window. These tabs show information such as the number of functions and
lines hit and missed by your tests, as well as the percentage of functions and
lines hit and missed. If debug line data is available and you monitored your
code at line level, you can also use the Annotated Source window to analyze
coverage for functions line by line.
Purify automatically filters out coverage data that is less interesting, such
as data from system libraries, before displaying coverage data. You can create
your own filters to hide additional data that you do not want to see, so that
you can focus on what's important to your analysis.
By default, Purify automatically creates an Auto Merge entry in the Navigator
window, so that you can easily analyze the total coverage of the program over
multiple runs. You can also merge specific runs yourself to see the cumulative
effect of selected runs.
When you find weak spots in your coverage, rerun your program and test all of
the important parts, or revise your makefiles or test scripts to do a more
thorough job. You can now have the confidence that errors are not lurking
somewhere in the code that you failed to test, waiting to cause unexpected
problems.
Tip: You can use /Coverage
and related options to collect coverage data with Purify during automated
testing.
For more information, look up the following topics in the Purify online
Help index:
- command line options
- coverage data
Copyright
© 1987 - 2001 Rational Software Corporation
|