SLAC PEP-II
BABAR
SLAC<->RAL
Babar logo
HEPIC E,S & H Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Unwrap page!
Comp. Search
Who's who?
Meetings
FAQ Homepage
Archive
Environment
Administration
New User Info.
Web Info/Tools
Monitoring
Training
Tools & Utils
Programming
C++ Standard
SRT, AFS, CVS
QA and QC
Remedy
Histogramming
Operations
PromptReco
Simulation Production
Online SW
Dataflow
Detector Control
Evt Processing
Run Control
Calibration
Databases
Offline
Workbook
Coding Standards
Simulation
Reconstruction
Prompt Reco.
BaBar Grid
Data Distribution
Beta & BetaTools
Kanga & Root
Analysis Tools
RooFit Toolkit
Data Management
Data Quality
Event display
Event Browser
Code releases
Databases
Check this page for HTML 4.01 Transitional compliance with the
W3C Validator
(More checks...)

Using Insure++ at SLAC

Insure++ is a commercial C/C++ developer's tool specifically designed to help detect misuses of memory. This product can, for example, detect dangling pointers and array overruns. Stanford/SLAC currently has a site-license for running this software and it operates on all BABAR-supported platforms. This page provides a mini-reference for getting started with Insure++.

Users of Insure++ may be interested in a companion program, CodeWizard.

Note that this page refers to Insure++ version 4.0 (patch 2), although installed in a directory called V4.1.
The "test" version really is version 4.1, installed in V4.1A (see below).

NOTE!
Updated 21 Sept 2001: "current" is now Insure 5.1, but people should move to "newest" which is V5.1-3.2 (newer CodeWizard, and with Threads++). There have been some problems with 5.1 on linux, so we have installed 5.2 ("test"). NOTE: 5.2 will soon be replaced by 6.0 (for linux). Source the parasoft.csh in the appropriate subdir to setup your paths. (John Bartelt)
[old note: Our license for V4.1 expired and was replaced by V5.1. It is installed for Solaris, OSF1, and two versions of Linux: "linux"<->glibc version 2 (e.g., RedHat 5.2) and "linux2"<->glibc version 2.1 (RedHat 6.0). The file parasoft.csh (see below) has not been updated, since we are waiting for the new version of CodeWizard to be released (version 2.0 still works).]

Last edit: 11 Sept 2001



Documentation

