1 package Test::Valgrind::Parser::Suppressions::Text;
8 Test::Valgrind::Parser::Suppressions::Text - Parse valgrind suppressions output as text blocks.
16 our $VERSION = '1.15';
20 This is a L<Test::Valgrind::Parser::Text> object that can extract suppressions from C<valgrind>'s text output.
24 use Test::Valgrind::Suppressions;
26 use base qw<Test::Valgrind::Parser::Text Test::Valgrind::Carp>;
30 =head2 C<report_class>
32 Generated reports are C<Test::Valgrind::Report::Suppressions> objects.
33 Their C<data> member contains the raw text of the suppression.
37 sub report_class { 'Test::Valgrind::Report::Suppressions' }
40 my ($self, $sess, $fh) = @_;
42 my ($s, $in) = ('', 0);
46 s/^\s*#\s//; # Strip comments
48 if (/^==/) { # Valgrind info line
49 if (/Signal 11 being dropped from thread/) {
50 # This might loop endlessly
56 s/^\s*//; # Strip leading spaces
57 s/<[^>]+>//; # Strip tags
58 s/\s*$//; # Strip trailing spaces
61 if ($_ eq '{') { # A suppression block begins
63 } elsif ($_ eq '}') { # A suppression block ends
64 $s = Test::Valgrind::Suppressions->strip_tail($sess, $s); # Strip the tail
65 push @supps, $s; # Add the suppression that just ended to the list
66 $s = ''; # Reset the state
68 } elsif ($in) { # We're inside a suppresion block
69 if (/^fun\s*:\s*(.*)/) {
70 # Sometimes valgrind seems to forget to Z-demangle the symbol names.
71 # Make sure it's done and append the result to the state.
73 $s .= 'fun:' . Test::Valgrind::Suppressions->maybe_z_demangle($sym) . "\n";
83 if (/\bfun:(m|c|re)alloc\b/) {
86 my %call; # Frames to append (if the value is 1) or to prepend (if it's 0)
87 if ($t eq 'm') { # malloc can also be called by calloc or realloc
88 $call{$_} = 1 for qw<calloc realloc>;
89 } elsif ($t eq 're') { # realloc can also call malloc or free
90 $call{$_} = 0 for qw<malloc free>;
91 } elsif ($t eq 'c') { # calloc can also call malloc
92 $call{$_} = 0 for qw<malloc>;
98 $d =~ s/\b(fun:${t}alloc)\b/$call{$_} ? "$1\nfun:$_" : "fun:$_\n$1"/e;
99 # Remove one line for each line added or valgrind will hate us
100 $d =~ s/\n(.+?)\s*$/\n/;
107 $sess->report($self->report_class($sess)->new(
109 kind => 'Suppression',
111 )) for @supps, @extra;
118 L<Test::Valgrind>, L<Test::Valgrind::Parser::Text>.
122 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
124 You can contact me by mail or on C<irc.perl.org> (vincent).
128 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>.
129 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
133 You can find documentation for this module with the perldoc command.
135 perldoc Test::Valgrind::Parser::Suppressions::Text
137 =head1 COPYRIGHT & LICENSE
139 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
141 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
145 # End of Test::Valgrind::Parser::Suppressions::Text
147 package Test::Valgrind::Report::Suppressions;
149 use base qw<Test::Valgrind::Report>;
151 sub kinds { shift->SUPER::kinds(), 'Suppression' }
154 my ($self, $kind) = @_;
156 $self->SUPER::valid_kind($kind) or $kind eq 'Suppression'
159 1; # End of Test::Valgrind::Report::Suppressions