Develop Better Software Faster with IBM Rational Systems Developer and IBM Rational PurifyPlus

from The Rational Edge: This article describes how to use the IBM Rational PurifyPlus for Linux and UNIX family of runtime analysis tools from the IDE to improve the quality and performance of their software products. Written specially for users of IBM Rational Systems Developer Version7.0.


Anandi Krishnamurthy, Runtime Analysis Project Manager, IBM, Software Group

Author photoAnandi Krishnamurthy is a senior software engineer in the IBM Rational PurifyPlus team. Her areas of interest include C/C++ and Java Runtime Analysis, Eclipse TPTP, and CDT.

15 April 2007

Also available in Chinese

New forum for Rational Edge readers
At the end of this article, you'll find a link to a new forum created specially for readers of The Rational Edge ezine. Get ready to add your thoughts about this article or other topics you've found in our pages.

race car at a pit stopWritten for users of IBM® Rational® Systems Developer Version 7.0 (RSD), this article describes how to use the IBM Rational PurifyPlus™ for Linux and UNIX family of runtime analysis tools from RSD to improve the quality and performance of software products. Rational Systems Developer V7.0 leverages the power of Eclipse and helps development teams use UML 2 to create well-architected, model-driven C/C++, Java™ (J2SE™), and CORBA®-based applications. Rational PurifyPlus for Linux and UNIX is a runtime analysis toolset for Linux- and UNIX-based Java and C/C++ development that pinpoints memory errors and leaks, profiles application performance, and analyzes code coverage.

RSD supports three broad types of C/C++ projects: Managed Make, Standard Make, and Remote Invocation. This paper describes running PurifyPlus with each type of project. Before starting RSD, please make sure that the PurifyPlus tools are in your path. You can confirm this by running "<tool name> -version" from the command line, where <tool name> is purify, quantify, or purecov.

Managed Make C++ project

"Managed Make" refers to the type of project where the IDE creates and manages the makefiles. You control the characteristics of the makefile by specifying appropriate properties for your project using the Project Properties GUI. Through this GUI, you may specify different types of builds, such as debug and release builds. Each build is specified using a Build Configuration and the IDE automatically creates a makefile for each Build Configuration.

To invoke a tool in the PurifyPlus family of tools on the executables created in a Managed Make C++ project, you start with the pre-built Debug Build Configuration and modify it to invoke the PurifyPlus tool you wish to use.

The steps to do this are:

  • Open the C/C++ Perspective and go to the C/C++ Projects pane.
  • Right-click on the project entry ("Shapes" is the example name shown in Figure 1) and select Properties.
  • In the Properties window, select C/C++ Build from the list on the left.
  • Click Manage.
  • In the Manage window, click New to create a new configuration. You can name this as you wish; in the example we have chosen purify.
  • In the Create configuration window, select an appropriate configuration to copy most of the properties. We have chosen the Debug configuration.
  • Click OK twice until you are back in the Properties window, shown in Figure 1.

A screen image of the PurifyPlus properties window

Figure 1: Creating the Purify configuration
Click to enlarge

Your new configuration should appear on the drop-down list in the Properties for <Project Name> window. To make your application build with Purify, select the purify configuration, then select GCC C++ Linker in the Tool Settings tab. The Command field should name your linker command, most likely g++. Precede these characters with the word purify and a space, so the command reads "purify g++" as shown. When you put "purify" (or "quantify" or purecov) at the start of your link command, the PurifyPlus tools intercept the command and instruments all the files being linked. (Instrumentation is when the PurifyPlus tools perform Object Code Insertion (OCI) on C/C++ object files and libraries.)

Screen image shows making a build with Purify

Figure 2: Customizing the link command to build with Purify
Click to enlarge

Now select the Build Settings tab and enter an extension to identify your Purify'd executable. The example in Figure 3 uses p. Click Apply to save the changes to the newly created Configuration.

Screen image shows creating artifact extension in Purify

Figure 3: Naming the Purify'd executable
Click to enlarge

Whenever the project is being built or re-built you will see console output from Purify, as shown in Figure 4.

Screen image shows output from Purify

Figure 4: Console output from Purify
Click to enlarge

To run your Purify'd program, go to where the binaries are listed in your Project tab and right-click on the Purify'd binary ("Shapes.p" in the example). Select Run As > Run Local C/C++ Application. The Purify window comes up as shown in Figure 5. As you exercise your application, Purify displays memory errors your testing exposes. When you exit your program, Purify lists all memory leaks. Please refer to PurifyPlus documentation for more advanced use patterns. After analyzing the errors in the Purify window, quit Purify. RSD will consider your application to be active as long as the Purify window is open. This is a current limitation.

Screen image of Purify displaying memory errors

Figure 5: Purify displays memory errors exposed by testing
Click to enlarge

Standard Make C project

"Standard Make" is the project type you choose when you want to use existing makefiles or create ones and manage their contents without the IDE modifying them in any way. You define the structure of these makefiles and control decisions such as how many targets there are and how they are distributed, possibly among multiple makefiles. You also define the top level make targets for building and cleaning your project.

