]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Parser/Suppressions/Text.pm
There's no need to strip out lines containing "valgrind" from suppressions anymore
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Parser / Suppressions / Text.pm
1 package Test::Valgrind::Parser::Suppressions::Text;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Parser::Suppressions::Text - Parse valgrind suppressions output as text blocks.
9
10 =head1 VERSION
11
12 Version 1.11
13
14 =cut
15
16 our $VERSION = '1.11';
17
18 =head1 DESCRIPTION
19
20 This is a L<Test::Valgrind::Parser::Text> object that can extract suppressions from C<valgrind>'s text output.
21
22 =cut
23
24 use Test::Valgrind::Suppressions;
25
26 use base qw/Test::Valgrind::Parser::Text Test::Valgrind::Carp/;
27
28 =head1 METHODS
29
30 =head2 C<report_class>
31
32 Generated reports are C<Test::Valgrind::Report::Suppressions> objects.
33 Their C<data> member contains the raw text of the suppression.
34
35 =cut
36
37 sub report_class { 'Test::Valgrind::Report::Suppressions' }
38
39 sub parse {
40  my ($self, $sess, $fh) = @_;
41
42  my ($s, $in) = ('', 0);
43  my @supps;
44
45  while (<$fh>) {
46   s/^\s*#\s//;        # Strip comments
47
48   next if /^==/;      # Valgrind info line
49
50   s/^\s*//;           # Strip leading spaces
51   s/<[^>]+>//;        # Strip tags
52   s/\s*$//;           # Strip trailing spaces
53   next unless length;
54
55   if ($_ eq '{') {      # A suppression block begins
56    $in = 1;
57   } elsif ($_ eq '}') { # A suppression block ends
58    $s = Test::Valgrind::Suppressions->strip_tail($sess, $s); # Strip the tail
59    push @supps, $s;     # Add the suppression that just ended to the list
60    $s  = '';            # Reset the state
61    $in = 0;
62   } elsif ($in) {       # We're inside a suppresion block
63    $s .= "$_\n";        # Append the current line to the state
64   }
65  }
66
67  my @extra;
68
69  for (@supps) {
70   if (/\bfun:(m|c|re)alloc\b/) {
71    my $t = $1;
72
73    my %call; # Frames to append (if the value is 1) or to prepend (if it's 0)
74    if ($t eq 'm') {       # malloc can also be called by calloc or realloc
75     $call{$_} = 1 for qw/calloc realloc/;
76    } elsif ($t eq 're') { # realloc can also call malloc or free
77     $call{$_} = 0 for qw/malloc free/;
78    } elsif ($t eq 'c') {  # calloc can also call malloc
79     $call{$_} = 0 for qw/malloc/;
80    }
81
82    my $c = $_;
83    for (keys %call) {
84     my $d = $c;
85     $d =~ s/\b(fun:${t}alloc)\b/$call{$_} ? "$1\nfun:$_" : "fun:$_\n$1"/e;
86     # Remove one line for each line added or valgrind will hate us
87     $d =~ s/\n(.+?)\s*$/\n/;
88     push @extra, $d;
89    }
90   }
91  }
92
93  my $num;
94  $sess->report($self->report_class($sess)->new(
95   id   => ++$num,
96   kind => 'Suppression',
97   data => $_,
98  )) for @supps, @extra;
99 }
100
101 =head1 SEE ALSO
102
103 L<Test::Valgrind>, L<Test::Valgrind::Parser::Text>.
104
105 =head1 AUTHOR
106
107 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
108
109 You can contact me by mail or on C<irc.perl.org> (vincent).
110
111 =head1 BUGS
112
113 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
114 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
115
116 =head1 SUPPORT
117
118 You can find documentation for this module with the perldoc command.
119
120     perldoc Test::Valgrind::Parser::Suppressions::Text
121
122 =head1 COPYRIGHT & LICENSE
123
124 Copyright 2009 Vincent Pit, all rights reserved.
125
126 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
127
128 =cut
129
130 # End of Test::Valgrind::Parser::Suppressions::Text
131
132 package Test::Valgrind::Report::Suppressions;
133
134 use base qw/Test::Valgrind::Report/;
135
136 sub kinds { shift->SUPER::kinds(), 'Suppression' }
137
138 sub valid_kind {
139  my ($self, $kind) = @_;
140
141  $self->SUPER::valid_kind($kind) or $kind eq 'Suppression'
142 }
143
144 1; # End of Test::Valgrind::Report::Suppressions