| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
|  | 2 | # | 
|  | 3 | #                     The LLVM Compiler Infrastructure | 
|  | 4 | # | 
|  | 5 | # This file is distributed under the University of Illinois Open Source | 
|  | 6 | # License. See LICENSE.TXT for details. | 
|  | 7 | # | 
|  | 8 | ##===----------------------------------------------------------------------===## | 
|  | 9 | # | 
|  | 10 | # A script designed to wrap a build so that all calls to gcc are intercepted | 
|  | 11 | # and piped to the static analyzer. | 
|  | 12 | # | 
|  | 13 | ##===----------------------------------------------------------------------===## | 
|  | 14 |  | 
|  | 15 | use strict; | 
|  | 16 | use warnings; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 17 | use FindBin qw($RealBin); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 18 | use Digest::MD5; | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 19 | use File::Basename; | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 20 | use Term::ANSIColor; | 
|  | 21 | use Term::ANSIColor qw(:constants); | 
| Ted Kremenek | cd25c13 | 2008-12-03 19:50:37 +0000 | [diff] [blame] | 22 | use Cwd qw/ getcwd abs_path /; | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 23 | use Sys::Hostname; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 24 |  | 
|  | 25 | my $Verbose = 0;       # Verbose output from this script. | 
|  | 26 | my $Prog = "scan-build"; | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 27 | my $BuildName; | 
|  | 28 | my $BuildDate; | 
| Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 29 | my $CXX;  # Leave undefined initially. | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 30 |  | 
| Ted Kremenek | 0e68938 | 2008-09-11 18:17:51 +0000 | [diff] [blame] | 31 | my $TERM = $ENV{'TERM'}; | 
|  | 32 | my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT | 
|  | 33 | and defined $ENV{'SCAN_BUILD_COLOR'}); | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 34 |  | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 35 | my $UserName = HtmlEscape(getpwuid($<) || 'unknown'); | 
|  | 36 | my $HostName = HtmlEscape(hostname() || 'unknown'); | 
|  | 37 | my $CurrentDir = HtmlEscape(getcwd()); | 
|  | 38 | my $CurrentDirSuffix = basename($CurrentDir); | 
|  | 39 |  | 
|  | 40 | my $CmdArgs; | 
|  | 41 |  | 
|  | 42 | my $HtmlTitle; | 
|  | 43 |  | 
|  | 44 | my $Date = localtime(); | 
|  | 45 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 46 | ##----------------------------------------------------------------------------## | 
|  | 47 | # Diagnostics | 
|  | 48 | ##----------------------------------------------------------------------------## | 
|  | 49 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 50 | sub Diag { | 
|  | 51 | if ($UseColor) { | 
|  | 52 | print BOLD, MAGENTA "$Prog: @_"; | 
|  | 53 | print RESET; | 
|  | 54 | } | 
|  | 55 | else { | 
|  | 56 | print "$Prog: @_"; | 
|  | 57 | } | 
|  | 58 | } | 
|  | 59 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 60 | sub DiagCrashes { | 
|  | 61 | my $Dir = shift; | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 62 | Diag ("The analyzer encountered problems on some source files.\n"); | 
|  | 63 | Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n"); | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 64 | Diag ("Please consider submitting a bug report using these files:\n"); | 
|  | 65 | Diag ("  http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n") | 
|  | 66 | } | 
|  | 67 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 68 | sub DieDiag { | 
|  | 69 | if ($UseColor) { | 
|  | 70 | print BOLD, RED "$Prog: "; | 
|  | 71 | print RESET, RED @_; | 
|  | 72 | print RESET; | 
|  | 73 | } | 
|  | 74 | else { | 
|  | 75 | print "$Prog: ", @_; | 
|  | 76 | } | 
|  | 77 | exit(0); | 
|  | 78 | } | 
|  | 79 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 80 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 81 | # Some initial preprocessing of Clang options. | 
|  | 82 | ##----------------------------------------------------------------------------## | 
|  | 83 |  | 
| Ted Kremenek | 833da02 | 2009-03-29 00:31:32 +0000 | [diff] [blame] | 84 | # First, look for 'clang-cc' in libexec. | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 85 | my $ClangCCSB = Cwd::realpath("$RealBin/libexec/clang-cc"); | 
| Ted Kremenek | 833da02 | 2009-03-29 00:31:32 +0000 | [diff] [blame] | 86 | # Second, look for 'clang-cc' in the same directory as scan-build. | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 87 | if (!defined $ClangCCSB || ! -x $ClangCCSB) { | 
|  | 88 | $ClangCCSB = Cwd::realpath("$RealBin/clang-cc"); | 
| Ted Kremenek | 43b7bd3 | 2009-03-09 23:14:38 +0000 | [diff] [blame] | 89 | } | 
| Ted Kremenek | 833da02 | 2009-03-29 00:31:32 +0000 | [diff] [blame] | 90 | # Third, look for 'clang-cc' in ../libexec | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 91 | if (!defined $ClangCCSB || ! -x $ClangCCSB) { | 
|  | 92 | $ClangCCSB = Cwd::realpath("$RealBin/../libexec/clang-cc"); | 
|  | 93 | } | 
|  | 94 | # Finally, default to looking for 'clang-cc' in the path. | 
|  | 95 | if (!defined $ClangCCSB || ! -x $ClangCCSB) { | 
|  | 96 | $ClangCCSB = "clang-cc"; | 
|  | 97 | } | 
|  | 98 | my $ClangCC = $ClangCCSB; | 
|  | 99 |  | 
|  | 100 | # Now find 'clang' | 
|  | 101 | my $ClangSB = Cwd::realpath("$RealBin/bin/clang"); | 
| Ted Kremenek | 8d10cdd | 2009-02-20 04:34:29 +0000 | [diff] [blame] | 102 | if (!defined $ClangSB || ! -x $ClangSB) { | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 103 | $ClangSB = Cwd::realpath("$RealBin/clang"); | 
|  | 104 | } | 
|  | 105 | # Third, look for 'clang' in ../bin | 
|  | 106 | if (!defined $ClangSB || ! -x $ClangSB) { | 
|  | 107 | $ClangSB = Cwd::realpath("$RealBin/../bin/clang"); | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 108 | } | 
| Ted Kremenek | 833da02 | 2009-03-29 00:31:32 +0000 | [diff] [blame] | 109 | # Finally, default to looking for 'clang-cc' in the path. | 
|  | 110 | if (!defined $ClangSB || ! -x $ClangSB) { | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 111 | $ClangSB = "clang"; | 
| Ted Kremenek | 833da02 | 2009-03-29 00:31:32 +0000 | [diff] [blame] | 112 | } | 
|  | 113 | my $Clang = $ClangSB; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 114 |  | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 115 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 116 | my %AvailableAnalyses; | 
|  | 117 |  | 
|  | 118 | # Query clang for analysis options. | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 119 | open(PIPE, "-|", $ClangCC, "--help") or | 
|  | 120 | DieDiag("Cannot execute '$ClangCC'\n"); | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 121 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 122 | my $FoundAnalysis = 0; | 
|  | 123 |  | 
|  | 124 | while(<PIPE>) { | 
|  | 125 | if ($FoundAnalysis == 0) { | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 126 | if (/Checks and Analyses/) { | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 127 | $FoundAnalysis = 1; | 
|  | 128 | } | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 129 | next; | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | if (/^\s\s\s\s([^\s]+)\s(.+)$/) { | 
|  | 133 | next if ($1 =~ /-dump/ or $1 =~ /-view/ | 
|  | 134 | or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); | 
|  | 135 |  | 
|  | 136 | $AvailableAnalyses{$1} = $2; | 
|  | 137 | next; | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 138 | } | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 139 | last; | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | close (PIPE); | 
|  | 143 |  | 
|  | 144 | my %AnalysesDefaultEnabled = ( | 
|  | 145 | '-warn-dead-stores' => 1, | 
|  | 146 | '-checker-cfref' => 1, | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 147 | '-warn-objc-methodsigs' => 1, | 
| Ted Kremenek | d76c6a3 | 2009-02-25 21:08:30 +0000 | [diff] [blame] | 148 | # Do not enable the missing -dealloc check by default. | 
|  | 149 | #  '-warn-objc-missing-dealloc' => 1, | 
| Ted Kremenek | 5d44349 | 2008-09-18 06:34:16 +0000 | [diff] [blame] | 150 | '-warn-objc-unused-ivars' => 1, | 
| Ted Kremenek | 3a92d6d | 2009-07-24 02:52:07 +0000 | [diff] [blame] | 151 | '-warn-security-syntactic' => 1 | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 152 | ); | 
|  | 153 |  | 
|  | 154 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 155 | # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 156 | ##----------------------------------------------------------------------------## | 
|  | 157 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 158 | sub GetHTMLRunDir { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 159 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 160 | die "Not enough arguments." if (@_ == 0); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 161 | my $Dir = shift @_; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 162 |  | 
|  | 163 | my $TmpMode = 0; | 
|  | 164 | if (!defined $Dir) { | 
| Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 165 | if (`uname` =~ /Darwin/) { | 
|  | 166 | $Dir = $ENV{'TMPDIR'}; | 
|  | 167 | if (!defined $Dir) { $Dir = "/tmp"; } | 
|  | 168 | } | 
|  | 169 | else { | 
|  | 170 | $Dir = "/tmp"; | 
|  | 171 | } | 
|  | 172 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 173 | $TmpMode = 1; | 
|  | 174 | } | 
| Ted Kremenek | bf762c9 | 2009-02-24 02:38:02 +0000 | [diff] [blame] | 175 |  | 
|  | 176 | # Chop off any trailing '/' characters. | 
|  | 177 | while ($Dir =~ /\/$/) { chop $Dir; } | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 178 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 179 | # Get current date and time. | 
|  | 180 |  | 
|  | 181 | my @CurrentTime = localtime(); | 
|  | 182 |  | 
|  | 183 | my $year  = $CurrentTime[5] + 1900; | 
|  | 184 | my $day   = $CurrentTime[3]; | 
|  | 185 | my $month = $CurrentTime[4] + 1; | 
|  | 186 |  | 
| Ted Kremenek | 9d7405f | 2008-05-14 17:23:56 +0000 | [diff] [blame] | 187 | my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 188 |  | 
|  | 189 | # Determine the run number. | 
|  | 190 |  | 
|  | 191 | my $RunNumber; | 
|  | 192 |  | 
|  | 193 | if (-d $Dir) { | 
|  | 194 |  | 
|  | 195 | if (! -r $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 196 | DieDiag("directory '$Dir' exists but is not readable.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 197 | } | 
|  | 198 |  | 
|  | 199 | # Iterate over all files in the specified directory. | 
|  | 200 |  | 
|  | 201 | my $max = 0; | 
|  | 202 |  | 
|  | 203 | opendir(DIR, $Dir); | 
| Ted Kremenek | 29da6c5 | 2008-08-07 17:57:34 +0000 | [diff] [blame] | 204 | my @FILES = grep { -d "$Dir/$_" } readdir(DIR); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 205 | closedir(DIR); | 
|  | 206 |  | 
|  | 207 | foreach my $f (@FILES) { | 
|  | 208 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 209 | # Strip the prefix '$Prog-' if we are dumping files to /tmp. | 
|  | 210 | if ($TmpMode) { | 
|  | 211 | next if (!($f =~ /^$Prog-(.+)/)); | 
|  | 212 | $f = $1; | 
|  | 213 | } | 
|  | 214 |  | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 215 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 216 | my @x = split/-/, $f; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 217 | next if (scalar(@x) != 4); | 
|  | 218 | next if ($x[0] != $year); | 
|  | 219 | next if ($x[1] != $month); | 
|  | 220 | next if ($x[2] != $day); | 
|  | 221 |  | 
|  | 222 | if ($x[3] > $max) { | 
|  | 223 | $max = $x[3]; | 
|  | 224 | } | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | $RunNumber = $max + 1; | 
|  | 228 | } | 
|  | 229 | else { | 
|  | 230 |  | 
|  | 231 | if (-x $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 232 | DieDiag("'$Dir' exists but is not a directory.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 233 | } | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 234 |  | 
|  | 235 | if ($TmpMode) { | 
| Ted Kremenek | 445fa77 | 2008-10-10 00:17:08 +0000 | [diff] [blame] | 236 | DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n"); | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 237 | } | 
|  | 238 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 239 | # $Dir does not exist.  It will be automatically created by the | 
|  | 240 | # clang driver.  Set the run number to 1. | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 241 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 242 | $RunNumber = 1; | 
|  | 243 | } | 
|  | 244 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 245 | die "RunNumber must be defined!" if (!defined $RunNumber); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 246 |  | 
|  | 247 | # Append the run number. | 
| Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 248 | my $NewDir; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 249 | if ($TmpMode) { | 
| Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 250 | $NewDir = "$Dir/$Prog-$DateString-$RunNumber"; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 251 | } | 
|  | 252 | else { | 
| Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 253 | $NewDir = "$Dir/$DateString-$RunNumber"; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 254 | } | 
| Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 255 | system 'mkdir','-p',$NewDir; | 
|  | 256 | return $NewDir; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 257 | } | 
|  | 258 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 259 | sub SetHtmlEnv { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 260 |  | 
|  | 261 | die "Wrong number of arguments." if (scalar(@_) != 2); | 
|  | 262 |  | 
|  | 263 | my $Args = shift; | 
|  | 264 | my $Dir = shift; | 
|  | 265 |  | 
|  | 266 | die "No build command." if (scalar(@$Args) == 0); | 
|  | 267 |  | 
|  | 268 | my $Cmd = $$Args[0]; | 
|  | 269 |  | 
|  | 270 | if ($Cmd =~ /configure/) { | 
|  | 271 | return; | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | if ($Verbose) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 275 | Diag("Emitting reports for this run to '$Dir'.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 276 | } | 
|  | 277 |  | 
|  | 278 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 282 | # ComputeDigest - Compute a digest of the specified file. | 
|  | 283 | ##----------------------------------------------------------------------------## | 
|  | 284 |  | 
|  | 285 | sub ComputeDigest { | 
|  | 286 | my $FName = shift; | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 287 | DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 288 |  | 
|  | 289 | # Use Digest::MD5.  We don't have to be cryptographically secure.  We're | 
| Ted Kremenek | 7ea02e6 | 2008-04-19 18:07:44 +0000 | [diff] [blame] | 290 | # just looking for duplicate files that come from a non-malicious source. | 
|  | 291 | # We use Digest::MD5 because it is a standard Perl module that should | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 292 | # come bundled on most systems. | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 293 | open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 294 | binmode FILE; | 
|  | 295 | my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; | 
|  | 296 | close(FILE); | 
|  | 297 |  | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 298 | # Return the digest. | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 299 | return $Result; | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 300 | } | 
|  | 301 |  | 
|  | 302 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 303 | #  UpdatePrefix - Compute the common prefix of files. | 
|  | 304 | ##----------------------------------------------------------------------------## | 
|  | 305 |  | 
|  | 306 | my $Prefix; | 
|  | 307 |  | 
|  | 308 | sub UpdatePrefix { | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 309 | my $x = shift; | 
|  | 310 | my $y = basename($x); | 
|  | 311 | $x =~ s/\Q$y\E$//; | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 312 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 313 | if (!defined $Prefix) { | 
|  | 314 | $Prefix = $x; | 
|  | 315 | return; | 
|  | 316 | } | 
|  | 317 |  | 
| Ted Kremenek | 20b2bae | 2008-09-11 21:15:10 +0000 | [diff] [blame] | 318 | chop $Prefix while (!($x =~ /^\Q$Prefix/)); | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 319 | } | 
|  | 320 |  | 
|  | 321 | sub GetPrefix { | 
|  | 322 | return $Prefix; | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | ##----------------------------------------------------------------------------## | 
|  | 326 | #  UpdateInFilePath - Update the path in the report file. | 
|  | 327 | ##----------------------------------------------------------------------------## | 
|  | 328 |  | 
|  | 329 | sub UpdateInFilePath { | 
|  | 330 | my $fname = shift; | 
|  | 331 | my $regex = shift; | 
|  | 332 | my $newtext = shift; | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 333 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 334 | open (RIN, $fname) or die "cannot open $fname"; | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 335 | open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp"; | 
|  | 336 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 337 | while (<RIN>) { | 
|  | 338 | s/$regex/$newtext/; | 
|  | 339 | print ROUT $_; | 
|  | 340 | } | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 341 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 342 | close (ROUT); | 
|  | 343 | close (RIN); | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 344 | system("mv", "$fname.tmp", $fname); | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 345 | } | 
|  | 346 |  | 
|  | 347 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 348 | # ScanFile - Scan a report file for various identifying attributes. | 
|  | 349 | ##----------------------------------------------------------------------------## | 
|  | 350 |  | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 351 | # Sometimes a source file is scanned more than once, and thus produces | 
|  | 352 | # multiple error reports.  We use a cache to solve this problem. | 
|  | 353 |  | 
|  | 354 | my %AlreadyScanned; | 
|  | 355 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 356 | sub ScanFile { | 
|  | 357 |  | 
|  | 358 | my $Index = shift; | 
|  | 359 | my $Dir = shift; | 
|  | 360 | my $FName = shift; | 
|  | 361 |  | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 362 | # Compute a digest for the report file.  Determine if we have already | 
|  | 363 | # scanned a file that looks just like it. | 
|  | 364 |  | 
|  | 365 | my $digest = ComputeDigest("$Dir/$FName"); | 
|  | 366 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 367 | if (defined $AlreadyScanned{$digest}) { | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 368 | # Redundant file.  Remove it. | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 369 | system ("rm", "-f", "$Dir/$FName"); | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 370 | return; | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | $AlreadyScanned{$digest} = 1; | 
|  | 374 |  | 
| Ted Kremenek | 809709f | 2008-04-18 16:58:34 +0000 | [diff] [blame] | 375 | # At this point the report file is not world readable.  Make it happen. | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 376 | system ("chmod", "644", "$Dir/$FName"); | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 377 |  | 
|  | 378 | # Scan the report file for tags. | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 379 | open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 380 |  | 
| Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 381 | my $BugType = ""; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 382 | my $BugFile = ""; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 383 | my $BugCategory; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 384 | my $BugPathLength = 1; | 
|  | 385 | my $BugLine = 0; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 386 | my $found = 0; | 
|  | 387 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 388 | while (<IN>) { | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 389 |  | 
|  | 390 | last if ($found == 5); | 
|  | 391 |  | 
| Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 392 | if (/<!-- BUGTYPE (.*) -->$/) { | 
|  | 393 | $BugType = $1; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 394 | ++$found; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 395 | } | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 396 | elsif (/<!-- BUGFILE (.*) -->$/) { | 
| Ted Kremenek | 990c2f4 | 2008-12-03 19:19:23 +0000 | [diff] [blame] | 397 | $BugFile = abs_path($1); | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 398 | UpdatePrefix($BugFile); | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 399 | ++$found; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 400 | } | 
|  | 401 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { | 
|  | 402 | $BugPathLength = $1; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 403 | ++$found; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 404 | } | 
|  | 405 | elsif (/<!-- BUGLINE (.*) -->$/) { | 
|  | 406 | $BugLine = $1; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 407 | ++$found; | 
|  | 408 | } | 
|  | 409 | elsif (/<!-- BUGCATEGORY (.*) -->$/) { | 
|  | 410 | $BugCategory = $1; | 
|  | 411 | ++$found; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 412 | } | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 413 | } | 
|  | 414 |  | 
|  | 415 | close(IN); | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 416 |  | 
|  | 417 | if (!defined $BugCategory) { | 
|  | 418 | $BugCategory = "Other"; | 
|  | 419 | } | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 420 |  | 
| Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 421 | push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugLine, | 
| Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 422 | $BugPathLength ]; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
|  | 425 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 426 | # CopyFiles - Copy resource files to target directory. | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 427 | ##----------------------------------------------------------------------------## | 
|  | 428 |  | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 429 | sub CopyFiles { | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 430 |  | 
|  | 431 | my $Dir = shift; | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 432 |  | 
|  | 433 | my $JS = Cwd::realpath("$RealBin/sorttable.js"); | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 434 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 435 | DieDiag("Cannot find 'sorttable.js'.\n") | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 436 | if (! -r $JS); | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 437 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 438 | system ("cp", $JS, "$Dir"); | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 439 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 440 | DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 441 | if (! -r "$Dir/sorttable.js"); | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 442 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 443 | my $CSS = Cwd::realpath("$RealBin/scanview.css"); | 
|  | 444 |  | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 445 | DieDiag("Cannot find 'scanview.css'.\n") | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 446 | if (! -r $CSS); | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 447 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 448 | system ("cp", $CSS, "$Dir"); | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 449 |  | 
|  | 450 | DieDiag("Could not copy 'scanview.css' to '$Dir'.\n") | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 451 | if (! -r $CSS); | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 452 | } | 
|  | 453 |  | 
|  | 454 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 455 | # Postprocess - Postprocess the results of an analysis scan. | 
|  | 456 | ##----------------------------------------------------------------------------## | 
|  | 457 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 458 | sub Postprocess { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 459 |  | 
|  | 460 | my $Dir = shift; | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 461 | my $BaseDir = shift; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 462 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 463 | die "No directory specified." if (!defined $Dir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 464 |  | 
|  | 465 | if (! -d $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 466 | Diag("No bugs found.\n"); | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 467 | return 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 468 | } | 
|  | 469 |  | 
|  | 470 | opendir(DIR, $Dir); | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 471 | my @files = grep { /^report-.*\.html$/ } readdir(DIR); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 472 | closedir(DIR); | 
|  | 473 |  | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 474 | if (scalar(@files) == 0 and ! -e "$Dir/failures") { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 475 | Diag("Removing directory '$Dir' because it contains no reports.\n"); | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 476 | system ("rm", "-fR", $Dir); | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 477 | return 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 478 | } | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 479 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 480 | # Scan each report file and build an index. | 
|  | 481 | my @Index; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 482 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } | 
|  | 483 |  | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 484 | # Scan the failures directory and use the information in the .info files | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 485 | # to update the common prefix directory. | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 486 | my @failures; | 
|  | 487 | my @attributes_ignored; | 
|  | 488 | if (-d "$Dir/failures") { | 
|  | 489 | opendir(DIR, "$Dir/failures"); | 
|  | 490 | @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR); | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 491 | closedir(DIR); | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 492 | opendir(DIR, "$Dir/failures"); | 
|  | 493 | @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR); | 
|  | 494 | closedir(DIR); | 
|  | 495 | foreach my $file (@failures) { | 
|  | 496 | open IN, "$Dir/failures/$file" or DieDiag("cannot open $file\n"); | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 497 | my $Path = <IN>; | 
|  | 498 | if (defined $Path) { UpdatePrefix($Path); } | 
|  | 499 | close IN; | 
|  | 500 | } | 
|  | 501 | } | 
|  | 502 |  | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 503 | # Generate an index.html file. | 
|  | 504 | my $FName = "$Dir/index.html"; | 
|  | 505 | open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n"); | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 506 |  | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 507 | # Print out the header. | 
|  | 508 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 509 | print OUT <<ENDTEXT; | 
|  | 510 | <html> | 
|  | 511 | <head> | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 512 | <title>${HtmlTitle}</title> | 
| Ted Kremenek | f143545 | 2008-09-23 22:34:51 +0000 | [diff] [blame] | 513 | <link type="text/css" rel="stylesheet" href="scanview.css"/> | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 514 | <script src="sorttable.js"></script> | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 515 | <script language='javascript' type="text/javascript"> | 
|  | 516 | function SetDisplay(RowClass, DisplayVal) | 
|  | 517 | { | 
|  | 518 | var Rows = document.getElementsByTagName("tr"); | 
|  | 519 | for ( var i = 0 ; i < Rows.length; ++i ) { | 
|  | 520 | if (Rows[i].className == RowClass) { | 
|  | 521 | Rows[i].style.display = DisplayVal; | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 | } | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 525 |  | 
| Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 526 | function CopyCheckedStateToCheckButtons(SummaryCheckButton) { | 
|  | 527 | var Inputs = document.getElementsByTagName("input"); | 
|  | 528 | for ( var i = 0 ; i < Inputs.length; ++i ) { | 
|  | 529 | if (Inputs[i].type == "checkbox") { | 
|  | 530 | if(Inputs[i] != SummaryCheckButton) { | 
|  | 531 | Inputs[i].checked = SummaryCheckButton.checked; | 
|  | 532 | Inputs[i].onclick(); | 
|  | 533 | } | 
|  | 534 | } | 
|  | 535 | } | 
|  | 536 | } | 
|  | 537 |  | 
| Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 538 | function returnObjById( id ) { | 
|  | 539 | if (document.getElementById) | 
|  | 540 | var returnVar = document.getElementById(id); | 
|  | 541 | else if (document.all) | 
|  | 542 | var returnVar = document.all[id]; | 
|  | 543 | else if (document.layers) | 
|  | 544 | var returnVar = document.layers[id]; | 
|  | 545 | return returnVar; | 
|  | 546 | } | 
|  | 547 |  | 
|  | 548 | var NumUnchecked = 0; | 
|  | 549 |  | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 550 | function ToggleDisplay(CheckButton, ClassName) { | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 551 | if (CheckButton.checked) { | 
|  | 552 | SetDisplay(ClassName, ""); | 
| Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 553 | if (--NumUnchecked == 0) { | 
|  | 554 | returnObjById("AllBugsCheck").checked = true; | 
|  | 555 | } | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 556 | } | 
|  | 557 | else { | 
|  | 558 | SetDisplay(ClassName, "none"); | 
| Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 559 | NumUnchecked++; | 
|  | 560 | returnObjById("AllBugsCheck").checked = false; | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 561 | } | 
|  | 562 | } | 
|  | 563 | </script> | 
| Ted Kremenek | 1d1abb1 | 2008-09-22 17:52:58 +0000 | [diff] [blame] | 564 | <!-- SUMMARYENDHEAD --> | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 565 | </head> | 
|  | 566 | <body> | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 567 | <h1>${HtmlTitle}</h1> | 
|  | 568 |  | 
|  | 569 | <table> | 
|  | 570 | <tr><th>User:</th><td>${UserName}\@${HostName}</td></tr> | 
|  | 571 | <tr><th>Working Directory:</th><td>${CurrentDir}</td></tr> | 
|  | 572 | <tr><th>Command Line:</th><td>${CmdArgs}</td></tr> | 
|  | 573 | <tr><th>Date:</th><td>${Date}</td></tr> | 
|  | 574 | ENDTEXT | 
|  | 575 |  | 
|  | 576 | print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n" | 
|  | 577 | if (defined($BuildName) && defined($BuildDate)); | 
|  | 578 |  | 
|  | 579 | print OUT <<ENDTEXT; | 
|  | 580 | </table> | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 581 | ENDTEXT | 
|  | 582 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 583 | if (scalar(@files)) { | 
|  | 584 | # Print out the summary table. | 
|  | 585 | my %Totals; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 586 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 587 | for my $row ( @Index ) { | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 588 | my $bug_type = ($row->[2]); | 
|  | 589 | my $bug_category = ($row->[1]); | 
|  | 590 | my $key = "$bug_category:$bug_type"; | 
|  | 591 |  | 
|  | 592 | if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; } | 
|  | 593 | else { $Totals{$key}->[0]++; } | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 594 | } | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 595 |  | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 596 | print OUT "<h2>Bug Summary</h2>"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 597 |  | 
|  | 598 | if (defined $BuildName) { | 
|  | 599 | print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n" | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 600 | } | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 601 |  | 
| Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 602 | my $TotalBugs = scalar(@Index); | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 603 | print OUT <<ENDTEXT; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 604 | <table> | 
|  | 605 | <thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead> | 
| Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 606 | <tr style="font-weight:bold"><td class="SUMM_DESC">All Bugs</td><td class="Q">$TotalBugs</td><td><center><input type="checkbox" id="AllBugsCheck" onClick="CopyCheckedStateToCheckButtons(this);" checked/></center></td></tr> | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 607 | ENDTEXT | 
|  | 608 |  | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 609 | my $last_category; | 
|  | 610 |  | 
|  | 611 | for my $key ( | 
|  | 612 | sort { | 
|  | 613 | my $x = $Totals{$a}; | 
|  | 614 | my $y = $Totals{$b}; | 
|  | 615 | my $res = $x->[1] cmp $y->[1]; | 
|  | 616 | $res = $x->[2] cmp $y->[2] if ($res == 0); | 
|  | 617 | $res | 
|  | 618 | } keys %Totals ) | 
|  | 619 | { | 
|  | 620 | my $val = $Totals{$key}; | 
|  | 621 | my $category = $val->[1]; | 
|  | 622 | if (!defined $last_category or $last_category ne $category) { | 
|  | 623 | $last_category = $category; | 
|  | 624 | print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n"; | 
|  | 625 | } | 
|  | 626 | my $x = lc $key; | 
|  | 627 | $x =~ s/[ ,'":\/()]+/_/g; | 
|  | 628 | print OUT "<tr><td class=\"SUMM_DESC\">"; | 
|  | 629 | print OUT $val->[2]; | 
| Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 630 | print OUT "</td><td class=\"Q\">"; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 631 | print OUT $val->[0]; | 
|  | 632 | print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 633 | } | 
| Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 634 |  | 
|  | 635 | # Print out the table of errors. | 
|  | 636 |  | 
|  | 637 | print OUT <<ENDTEXT; | 
|  | 638 | </table> | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 639 | <h2>Reports</h2> | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 640 |  | 
|  | 641 | <table class="sortable" style="table-layout:automatic"> | 
|  | 642 | <thead><tr> | 
|  | 643 | <td>Bug Group</td> | 
|  | 644 | <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind"> ▾</span></td> | 
| Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 645 | <td>File</td> | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 646 | <td class="Q">Line</td> | 
| Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 647 | <td class="Q">Path Length</td> | 
| Ted Kremenek | 2645c77 | 2008-07-07 16:58:44 +0000 | [diff] [blame] | 648 | <td class="sorttable_nosort"></td> | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 649 | <!-- REPORTBUGCOL --> | 
|  | 650 | </tr></thead> | 
|  | 651 | <tbody> | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 652 | ENDTEXT | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 653 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 654 | my $prefix = GetPrefix(); | 
|  | 655 | my $regex; | 
|  | 656 | my $InFileRegex; | 
|  | 657 | my $InFilePrefix = "File:</td><td>"; | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 658 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 659 | if (defined $prefix) { | 
|  | 660 | $regex = qr/^\Q$prefix\E/is; | 
|  | 661 | $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is; | 
|  | 662 | } | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 663 |  | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 664 | for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) { | 
|  | 665 | my $x = "$row->[1]:$row->[2]"; | 
|  | 666 | $x = lc $x; | 
|  | 667 | $x =~ s/[ ,'":\/()]+/_/g; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 668 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 669 | my $ReportFile = $row->[0]; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 670 |  | 
|  | 671 | print OUT "<tr class=\"bt_$x\">"; | 
|  | 672 | print OUT "<td class=\"DESC\">"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 673 | print OUT $row->[1]; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 674 | print OUT "</td>"; | 
|  | 675 | print OUT "<td class=\"DESC\">"; | 
|  | 676 | print OUT $row->[2]; | 
|  | 677 | print OUT "</td>"; | 
|  | 678 |  | 
|  | 679 | # Update the file prefix. | 
|  | 680 | my $fname = $row->[3]; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 681 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 682 | if (defined $regex) { | 
|  | 683 | $fname =~ s/$regex//; | 
|  | 684 | UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix) | 
|  | 685 | } | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 686 |  | 
| Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 687 | print OUT "<td>"; | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 688 | my @fname = split /\//,$fname; | 
|  | 689 | if ($#fname > 0) { | 
|  | 690 | while ($#fname >= 0) { | 
|  | 691 | my $x = shift @fname; | 
|  | 692 | print OUT $x; | 
|  | 693 | if ($#fname >= 0) { | 
|  | 694 | print OUT "<span class=\"W\"> </span>/"; | 
|  | 695 | } | 
|  | 696 | } | 
|  | 697 | } | 
|  | 698 | else { | 
|  | 699 | print OUT $fname; | 
| Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 700 | } | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 701 | print OUT "</td>"; | 
|  | 702 |  | 
|  | 703 | # Print out the quantities. | 
| Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 704 | for my $j ( 4 .. 5 ) { | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 705 | print OUT "<td class=\"Q\">$row->[$j]</td>"; | 
|  | 706 | } | 
|  | 707 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 708 | # Print the rest of the columns. | 
| Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 709 | for (my $j = 6; $j <= $#{$row}; ++$j) { | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 710 | print OUT "<td>$row->[$j]</td>" | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 711 | } | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 712 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 713 | # Emit the "View" link. | 
| Ted Kremenek | 68005dd | 2008-09-22 17:39:18 +0000 | [diff] [blame] | 714 | print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>"; | 
| Ted Kremenek | 3cea9ee | 2008-07-30 17:58:08 +0000 | [diff] [blame] | 715 |  | 
| Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 716 | # Emit REPORTBUG markers. | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 717 | print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n"; | 
| Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 718 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 719 | # End the row. | 
|  | 720 | print OUT "</tr>\n"; | 
|  | 721 | } | 
|  | 722 |  | 
| Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 723 | print OUT "</tbody>\n</table>\n\n"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 724 | } | 
|  | 725 |  | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 726 | if (scalar (@failures) || scalar(@attributes_ignored)) { | 
|  | 727 | print OUT "<h2>Analyzer Failures</h2>\n"; | 
|  | 728 |  | 
|  | 729 | if (scalar @attributes_ignored) { | 
|  | 730 | print OUT "The analyzer's parser ignored the following attributes:<p>\n"; | 
|  | 731 | print OUT "<table>\n"; | 
|  | 732 | print OUT "<thead><tr><td>Attribute</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n"; | 
|  | 733 | foreach my $file (sort @attributes_ignored) { | 
|  | 734 | die "cannot demangle attribute name\n" if (! ($file =~ /^attribute_ignored_(.+).txt/)); | 
|  | 735 | my $attribute = $1; | 
|  | 736 | # Open the attribute file to get the first file that failed. | 
|  | 737 | next if (!open (ATTR, "$Dir/failures/$file")); | 
|  | 738 | my $ppfile = <ATTR>; | 
|  | 739 | chomp $ppfile; | 
|  | 740 | close ATTR; | 
|  | 741 | next if (! -e "$Dir/failures/$ppfile"); | 
|  | 742 | # Open the info file and get the name of the source file. | 
|  | 743 | open (INFO, "$Dir/failures/$ppfile.info.txt") or | 
|  | 744 | die "Cannot open $Dir/failures/$ppfile.info.txt\n"; | 
|  | 745 | my $srcfile = <INFO>; | 
|  | 746 | chomp $srcfile; | 
|  | 747 | close (INFO); | 
|  | 748 | # Print the information in the table. | 
|  | 749 | my $prefix = GetPrefix(); | 
|  | 750 | if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; } | 
|  | 751 | print OUT "<tr><td>$attribute</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n"; | 
|  | 752 | my $ppfile_clang = $ppfile; | 
|  | 753 | $ppfile_clang =~ s/[.](.+)$/.clang.$1/; | 
|  | 754 | print OUT "  <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n"; | 
|  | 755 | } | 
|  | 756 | print OUT "</table>\n"; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | if (scalar @failures) { | 
|  | 760 | print OUT "<p>The analyzer had problems processing the following files:</p>\n"; | 
|  | 761 | print OUT "<table>\n"; | 
|  | 762 | print OUT "<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n"; | 
|  | 763 | foreach my $file (sort @failures) { | 
| Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 764 | $file =~ /(.+).info.txt$/; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 765 | # Get the preprocessed file. | 
|  | 766 | my $ppfile = $1; | 
|  | 767 | # Open the info file and get the name of the source file. | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 768 | open (INFO, "$Dir/failures/$file") or | 
|  | 769 | die "Cannot open $Dir/failures/$file\n"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 770 | my $srcfile = <INFO>; | 
| Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 771 | chomp $srcfile; | 
|  | 772 | my $problem = <INFO>; | 
|  | 773 | chomp $problem; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 774 | close (INFO); | 
|  | 775 | # Print the information in the table. | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 776 | my $prefix = GetPrefix(); | 
| Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 777 | if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; } | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 778 | print OUT "<tr><td>$problem</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n"; | 
| Daniel Dunbar | ce723ce | 2008-09-25 01:10:50 +0000 | [diff] [blame] | 779 | my $ppfile_clang = $ppfile; | 
|  | 780 | $ppfile_clang =~ s/[.](.+)$/.clang.$1/; | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 781 | print OUT "  <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n"; | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 782 | } | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 783 | print OUT "</table>\n"; | 
|  | 784 | } | 
|  | 785 | print OUT "<p>Please consider submitting preprocessed files as <a href=\"http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\">bug reports</a>. <!-- REPORTCRASHES --> </p>\n"; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 786 | } | 
|  | 787 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 788 | print OUT "</body></html>\n"; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 789 | close(OUT); | 
| Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 790 | CopyFiles($Dir); | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 791 |  | 
|  | 792 | # Make sure $Dir and $BaseDir are world readable/executable. | 
|  | 793 | system("chmod", "755", $Dir); | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 794 | if (defined $BaseDir) { system("chmod", "755", $BaseDir); } | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 795 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 796 | my $Num = scalar(@Index); | 
| Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 797 | Diag("$Num bugs found.\n"); | 
|  | 798 | if ($Num > 0 && -r "$Dir/index.html") { | 
| Ted Kremenek | 5950b3f | 2008-09-22 06:47:01 +0000 | [diff] [blame] | 799 | Diag("Run 'scan-view $Dir' to examine bug reports.\n"); | 
| Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 800 | } | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 801 |  | 
| Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 802 | DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored); | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 803 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 804 | return $Num; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 805 | } | 
|  | 806 |  | 
|  | 807 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 808 | # RunBuildCommand - Run the build command. | 
|  | 809 | ##----------------------------------------------------------------------------## | 
|  | 810 |  | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 811 | sub AddIfNotPresent { | 
|  | 812 | my $Args = shift; | 
|  | 813 | my $Arg = shift; | 
|  | 814 | my $found = 0; | 
|  | 815 |  | 
|  | 816 | foreach my $k (@$Args) { | 
|  | 817 | if ($k eq $Arg) { | 
|  | 818 | $found = 1; | 
|  | 819 | last; | 
|  | 820 | } | 
|  | 821 | } | 
|  | 822 |  | 
|  | 823 | if ($found == 0) { | 
|  | 824 | push @$Args, $Arg; | 
|  | 825 | } | 
|  | 826 | } | 
|  | 827 |  | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 828 | sub RunBuildCommand { | 
|  | 829 |  | 
|  | 830 | my $Args = shift; | 
| Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 831 | my $IgnoreErrors = shift; | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 832 | my $Cmd = $Args->[0]; | 
| Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 833 | my $CCAnalyzer = shift; | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 834 |  | 
| Ted Kremenek | 3301cb1 | 2008-06-30 18:18:16 +0000 | [diff] [blame] | 835 | # Get only the part of the command after the last '/'. | 
|  | 836 | if ($Cmd =~ /\/([^\/]+)$/) { | 
|  | 837 | $Cmd = $1; | 
|  | 838 | } | 
|  | 839 |  | 
| Ted Kremenek | 92548fe | 2008-11-19 01:46:21 +0000 | [diff] [blame] | 840 | if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or | 
|  | 841 | $Cmd =~ /(.*\/?cc[^\/]*$)/ or | 
|  | 842 | $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or | 
|  | 843 | $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) { | 
|  | 844 |  | 
|  | 845 | if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) { | 
|  | 846 | $ENV{"CCC_CC"} = $1; | 
|  | 847 | } | 
|  | 848 |  | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 849 | shift @$Args; | 
| Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 850 | unshift @$Args, $CCAnalyzer; | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 851 | } | 
| Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 852 | elsif ($IgnoreErrors) { | 
|  | 853 | if ($Cmd eq "make" or $Cmd eq "gmake") { | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 854 | AddIfNotPresent($Args,"-k"); | 
| Ted Kremenek | 8912b54 | 2008-05-13 21:28:02 +0000 | [diff] [blame] | 855 | AddIfNotPresent($Args,"-i"); | 
| Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 856 | } | 
|  | 857 | elsif ($Cmd eq "xcodebuild") { | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 858 | AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES"); | 
| Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 859 | } | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 860 | } | 
|  | 861 |  | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 862 | if ($Cmd eq "xcodebuild") { | 
| Ted Kremenek | 87752b2 | 2009-05-15 21:14:16 +0000 | [diff] [blame] | 863 | # Check if using iPhone SDK 3.0 (simulator).  If so the compiler being | 
|  | 864 | # used should be gcc-4.2. | 
|  | 865 | if (!defined $ENV{"CCC_CC"}) { | 
|  | 866 | for (my $i = 0 ; $i < scalar(@$Args); ++$i) { | 
|  | 867 | if ($Args->[$i] eq "-sdk" && $i + 1 < scalar(@$Args)) { | 
|  | 868 | if (@$Args[$i+1] =~ /^iphonesimulator3/) { | 
|  | 869 | $ENV{"CCC_CC"} = "gcc-4.2"; | 
|  | 870 | } | 
|  | 871 | } | 
|  | 872 | } | 
|  | 873 | } | 
|  | 874 |  | 
| Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 875 | # Disable distributed builds for xcodebuild. | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 876 | AddIfNotPresent($Args,"-nodistribute"); | 
| Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 877 |  | 
|  | 878 | # Disable PCH files until clang supports them. | 
|  | 879 | AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO"); | 
| Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 880 |  | 
|  | 881 | # When 'CC' is set, xcodebuild uses it to do all linking, even if we are | 
|  | 882 | # linking C++ object files.  Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' | 
|  | 883 | # when linking such files. | 
| Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 884 | die if (!defined $CXX); | 
|  | 885 | my $LDPLUSPLUS = `which $CXX`; | 
| Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 886 | $LDPLUSPLUS =~ s/\015?\012//;  # strip newlines | 
|  | 887 | $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS; | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 888 | } | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 889 |  | 
| Ted Kremenek | 5a4ddaf | 2008-08-25 20:10:45 +0000 | [diff] [blame] | 890 | return (system(@$Args) >> 8); | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 891 | } | 
|  | 892 |  | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 893 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 894 | # DisplayHelp - Utility function to display all help options. | 
|  | 895 | ##----------------------------------------------------------------------------## | 
|  | 896 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 897 | sub DisplayHelp { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 898 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 899 | print <<ENDTEXT; | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 900 | USAGE: $Prog [options] <build command> [build options] | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 901 |  | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 902 | ENDTEXT | 
|  | 903 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 904 | if (defined $BuildName) { | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 905 | print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n"; | 
|  | 906 | } | 
|  | 907 |  | 
|  | 908 | print <<ENDTEXT; | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 909 | OPTIONS: | 
|  | 910 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 911 | -analyze-headers - Also analyze functions in #included files. | 
|  | 912 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 913 | -o             - Target directory for HTML report files.  Subdirectories | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 914 | will be created as needed to represent separate "runs" of | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 915 | the analyzer.  If this option is not specified, a directory | 
| Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 916 | is created in /tmp (TMPDIR on Mac OS X) to store the reports. | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 917 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 918 | -h             - Display this message. | 
|  | 919 | --help | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 920 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 921 | -k             - Add a "keep on going" option to the specified build command. | 
|  | 922 | --keep-going     This option currently supports make and xcodebuild. | 
| Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 923 | This is a convenience option; one can specify this | 
|  | 924 | behavior directly using build options. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 925 |  | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 926 | --html-title [title]       - Specify the title used on generated HTML pages. | 
|  | 927 | --html-title=[title]         If not specified, a default title will be used. | 
|  | 928 |  | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 929 | -plist         - By default the output of scan-build is a set of HTML files. | 
|  | 930 | This option outputs the results as a set of .plist files. | 
|  | 931 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 932 | --status-bugs  - By default, the exit status of $Prog is the same as the | 
|  | 933 | executed build command.  Specifying this option causes the | 
|  | 934 | exit status of $Prog to be 1 if it found potential bugs | 
|  | 935 | and 0 otherwise. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 936 |  | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 937 | --use-cc [compiler path]   - By default, $Prog uses 'gcc' to compile and link | 
|  | 938 | --use-cc=[compiler path]     your C and Objective-C code. Use this option | 
|  | 939 | to specify an alternate compiler. | 
|  | 940 |  | 
|  | 941 | --use-c++ [compiler path]  - By default, $Prog uses 'g++' to compile and link | 
|  | 942 | --use-c++=[compiler path]    your C++ and Objective-C++ code. Use this option | 
|  | 943 | to specify an alternate compiler. | 
| Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 944 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 945 | -v             - Verbose output from $Prog and the analyzer. | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 946 | A second and third '-v' increases verbosity. | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 947 |  | 
|  | 948 | -V             - View analysis results in a web browser when the build | 
|  | 949 | --view           completes. | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 950 |  | 
| Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 951 | ADVANCED OPTIONS: | 
|  | 952 |  | 
| Ted Kremenek | 9f4ecb3 | 2009-02-20 21:49:22 +0000 | [diff] [blame] | 953 | -constraints [model] - Specify the contraint engine used by the analyzer. | 
|  | 954 | By default the 'range' model is used.  Specifying | 
|  | 955 | 'basic' uses a simpler, less powerful constraint model | 
| Ted Kremenek | d4c7684 | 2009-02-21 04:46:41 +0000 | [diff] [blame] | 956 | used by checker-0.160 and earlier. | 
| Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 957 |  | 
|  | 958 | -store [model] - Specify the store model used by the analyzer. By default, | 
|  | 959 | the 'basic' store model is used. 'region' specifies a field- | 
|  | 960 | sensitive store model. Be warned that the 'region' model | 
|  | 961 | is still in very early testing phase and may often crash. | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 962 |  | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 963 | AVAILABLE ANALYSES (multiple analyses may be specified): | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 964 |  | 
|  | 965 | ENDTEXT | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 966 |  | 
|  | 967 | foreach my $Analysis (sort keys %AvailableAnalyses) { | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 968 | if (defined $AnalysesDefaultEnabled{$Analysis}) { | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 969 | print " (+)"; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 970 | } | 
|  | 971 | else { | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 972 | print "    "; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 973 | } | 
|  | 974 |  | 
|  | 975 | print " $Analysis  $AvailableAnalyses{$Analysis}\n"; | 
|  | 976 | } | 
|  | 977 |  | 
|  | 978 | print <<ENDTEXT | 
|  | 979 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 980 | NOTE: "(+)" indicates that an analysis is enabled by default unless one | 
|  | 981 | or more analysis options are specified | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 982 |  | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 983 | BUILD OPTIONS | 
|  | 984 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 985 | You can specify any build option acceptable to the build command. | 
| Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 986 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 987 | EXAMPLE | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 988 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 989 | $Prog -o /tmp/myhtmldir make -j4 | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 990 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 991 | The above example causes analysis reports to be deposited into | 
|  | 992 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. | 
|  | 993 | A different subdirectory is created each time $Prog analyzes a project. | 
|  | 994 | The analyzer should support most parallel builds, but not distributed builds. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 995 |  | 
|  | 996 | ENDTEXT | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 997 | } | 
|  | 998 |  | 
|  | 999 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1000 | # HtmlEscape - HTML entity encode characters that are special in HTML | 
|  | 1001 | ##----------------------------------------------------------------------------## | 
|  | 1002 |  | 
|  | 1003 | sub HtmlEscape { | 
|  | 1004 | # copy argument to new variable so we don't clobber the original | 
|  | 1005 | my $arg = shift || ''; | 
|  | 1006 | my $tmp = $arg; | 
| Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 1007 | $tmp =~ s/&/&/g; | 
|  | 1008 | $tmp =~ s/</</g; | 
|  | 1009 | $tmp =~ s/>/>/g; | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1010 | return $tmp; | 
|  | 1011 | } | 
|  | 1012 |  | 
|  | 1013 | ##----------------------------------------------------------------------------## | 
|  | 1014 | # ShellEscape - backslash escape characters that are special to the shell | 
|  | 1015 | ##----------------------------------------------------------------------------## | 
|  | 1016 |  | 
|  | 1017 | sub ShellEscape { | 
|  | 1018 | # copy argument to new variable so we don't clobber the original | 
|  | 1019 | my $arg = shift || ''; | 
| Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 1020 | if ($arg =~ /["\s]/) { return "'" . $arg . "'"; } | 
|  | 1021 | return $arg; | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1022 | } | 
|  | 1023 |  | 
|  | 1024 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1025 | # Process command-line arguments. | 
|  | 1026 | ##----------------------------------------------------------------------------## | 
|  | 1027 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1028 | my $AnalyzeHeaders = 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1029 | my $HtmlDir;           # Parent directory to store HTML files. | 
|  | 1030 | my $IgnoreErrors = 0;  # Ignore build errors. | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1031 | my $ViewResults  = 0;  # View results when the build terminates. | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1032 | my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 1033 | my @AnalysesToRun; | 
| Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1034 | my $StoreModel; | 
| Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 1035 | my $ConstraintsModel; | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1036 | my $OutputFormat; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1037 |  | 
|  | 1038 | if (!@ARGV) { | 
|  | 1039 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1040 | exit 1; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1041 | } | 
|  | 1042 |  | 
|  | 1043 | while (@ARGV) { | 
|  | 1044 |  | 
|  | 1045 | # Scan for options we recognize. | 
|  | 1046 |  | 
|  | 1047 | my $arg = $ARGV[0]; | 
|  | 1048 |  | 
| Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 1049 | if ($arg eq "-h" or $arg eq "--help") { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1050 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1051 | exit 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1052 | } | 
|  | 1053 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1054 | if ($arg eq '-analyze-headers') { | 
|  | 1055 | shift @ARGV; | 
|  | 1056 | $AnalyzeHeaders = 1; | 
|  | 1057 | next; | 
|  | 1058 | } | 
|  | 1059 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 1060 | if (defined $AvailableAnalyses{$arg}) { | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1061 | shift @ARGV; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 1062 | push @AnalysesToRun, $arg; | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1063 | next; | 
|  | 1064 | } | 
|  | 1065 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1066 | if ($arg eq "-o") { | 
|  | 1067 | shift @ARGV; | 
|  | 1068 |  | 
|  | 1069 | if (!@ARGV) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1070 | DieDiag("'-o' option requires a target directory name.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1071 | } | 
|  | 1072 |  | 
| Ted Kremenek | db51a55 | 2009-03-11 18:20:33 +0000 | [diff] [blame] | 1073 | # Construct an absolute path.  Uses the current working directory | 
|  | 1074 | # as a base if the original path was not absolute. | 
|  | 1075 | $HtmlDir = abs_path(shift @ARGV); | 
|  | 1076 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1077 | next; | 
|  | 1078 | } | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1079 |  | 
|  | 1080 | if ($arg =~ /^--html-title(=(.+))?$/) { | 
|  | 1081 | shift @ARGV; | 
|  | 1082 |  | 
| Ted Kremenek | 278a551 | 2009-05-12 18:04:43 +0000 | [diff] [blame] | 1083 | if (!defined $2 || $2 eq '') { | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1084 | if (!@ARGV) { | 
|  | 1085 | DieDiag("'--html-title' option requires a string.\n"); | 
|  | 1086 | } | 
|  | 1087 |  | 
|  | 1088 | $HtmlTitle = shift @ARGV; | 
|  | 1089 | } else { | 
|  | 1090 | $HtmlTitle = $2; | 
|  | 1091 | } | 
|  | 1092 |  | 
|  | 1093 | next; | 
|  | 1094 | } | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1095 |  | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 1096 | if ($arg eq "-k" or $arg eq "--keep-going") { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1097 | shift @ARGV; | 
|  | 1098 | $IgnoreErrors = 1; | 
|  | 1099 | next; | 
|  | 1100 | } | 
|  | 1101 |  | 
| Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 1102 | if ($arg =~ /^--use-cc(=(.+))?$/) { | 
|  | 1103 | shift @ARGV; | 
|  | 1104 | my $cc; | 
|  | 1105 |  | 
| Ted Kremenek | 278a551 | 2009-05-12 18:04:43 +0000 | [diff] [blame] | 1106 | if (!defined $2 || $2 eq "") { | 
| Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 1107 | if (!@ARGV) { | 
|  | 1108 | DieDiag("'--use-cc' option requires a compiler executable name.\n"); | 
|  | 1109 | } | 
|  | 1110 | $cc = shift @ARGV; | 
|  | 1111 | } | 
|  | 1112 | else { | 
|  | 1113 | $cc = $2; | 
|  | 1114 | } | 
|  | 1115 |  | 
|  | 1116 | $ENV{"CCC_CC"} = $cc; | 
|  | 1117 | next; | 
|  | 1118 | } | 
|  | 1119 |  | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1120 | if ($arg =~ /^--use-c\+\+(=(.+))?$/) { | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1121 | shift @ARGV; | 
|  | 1122 |  | 
| Ted Kremenek | 278a551 | 2009-05-12 18:04:43 +0000 | [diff] [blame] | 1123 | if (!defined $2 || $2 eq "") { | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1124 | if (!@ARGV) { | 
|  | 1125 | DieDiag("'--use-c++' option requires a compiler executable name.\n"); | 
|  | 1126 | } | 
|  | 1127 | $CXX = shift @ARGV; | 
|  | 1128 | } | 
|  | 1129 | else { | 
|  | 1130 | $CXX = $2; | 
|  | 1131 | } | 
|  | 1132 | next; | 
|  | 1133 | } | 
|  | 1134 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1135 | if ($arg eq "-v") { | 
|  | 1136 | shift @ARGV; | 
|  | 1137 | $Verbose++; | 
|  | 1138 | next; | 
|  | 1139 | } | 
|  | 1140 |  | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1141 | if ($arg eq "-V" or $arg eq "--view") { | 
|  | 1142 | shift @ARGV; | 
|  | 1143 | $ViewResults = 1; | 
|  | 1144 | next; | 
|  | 1145 | } | 
|  | 1146 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1147 | if ($arg eq "--status-bugs") { | 
|  | 1148 | shift @ARGV; | 
|  | 1149 | $ExitStatusFoundBugs = 1; | 
|  | 1150 | next; | 
|  | 1151 | } | 
| Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1152 |  | 
|  | 1153 | if ($arg eq "-store") { | 
|  | 1154 | shift @ARGV; | 
| Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 1155 | $StoreModel = shift @ARGV; | 
|  | 1156 | next; | 
|  | 1157 | } | 
|  | 1158 |  | 
|  | 1159 | if ($arg eq "-constraints") { | 
|  | 1160 | shift @ARGV; | 
|  | 1161 | $ConstraintsModel = shift @ARGV; | 
| Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1162 | next; | 
|  | 1163 | } | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1164 |  | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1165 | if ($arg eq "-plist") { | 
|  | 1166 | shift @ARGV; | 
|  | 1167 | $OutputFormat = "plist"; | 
|  | 1168 | next; | 
|  | 1169 | } | 
| Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 1170 | if ($arg eq "-plist-html") { | 
|  | 1171 | shift @ARGV; | 
|  | 1172 | $OutputFormat = "plist-html"; | 
|  | 1173 | next; | 
|  | 1174 | } | 
|  | 1175 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1176 | DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); | 
| Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 1177 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1178 | last; | 
|  | 1179 | } | 
|  | 1180 |  | 
|  | 1181 | if (!@ARGV) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1182 | Diag("No build command specified.\n\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1183 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1184 | exit 1; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1185 | } | 
|  | 1186 |  | 
| Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1187 | $CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV))); | 
|  | 1188 | $HtmlTitle = "${CurrentDirSuffix} - scan-build results" | 
|  | 1189 | unless (defined($HtmlTitle)); | 
| Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1190 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1191 | # Determine the output directory for the HTML reports. | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 1192 | my $BaseDir = $HtmlDir; | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1193 | $HtmlDir = GetHTMLRunDir($HtmlDir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1194 |  | 
|  | 1195 | # Set the appropriate environment variables. | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1196 | SetHtmlEnv(\@ARGV, $HtmlDir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1197 |  | 
| Ted Kremenek | 91ea79d | 2009-03-24 05:30:14 +0000 | [diff] [blame] | 1198 | my $Cmd = Cwd::realpath("$RealBin/libexec/ccc-analyzer"); | 
| Ted Kremenek | ce87b92 | 2009-02-25 22:54:02 +0000 | [diff] [blame] | 1199 | if (!defined $Cmd || ! -x $Cmd) { | 
|  | 1200 | $Cmd = Cwd::realpath("$RealBin/ccc-analyzer"); | 
| Ted Kremenek | 6b89636 | 2009-02-27 06:17:05 +0000 | [diff] [blame] | 1201 | DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") if(! -x $Cmd); | 
| Ted Kremenek | ce87b92 | 2009-02-25 22:54:02 +0000 | [diff] [blame] | 1202 | } | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1203 |  | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 1204 | if (!defined $ClangCCSB || ! -x $ClangCCSB) { | 
| Ted Kremenek | 91ea79d | 2009-03-24 05:30:14 +0000 | [diff] [blame] | 1205 | Diag("'clang-cc' executable not found in '$RealBin/libexec'.\n"); | 
| Ted Kremenek | 318e6a6 | 2009-03-24 04:29:13 +0000 | [diff] [blame] | 1206 | Diag("Using 'clang-cc' from path.\n"); | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1207 | } | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 1208 | if (!defined $ClangSB || ! -x $ClangSB) { | 
|  | 1209 | Diag("'clang' executable not found in '$RealBin/bin'.\n"); | 
|  | 1210 | Diag("Using 'clang' from path.\n"); | 
|  | 1211 | } | 
| Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1212 |  | 
| Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 1213 | if (defined $CXX) { | 
|  | 1214 | $ENV{'CXX'} = $CXX; | 
|  | 1215 | } | 
|  | 1216 | else { | 
|  | 1217 | $CXX = 'g++';  # This variable is used by other parts of scan-build | 
|  | 1218 | # that need to know a default C++ compiler to fall back to. | 
|  | 1219 | } | 
|  | 1220 |  | 
| Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 1221 | $ENV{'CC'} = $Cmd; | 
| Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 1222 | $ENV{'CLANG_CC'} = $ClangCC; | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1223 | $ENV{'CLANG'} = $Clang; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1224 |  | 
|  | 1225 | if ($Verbose >= 2) { | 
|  | 1226 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; | 
|  | 1227 | } | 
|  | 1228 |  | 
| Ted Kremenek | a9525c9 | 2008-05-12 22:07:14 +0000 | [diff] [blame] | 1229 | if ($Verbose >= 3) { | 
|  | 1230 | $ENV{'CCC_ANALYZER_LOG'} = 1; | 
|  | 1231 | } | 
|  | 1232 |  | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1233 | if (scalar(@AnalysesToRun) == 0) { | 
|  | 1234 | foreach my $key (keys %AnalysesDefaultEnabled) { | 
|  | 1235 | push @AnalysesToRun,$key; | 
|  | 1236 | } | 
| Ted Kremenek | 0100678 | 2008-07-02 23:16:10 +0000 | [diff] [blame] | 1237 | } | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1238 |  | 
| Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1239 | if ($AnalyzeHeaders) { | 
|  | 1240 | push @AnalysesToRun,"-analyzer-opt-analyze-headers"; | 
|  | 1241 | } | 
|  | 1242 |  | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1243 | $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; | 
|  | 1244 |  | 
| Zhongxing Xu | 3cab2b1 | 2008-11-02 10:58:16 +0000 | [diff] [blame] | 1245 | if (defined $StoreModel) { | 
| Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1246 | $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel; | 
|  | 1247 | } | 
|  | 1248 |  | 
| Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 1249 | if (defined $ConstraintsModel) { | 
|  | 1250 | $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'} = $ConstraintsModel; | 
|  | 1251 | } | 
|  | 1252 |  | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1253 | if (defined $OutputFormat) { | 
|  | 1254 | $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'} = $OutputFormat; | 
|  | 1255 | } | 
|  | 1256 |  | 
|  | 1257 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1258 | # Run the build. | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1259 | my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1260 |  | 
| Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 1261 | if (defined $OutputFormat) { | 
| Daniel Dunbar | 1182502 | 2009-07-29 16:21:23 +0000 | [diff] [blame^] | 1262 | if ($OutputFormat =~ /plist/) { | 
|  | 1263 | Diag "Analysis run complete.\n"; | 
|  | 1264 | Diag "Analysis results (plist files) deposited in '$HtmlDir'\n"; | 
|  | 1265 | } | 
|  | 1266 | elsif ($OutputFormat =~ /html/) { | 
| Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 1267 | # Postprocess the HTML directory. | 
|  | 1268 | my $NumBugs = Postprocess($HtmlDir, $BaseDir); | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1269 |  | 
| Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 1270 | if ($ViewResults and -r "$HtmlDir/index.html") { | 
|  | 1271 | Diag "Analysis run complete.\n"; | 
|  | 1272 | Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n"; | 
|  | 1273 | my $ScanView = Cwd::realpath("$RealBin/scan-view"); | 
|  | 1274 | if (! -x $ScanView) { $ScanView = "scan-view"; } | 
|  | 1275 | exec $ScanView, "$HtmlDir"; | 
|  | 1276 | } | 
|  | 1277 |  | 
|  | 1278 | if ($ExitStatusFoundBugs) { | 
|  | 1279 | exit 1 if ($NumBugs > 0); | 
|  | 1280 | exit 0; | 
|  | 1281 | } | 
| Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1282 | } | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1283 | } | 
|  | 1284 |  | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1285 | exit $ExitStatus; | 
|  | 1286 |  |