All relevant documentation for setting up, configuring, running and interpreting the output of Insure++ is available on-line in both html and PostScript formats.
  • Online Documentation for Insure++
  • Insure++ Frequently Asked Questions
  • Available architectures
  • IBM AIX v4
  • Sun Solaris v2
  • DEC Unix v4
  • HP HP-UX v10
  • Intel Linux
  • Common Insure++ commands (and onine man pages)
    insure
    Replacement command for compiling and linking
    ins_ld
    Link (only) a program with Insure++
    insra
    INSure++ Report Analyzer - GUI for investigating Insure++ output reports
    inuse
    Graphical dynamic memory activity display
    psrcdump
    List all current CodeWizard and Insure++ options in effect

  • Getting started

    1. Make the necessary Insure++ executables and man pages visible to your login session. For example, execute the following script or put it into your ~/.cshrc file. This example is only for csh or tcsh users.
      $ source $BFROOT/package/ParaSoft/current/parasoft.csh
      
      

      To use the "test" (new version) instead:

      $ source $BFROOT/package/ParaSoft/test/parasoft.csh
      
      
    2. Create an Insure++ configuration file. Save the contents of this example file in your personal $HOME/.psrc. This is your primary configuration file. You may override the settings in this file on a directory-by-directory basis by simply providing a secondary configuration file which has the same name, .psrc, with those new settings you wish to override.

      Note that configurations for both Insure++ and CodeWizard are saved in the same file; if you already have such a file, then you may want to combine the contents of the example with what you already have.

      Also note that Insure++ comes with a nice interactive GUI for interpreting your error reports. If you wish to use this GUI, called insra, you need only add the insure++.report_file insra in your .psrc file. If you do this, then you may wish to also select your favorite text editor in another configuration called insra.visual (by default you will get vi), e.g.,

      codewizard.report_file insra
           #
           insra.visual emacs +%l %f 
      
      
    3. You are ready to try an example below.

    Examples provided by Insure++

    Log onto a SLAC Unix machine of a supported architecture. Set up your environment as described above, and locate the examples in the directory $INSURE/examples/cpp. Copy leak.C to a directory where you have write privilege. Compile and link it using the insight command, and run it. Also try other examples.
    $ cd mytest
    $ cp $INSURE/examples/cpp/leak.C .
    $ more leak.C
    /*
     * File: leak.C
     */
    #include <string.h>
    
    union S1 {
            char *cp;
            S1() { cp=new char[10]; }
            S1(char *p) {
                    cp=new char[10];
                    strcpy(cp,p);
            }
            S1(S1 &s) {
                    cp=new char[10];
                    strcpy(cp,s.cp);
            }
            void mf(char *p) { strcpy(cp,p); }
    };
    void foo() {
            S1 s1,s2("Hello "),s3=s2;
            s1.mf("SADF");
            s3.mf("World");
    }
    int main() {
            foo();
            return(0);
    }
    $ insure -g -o foo leak.C
    WARNING: /afs/slac/g/babar/package/ParaSoft/Insure++.new/lib.aix4/lib_cSM
       was built on morgan10
       now executing on firecrown
    make sure system libraries match on these hosts
    
    
    
    (Note: this last message is a legitimate warning about a possible mismatch between the shared libraries on the Insure++ build machine and the machine you are currently using. If both machines use the same version of the operating system, you should not need to worry.)
    $ ./foo
    ** Insight messages will be written to foo-errs.980312115852 **
    main
      foo                                              leak.C, 25
        S1::S1                                         [called by non-insight code]
          malloc(10) = 0x200048d8
        S1::S1                                         [called by non-insight code]
          malloc(10) = 0x20004910
          _InSight_strcpy                              leak.C, 11
        S1::S1                                         [called by non-insight code]
          malloc(10) = 0x20004948
          _InSight_strcpy                              leak.C, 15
        S1::mf                                         leak.C, 21
          _InSight_strcpy                              leak.C, 17
        S1::mf                                         leak.C, 22
          _InSight_strcpy                              leak.C, 17
    ** TCA log data will be merged with tca.log **
    $ more foo-errs.980312115852
    [leak.C:23] **LEAK_SCOPE**
    >> }
    
      Memory leaked leaving scope: cp
    
      Lost block : 0x20002530 thru 0x20002539 (10 bytes)
                   cp, allocated at:
                        operator new()  ../new.C
                              S1::S1()  leak.C, 8
                                 foo()  leak.C, 20
                                main()  leak.C, 25
    
      Stack trace where the error occurred:
                                 foo()  leak.C, 23
                                main()  leak.C, 25
    
    ************************** INSURE SUMMARY ************************* v4.0 **
    *   Program      : foo                                                    *
    *   Arguments    :                                                        *
    *   Directory    : /afs/slac.stanford.edu/u/ec/dragon/ctests/insure/examples/cpp *
    *   Compiled on  : Mar 12, 1998  11:58:32                                 *
    *   Run on       : Mar 12, 1998  11:58:54                                 *
    *   Elapsed time : 00:00:02                                               *
    *   Malloc HWM   : 310 bytes                                              *
    ***************************************************************************
    
    PROBLEM SUMMARY - by type
    ===============
    
              Problem                Reported      Suppressed
              -------------------------------------------------
              LEAK_SCOPE                   1                2
              -------------------------------------------------
              TOTAL                        1                2
              -------------------------------------------------
    
    PROBLEM SUMMARY - by location
    ===============
    
    LEAK_SCOPE: Memory leaked leaving scope, 1 unique occurrence
             3 at leak.C, 23
    
    
    
    MEMORY LEAK SUMMARY
    ===================
    
    8 outstanding memory references for 310 bytes.
    
    Leaks detected during execution
    -------------------------------
            10 bytes allocated in new.C
                        operator new()  ../new.C
                              S1::S1()  leak.C, 8
                                 foo()  leak.C, 20
                                main()  leak.C, 25
    
    
    Leaks detected at exit
    ----------------------
            10 bytes allocated in new.C
                        operator new()  ../new.C
                              S1::S1()  leak.C, 14
                                 foo()  leak.C, 20
                                main()  leak.C, 25
    
            10 bytes allocated in new.C
                        operator new()  ../new.C
                              S1::S1()  leak.C, 10
                                 foo()  leak.C, 20
                                main()  leak.C, 25
    
    
    Outstanding allocated memory
    ----------------------------
            24 bytes allocated in startup.C
                 __C_runtime_startup()  ../startup.C
                             __start()  crt0main.s
    
            64 bytes allocated in new.C
                        operator new()  ../new.C
        Iostream_init::Iostream_init()  ../cstreams.c
    sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec()  ../cstreams.c
                 __C_runtime_startup()  ../startup.C
                             __start()  crt0main.s
    
            64 bytes allocated in new.C
                        operator new()  ../new.C
        Iostream_init::Iostream_init()  ../cstreams.c
    sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec()  ../cstreams.c
                 __C_runtime_startup()  ../startup.C
                             __start()  crt0main.s
    
            64 bytes allocated in new.C
                        operator new()  ../new.C
        Iostream_init::Iostream_init()  ../cstreams.c
    sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec()  ../cstreams.c
                 __C_runtime_startup()  ../startup.C
                             __start()  crt0main.s
    
            64 bytes allocated in new.C
                        operator new()  ../new.C
        Iostream_init::Iostream_init()  ../cstreams.c
    sinit64_x_2flocal_2fattlib_2f2_2e1_2fstream_2fcstreams_2ec()  ../cstreams.c
                 __C_runtime_startup()  ../startup.C
                             __start()  crt0main.s
    
    
    
    $ 
    
    

    Compilation and execution of Beta analysis jobs

    (Charlie Young provided this section for a previous version of Insure++. It has been updated with obvious changes, but not yet tested - in the interests of getting this page ready asap. If you run into problems with running Beta using the instructions below, please contact either Tom or Charlie.)

    Log onto a SLAC Unix machine for your compilation and execution.Set up your environment for Insight. Recompile your code, and run it in the usual way. For example,

    young@morgan01 $ source $BFROOT/package/ParaSoft/current/parasoft.csh   [optional, if not in ~/.cshrc]
    young@morgan01 $ gmake clean
    young@morgan01 $ gmake CXX=insure CC=insure
    young@morgan01 $ cd workdir
    young@morgan01 $ ./betarun ../BetaUser/script.tcl
    
    
    The error report file when I ran the job was ~/myBeta/workdir/BetaApp-errs.970126075654. BetaApp is the executable name, and 970126075654 gives the execution time of January 26, 1997, 07:56:54. Now comes the hard part of interpreting the error report and fixing the bugs. I can offer nothing on these points, since I haven't been through it. Please consult the User Guide, and/or experts.

    Hints, tricks and gotchas

    • The error report can be intimidatingly detailed. If you are debugging a specific piece of code and are confident that problems elsewhere are not directly relevant, you can selectively activate and deactivate runtime error checking by adding these lines to your code.
        #ifdef __INSURE__
        _Insure_set_option("runtime","off");
        #endif
      
        #ifdef __INSURE__
        _Insure_set_option("runtime","on");
        #endif
      
      Code in between will not be checked, and your report should be correspondingly shorter and more easily decipherable. It is not essential to remove them when you are finished debugging and go back to using the standard compiler. __INSURE__ is defined only when using Insure++.

    This page is currently maintained by Tom Glanzman with help from Charlie Young. If you experience a problem with Insure++ (either the code itself, the installation or documentation), please report this to the BABAR problem tracking system.