blob: 99a799052d86c8b6cff20ef811f86fc5c63ae669 [file] [log] [blame]
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001#!/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
15use strict;
16use warnings;
Ted Kremenek22d6a632008-04-02 20:43:36 +000017use FindBin qw($RealBin);
Ted Kremeneka6e24812008-04-19 18:05:48 +000018use Digest::MD5;
Ted Kremenek7a4648d2008-05-02 22:04:53 +000019use File::Basename;
Ted Kremenek23cfca32008-06-16 22:40:14 +000020use Term::ANSIColor;
21use Term::ANSIColor qw(:constants);
Ted Kremenekcd25c132008-12-03 19:50:37 +000022use Cwd qw/ getcwd abs_path /;
Ted Kremenek7cba1122008-09-22 01:35:58 +000023use Sys::Hostname;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000024
25my $Verbose = 0; # Verbose output from this script.
26my $Prog = "scan-build";
Ted Kremenekf4cdf412008-05-23 18:17:05 +000027my $BuildName;
28my $BuildDate;
Ted Kremenek95aa1052008-09-04 17:52:41 +000029my $CXX; # Leave undefined initially.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000030
Ted Kremenek0e689382008-09-11 18:17:51 +000031my $TERM = $ENV{'TERM'};
32my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT
33 and defined $ENV{'SCAN_BUILD_COLOR'});
Ted Kremenek23cfca32008-06-16 22:40:14 +000034
Ted Kremenek7cba1122008-09-22 01:35:58 +000035my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
36my $HostName = HtmlEscape(hostname() || 'unknown');
37my $CurrentDir = HtmlEscape(getcwd());
38my $CurrentDirSuffix = basename($CurrentDir);
39
40my $CmdArgs;
41
42my $HtmlTitle;
43
44my $Date = localtime();
45
Ted Kremenekb7770c02008-07-15 17:06:13 +000046##----------------------------------------------------------------------------##
47# Diagnostics
48##----------------------------------------------------------------------------##
49
Ted Kremenek23cfca32008-06-16 22:40:14 +000050sub Diag {
51 if ($UseColor) {
52 print BOLD, MAGENTA "$Prog: @_";
53 print RESET;
54 }
55 else {
56 print "$Prog: @_";
57 }
58}
59
Ted Kremenek991c54b2008-08-08 20:46:42 +000060sub DiagCrashes {
61 my $Dir = shift;
Ted Kremenek938eef12009-02-17 23:31:05 +000062 Diag ("The analyzer encountered problems on some source files.\n");
63 Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n");
Ted Kremenek991c54b2008-08-08 20:46:42 +000064 Diag ("Please consider submitting a bug report using these files:\n");
65 Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n")
66}
67
Ted Kremenek23cfca32008-06-16 22:40:14 +000068sub 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 Kremenek9cc8c2c2008-04-01 20:47:38 +000080##----------------------------------------------------------------------------##
Ted Kremenekb7770c02008-07-15 17:06:13 +000081# Some initial preprocessing of Clang options.
82##----------------------------------------------------------------------------##
83
Ted Kremenek2d62ab12009-02-23 23:01:06 +000084my $ClangSB = Cwd::realpath("$RealBin/bin/clang");
Ted Kremenekb7770c02008-07-15 17:06:13 +000085my $Clang = $ClangSB;
86
Ted Kremenek8d10cdd2009-02-20 04:34:29 +000087if (!defined $ClangSB || ! -x $ClangSB) {
Ted Kremenekb7770c02008-07-15 17:06:13 +000088 $Clang = "clang";
89}
90
91my %AvailableAnalyses;
92
93# Query clang for analysis options.
Ted Kremenek63c20172008-08-04 17:34:06 +000094open(PIPE, "-|", $Clang, "--help") or
Ted Kremenek445fa772008-10-10 00:17:08 +000095 DieDiag("Cannot execute '$Clang'\n");
Ted Kremenek63c20172008-08-04 17:34:06 +000096
Ted Kremenekb7770c02008-07-15 17:06:13 +000097my $FoundAnalysis = 0;
98
99while(<PIPE>) {
100 if ($FoundAnalysis == 0) {
Ted Kremenek938eef12009-02-17 23:31:05 +0000101 if (/Checks and Analyses/) {
Ted Kremenekb7770c02008-07-15 17:06:13 +0000102 $FoundAnalysis = 1;
103 }
Ted Kremenekb7770c02008-07-15 17:06:13 +0000104 next;
105 }
106
107 if (/^\s\s\s\s([^\s]+)\s(.+)$/) {
108 next if ($1 =~ /-dump/ or $1 =~ /-view/
109 or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/);
110
111 $AvailableAnalyses{$1} = $2;
112 next;
Ted Kremenek938eef12009-02-17 23:31:05 +0000113 }
Ted Kremenekb7770c02008-07-15 17:06:13 +0000114 last;
115}
116
117close (PIPE);
118
119my %AnalysesDefaultEnabled = (
120 '-warn-dead-stores' => 1,
121 '-checker-cfref' => 1,
Ted Kremenek90125992008-07-15 23:41:32 +0000122 '-warn-objc-methodsigs' => 1,
Ted Kremenekbde3a052008-07-25 20:35:01 +0000123 '-warn-objc-missing-dealloc' => 1,
Ted Kremenek5d443492008-09-18 06:34:16 +0000124 '-warn-objc-unused-ivars' => 1,
Ted Kremenekb7770c02008-07-15 17:06:13 +0000125);
126
127##----------------------------------------------------------------------------##
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000128# GetHTMLRunDir - Construct an HTML directory name for the current sub-run.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000129##----------------------------------------------------------------------------##
130
Sam Bishopa0e22662008-04-02 03:35:43 +0000131sub GetHTMLRunDir {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000132
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000133 die "Not enough arguments." if (@_ == 0);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000134 my $Dir = shift @_;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000135
136 my $TmpMode = 0;
137 if (!defined $Dir) {
Ted Kremenekffda0b42008-10-31 05:48:42 +0000138 if (`uname` =~ /Darwin/) {
139 $Dir = $ENV{'TMPDIR'};
140 if (!defined $Dir) { $Dir = "/tmp"; }
141 }
142 else {
143 $Dir = "/tmp";
144 }
145
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000146 $TmpMode = 1;
147 }
Ted Kremenekbf762c92009-02-24 02:38:02 +0000148
149 # Chop off any trailing '/' characters.
150 while ($Dir =~ /\/$/) { chop $Dir; }
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000151
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000152 # Get current date and time.
153
154 my @CurrentTime = localtime();
155
156 my $year = $CurrentTime[5] + 1900;
157 my $day = $CurrentTime[3];
158 my $month = $CurrentTime[4] + 1;
159
Ted Kremenek9d7405f2008-05-14 17:23:56 +0000160 my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000161
162 # Determine the run number.
163
164 my $RunNumber;
165
166 if (-d $Dir) {
167
168 if (! -r $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000169 DieDiag("directory '$Dir' exists but is not readable.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000170 }
171
172 # Iterate over all files in the specified directory.
173
174 my $max = 0;
175
176 opendir(DIR, $Dir);
Ted Kremenek29da6c52008-08-07 17:57:34 +0000177 my @FILES = grep { -d "$Dir/$_" } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000178 closedir(DIR);
179
180 foreach my $f (@FILES) {
181
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000182 # Strip the prefix '$Prog-' if we are dumping files to /tmp.
183 if ($TmpMode) {
184 next if (!($f =~ /^$Prog-(.+)/));
185 $f = $1;
186 }
187
Ted Kremenekebb74132008-09-21 06:58:09 +0000188
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000189 my @x = split/-/, $f;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000190 next if (scalar(@x) != 4);
191 next if ($x[0] != $year);
192 next if ($x[1] != $month);
193 next if ($x[2] != $day);
194
195 if ($x[3] > $max) {
196 $max = $x[3];
197 }
198 }
199
200 $RunNumber = $max + 1;
201 }
202 else {
203
204 if (-x $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000205 DieDiag("'$Dir' exists but is not a directory.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000206 }
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000207
208 if ($TmpMode) {
Ted Kremenek445fa772008-10-10 00:17:08 +0000209 DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n");
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000210 }
211
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000212 # $Dir does not exist. It will be automatically created by the
213 # clang driver. Set the run number to 1.
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000214
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000215 $RunNumber = 1;
216 }
217
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000218 die "RunNumber must be defined!" if (!defined $RunNumber);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000219
220 # Append the run number.
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000221 my $NewDir;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000222 if ($TmpMode) {
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000223 $NewDir = "$Dir/$Prog-$DateString-$RunNumber";
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000224 }
225 else {
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000226 $NewDir = "$Dir/$DateString-$RunNumber";
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000227 }
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000228 system 'mkdir','-p',$NewDir;
229 return $NewDir;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000230}
231
Sam Bishopa0e22662008-04-02 03:35:43 +0000232sub SetHtmlEnv {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000233
234 die "Wrong number of arguments." if (scalar(@_) != 2);
235
236 my $Args = shift;
237 my $Dir = shift;
238
239 die "No build command." if (scalar(@$Args) == 0);
240
241 my $Cmd = $$Args[0];
242
243 if ($Cmd =~ /configure/) {
244 return;
245 }
246
247 if ($Verbose) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000248 Diag("Emitting reports for this run to '$Dir'.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000249 }
250
251 $ENV{'CCC_ANALYZER_HTML'} = $Dir;
252}
253
254##----------------------------------------------------------------------------##
Ted Kremenek57cf4462008-04-18 15:09:30 +0000255# ComputeDigest - Compute a digest of the specified file.
256##----------------------------------------------------------------------------##
257
258sub ComputeDigest {
259 my $FName = shift;
Ted Kremenek23cfca32008-06-16 22:40:14 +0000260 DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName);
Ted Kremeneka6e24812008-04-19 18:05:48 +0000261
262 # Use Digest::MD5. We don't have to be cryptographically secure. We're
Ted Kremenek7ea02e62008-04-19 18:07:44 +0000263 # just looking for duplicate files that come from a non-malicious source.
264 # We use Digest::MD5 because it is a standard Perl module that should
Ted Kremenek63c20172008-08-04 17:34:06 +0000265 # come bundled on most systems.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000266 open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n");
Ted Kremeneka6e24812008-04-19 18:05:48 +0000267 binmode FILE;
268 my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
269 close(FILE);
270
Ted Kremenek63c20172008-08-04 17:34:06 +0000271 # Return the digest.
Ted Kremeneka6e24812008-04-19 18:05:48 +0000272 return $Result;
Ted Kremenek57cf4462008-04-18 15:09:30 +0000273}
274
275##----------------------------------------------------------------------------##
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000276# UpdatePrefix - Compute the common prefix of files.
277##----------------------------------------------------------------------------##
278
279my $Prefix;
280
281sub UpdatePrefix {
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000282 my $x = shift;
283 my $y = basename($x);
284 $x =~ s/\Q$y\E$//;
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000285
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000286 if (!defined $Prefix) {
287 $Prefix = $x;
288 return;
289 }
290
Ted Kremenek20b2bae2008-09-11 21:15:10 +0000291 chop $Prefix while (!($x =~ /^\Q$Prefix/));
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000292}
293
294sub GetPrefix {
295 return $Prefix;
296}
297
298##----------------------------------------------------------------------------##
299# UpdateInFilePath - Update the path in the report file.
300##----------------------------------------------------------------------------##
301
302sub UpdateInFilePath {
303 my $fname = shift;
304 my $regex = shift;
305 my $newtext = shift;
Ted Kremenek63c20172008-08-04 17:34:06 +0000306
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000307 open (RIN, $fname) or die "cannot open $fname";
Ted Kremenek63c20172008-08-04 17:34:06 +0000308 open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp";
309
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000310 while (<RIN>) {
311 s/$regex/$newtext/;
312 print ROUT $_;
313 }
Ted Kremenek63c20172008-08-04 17:34:06 +0000314
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000315 close (ROUT);
316 close (RIN);
Ted Kremenek20161e92008-07-15 20:18:21 +0000317 system("mv", "$fname.tmp", $fname);
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000318}
319
320##----------------------------------------------------------------------------##
Ted Kremenek5744dc22008-04-02 18:03:36 +0000321# ScanFile - Scan a report file for various identifying attributes.
322##----------------------------------------------------------------------------##
323
Ted Kremenek57cf4462008-04-18 15:09:30 +0000324# Sometimes a source file is scanned more than once, and thus produces
325# multiple error reports. We use a cache to solve this problem.
326
327my %AlreadyScanned;
328
Ted Kremenek5744dc22008-04-02 18:03:36 +0000329sub ScanFile {
330
331 my $Index = shift;
332 my $Dir = shift;
333 my $FName = shift;
334
Ted Kremenek57cf4462008-04-18 15:09:30 +0000335 # Compute a digest for the report file. Determine if we have already
336 # scanned a file that looks just like it.
337
338 my $digest = ComputeDigest("$Dir/$FName");
339
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000340 if (defined $AlreadyScanned{$digest}) {
Ted Kremenek57cf4462008-04-18 15:09:30 +0000341 # Redundant file. Remove it.
Ted Kremenek20161e92008-07-15 20:18:21 +0000342 system ("rm", "-f", "$Dir/$FName");
Ted Kremenek57cf4462008-04-18 15:09:30 +0000343 return;
344 }
345
346 $AlreadyScanned{$digest} = 1;
347
Ted Kremenek809709f2008-04-18 16:58:34 +0000348 # At this point the report file is not world readable. Make it happen.
Ted Kremenek20161e92008-07-15 20:18:21 +0000349 system ("chmod", "644", "$Dir/$FName");
Ted Kremenek684bb092008-04-18 15:18:20 +0000350
351 # Scan the report file for tags.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000352 open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000353
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000354 my $BugType = "";
Ted Kremenek22d6a632008-04-02 20:43:36 +0000355 my $BugFile = "";
Ted Kremenekebb74132008-09-21 06:58:09 +0000356 my $BugCategory;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000357 my $BugPathLength = 1;
358 my $BugLine = 0;
Ted Kremenekebb74132008-09-21 06:58:09 +0000359 my $found = 0;
360
Ted Kremenek5744dc22008-04-02 18:03:36 +0000361 while (<IN>) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000362
363 last if ($found == 5);
364
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000365 if (/<!-- BUGTYPE (.*) -->$/) {
366 $BugType = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000367 ++$found;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000368 }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000369 elsif (/<!-- BUGFILE (.*) -->$/) {
Ted Kremenek990c2f42008-12-03 19:19:23 +0000370 $BugFile = abs_path($1);
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000371 UpdatePrefix($BugFile);
Ted Kremenekebb74132008-09-21 06:58:09 +0000372 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000373 }
374 elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
375 $BugPathLength = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000376 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000377 }
378 elsif (/<!-- BUGLINE (.*) -->$/) {
379 $BugLine = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000380 ++$found;
381 }
382 elsif (/<!-- BUGCATEGORY (.*) -->$/) {
383 $BugCategory = $1;
384 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000385 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000386 }
387
388 close(IN);
Ted Kremenekebb74132008-09-21 06:58:09 +0000389
390 if (!defined $BugCategory) {
391 $BugCategory = "Other";
392 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000393
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000394 push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugLine,
Ted Kremenek81983112008-09-28 04:13:09 +0000395 $BugPathLength ];
Ted Kremenek22d6a632008-04-02 20:43:36 +0000396}
397
398##----------------------------------------------------------------------------##
Ted Kremenek3ce12072008-09-22 17:50:47 +0000399# CopyFiles - Copy resource files to target directory.
Ted Kremenek22d6a632008-04-02 20:43:36 +0000400##----------------------------------------------------------------------------##
401
Ted Kremenek3ce12072008-09-22 17:50:47 +0000402sub CopyFiles {
Ted Kremenek22d6a632008-04-02 20:43:36 +0000403
404 my $Dir = shift;
Ted Kremeneke15fa272008-10-13 21:46:42 +0000405
406 my $JS = Cwd::realpath("$RealBin/sorttable.js");
Ted Kremenek22d6a632008-04-02 20:43:36 +0000407
Ted Kremenek23cfca32008-06-16 22:40:14 +0000408 DieDiag("Cannot find 'sorttable.js'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000409 if (! -r $JS);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000410
Ted Kremeneke15fa272008-10-13 21:46:42 +0000411 system ("cp", $JS, "$Dir");
Ted Kremenek22d6a632008-04-02 20:43:36 +0000412
Ted Kremenek23cfca32008-06-16 22:40:14 +0000413 DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
Ted Kremenek22d6a632008-04-02 20:43:36 +0000414 if (! -r "$Dir/sorttable.js");
Ted Kremenek3ce12072008-09-22 17:50:47 +0000415
Ted Kremeneke15fa272008-10-13 21:46:42 +0000416 my $CSS = Cwd::realpath("$RealBin/scanview.css");
417
Ted Kremenek3ce12072008-09-22 17:50:47 +0000418 DieDiag("Cannot find 'scanview.css'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000419 if (! -r $CSS);
Ted Kremenek3ce12072008-09-22 17:50:47 +0000420
Ted Kremeneke15fa272008-10-13 21:46:42 +0000421 system ("cp", $CSS, "$Dir");
Ted Kremenek3ce12072008-09-22 17:50:47 +0000422
423 DieDiag("Could not copy 'scanview.css' to '$Dir'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000424 if (! -r $CSS);
Ted Kremenek5744dc22008-04-02 18:03:36 +0000425}
426
427##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000428# Postprocess - Postprocess the results of an analysis scan.
429##----------------------------------------------------------------------------##
430
Sam Bishopa0e22662008-04-02 03:35:43 +0000431sub Postprocess {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000432
433 my $Dir = shift;
Ted Kremenek684bb092008-04-18 15:18:20 +0000434 my $BaseDir = shift;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000435
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000436 die "No directory specified." if (!defined $Dir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000437
438 if (! -d $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000439 Diag("No bugs found.\n");
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000440 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000441 }
442
443 opendir(DIR, $Dir);
Ted Kremenek938eef12009-02-17 23:31:05 +0000444 my @files = grep { /^report-.*\.html$/ } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000445 closedir(DIR);
446
Ted Kremenek938eef12009-02-17 23:31:05 +0000447 if (scalar(@files) == 0 and ! -e "$Dir/failures") {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000448 Diag("Removing directory '$Dir' because it contains no reports.\n");
Ted Kremenek20161e92008-07-15 20:18:21 +0000449 system ("rm", "-fR", $Dir);
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000450 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000451 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000452
Ted Kremenek991c54b2008-08-08 20:46:42 +0000453 # Scan each report file and build an index.
454 my @Index;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000455 foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); }
456
Ted Kremenek938eef12009-02-17 23:31:05 +0000457 # Scan the failures directory and use the information in the .info files
Ted Kremenekd52e4252008-08-25 20:45:07 +0000458 # to update the common prefix directory.
Ted Kremenek938eef12009-02-17 23:31:05 +0000459 my @failures;
460 my @attributes_ignored;
461 if (-d "$Dir/failures") {
462 opendir(DIR, "$Dir/failures");
463 @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR);
Ted Kremenekd52e4252008-08-25 20:45:07 +0000464 closedir(DIR);
Ted Kremenek938eef12009-02-17 23:31:05 +0000465 opendir(DIR, "$Dir/failures");
466 @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR);
467 closedir(DIR);
468 foreach my $file (@failures) {
469 open IN, "$Dir/failures/$file" or DieDiag("cannot open $file\n");
Ted Kremenekd52e4252008-08-25 20:45:07 +0000470 my $Path = <IN>;
471 if (defined $Path) { UpdatePrefix($Path); }
472 close IN;
473 }
474 }
475
Ted Kremenek63c20172008-08-04 17:34:06 +0000476 # Generate an index.html file.
477 my $FName = "$Dir/index.html";
478 open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000479
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000480 # Print out the header.
481
Ted Kremenek5744dc22008-04-02 18:03:36 +0000482print OUT <<ENDTEXT;
483<html>
484<head>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000485<title>${HtmlTitle}</title>
Ted Kremenekf1435452008-09-23 22:34:51 +0000486<link type="text/css" rel="stylesheet" href="scanview.css"/>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000487<script src="sorttable.js"></script>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000488<script language='javascript' type="text/javascript">
489function SetDisplay(RowClass, DisplayVal)
490{
491 var Rows = document.getElementsByTagName("tr");
492 for ( var i = 0 ; i < Rows.length; ++i ) {
493 if (Rows[i].className == RowClass) {
494 Rows[i].style.display = DisplayVal;
495 }
496 }
497}
Ted Kremenekebb74132008-09-21 06:58:09 +0000498
Ted Kremenek2350a462008-10-28 19:56:52 +0000499function CopyCheckedStateToCheckButtons(SummaryCheckButton) {
500 var Inputs = document.getElementsByTagName("input");
501 for ( var i = 0 ; i < Inputs.length; ++i ) {
502 if (Inputs[i].type == "checkbox") {
503 if(Inputs[i] != SummaryCheckButton) {
504 Inputs[i].checked = SummaryCheckButton.checked;
505 Inputs[i].onclick();
506 }
507 }
508 }
509}
510
Ted Kremenek999e1202008-10-28 20:09:57 +0000511function returnObjById( id ) {
512 if (document.getElementById)
513 var returnVar = document.getElementById(id);
514 else if (document.all)
515 var returnVar = document.all[id];
516 else if (document.layers)
517 var returnVar = document.layers[id];
518 return returnVar;
519}
520
521var NumUnchecked = 0;
522
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000523function ToggleDisplay(CheckButton, ClassName) {
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000524 if (CheckButton.checked) {
525 SetDisplay(ClassName, "");
Ted Kremenek999e1202008-10-28 20:09:57 +0000526 if (--NumUnchecked == 0) {
527 returnObjById("AllBugsCheck").checked = true;
528 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000529 }
530 else {
531 SetDisplay(ClassName, "none");
Ted Kremenek999e1202008-10-28 20:09:57 +0000532 NumUnchecked++;
533 returnObjById("AllBugsCheck").checked = false;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000534 }
535}
536</script>
Ted Kremenek1d1abb12008-09-22 17:52:58 +0000537<!-- SUMMARYENDHEAD -->
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000538</head>
539<body>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000540<h1>${HtmlTitle}</h1>
541
542<table>
543<tr><th>User:</th><td>${UserName}\@${HostName}</td></tr>
544<tr><th>Working Directory:</th><td>${CurrentDir}</td></tr>
545<tr><th>Command Line:</th><td>${CmdArgs}</td></tr>
546<tr><th>Date:</th><td>${Date}</td></tr>
547ENDTEXT
548
549print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n"
550 if (defined($BuildName) && defined($BuildDate));
551
552print OUT <<ENDTEXT;
553</table>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000554ENDTEXT
555
Ted Kremenek991c54b2008-08-08 20:46:42 +0000556 if (scalar(@files)) {
557 # Print out the summary table.
558 my %Totals;
Ted Kremenekebb74132008-09-21 06:58:09 +0000559
Ted Kremenek991c54b2008-08-08 20:46:42 +0000560 for my $row ( @Index ) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000561 my $bug_type = ($row->[2]);
562 my $bug_category = ($row->[1]);
563 my $key = "$bug_category:$bug_type";
564
565 if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; }
566 else { $Totals{$key}->[0]++; }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000567 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000568
Ted Kremenek7cba1122008-09-22 01:35:58 +0000569 print OUT "<h2>Bug Summary</h2>";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000570
571 if (defined $BuildName) {
572 print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n"
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000573 }
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000574
Ted Kremenek2350a462008-10-28 19:56:52 +0000575 my $TotalBugs = scalar(@Index);
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000576print OUT <<ENDTEXT;
Ted Kremenekebb74132008-09-21 06:58:09 +0000577<table>
578<thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead>
Ted Kremenek999e1202008-10-28 20:09:57 +0000579<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 Kremenek6e6eff72008-04-15 20:47:02 +0000580ENDTEXT
581
Ted Kremenekebb74132008-09-21 06:58:09 +0000582 my $last_category;
583
584 for my $key (
585 sort {
586 my $x = $Totals{$a};
587 my $y = $Totals{$b};
588 my $res = $x->[1] cmp $y->[1];
589 $res = $x->[2] cmp $y->[2] if ($res == 0);
590 $res
591 } keys %Totals )
592 {
593 my $val = $Totals{$key};
594 my $category = $val->[1];
595 if (!defined $last_category or $last_category ne $category) {
596 $last_category = $category;
597 print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n";
598 }
599 my $x = lc $key;
600 $x =~ s/[ ,'":\/()]+/_/g;
601 print OUT "<tr><td class=\"SUMM_DESC\">";
602 print OUT $val->[2];
Ted Kremenek2350a462008-10-28 19:56:52 +0000603 print OUT "</td><td class=\"Q\">";
Ted Kremenekebb74132008-09-21 06:58:09 +0000604 print OUT $val->[0];
605 print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000606 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000607
608 # Print out the table of errors.
609
610print OUT <<ENDTEXT;
611</table>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000612<h2>Reports</h2>
Ted Kremenekebb74132008-09-21 06:58:09 +0000613
614<table class="sortable" style="table-layout:automatic">
615<thead><tr>
616 <td>Bug Group</td>
617 <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000618 <td>File</td>
Ted Kremenekebb74132008-09-21 06:58:09 +0000619 <td class="Q">Line</td>
Ted Kremenek81983112008-09-28 04:13:09 +0000620 <td class="Q">Path Length</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000621 <td class="sorttable_nosort"></td>
Ted Kremenekebb74132008-09-21 06:58:09 +0000622 <!-- REPORTBUGCOL -->
623</tr></thead>
624<tbody>
Ted Kremenek5744dc22008-04-02 18:03:36 +0000625ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000626
Ted Kremenek991c54b2008-08-08 20:46:42 +0000627 my $prefix = GetPrefix();
628 my $regex;
629 my $InFileRegex;
630 my $InFilePrefix = "File:</td><td>";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000631
Ted Kremenek991c54b2008-08-08 20:46:42 +0000632 if (defined $prefix) {
633 $regex = qr/^\Q$prefix\E/is;
634 $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
635 }
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000636
Ted Kremenekebb74132008-09-21 06:58:09 +0000637 for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) {
638 my $x = "$row->[1]:$row->[2]";
639 $x = lc $x;
640 $x =~ s/[ ,'":\/()]+/_/g;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000641
Ted Kremenek991c54b2008-08-08 20:46:42 +0000642 my $ReportFile = $row->[0];
Ted Kremenekebb74132008-09-21 06:58:09 +0000643
644 print OUT "<tr class=\"bt_$x\">";
645 print OUT "<td class=\"DESC\">";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000646 print OUT $row->[1];
Ted Kremenekebb74132008-09-21 06:58:09 +0000647 print OUT "</td>";
648 print OUT "<td class=\"DESC\">";
649 print OUT $row->[2];
650 print OUT "</td>";
651
652 # Update the file prefix.
653 my $fname = $row->[3];
Ted Kremenekebb74132008-09-21 06:58:09 +0000654
Ted Kremenek991c54b2008-08-08 20:46:42 +0000655 if (defined $regex) {
656 $fname =~ s/$regex//;
657 UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
658 }
Ted Kremenekebb74132008-09-21 06:58:09 +0000659
Ted Kremenek91639ef2008-09-22 17:42:31 +0000660 print OUT "<td>";
Ted Kremenekebb74132008-09-21 06:58:09 +0000661 my @fname = split /\//,$fname;
662 if ($#fname > 0) {
663 while ($#fname >= 0) {
664 my $x = shift @fname;
665 print OUT $x;
666 if ($#fname >= 0) {
667 print OUT "<span class=\"W\"> </span>/";
668 }
669 }
670 }
671 else {
672 print OUT $fname;
Ted Kremenek91639ef2008-09-22 17:42:31 +0000673 }
Ted Kremenekebb74132008-09-21 06:58:09 +0000674 print OUT "</td>";
675
676 # Print out the quantities.
Ted Kremenek81983112008-09-28 04:13:09 +0000677 for my $j ( 4 .. 5 ) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000678 print OUT "<td class=\"Q\">$row->[$j]</td>";
679 }
680
Ted Kremenek991c54b2008-08-08 20:46:42 +0000681 # Print the rest of the columns.
Ted Kremenek81983112008-09-28 04:13:09 +0000682 for (my $j = 6; $j <= $#{$row}; ++$j) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000683 print OUT "<td>$row->[$j]</td>"
Ted Kremenek991c54b2008-08-08 20:46:42 +0000684 }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000685
Ted Kremenek991c54b2008-08-08 20:46:42 +0000686 # Emit the "View" link.
Ted Kremenek68005dd2008-09-22 17:39:18 +0000687 print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>";
Ted Kremenek3cea9ee2008-07-30 17:58:08 +0000688
Daniel Dunbare43038e2008-09-19 23:18:44 +0000689 # Emit REPORTBUG markers.
Ted Kremenekebb74132008-09-21 06:58:09 +0000690 print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n";
Daniel Dunbare43038e2008-09-19 23:18:44 +0000691
Ted Kremenek991c54b2008-08-08 20:46:42 +0000692 # End the row.
693 print OUT "</tr>\n";
694 }
695
Ted Kremenekebb74132008-09-21 06:58:09 +0000696 print OUT "</tbody>\n</table>\n\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000697 }
698
Ted Kremenek938eef12009-02-17 23:31:05 +0000699 if (scalar (@failures) || scalar(@attributes_ignored)) {
700 print OUT "<h2>Analyzer Failures</h2>\n";
701
702 if (scalar @attributes_ignored) {
703 print OUT "The analyzer's parser ignored the following attributes:<p>\n";
704 print OUT "<table>\n";
705 print OUT "<thead><tr><td>Attribute</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
706 foreach my $file (sort @attributes_ignored) {
707 die "cannot demangle attribute name\n" if (! ($file =~ /^attribute_ignored_(.+).txt/));
708 my $attribute = $1;
709 # Open the attribute file to get the first file that failed.
710 next if (!open (ATTR, "$Dir/failures/$file"));
711 my $ppfile = <ATTR>;
712 chomp $ppfile;
713 close ATTR;
714 next if (! -e "$Dir/failures/$ppfile");
715 # Open the info file and get the name of the source file.
716 open (INFO, "$Dir/failures/$ppfile.info.txt") or
717 die "Cannot open $Dir/failures/$ppfile.info.txt\n";
718 my $srcfile = <INFO>;
719 chomp $srcfile;
720 close (INFO);
721 # Print the information in the table.
722 my $prefix = GetPrefix();
723 if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
724 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";
725 my $ppfile_clang = $ppfile;
726 $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
727 print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
728 }
729 print OUT "</table>\n";
730 }
731
732 if (scalar @failures) {
733 print OUT "<p>The analyzer had problems processing the following files:</p>\n";
734 print OUT "<table>\n";
735 print OUT "<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
736 foreach my $file (sort @failures) {
Ted Kremenek82a12532008-09-25 00:25:16 +0000737 $file =~ /(.+).info.txt$/;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000738 # Get the preprocessed file.
739 my $ppfile = $1;
740 # Open the info file and get the name of the source file.
Ted Kremenek938eef12009-02-17 23:31:05 +0000741 open (INFO, "$Dir/failures/$file") or
742 die "Cannot open $Dir/failures/$file\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000743 my $srcfile = <INFO>;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000744 chomp $srcfile;
745 my $problem = <INFO>;
746 chomp $problem;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000747 close (INFO);
748 # Print the information in the table.
Ted Kremenekd52e4252008-08-25 20:45:07 +0000749 my $prefix = GetPrefix();
Ted Kremenek9f9b1fd2008-09-12 22:49:36 +0000750 if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
Ted Kremenek938eef12009-02-17 23:31:05 +0000751 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 Dunbarce723ce2008-09-25 01:10:50 +0000752 my $ppfile_clang = $ppfile;
753 $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
Ted Kremenek938eef12009-02-17 23:31:05 +0000754 print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000755 }
Ted Kremenek938eef12009-02-17 23:31:05 +0000756 print OUT "</table>\n";
757 }
758 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 Kremenek5744dc22008-04-02 18:03:36 +0000759 }
760
Ted Kremenek991c54b2008-08-08 20:46:42 +0000761 print OUT "</body></html>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000762 close(OUT);
Ted Kremenek3ce12072008-09-22 17:50:47 +0000763 CopyFiles($Dir);
Ted Kremenek20161e92008-07-15 20:18:21 +0000764
765 # Make sure $Dir and $BaseDir are world readable/executable.
766 system("chmod", "755", $Dir);
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000767 if (defined $BaseDir) { system("chmod", "755", $BaseDir); }
Ted Kremenek20161e92008-07-15 20:18:21 +0000768
Ted Kremenek23cfca32008-06-16 22:40:14 +0000769 my $Num = scalar(@Index);
Ted Kremenek150c2122008-07-11 19:15:05 +0000770 Diag("$Num bugs found.\n");
771 if ($Num > 0 && -r "$Dir/index.html") {
Ted Kremenek5950b3f2008-09-22 06:47:01 +0000772 Diag("Run 'scan-view $Dir' to examine bug reports.\n");
Ted Kremenek150c2122008-07-11 19:15:05 +0000773 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000774
Ted Kremenek938eef12009-02-17 23:31:05 +0000775 DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored);
Ted Kremenek991c54b2008-08-08 20:46:42 +0000776
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000777 return $Num;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000778}
779
780##----------------------------------------------------------------------------##
Ted Kremenekdab11102008-04-02 04:43:42 +0000781# RunBuildCommand - Run the build command.
782##----------------------------------------------------------------------------##
783
Ted Kremenek6b628982008-04-30 23:47:12 +0000784sub AddIfNotPresent {
785 my $Args = shift;
786 my $Arg = shift;
787 my $found = 0;
788
789 foreach my $k (@$Args) {
790 if ($k eq $Arg) {
791 $found = 1;
792 last;
793 }
794 }
795
796 if ($found == 0) {
797 push @$Args, $Arg;
798 }
799}
800
Ted Kremenekdab11102008-04-02 04:43:42 +0000801sub RunBuildCommand {
802
803 my $Args = shift;
Ted Kremenek7442ca62008-04-02 16:04:51 +0000804 my $IgnoreErrors = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000805 my $Cmd = $Args->[0];
Ted Kremenek6195c372008-06-02 21:52:47 +0000806 my $CCAnalyzer = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000807
Ted Kremenek3301cb12008-06-30 18:18:16 +0000808 # Get only the part of the command after the last '/'.
809 if ($Cmd =~ /\/([^\/]+)$/) {
810 $Cmd = $1;
811 }
812
Ted Kremenek92548fe2008-11-19 01:46:21 +0000813 if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or
814 $Cmd =~ /(.*\/?cc[^\/]*$)/ or
815 $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or
816 $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) {
817
818 if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) {
819 $ENV{"CCC_CC"} = $1;
820 }
821
Ted Kremenekdab11102008-04-02 04:43:42 +0000822 shift @$Args;
Ted Kremenek6195c372008-06-02 21:52:47 +0000823 unshift @$Args, $CCAnalyzer;
Ted Kremenekdab11102008-04-02 04:43:42 +0000824 }
Ted Kremenek7442ca62008-04-02 16:04:51 +0000825 elsif ($IgnoreErrors) {
826 if ($Cmd eq "make" or $Cmd eq "gmake") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000827 AddIfNotPresent($Args,"-k");
Ted Kremenek8912b542008-05-13 21:28:02 +0000828 AddIfNotPresent($Args,"-i");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000829 }
830 elsif ($Cmd eq "xcodebuild") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000831 AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000832 }
Ted Kremenek6b628982008-04-30 23:47:12 +0000833 }
834
Ted Kremenek6b628982008-04-30 23:47:12 +0000835 if ($Cmd eq "xcodebuild") {
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000836 # Disable distributed builds for xcodebuild.
Ted Kremenek6b628982008-04-30 23:47:12 +0000837 AddIfNotPresent($Args,"-nodistribute");
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000838
839 # Disable PCH files until clang supports them.
840 AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO");
Ted Kremenek915e9722008-05-27 23:18:07 +0000841
842 # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
843 # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
844 # when linking such files.
Ted Kremenek95aa1052008-09-04 17:52:41 +0000845 die if (!defined $CXX);
846 my $LDPLUSPLUS = `which $CXX`;
Ted Kremenek915e9722008-05-27 23:18:07 +0000847 $LDPLUSPLUS =~ s/\015?\012//; # strip newlines
848 $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS;
Ted Kremenek6b628982008-04-30 23:47:12 +0000849 }
Ted Kremenekdab11102008-04-02 04:43:42 +0000850
Ted Kremenek5a4ddaf2008-08-25 20:10:45 +0000851 return (system(@$Args) >> 8);
Ted Kremenekdab11102008-04-02 04:43:42 +0000852}
853
Ted Kremenekdab11102008-04-02 04:43:42 +0000854##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000855# DisplayHelp - Utility function to display all help options.
856##----------------------------------------------------------------------------##
857
Sam Bishopa0e22662008-04-02 03:35:43 +0000858sub DisplayHelp {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000859
Ted Kremenek5744dc22008-04-02 18:03:36 +0000860print <<ENDTEXT;
Sam Bishopa0e22662008-04-02 03:35:43 +0000861USAGE: $Prog [options] <build command> [build options]
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000862
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000863ENDTEXT
864
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000865 if (defined $BuildName) {
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000866 print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n";
867 }
868
869print <<ENDTEXT;
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000870OPTIONS:
871
Ted Kremeneke15fa272008-10-13 21:46:42 +0000872 -analyze-headers - Also analyze functions in #included files.
873
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000874 -o - Target directory for HTML report files. Subdirectories
Sam Bishopa0e22662008-04-02 03:35:43 +0000875 will be created as needed to represent separate "runs" of
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000876 the analyzer. If this option is not specified, a directory
Ted Kremenekffda0b42008-10-31 05:48:42 +0000877 is created in /tmp (TMPDIR on Mac OS X) to store the reports.
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000878
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000879 -h - Display this message.
880 --help
Ted Kremenek1262fc42008-05-14 20:10:33 +0000881
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000882 -k - Add a "keep on going" option to the specified build command.
883 --keep-going This option currently supports make and xcodebuild.
Ted Kremenekf02e8db2008-04-02 16:41:25 +0000884 This is a convenience option; one can specify this
885 behavior directly using build options.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000886
Ted Kremenek7cba1122008-09-22 01:35:58 +0000887 --html-title [title] - Specify the title used on generated HTML pages.
888 --html-title=[title] If not specified, a default title will be used.
889
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000890 -plist - By default the output of scan-build is a set of HTML files.
891 This option outputs the results as a set of .plist files.
892
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000893 --status-bugs - By default, the exit status of $Prog is the same as the
894 executed build command. Specifying this option causes the
895 exit status of $Prog to be 1 if it found potential bugs
896 and 0 otherwise.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000897
Ted Kremenek386c6932008-09-03 17:59:35 +0000898 --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile and link
899 --use-cc=[compiler path] your C and Objective-C code. Use this option
900 to specify an alternate compiler.
901
902 --use-c++ [compiler path] - By default, $Prog uses 'g++' to compile and link
903 --use-c++=[compiler path] your C++ and Objective-C++ code. Use this option
904 to specify an alternate compiler.
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000905
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000906 -v - Verbose output from $Prog and the analyzer.
Ted Kremenek386c6932008-09-03 17:59:35 +0000907 A second and third '-v' increases verbosity.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000908
909 -V - View analysis results in a web browser when the build
910 --view completes.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000911
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000912ADVANCED OPTIONS:
913
Ted Kremenek9f4ecb32009-02-20 21:49:22 +0000914 -constraints [model] - Specify the contraint engine used by the analyzer.
915 By default the 'range' model is used. Specifying
916 'basic' uses a simpler, less powerful constraint model
Ted Kremenekd4c76842009-02-21 04:46:41 +0000917 used by checker-0.160 and earlier.
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000918
919 -store [model] - Specify the store model used by the analyzer. By default,
920 the 'basic' store model is used. 'region' specifies a field-
921 sensitive store model. Be warned that the 'region' model
922 is still in very early testing phase and may often crash.
Ted Kremenekb7770c02008-07-15 17:06:13 +0000923
Ted Kremenek386c6932008-09-03 17:59:35 +0000924AVAILABLE ANALYSES (multiple analyses may be specified):
Ted Kremenekd52e4252008-08-25 20:45:07 +0000925
926ENDTEXT
Ted Kremenekb7770c02008-07-15 17:06:13 +0000927
928 foreach my $Analysis (sort keys %AvailableAnalyses) {
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000929 if (defined $AnalysesDefaultEnabled{$Analysis}) {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000930 print " (+)";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000931 }
932 else {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000933 print " ";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000934 }
935
936 print " $Analysis $AvailableAnalyses{$Analysis}\n";
937 }
938
939print <<ENDTEXT
940
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000941 NOTE: "(+)" indicates that an analysis is enabled by default unless one
942 or more analysis options are specified
Ted Kremenekb7770c02008-07-15 17:06:13 +0000943
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000944BUILD OPTIONS
945
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000946 You can specify any build option acceptable to the build command.
Ted Kremenek39eefde2008-04-02 16:47:27 +0000947
Ted Kremenek5744dc22008-04-02 18:03:36 +0000948EXAMPLE
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000949
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000950 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000951
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000952 The above example causes analysis reports to be deposited into
953 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
954 A different subdirectory is created each time $Prog analyzes a project.
955 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000956
957ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000958}
959
960##----------------------------------------------------------------------------##
Ted Kremenek7cba1122008-09-22 01:35:58 +0000961# HtmlEscape - HTML entity encode characters that are special in HTML
962##----------------------------------------------------------------------------##
963
964sub HtmlEscape {
965 # copy argument to new variable so we don't clobber the original
966 my $arg = shift || '';
967 my $tmp = $arg;
Ted Kremenek87f8de72008-11-03 07:44:16 +0000968 $tmp =~ s/&/&amp;/g;
969 $tmp =~ s/</&lt;/g;
970 $tmp =~ s/>/&gt;/g;
Ted Kremenek7cba1122008-09-22 01:35:58 +0000971 return $tmp;
972}
973
974##----------------------------------------------------------------------------##
975# ShellEscape - backslash escape characters that are special to the shell
976##----------------------------------------------------------------------------##
977
978sub ShellEscape {
979 # copy argument to new variable so we don't clobber the original
980 my $arg = shift || '';
Ted Kremenek87f8de72008-11-03 07:44:16 +0000981 if ($arg =~ /["\s]/) { return "'" . $arg . "'"; }
982 return $arg;
Ted Kremenek7cba1122008-09-22 01:35:58 +0000983}
984
985##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000986# Process command-line arguments.
987##----------------------------------------------------------------------------##
988
Ted Kremeneke15fa272008-10-13 21:46:42 +0000989my $AnalyzeHeaders = 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000990my $HtmlDir; # Parent directory to store HTML files.
991my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000992my $ViewResults = 0; # View results when the build terminates.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000993my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found
Ted Kremenekb7770c02008-07-15 17:06:13 +0000994my @AnalysesToRun;
Zhongxing Xu07c37672008-10-27 14:26:32 +0000995my $StoreModel;
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000996my $ConstraintsModel;
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000997my $OutputFormat;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000998
999if (!@ARGV) {
1000 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001001 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001002}
1003
1004while (@ARGV) {
1005
1006 # Scan for options we recognize.
1007
1008 my $arg = $ARGV[0];
1009
Sam Bishop2f2418e2008-04-03 14:29:47 +00001010 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001011 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001012 exit 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001013 }
1014
Ted Kremeneke15fa272008-10-13 21:46:42 +00001015 if ($arg eq '-analyze-headers') {
1016 shift @ARGV;
1017 $AnalyzeHeaders = 1;
1018 next;
1019 }
1020
Ted Kremenekfc1d3402008-08-04 18:15:26 +00001021 if (defined $AvailableAnalyses{$arg}) {
Ted Kremenek1262fc42008-05-14 20:10:33 +00001022 shift @ARGV;
Ted Kremenekb7770c02008-07-15 17:06:13 +00001023 push @AnalysesToRun, $arg;
Ted Kremenek1262fc42008-05-14 20:10:33 +00001024 next;
1025 }
1026
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001027 if ($arg eq "-o") {
1028 shift @ARGV;
1029
1030 if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +00001031 DieDiag("'-o' option requires a target directory name.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001032 }
1033
1034 $HtmlDir = shift @ARGV;
1035 next;
1036 }
Ted Kremenek7cba1122008-09-22 01:35:58 +00001037
1038 if ($arg =~ /^--html-title(=(.+))?$/) {
1039 shift @ARGV;
1040
1041 if ($2 eq '') {
1042 if (!@ARGV) {
1043 DieDiag("'--html-title' option requires a string.\n");
1044 }
1045
1046 $HtmlTitle = shift @ARGV;
1047 } else {
1048 $HtmlTitle = $2;
1049 }
1050
1051 next;
1052 }
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001053
Ted Kremenek2b74ab62008-04-01 21:22:03 +00001054 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001055 shift @ARGV;
1056 $IgnoreErrors = 1;
1057 next;
1058 }
1059
Ted Kremenekf17ef3c2008-08-21 21:47:09 +00001060 if ($arg =~ /^--use-cc(=(.+))?$/) {
1061 shift @ARGV;
1062 my $cc;
1063
1064 if ($2 eq "") {
1065 if (!@ARGV) {
1066 DieDiag("'--use-cc' option requires a compiler executable name.\n");
1067 }
1068 $cc = shift @ARGV;
1069 }
1070 else {
1071 $cc = $2;
1072 }
1073
1074 $ENV{"CCC_CC"} = $cc;
1075 next;
1076 }
1077
Ted Kremenek7cba1122008-09-22 01:35:58 +00001078 if ($arg =~ /^--use-c\+\+(=(.+))?$/) {
Ted Kremenek386c6932008-09-03 17:59:35 +00001079 shift @ARGV;
1080
1081 if ($2 eq "") {
1082 if (!@ARGV) {
1083 DieDiag("'--use-c++' option requires a compiler executable name.\n");
1084 }
1085 $CXX = shift @ARGV;
1086 }
1087 else {
1088 $CXX = $2;
1089 }
1090 next;
1091 }
1092
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001093 if ($arg eq "-v") {
1094 shift @ARGV;
1095 $Verbose++;
1096 next;
1097 }
1098
Ted Kremenek7f8a3252008-04-02 18:42:49 +00001099 if ($arg eq "-V" or $arg eq "--view") {
1100 shift @ARGV;
1101 $ViewResults = 1;
1102 next;
1103 }
1104
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001105 if ($arg eq "--status-bugs") {
1106 shift @ARGV;
1107 $ExitStatusFoundBugs = 1;
1108 next;
1109 }
Zhongxing Xu07c37672008-10-27 14:26:32 +00001110
1111 if ($arg eq "-store") {
1112 shift @ARGV;
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001113 $StoreModel = shift @ARGV;
1114 next;
1115 }
1116
1117 if ($arg eq "-constraints") {
1118 shift @ARGV;
1119 $ConstraintsModel = shift @ARGV;
Zhongxing Xu07c37672008-10-27 14:26:32 +00001120 next;
1121 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001122
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001123 if ($arg eq "-plist") {
1124 shift @ARGV;
1125 $OutputFormat = "plist";
1126 next;
1127 }
1128
Ted Kremenek23cfca32008-06-16 22:40:14 +00001129 DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
Ted Kremenek0062ad42008-04-02 16:35:01 +00001130
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001131 last;
1132}
1133
1134if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +00001135 Diag("No build command specified.\n\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001136 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001137 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001138}
1139
Ted Kremenek7cba1122008-09-22 01:35:58 +00001140$CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV)));
1141$HtmlTitle = "${CurrentDirSuffix} - scan-build results"
1142 unless (defined($HtmlTitle));
Ted Kremenek386c6932008-09-03 17:59:35 +00001143
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001144# Determine the output directory for the HTML reports.
Ted Kremenek684bb092008-04-18 15:18:20 +00001145my $BaseDir = $HtmlDir;
Sam Bishopa0e22662008-04-02 03:35:43 +00001146$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001147
1148# Set the appropriate environment variables.
Sam Bishopa0e22662008-04-02 03:35:43 +00001149SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001150
Ted Kremeneke15fa272008-10-13 21:46:42 +00001151my $Cmd = Cwd::realpath("$RealBin/ccc-analyzer");
Ted Kremenek0b6c1532008-04-08 20:22:12 +00001152
Ted Kremenek23cfca32008-06-16 22:40:14 +00001153DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n")
Ted Kremenek0b6c1532008-04-08 20:22:12 +00001154 if (! -x $Cmd);
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001155
Ted Kremenek2d62ab12009-02-23 23:01:06 +00001156if (!defined $ClangSB || ! -x $ClangSB) {
1157 Diag("'clang' executable not found in '$RealBin/bin'.\n");
Ted Kremenekb7770c02008-07-15 17:06:13 +00001158 Diag("Using 'clang' from path.\n");
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001159}
Ted Kremenek0b6c1532008-04-08 20:22:12 +00001160
Ted Kremenek95aa1052008-09-04 17:52:41 +00001161if (defined $CXX) {
1162 $ENV{'CXX'} = $CXX;
1163}
1164else {
1165 $CXX = 'g++'; # This variable is used by other parts of scan-build
1166 # that need to know a default C++ compiler to fall back to.
1167}
1168
Ted Kremenek4f4b17d2008-04-03 20:08:18 +00001169$ENV{'CC'} = $Cmd;
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001170$ENV{'CLANG'} = $Clang;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001171
1172if ($Verbose >= 2) {
1173 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
1174}
1175
Ted Kremeneka9525c92008-05-12 22:07:14 +00001176if ($Verbose >= 3) {
1177 $ENV{'CCC_ANALYZER_LOG'} = 1;
1178}
1179
Ted Kremenek90125992008-07-15 23:41:32 +00001180if (scalar(@AnalysesToRun) == 0) {
1181 foreach my $key (keys %AnalysesDefaultEnabled) {
1182 push @AnalysesToRun,$key;
1183 }
Ted Kremenek01006782008-07-02 23:16:10 +00001184}
Ted Kremenek1262fc42008-05-14 20:10:33 +00001185
Ted Kremeneke15fa272008-10-13 21:46:42 +00001186if ($AnalyzeHeaders) {
1187 push @AnalysesToRun,"-analyzer-opt-analyze-headers";
1188}
1189
Ted Kremenek90125992008-07-15 23:41:32 +00001190$ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
1191
Zhongxing Xu3cab2b12008-11-02 10:58:16 +00001192if (defined $StoreModel) {
Zhongxing Xu07c37672008-10-27 14:26:32 +00001193 $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel;
1194}
1195
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001196if (defined $ConstraintsModel) {
1197 $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'} = $ConstraintsModel;
1198}
1199
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001200if (defined $OutputFormat) {
1201 $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'} = $OutputFormat;
1202}
1203
1204
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001205# Run the build.
Ted Kremenek5656a982008-07-15 17:09:28 +00001206my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001207
Ted Kremenek655aba72008-11-04 00:22:12 +00001208if (defined $OutputFormat and $OutputFormat eq "plist") {
Ted Kremenek50534dc2008-09-22 17:38:23 +00001209 Diag "Analysis run complete.\n";
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001210 Diag "Analysis results (plist files) deposited in '$HtmlDir'\n";
Ted Kremenek7f8a3252008-04-02 18:42:49 +00001211}
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001212else {
1213 # Postprocess the HTML directory.
1214 my $NumBugs = Postprocess($HtmlDir, $BaseDir);
Ted Kremenek5656a982008-07-15 17:09:28 +00001215
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001216 if ($ViewResults and -r "$HtmlDir/index.html") {
1217 Diag "Analysis run complete.\n";
1218 Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n";
1219 my $ScanView = Cwd::realpath("$RealBin/scan-view");
1220 if (! -x $ScanView) { $ScanView = "scan-view"; }
1221 exec $ScanView, "$HtmlDir";
1222 }
1223
1224 if ($ExitStatusFoundBugs) {
1225 exit 1 if ($NumBugs > 0);
1226 exit 0;
1227 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001228}
1229
Ted Kremenek5656a982008-07-15 17:09:28 +00001230exit $ExitStatus;
1231