fdce709bd4b4162ebe34b8c144e0f611fea86560
[nethome.git] / bin / diffgdb
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4
5 sub gitmark($) {
6   my($s)=@_;
7   return "" if $s!~m{^(... )([^/]*/+[^/]*)/};
8   my($pfx,$dir)=($1,$2);
9   local *GIT;
10   $dir.="/build/gdbgit";
11   return "" if !-d $dir;
12   open GIT,"cd '$dir';git log --format=%H HEAD^..HEAD|" or return "";
13   my $git=do { local $/; <GIT>; };
14   close GIT;
15   chomp $git;
16   return "${pfx}GIT commit $git\n" if $git=~/^[0-9a-f]{40}$/;
17   return "";
18 }
19
20 my @ignore=(
21 qr{^.PASS: }o,
22 qr{^.KPASS: }o,
23 qr{^-FAIL: }o,
24 qr{^-KFAIL: }o,
25 qr{^-XFAIL: }o,
26 qr{^.Test Run By }o,
27 qr{^.gnatbind }o,
28 qr{^.gnatlink }o,
29 qr{^.gnatlink: }o,
30 qr{^.gnatmake: }o,
31 qr{^.gcc }o,
32 qr{^./usr/bin/ld: .* architecture of input file .* is incompatible with .* output\n$}o,
33 qr{^.collect2: }o,
34 #qr{^.UNSUPPORTED: }o,
35 #qr{^.UNTESTED: }o,
36 #qr{^.UNRESOLVED: }o,
37 #qr{^.ERROR: }o,
38 #qr{^.WARNING: }o,
39 qr{^.[^:]*[.]ad[sb]:[0-9]}o,
40 qr{^.gdb compile failed, }o,
41 qr{^.gdb compile failed, /usr/bin/ld: /tmp/[a-zA-Z0-9]*.o: relocation R_X86_64_32S against `a local symbol. can not be used when making a shared object; recompile with -fPIC\n$}o,
42 qr{^./tmp/[a-zA-Z0-9]*.o: could not read symbols: Bad value\n$}o,
43 qr{^./tmp/[a-zA-Z0-9]*.s:\d+: Error: unrecognized symbol type "gnu_indirect_function"\n$}o,
44 qr{^./tmp/[a-zA-Z0-9]*.o: In function `\S+':\n$}o,
45 qr{^./tmp/[a-zA-Z0-9]*.o:.*: undefined reference to `.*'\n$}o,
46 qr{^./tmp/[a-zA-Z0-9]*.s:\d+: Error: syntax error; found `.' but expected `,'\n$}o,
47 qr{^./tmp/[a-zA-Z0-9]*.s:\d+: Error: junk at end of line: `.(?:plt|local)'\n$}o,
48 qr{^./usr/bin/ld: /tmp/[a-zA-Z0-9]*.o\(\.text\+0x[0-9a-f]+\): unresolvable R_PPC64_REL24 relocation against symbol `\S+'\n$}o,
49 qr{^.# of }o,
50 qr{^./home/}o,
51 qr{^.\.\./as-new [0-9.]*\n$}o,
52 qr{^.(?:/unsafe)?ld/ld-new [0-9.]*\n$}o,
53 qr{\bgdb version  \d\S+ -nw -nx\b}o,
54 qr{^.FAIL: \S+\.exp: valgrind check \d+\n$}o,
55 qr{^.KFAIL: gdb.threads/watchthreads2.exp: gdb can drop watchpoints in multithreaded app \(PRMS: gdb/10116\)\n$}o,
56 qr{^.FAIL: gdb.base/info-os.exp: .*\n$}o,
57 qr{^.FAIL: gdb.threads/multiple-step-overs.exp: .*\n$}o,
58 qr{^.FAIL: gdb.base/random-signal.exp: stop with control-c \Q(timeout)\E\n$}o,
59 qr{^.(?:XFAIL|PASS): gdb.threads/attach-many-short-lived-threads.exp: iter \d+: attach(?: \(EPERM\))?\n$}o,
60 );
61 my $ignore=shift @ignore;
62 $ignore=qr/$ignore|$_/ for @ignore;
63
64 my $opt_new;
65 while (1) {
66   if ($ARGV[0] eq "-r") {
67     $ignore=undef;
68     shift;
69     next;
70   }
71   if ($ARGV[0] eq "-N") {
72     $opt_new=1;
73     shift;
74     next;
75   }
76   last;
77 }
78
79 my $last;
80 my $lastfile;
81 local *DIFF;
82 my(@diff)=("diff","-rU-1",@ARGV);
83 open DIFF,"-|",@diff or die join(" ",@diff).": $!";
84 while (<DIFF>) {
85   next if /^diff /;
86   my($thisname)=m{^.(?:Running (?:.*/)?|[A-Z]+: )(gdb[.]\w+/\S+[.]exp)(?: \Q...\E|: .*)$};
87   $thisname||=(m{^.\t\t=== gdb (Summary) ===\n$})[0];
88   $thisname||=(m{^(Only in) })[0];
89   my $this;
90   if (!$thisname || ($last && $thisname eq $last->{"name"})) {
91 #if (!$thisname) { print "X: !thisname\n"; } else { print "X: \"".$last->{"name"}."\" -> \"$thisname\"\n"; }
92     $this=$last;
93   } else {
94 #print "X: new \"$thisname\"\n";
95     $last=$this={"name"=>$thisname,"+Running"=>(/^[+]/||0)};
96   }
97   next if /^@@ .* @@\n$/;
98   if ($this->{"print"}) {
99     print;
100     next;
101   }
102   if (/^Only in /) {
103     $lastfile=$_;
104   }
105   if (/^--- /) {
106     $lastfile=$_.gitmark($_);
107     next;
108   }
109   if (/^\Q+++\E /) {
110     $lastfile.=$_.gitmark($_);
111     next;
112   }
113   $this->{"buffer"}.=$_;
114   next if /^ /;
115   next if /^[+]Running / && $thisname && !$opt_new;
116   next if $ignore && /$ignore/o;
117   next if /^[+]FAIL: / && $this->{"+Running"};
118   next if /^[+]KFAIL: / && $this->{"+Running"};
119   next if /^[+]XFAIL: / && $this->{"+Running"};
120   next if /^[+]UNTESTED: / && $this->{"+Running"};
121   next if /^[+]gdb compile failed, / && $this->{"+Running"};
122   next if /^[+].*: Error: bad register name `%.*'\n$/ && $this->{"+Running"};
123   next if /^[+].*: Error: `.*' is only supported in 64-bit mode\n$/ && $this->{"+Running"};
124
125   $this->{"print"}=1;
126   print $lastfile||""; $lastfile=undef();
127   print "\n#".($this->{"name"}||"???")."\n";
128   print $this->{"buffer"}; $this->{"buffer"}=undef();
129   next;
130 }