Figure 6 shows that we have imported the testHash program that is shipped as a sample with Quantify. Right-click on testHash in the C/C++ Projects tab, and select the Properties menu. The Properties for testHash window comes up. Specify your make-related information here -- most importantly the top-level build and clean make targets. As shown in Figure 6, we have used the default values of all and clean.

Screen image showing Quantify environment

Figure 6: Using the sample testHash program shipped as part of the Quantify tool
Click to enlarge

For Standard C/C++ projects, you edit your makefile and include the PurifyPlus tools in your build as additional make targets. This example uses Rational Quantify; the same steps apply to Rational Purify and Rational PureCoverage. Double-click on the makefile in the C/C++ Projects window. RSD opens the makefile for editing. Copy the link target and the make rule for the executable that you plan to monitor with Quantify, preferably the debug version of both. Rename the target by adding ".q" to the end of its name and add the word quantify to the start of the link line. You may define macros such as QUANTIFY and QUANTIFYOPTIONS to specify full paths and options to Quantify. In the makefile example shown in Figure 7, testHash.q is the target to build the Quantify'd program and it is a copy of the testHash target with changes to include Quantify. Optionally, include the new Quantify target in the target all to cause it to be built whenever all is built. Save the modified makefile and if necessary, force a build of the relevant target: either all or only the new testHash.q target. Look at the console output for details of the Quantify build and to ensure that the build succeeded.

Screen image showing Quantify environment

Figure 7: Including Rational Quantify as an additional "make" target
Click to enlarge

To run the newly built Quantify'd application, go to C/C++ Projects, right-click on testHash.q, and select Run As > Run ... from the menu. This brings up the Run window; enter the program arguments (if any) in the Arguments tab. Click Run from the Run window. The top-level Quantify window comes up as your application runs. Only the Help button is active when your program is running. The Function List, Call Graph, and Exit buttons become active once your application has completed. Run your program through a test case and let it exit. Start your Quantify analysis by bringing up the Call Graph, as shown in Figure 8; the "River of Time" visualization highlights the code path that consumed the most time. You can double-click on a method listed here to view further details, including source code annotated with timing data. Please refer to PurifyPlus documentation for further information.

Screen image shows application running in Quantify

Figure 8: Running the newly built Quantify'd application
Click to enlarge

Remote invocation

IBM Rational Software Developer (RSD) allows you to run and debug programs on a remote machine using the GNU debugger (gdb). Even in this mode, you can run your application with Rational Purify, Quantify, or PureCoverage. Since Quantify measures the number of machine cycles for each instruction, it generates useful data even when run under gdb on a remote machine.

Here is how to use Rational PurifyPlus tools with Remote Invocation projects:

  • Build your program in RSD with Purify, Quantify or PureCoverage as described above.
  • On the RSD machine: rlogin to the remote machine.
  • On the remote machine: set DISPLAY to your console, go to the program directory and run the repure command on your instrumented executable. The repure command updates the instrumented program to refer to system libraries for the current machine -- in this case, the remote machine where the program will run. The machines must have the same operating system version and you must access the same version of the Rational tool on both machines.
  • On the remote machine: choose a port number (10000 in this example) and start gdbserver with the following command: gdbserver rsdhostname:10000 instrumented program name
  • On the RSD machine: set up a debug configuration for your program. This is similar to the Run configuration in the previous section.
  • In the Debug window, go to the Debugger tab and select gdbserver Debugger from the Debugger drop-down menu.
  • Click Connection, select TCP for type, and enter the host name for your remote machine along with the port number you entered on the gdbserver command line (10000 in this example).
  • Click Debug.

Screen image shows debugging on a remote machine

Figure 9: Setup to run a program on a remote machine
Click to enlarge

RSD opens the Debug Perspective; and if your Debug configuration is set up to stop at main, it will come up as shown in Figure 10. Running Rational Purify this way is of particular advantage. You can set a breakpoint in the Purify function purify_stop_here and your program will stop in the debugger immediately after any Purify error report appears, so you can examine the program state at the time of the error.

Screen image shows RSD debug perspective

Figure 10: Debugging a program running on a remote machine
Click to enlarge


Use Rational Systems Developer to create well-architected, UML 2-based, model-driven C/C++, Java (J2SE), and CORBA applications. Use Rational PurifyPlus to pinpoint memory corruption, performance problems, code coverage deficiencies, and memory leaks. Develop faster, better quality, more robust code by integrating Rational PurifyPlus into your RSD-based development process as described in this article.

Discuss this article now!

Dear Reader: A new forum has been created specifically for Rational Edge articles, so now you can share your thoughts about this or other articles in the current issue or our archives. Read what your colleagues the world over have to say, generate your own discussion, or join discussions in progress. Begin by clicking HERE.


developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Rational software on developerWorks

ArticleTitle=Develop Better Software Faster with IBM Rational Systems Developer and IBM Rational PurifyPlus