HP UX Web Development Tools Configuring diagnostic messages, Suppressing warnings selectively

Page 25

5 Configuring diagnostic messages

You may want to limit the cadvise diagnostic messages depending on the need, such as the following cases:

Generate all possible messages to ensure that you get the maximum information about potential problems detected by cadvise.

Reduce the number of messages so that you are not overwhelmed by the sheer magnitude of the warnings.

Eliminate or reduce the number of benign or misleading messages.

Your requirement may vary depending on the size of the application, resources allotted to eliminate warnings by changing source code, total number of messages generated, new or ported code, coding standards, and so on. The recommended way is to use options like, +wlint, +w64bit and +w to enable only the required warnings, and then use the options to disable specific warnings that are not of interest or that are too arbitrary. Each distinct type of diagnostic message generated by cadvise has a number associated with it. You can generate separate reports of diagnostics messages for each of these numbers. This allows you to ignore warnings that you do not want and focus on those you want.

5.1 Diagnostic configuration options table

The following options and pragmas help you to manage the diagnostics:

“+Warg1[,arg2,...,argn]” (page 25)

Selectively suppresses warnings.

“+Wwarg1[,arg2,..,argn]” (page 25)

Selectively enables warnings.

“+Wearg1[,arg2,..,argn]” (page 26)

Selectively interprets warnings as errors.

“+Wmacro:MACRONAME:d1,d2,d3,..dn” (page 26)

Disables warnings in a macro.

5.2 Suppressing warnings selectively

The +Warg1[,arg2,...,argn] option selectively suppresses any specified warning messages.

NOTE: arg1 through argn must be valid warning message numbers.

Following is the syntax for selectively suppressing warnings.

$cadvise +wall -pdb <pdbname> +Warg1[,arg2,...,argn] compile-cmd <filename>

Following is an example for selectively suppressing warnings.

Example 16 Suppressing warnings selectively

$cadvise +wall -pdb testpdb +W600 cc -c foo.c

5.3 Enabling warnings selectively

The +Wwarg1[,arg2,..,argn] option selectively enables generation of cadvise warning messages that are not enabled by default.

NOTE: arg1 through argn must be valid warning message numbers.

Following is the syntax for selectively enabling warnings.

$cadvise +wall -pdb <pdbname> +Wwarg1[,arg2,...,argn] compile-cmd <filename>

Following is an example for selectively enabling warnings.

5.1 Diagnostic configuration options table

25

Image 25
Contents HP Code Advisor C.02.20 User Guide Page Contents Contents About this document Document conventions and symbolsIntended audience Related informationCadvise-help@lists.hp.com HP encourages your commentsCadvise user interface Features FeaturesIntroduction Cadvise user interface$ cadvise cc -c hello.c Advanced static code analysis$ cadvise -pdb ./mypdb +wlint aCC hello.cpp Supported compilersSteps in using cadvise Using CadviseSupported platforms Installing Cadvise Getting startedInvoking Cadvise For information on PDB, see Using the Program Database PDB Using Cadvise as a wrapper around Compiler or LinkerSee the following makefile content Integrating Cadvise with the makefiles and build processGenerating code complexity metrics Enabling different categories of diagnostic messagesExample 2 Sample wrapper script Objfile.metrics Example 3 Generating code complexity metricsGenerating code complexity metrics $ cat /tmp/example.c Example 4 Code complexity metrics+wcodeguide=rules-library Example 5 Writing a rule to enforce naming convention Source structure in the rules libraryUsing the Program Database PDB Specifying the PDB location PDB options tableDeleting PDB Disabling locks in PDB operationsDisplaying PDB version Creating a PDB snapshot at a specified locationExample 8 Removing object file information from the PDB Example 9 Creating a PDB snapshotUsage Using cross-file analysisCross-file analysis options Crossfile=auto Example 15 Specifying the location of object files Diagnostic configuration options table Configuring diagnostic messagesSuppressing warnings selectively Enabling warnings selectivelyDisabling warnings in a macro Interpreting selective warnings as errorsManaging warnings in a source file Report generation options table Generating reportsCadvise report report-options -pdb pdbdir Cadvise report report-options logfileGenerating file summary report Generating summary reportsGenerating detailed report $cadvise report -summary -pdb testpdb -noheaderGenerating Html report To save reports, run the following commandExample 23 Generating detailed report $ cadvise report -pdb testpdb -allFollowing example shows the command to generate XML report Printing diagnostics with specific diagnostic numbersGenerating XML report Example 24 Generating an XML reportGenerating reports based on severity Suppressing diagnostics for specific files$ cadvise report -pdb testpdb -diag Example 26 Generating reports based on severityReporting program complexity metrics Reporting diagnostics from specific files$ cadvise report -pdb test.pdb -summary -exclude inflate.c $ cadvise report -pdb test.pdb -summary -include inflate.cExample 29 Reporting program complexity metrics Generating report for a module$ cadvise report -pdb gzip.pdb +metrics -include inflate.c Suppressing report header Modifying the default severity level of a diagnosticGenerating PDB comparison report $ cadvise report -pdb test.pdb -summary -module test1$ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -all Example 34 Generating detailed diff report with the header$ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -diag Example 35 Generating diff report for any particular warning$ cadvise -pdb pdb1 cc one.c two.c $ cadvise report -pdb tmp.pdb -basepdb tmp1.pdb -severity$ cadvise report -pdb new.pdb -basepdb old.pdb -all Report options fileGenerate report for migration related warnings Example 42 Generating a report using -migration optionGenerating consolidated report from multiple PDBs Example 41 Report options fileGenerating PDB diffs with multiple PDBs Recommended process for analyzing the diagnostic messagesReport options interoperability $ cadvise report -pdb 1.pdb2.pdb3.pdb4.pdb -all$ cadvise report -pdb test.pdb -diag 2549 -exclude b.c Example 44 Reporting options interoperabilityExample 45 Ignoring the -includeoption $ cadvise report -pdb test.pdb -summary -include a.cb.cMiscellaneous driver options Example 48 Using -noabortHelp-h-H Example 47 Displaying the list of cadvise optionsFollowing command creates the file cadvdir/foo.cad Example 49 Using -nobuild optionExample 51 Using -tee option Following example shows the usage of -nobuildoptionLine generates the following messages Example 52 Using +opts filename optionCategories of diagnostics table Categories of diagnostics with examplesDetecting generic programming errors Categories of diagnostics with examples Such cases, cadvise generates the following warning Example 53 Null pointer dereference checkSuch cases, cadvise generates the following warnings Example 54 Potential memory leak checkExample 56 Out of scope access Example 55 Out of bound accessExample 57 Use of pointer after free Such cases, cadvise generates the following errorExample 58 Allocator/deallocator mismatch Detecting endianness migration issues Detecting 32-bit to 64-bit migraton issuesExample 60 Detecting 32-bit to 64-bit migraton issues Example 59 Signed bit field of lengthExample 61 Detecting endian dependent code fragments Detecting potential security vulnerabilitiesConsider the following code fragment This case, cadvise generates the following error Detecting multi-threaded programming issuesRunning cadvise generates the following error Example 63 Detecting multi-threaded programming issuesDetecting potential performance improvement opportunities Detecting potential performance improvement opportunities Fixing the warnings by source change AC++ standard conformance and compatibility changes Incompatibilities on PA-RISC based systemsIndex Symbols