How can you use the selective instrumentation (SI) feature in IBM Rational PurifyPlus, Rational Purify, Rational PureCoverage, or Rational Quantify?
Selective Instrumentation allows you to instrument a select group of modules instead of instrumenting an entire application. Although the functionality is similar to SI for Quantify and PureCoverage, there are some additional steps and considerations that apply specifically to Purify only.
Enabling and Using Selective Instrumentation
To enable selective instrumentation (SI), follow these steps:
- Add the following system-wide environment variable:
- Select Start > Settings > Control Panel > System. On the Advanced tab, select Environment Variables.
- Click New under "System variables".
- Set "Variable Name" equal to IBM_RATIONAL_PURIFY_ENABLE_SELECTIVE.
- Set "Variable Value" equal to 1.
- Rebuild the target modules with the static version of the C Runtime (CRT).
Purify manipulates memory in a way that can only be handled properly by instrumented modules. In order for SI to function properly, you must isolate the CRT heap being used by instrumented modules. The recommended way to achieve heap isolation is by building all modules that you plan to instrument with a static CRT. This ensures that each instrumented module has its own isolated CRT heap.
Switching to a static CRT can pose problems for modules that share CRT resources. See the MSDN article, Potential Errors Passing CRT Objects Across DLL Boundaries, linked under Related URL for additional information.
If you need to share CRT resources or you are otherwise unable to rebuild your modules with a static CRT, see the "Dynamic CRT Workaround" section at the end of this technote.
To use the static version of the CRT, replace /MD or /MDd with /MT (release) or /MTd (debug). This change needs to be made on all compile lines for the target module and all static libraries linked into the target module.
The change can also be made through the Visual Studio IDE:
- Visual Studio 6 (VS6):
Select Project > Settings > C/C++ tab > Category: "Code Generation" > Use runtime library: "Multithreaded" or "Debug Multithreaded"
- Visual Studio .NET (VS.NET 2002, VS.NET 2003, VS.NET 2005):
Select Project > Properties > C/C++ folder > Code Generation > Runtime Library: "Multi-threaded" or "Multi-threaded Debug"
The change should be made at the root configuration level for the target module and all static dependencies. It is not necessary to change the build settings for modules that are not instrumented.
If you need to use /MT or /MTd with a module that links with MFC, then you also need to use the static version of the MFC libraries:
- VS 6:
Select Project > Settings > General tab > Microsoft Foundation Classes: "Use MFC in a Static Library"
Select Project > Properties > General > Use of MFC: "Use MFC in a Static Library"
- Visual Studio 6 (VS6):
- Verify that you have the recommended build options set:
You should also verify that the target modules are built with the standard recommended settings for PurifyPlus. At a minimum, SI requires debug information and relocation data for the target modules.
See Recommended Settings for Visual Studio 6 or Recommended Settings for Visual Studio in the IBM Rational Purify help documentation for more information about these settings. If you build from the command line or through make files, see technote 1265414: Recommended Settings for Microsoft Visual Studio to use with PurifyPlus when building from the command line for the command line equivalent options to these settings.
- Selectively instrument the target modules:
- Start the Purify GUI
- Select Settings > Default Settings > PowerCheck > Selected Modules > Configure
- Add the target modules to the list
- Set each module's Instrumentation State to "Permanent"
- Click OK to instrument the selected modules
- Start the Purify GUI
- Run your application as you normally would outside of Purify. When an instrumented module is loaded, Purify will automatically start collecting data.
Dynamic CRT Workaround
It is highly recommended that you use a static CRT with SI, however, this is not always possible. Heap isolation can also be achieved through careful use of the dynamic debug CRT.
- All instrumented modules must link with the debug version of the dynamic CRT (/MDd).
- All uninstrumented modules must use a different CRT (/MD, /MTd, or /MT).
If you are using Visual Studio 2005 or 2008, you should do the following:
- Start your application under a debugger and set a breakpoint inside the module of interest (Purify should not be involved at this point).
- After the breakpoint is hit, go to the modules window and note the exact location of the loaded CRT libraries. The directory name should look something like the following: C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.507
- Selectively instrument (in permanent mode) the module or modules of interest and the CRT library or libraries in the directory, found in step 2.
- Run the application.
- Debug assertion failures received during an SI run may indicate that the CRT usage guidelines have not been met.
- The use of SI without adhering to the CRT usage guidelines is not supported.
- To see a viewlet on using Selective Instrumentation, go to this IBM Education Assistant module.
- For more information on using selective instrumentation with your application, contact IBM Rational Support.
|Software Development||Rational PureCoverage||Instrumentation||Windows||7.0.1, 7.0|
|Software Development||Rational Purify||Instrumentation||Windows||7.0.1, 7.0|
|Software Development||Rational Quantify||Instrumentation||Windows||7.0.1, 7.0|