Index: tools/scan-build/bin/scan-build =================================================================== --- tools/scan-build/bin/scan-build +++ tools/scan-build/bin/scan-build @@ -69,7 +69,8 @@ MaxLoop => 0, PluginsToLoad => [], AnalyzerDiscoveryMethod => undef, - OverrideCompiler => 0 # The flag corresponding to the --override-compiler command line option. + OverrideCompiler => 0, # The flag corresponding to the --override-compiler command line option. + ForceDebug => 0 ); lock_keys(%Options); @@ -951,7 +952,8 @@ 'CCC_CC', 'CCC_CXX', 'CCC_REPORT_FAILURES', - 'CLANG_ANALYZER_TARGET') { + 'CLANG_ANALYZER_TARGET', + 'CCC_ANALYZER_FORCE_DEBUG_CODE') { my $x = $EnvVars->{$var}; if (defined $x) { $ENV{$var} = $x } } @@ -1118,6 +1120,11 @@ Also analyze functions in #included files. By default, such functions are skipped unless they are called by functions within the main source file. + --force-debug + + Tells analyzer to enable assertions in code even if they were disabled + during compilation (to hopefully get more precise results). + -o Specifies the output directory for analyzer reports. Subdirectories will be @@ -1681,6 +1688,12 @@ next; } + if ($arg eq "--force-debug") { + shift @$Args; + $Options{ForceDebug} = 1; + next; + } + DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); $NumArgs--; @@ -1796,7 +1809,8 @@ 'CCC_ANALYZER_CONSTRAINTS_MODEL' => $Options{ConstraintsModel}, 'CCC_ANALYZER_INTERNAL_STATS' => $Options{InternalStats}, 'CCC_ANALYZER_OUTPUT_FORMAT' => $Options{OutputFormat}, - 'CLANG_ANALYZER_TARGET' => $Options{AnalyzerTarget} + 'CLANG_ANALYZER_TARGET' => $Options{AnalyzerTarget}, + 'CCC_ANALYZER_FORCE_DEBUG_CODE' => $Options{ForceDebug} ); # Run the build. Index: tools/scan-build/libexec/ccc-analyzer =================================================================== --- tools/scan-build/libexec/ccc-analyzer +++ tools/scan-build/libexec/ccc-analyzer @@ -492,6 +492,9 @@ # Get the HTML output directory. my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'}; +# Get force-debug option. +my $ForceDebug = $ENV{'CCC_ANALYZER_FORCE_DEBUG_CODE'}; + my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1); my %ArchsSeen; my $HadArch = 0; @@ -576,6 +579,17 @@ next; } + # Forcedly enable debugging if requested by user. + # TODO: support Windows _DEBUG + if ($ForceDebug) { + if ($Arg eq '-DNDEBUG') { + next; + } elsif ($Arg eq '-D' && $ARGV[$i + 1] eq 'NDEBUG') { + ++$i; + next; + } + } + # Ignored options. if (defined $IgnoredOptionMap{$ArgKey}) { my $Cnt = $IgnoredOptionMap{$ArgKey}; Index: www/analyzer/scan-build.html =================================================================== --- www/analyzer/scan-build.html +++ www/analyzer/scan-build.html @@ -226,6 +226,9 @@ in some cases can greatly reduce the number of false positives (bogus error reports) emitted by the tool.

+

Another option is to use --force-debug flag of scan-build tool +which would try to enable assertions automatically.

+

Use verbose output when debugging scan-build

scan-build takes a -v option to emit verbose output about