1 package Test::Valgrind::Suppressions;
8 Test::Valgrind::Suppressions - Generate suppressions for given tool and command.
16 our $VERSION = '1.13';
20 This module is an helper for generating suppressions.
24 use base qw<Test::Valgrind::Carp>;
28 =head2 C<< generate tool => $tool, command => $command, target => $target >>
30 Generates suppressions for the command C<< $command->new_trainer >> and the tool C<< $tool->new_trainer >>, and writes them in the file specified by C<$target>.
31 The action used behind the scenes is L<Test::Valgrind::Action::Suppressions>.
33 Returns the status code.
42 my $cmd = delete $args{command};
44 require Test::Valgrind::Command;
45 $cmd = Test::Valgrind::Command->new(
50 $cmd = $cmd->new_trainer;
51 return unless defined $cmd;
53 my $tool = delete $args{tool};
55 require Test::Valgrind::Tool;
56 $tool = Test::Valgrind::Tool->new(tool => $tool);
58 $tool = $tool->new_trainer;
59 return unless defined $tool;
61 my $target = delete $args{target};
62 $self->_croak('Invalid target') unless $target and not ref $target;
64 require Test::Valgrind::Action;
65 my $action = Test::Valgrind::Action->new(
66 action => 'Suppressions',
68 name => 'PerlSuppression',
71 require Test::Valgrind::Session;
72 my $sess = Test::Valgrind::Session->new(
73 min_version => $tool->requires_version,
83 $self->_croak($@) if $@;
85 my $status = $sess->status;
86 $status = 255 unless defined $status;
91 =head2 C<strip_tail $session, $suppression>
93 Removes all wildcard frames at the end of the suppression.
94 Moreover, C<'...'> is appended when C<valgrind> C<3.4.0> or higher is used.
95 Returns the mangled suppression.
102 my ($sess, $supp) = @_;
104 1 while $supp =~ s/[^\r\n]*:\s*\*\s*$//;
105 # With valgrind 3.4.0, we can replace unknown series of frames by '...'
106 if ($sess->version ge '3.4.0') {
107 1 while $supp =~ s/[^\r\n]*\.{3}\s*$//;
114 =head2 C<maybe_z_demangle $symbol>
116 If C<$symbol> is Z-encoded as described in C<valgrind>'s F<include/pub_tool_redir.h>, extract and decode its function name part.
117 Otherwise, C<$symbol> is returned as is.
119 This routine follows C<valgrind>'s F<coregrind/m_demangle/demangle.c:maybe_Z_demangle>.
138 sub maybe_z_demangle {
139 my ($self, $sym) = @_;
141 $sym =~ s/^_vg[rwn]Z([ZU])_// or return $sym;
143 my $fn_is_encoded = $1 eq 'Z';
145 $sym =~ /^VG_Z_/ and $self->_croak('Symbol with a "VG_Z_" prefix is invalid');
147 or $self->_croak('Symbol doesn\'t contain a function name');
149 if ($fn_is_encoded) {
151 my $c = $z_escapes{$1};
152 $self->_croak('Invalid escape sequence') unless defined $c;
157 $self->_croak('Empty symbol') unless length $sym;
164 L<Test::Valgrind>, L<Test::Valgrind::Command>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Action::Suppressions>.
168 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
170 You can contact me by mail or on C<irc.perl.org> (vincent).
174 Please report any bugs or feature requests to C<bug-test-valgrind-suppressions at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
175 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
179 You can find documentation for this module with the perldoc command.
181 perldoc Test::Valgrind::Suppressions
183 =head1 COPYRIGHT & LICENSE
185 Copyright 2008,2009,2010,2011 Vincent Pit, all rights reserved.
187 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
191 1; # End of Test::Valgrind::Suppressions