1 | package arb_build_common; |
---|
2 | |
---|
3 | # meant to be used from perl scripts used during build of ARB |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | |
---|
8 | BEGIN { |
---|
9 | use Exporter (); |
---|
10 | our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,%EXPORT_TAGS); |
---|
11 | $VERSION = 1.00; |
---|
12 | @ISA = qw(Exporter); |
---|
13 | @EXPORT = qw( |
---|
14 | &add_suffix |
---|
15 | &removeDirPrefix |
---|
16 | &format_asan_line |
---|
17 | ); |
---|
18 | %EXPORT_TAGS = qw(); |
---|
19 | @EXPORT_OK = qw(); |
---|
20 | } |
---|
21 | |
---|
22 | # ---------------------------------------- |
---|
23 | |
---|
24 | sub add_suffix($$) { |
---|
25 | my ($line,$suffix) = @_; |
---|
26 | # adds optional suffix to line (before optional linefeed) |
---|
27 | if (not defined $suffix) { |
---|
28 | $line; |
---|
29 | } |
---|
30 | elsif (chomp($line)) { |
---|
31 | $line.$suffix."\n"; |
---|
32 | } |
---|
33 | else { |
---|
34 | $line.$suffix; |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | sub removeDirPrefix($\$) { |
---|
39 | my ($prefix,$line_r) = @_; |
---|
40 | if (defined $prefix) { |
---|
41 | if ($$line_r =~ /^$prefix\//) { |
---|
42 | $$line_r = $'; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | my @alternative = (); |
---|
48 | my $ARBHOME = $ENV{ARBHOME}; |
---|
49 | |
---|
50 | sub format_asan_line($$) { |
---|
51 | my ($line,$topdir) = @_; |
---|
52 | # if $line is output from AddressSanitizer/LeakSanitizer -> reformat into 'file:lineno: msg' format |
---|
53 | # return undef if isnt (or source file is unknown) |
---|
54 | # if $topdir!=undef => remove topdir-prefix from path |
---|
55 | |
---|
56 | my $result = undef; |
---|
57 | |
---|
58 | my $dump_alternatives = 1; |
---|
59 | |
---|
60 | if ($line =~ /^\s+(\#[0-9]+\s.*)\s+([^\s]+):([0-9]+)$/o) { |
---|
61 | my ($msg,$file,$lineNo) = ($1,$2,$3); |
---|
62 | if (-f $file) { |
---|
63 | removeDirPrefix($topdir,$file); |
---|
64 | $result = "$file:$lineNo: $msg\n"; |
---|
65 | } |
---|
66 | elsif ($file =~ /^(C|GENC|GENH)\//o) { |
---|
67 | my $PROBE_file = 'PROBE_COM/'.$file; |
---|
68 | my $NAMES_file = 'NAMES_COM/'.$file; |
---|
69 | |
---|
70 | my $base = (defined $topdir) ? $topdir : $ARBHOME; |
---|
71 | $PROBE_file = $base.'/'.$PROBE_file; |
---|
72 | $NAMES_file = $base.'/'.$NAMES_file; |
---|
73 | |
---|
74 | $dump_alternatives = 0; # do later |
---|
75 | |
---|
76 | if (-f $PROBE_file) { |
---|
77 | removeDirPrefix($topdir,$PROBE_file); |
---|
78 | $result = "$PROBE_file:$lineNo: $msg\n"; |
---|
79 | } |
---|
80 | if (-f $NAMES_file) { |
---|
81 | removeDirPrefix($topdir,$NAMES_file); |
---|
82 | push @alternative, "$NAMES_file:$lineNo: $msg"; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | if ($dump_alternatives==1 and scalar(@alternative)>0) { |
---|
88 | my $pre_result .= "alternative callstack [start]\n"; |
---|
89 | foreach (@alternative) { |
---|
90 | $pre_result .= $_."\n"; |
---|
91 | } |
---|
92 | $pre_result .= "alternative callstack [end]\n"; |
---|
93 | @alternative = (); |
---|
94 | $result = $pre_result.$result; |
---|
95 | } |
---|
96 | |
---|
97 | return $result; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | # ---------------------------------------- |
---|
102 | # cleanup (if needed) |
---|
103 | END { } |
---|
104 | |
---|
105 | 1; # module initialization is ok |
---|