]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Suppressions.pm
This is 1.19
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Suppressions.pm
index ad27f6bf1e7d269a114a01e6ab9734e5e4f2512b..62d43e88cd9d3b4e35ad3eff4a91893ce2454271 100644 (file)
@@ -9,11 +9,11 @@ Test::Valgrind::Suppressions - Generate suppressions for given tool and command.
 
 =head1 VERSION
 
-Version 1.13
+Version 1.19
 
 =cut
 
-our $VERSION = '1.13';
+our $VERSION = '1.19';
 
 =head1 DESCRIPTION
 
@@ -25,7 +25,13 @@ use base qw<Test::Valgrind::Carp>;
 
 =head1 METHODS
 
-=head2 C<< generate tool => $tool, command => $command, target => $target >>
+=head2 C<generate>
+
+    Test::Valgrind::Suppressions->generate(
+     tool    => $tool,
+     command => $command,
+     target  => $target,
+    );
 
 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>.
 The action used behind the scenes is L<Test::Valgrind::Action::Suppressions>.
@@ -88,30 +94,59 @@ sub generate {
  return $status;
 }
 
-=head2 C<strip_tail $session, $suppression>
+=head2 C<maybe_generalize>
+
+    my $mangled_suppression = Test::Valgrind::Suppressions->maybe_generalize(
+     $session,
+     $suppression,
+    );
 
 Removes all wildcard frames at the end of the suppression.
-Moreover, C<'...'> is appended when C<valgrind> C<3.4.0> or higher is used.
+It also replaces sequences of wildcard frames by C<'...'> when C<valgrind> C<3.4.0> or higher is used.
 Returns the mangled suppression.
 
 =cut
 
-sub strip_tail {
+sub maybe_generalize {
  shift;
 
  my ($sess, $supp) = @_;
 
  1 while $supp =~ s/[^\r\n]*:\s*\*\s*$//;
+
  # With valgrind 3.4.0, we can replace unknown series of frames by '...'
- if ($sess->version ge '3.4.0') {
-  1 while $supp =~ s/[^\r\n]*\.{3}\s*$//;
-  $supp .= "...\n";
+ my $can_ellipsis = $sess->version >= '3.4.0';
+
+ my $did_length_check;
+
+ ELLIPSIS: {
+  if ($can_ellipsis) {
+   $supp .= "...\n";
+   $supp =~ s/(?:^\s*(?:\.{3}|\*:\S*|obj:\*)\s*(?:\n|\z))+/...\n/mg;
+  }
+
+  last if $did_length_check++;
+
+  my $frames_count =()= $supp =~ m/^(?:(?:obj|fun|\*):|\.{3}\s*$)/mg;
+  if ($frames_count > 24) {
+   # Keep only 24 frames, and even sacrifice one more if we can do ellipsis.
+   my $last = $can_ellipsis ? 23 : 24;
+   my $len  = length $supp;
+   $supp    =~ m/^(?:(?:obj|fun|\*):\S*|\.{3})\s*\n/mg for 1 .. $last;
+   my $p    = pos $supp;
+   substr $supp, $p, $len - $p, '';
+   redo ELLIPSIS if $can_ellipsis;
+  }
  }
 
  $supp;
 }
 
-=head2 C<maybe_z_demangle $symbol>
+=head2 C<maybe_z_demangle>
+
+    my $demangled_symbol = Test::Valgrind::Suppressions->maybe_z_demangle(
+     $symbol,
+    );
 
 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.
 Otherwise, C<$symbol> is returned as is.
@@ -182,7 +217,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2008,2009,2010,2011 Vincent Pit, all rights reserved.
+Copyright 2008,2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.