source: branches/help/SOURCE_TOOLS/arb_build_common.pm

Last change on this file was 17703, checked in by westram, 6 years ago
  • provide stacktraces for UndefinedBehaviorSanitizer
    • similar as done for AddressSanitizer and LeakSanitizer
    • add verbose-flags to debug code that filters logfiles and rewrites stacktrace into message-format (FILE:LINE: MESSAGE)
    • fix paths of stacktraces (expand+reduce pathprefixes; trace enter/leave directory messages)
File size: 2.4 KB
Line 
1package arb_build_common;
2
3# meant to be used from perl scripts used during build of ARB
4
5use strict;
6use warnings;
7
8BEGIN {
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
24sub 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
38sub removeDirPrefix($\$) {
39  my ($prefix,$line_r) = @_;
40  if (defined $prefix) {
41    if ($$line_r =~ /^$prefix\//) {
42      $$line_r = $';
43    }
44  }
45}
46
47my @alternative = ();
48my $ARBHOME = $ENV{ARBHOME};
49
50sub 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)
103END { }
104
1051; # module initialization is ok
Note: See TracBrowser for help on using the repository browser.