HP UX Web Development Tools manual Example 15 Specifying the location of object files

Page 24

NOTE: The combined use of the –crossfile=deferand –crossfile=[pdbmodulelistlistfile]options are useful in the following situations:

If you want to perform cross-file analysis on a set of object files that is bigger than the set of object files linked during the application build process, for example, if the application build creates multiple shared libraries, the default automatic cross-file analysis is done only across the files specified for each shared-library link command. In such cases, you can also force the analysis to be done on all the files by deferring the analysis using the -crossfile=deferoption until the whole application is built and then invoking the analysis on all the files in the PDB, by using the -crossfile=pdboption. Alternatively, you can use -crossfile=list option to specify object files from a subset of the shared libraries to perform cross-fileanalysis.

If you want to perform cross-file analysis on a set of object files that is smaller than the set of object files linked during the application build process, for example, if you want to perform cross-file analysis on a few object files, you can compile only those object files, get a PDB with the intermediate representation and then use the -crossfile=pdboption to perform cross-file analysis. Alternately, compile the whole application with the -crossfile=deferoption and then use -crossfile=listoption to do the cross-file analysis on a subset of object files.

However, do not use the -crossfile=pdboption if the PDB contains diagnostic information of multiple applications because HP Code Advisor can misinterpret multiple definitions for the same symbols.In this scenario it is better to use the -crossfile=listor -crossfile=moduleoption to perform cross-file analysis on a subset of object files in the PDB.

For the -crossfile=listor -crossfile=listfileoptions, the location of each object file specified must be one of the following:

Location of an existing object file build during the application compilation.

Location of the object file as it would have been created during the application compilation.

Therefore, an object file does not need to exist (it may have been removed or you may have used the “-nobuild”option) as long as cadvise and the PDB are used to monitor the compilation that creates the object file.

Example 15 Specifying the location of object files

cd /tmp

$cadvise -pdb testpdb -crossfile=defer aCC 1.c 2.c 3.c -o objdir/testexec

For cross-file analysis on all the files used to build testexec, run the following commands:

$cadvise -pdb testpdb -crossfile=module:objdir/testexec Or

$cadvise -pdb testpdb -crossfile=module:/tmp/objdir/testexec

NOTE: To specify the module name as specified with the-ooption you must be in the same directory where the first command was invoked. To invoke cadvise from any other location you must specify the absolute path of the module. For cross-file analysis on object files 1.o and 2.o, run the following command:

$cadvise -pdb testpdb -crossfile=list:1.o:2.o

OR

$cadvise -pdb testpdb -crossfile=list:/tmp/1.o:/tmp/2.o

24 Using cross-file analysis

Image 24
Contents HP Code Advisor C.02.20 User Guide Page Contents Contents Document conventions and symbols About this documentIntended audience Related informationHP encourages your comments Cadvise-help@lists.hp.comFeatures Cadvise user interface FeaturesIntroduction Cadvise user interfaceAdvanced static code analysis $ cadvise cc -c hello.cSupported compilers $ cadvise -pdb ./mypdb +wlint aCC hello.cppUsing Cadvise Steps in using cadviseSupported platforms Installing Cadvise Getting startedInvoking Cadvise Using Cadvise as a wrapper around Compiler or Linker For information on PDB, see Using the Program Database PDBSee the following makefile content Integrating Cadvise with the makefiles and build processEnabling different categories of diagnostic messages Generating code complexity metricsExample 2 Sample wrapper script Example 3 Generating code complexity metrics Objfile.metricsGenerating code complexity metrics Example 4 Code complexity metrics $ cat /tmp/example.c+wcodeguide=rules-library Source structure in the rules library Example 5 Writing a rule to enforce naming conventionUsing the Program Database PDB PDB options table Specifying the PDB locationDeleting PDB Disabling locks in PDB operationsCreating a PDB snapshot at a specified location Displaying PDB versionExample 8 Removing object file information from the PDB Example 9 Creating a PDB snapshotUsing cross-file analysis UsageCross-file analysis options Crossfile=auto Example 15 Specifying the location of object files Configuring diagnostic messages Diagnostic configuration options tableSuppressing warnings selectively Enabling warnings selectivelyInterpreting selective warnings as errors Disabling warnings in a macroManaging warnings in a source file Generating reports Report generation options tableCadvise report report-options -pdb pdbdir Cadvise report report-options logfileGenerating summary reports Generating file summary reportGenerating detailed report $cadvise report -summary -pdb testpdb -noheaderTo save reports, run the following command Generating Html reportExample 23 Generating detailed report $ cadvise report -pdb testpdb -allPrinting diagnostics with specific diagnostic numbers Following example shows the command to generate XML reportGenerating XML report Example 24 Generating an XML reportSuppressing diagnostics for specific files Generating reports based on severity$ cadvise report -pdb testpdb -diag Example 26 Generating reports based on severityReporting diagnostics from specific files Reporting program complexity metrics$ cadvise report -pdb test.pdb -summary -exclude inflate.c $ cadvise report -pdb test.pdb -summary -include inflate.cGenerating report for a module Example 29 Reporting program complexity metrics$ cadvise report -pdb gzip.pdb +metrics -include inflate.c Modifying the default severity level of a diagnostic Suppressing report headerGenerating PDB comparison report $ cadvise report -pdb test.pdb -summary -module test1Example 34 Generating detailed diff report with the header $ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -allExample 35 Generating diff report for any particular warning $ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -diag$ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -severity $ cadvise -pdb pdb1 cc one.c two.cReport options file $ cadvise report -pdb new.pdb -basepdb old.pdb -allExample 42 Generating a report using -migration option Generate report for migration related warningsGenerating consolidated report from multiple PDBs Example 41 Report options fileRecommended process for analyzing the diagnostic messages Generating PDB diffs with multiple PDBsReport options interoperability $ cadvise report -pdb 1.pdb2.pdb3.pdb4.pdb -allExample 44 Reporting options interoperability $ cadvise report -pdb test.pdb -diag 2549 -exclude b.cExample 45 Ignoring the -includeoption $ cadvise report -pdb test.pdb -summary -include a.cb.cExample 48 Using -noabort Miscellaneous driver optionsHelp-h-H Example 47 Displaying the list of cadvise optionsExample 49 Using -nobuild option Following command creates the file cadvdir/foo.cadExample 51 Using -tee option Following example shows the usage of -nobuildoptionExample 52 Using +opts filename option Line generates the following messagesCategories of diagnostics with examples Categories of diagnostics tableDetecting generic programming errors Categories of diagnostics with examples Example 53 Null pointer dereference check Such cases, cadvise generates the following warningExample 54 Potential memory leak check Such cases, cadvise generates the following warningsExample 55 Out of bound access Example 56 Out of scope accessSuch cases, cadvise generates the following error Example 57 Use of pointer after freeExample 58 Allocator/deallocator mismatch Detecting 32-bit to 64-bit migraton issues Detecting endianness migration issuesExample 60 Detecting 32-bit to 64-bit migraton issues Example 59 Signed bit field of lengthDetecting potential security vulnerabilities Example 61 Detecting endian dependent code fragmentsConsider the following code fragment Detecting multi-threaded programming issues This case, cadvise generates the following errorExample 63 Detecting multi-threaded programming issues Running cadvise generates the following errorDetecting potential performance improvement opportunities Detecting potential performance improvement opportunities Fixing the warnings by source change Incompatibilities on PA-RISC based systems AC++ standard conformance and compatibility changesSymbols Index