1 package Test::Valgrind::Suppressions;
8 Test::Valgrind::Suppressions - Generate suppressions for given tool and command.
16 our $VERSION = '1.19';
20 This module is an helper for generating suppressions.
24 use base qw<Test::Valgrind::Carp>;
30 Test::Valgrind::Suppressions->generate(
36 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>.
37 The action used behind the scenes is L<Test::Valgrind::Action::Suppressions>.
39 Returns the status code.
48 my $cmd = delete $args{command};
50 require Test::Valgrind::Command;
51 $cmd = Test::Valgrind::Command->new(
56 $cmd = $cmd->new_trainer;
57 return unless defined $cmd;
59 my $tool = delete $args{tool};
61 require Test::Valgrind::Tool;
62 $tool = Test::Valgrind::Tool->new(tool => $tool);
64 $tool = $tool->new_trainer;
65 return unless defined $tool;
67 my $target = delete $args{target};
68 $self->_croak('Invalid target') unless $target and not ref $target;
70 require Test::Valgrind::Action;
71 my $action = Test::Valgrind::Action->new(
72 action => 'Suppressions',
74 name => 'PerlSuppression',
77 require Test::Valgrind::Session;
78 my $sess = Test::Valgrind::Session->new(
79 min_version => $tool->requires_version,
89 $self->_croak($@) if $@;
91 my $status = $sess->status;
92 $status = 255 unless defined $status;
97 =head2 C<maybe_generalize>
99 my $mangled_suppression = Test::Valgrind::Suppressions->maybe_generalize(
104 Removes all wildcard frames at the end of the suppression.
105 It also replaces sequences of wildcard frames by C<'...'> when C<valgrind> C<3.4.0> or higher is used.
106 Returns the mangled suppression.
110 sub maybe_generalize {
113 my ($sess, $supp) = @_;
115 1 while $supp =~ s/[^\r\n]*:\s*\*\s*$//;
117 # With valgrind 3.4.0, we can replace unknown series of frames by '...'
118 my $can_ellipsis = $sess->version >= '3.4.0';
120 my $did_length_check;
125 $supp =~ s/(?:^\s*(?:\.{3}|\*:\S*|obj:\*)\s*(?:\n|\z))+/...\n/mg;
128 last if $did_length_check++;
130 my $frames_count =()= $supp =~ m/^(?:(?:obj|fun|\*):|\.{3}\s*$)/mg;
131 if ($frames_count > 24) {
132 # Keep only 24 frames, and even sacrifice one more if we can do ellipsis.
133 my $last = $can_ellipsis ? 23 : 24;
134 my $len = length $supp;
135 $supp =~ m/^(?:(?:obj|fun|\*):\S*|\.{3})\s*\n/mg for 1 .. $last;
137 substr $supp, $p, $len - $p, '';
138 redo ELLIPSIS if $can_ellipsis;
145 =head2 C<maybe_z_demangle>
147 my $demangled_symbol = Test::Valgrind::Suppressions->maybe_z_demangle(
151 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.
152 Otherwise, C<$symbol> is returned as is.
154 This routine follows C<valgrind>'s F<coregrind/m_demangle/demangle.c:maybe_Z_demangle>.
173 sub maybe_z_demangle {
174 my ($self, $sym) = @_;
176 $sym =~ s/^_vg[rwn]Z([ZU])_// or return $sym;
178 my $fn_is_encoded = $1 eq 'Z';
180 $sym =~ /^VG_Z_/ and $self->_croak('Symbol with a "VG_Z_" prefix is invalid');
182 or $self->_croak('Symbol doesn\'t contain a function name');
184 if ($fn_is_encoded) {
186 my $c = $z_escapes{$1};
187 $self->_croak('Invalid escape sequence') unless defined $c;
192 $self->_croak('Empty symbol') unless length $sym;
199 L<Test::Valgrind>, L<Test::Valgrind::Command>, L<Test::Valgrind::Tool>, L<Test::Valgrind::Action::Suppressions>.
203 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
205 You can contact me by mail or on C<irc.perl.org> (vincent).
209 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>.
210 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
214 You can find documentation for this module with the perldoc command.
216 perldoc Test::Valgrind::Suppressions
218 =head1 COPYRIGHT & LICENSE
220 Copyright 2008,2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
222 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
226 1; # End of Test::Valgrind::Suppressions