1 package Test::Valgrind::Parser::Suppressions::Text;
8 Test::Valgrind::Parser::Suppressions::Text - Parse valgrind suppressions output as text blocks.
16 our $VERSION = '1.11';
20 This is a L<Test::Valgrind::Parser::Text> object that can extract suppressions from C<valgrind>'s text output.
24 use base qw/Test::Valgrind::Parser::Text Test::Valgrind::Carp/;
28 =head2 C<report_class>
30 Generated reports are C<Test::Valgrind::Report::Suppressions> objects.
31 Their C<data> member contains the raw text of the suppression.
35 sub report_class { 'Test::Valgrind::Report::Suppressions' }
38 my ($self, $sess, $fh) = @_;
40 my ($s, $in) = ('', 0);
44 s/^\s*#\s//; # Strip comments
46 next if /^==/; # Valgrind info line
47 next if /valgrind/; # and /\Q$file\E/;
49 s/^\s*//; # Strip leading spaces
50 s/<[^>]+>//; # Strip tags
51 s/\s*$//; # Strip trailing spaces
54 if ($_ eq '{') { # A suppression block begins
56 } elsif ($_ eq '}') { # A suppression block ends
57 # With valgrind 3.4.0, we can replace unknown series of frames by '...'
58 if ($sess->version ge '3.4.0') {
60 ++$unknown_tail while $s =~ s/(\n)\s*obj:\*\s*$/$1/;
61 $s .= "...\n" if $unknown_tail;
64 push @supps, $s; # Add the suppression that just ended to the list
65 $s = ''; # Reset the state
67 } elsif ($in) { # We're inside a suppresion block
68 $s .= "$_\n"; # Append the current line to the state
75 if (/\bfun:(m|c|re)alloc\b/) {
78 my %call; # Frames to append (if the value is 1) or to prepend (if it's 0)
79 if ($t eq 'm') { # malloc can also be called by calloc or realloc
80 $call{$_} = 1 for qw/calloc realloc/;
81 } elsif ($t eq 're') { # realloc can also call malloc or free
82 $call{$_} = 0 for qw/malloc free/;
83 } elsif ($t eq 'c') { # calloc can also call malloc
84 $call{$_} = 0 for qw/malloc/;
90 $d =~ s/\b(fun:${t}alloc)\b/$call{$_} ? "$1\nfun:$_" : "fun:$_\n$1"/e;
91 # Remove one line for each line added or valgrind will hate us
92 $d =~ s/\n(.+?)\s*$/\n/;
99 $sess->report($self->report_class($sess)->new(
101 kind => 'Suppression',
103 )) for @supps, @extra;
108 L<Test::Valgrind>, L<Test::Valgrind::Parser::Text>.
112 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
114 You can contact me by mail or on C<irc.perl.org> (vincent).
118 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>.
119 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
123 You can find documentation for this module with the perldoc command.
125 perldoc Test::Valgrind::Parser::Suppressions::Text
127 =head1 COPYRIGHT & LICENSE
129 Copyright 2009 Vincent Pit, all rights reserved.
131 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
135 # End of Test::Valgrind::Parser::Suppressions::Text
137 package Test::Valgrind::Report::Suppressions;
139 use base qw/Test::Valgrind::Report/;
141 sub kinds { shift->SUPER::kinds(), 'Suppression' }
144 my ($self, $kind) = @_;
146 $self->SUPER::valid_kind($kind) or $kind eq 'Suppression'
149 1; # End of Test::Valgrind::Report::Suppressions