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