]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Tool/memcheck.pm
Bump copyright year
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Tool / memcheck.pm
index 87852cf5bed7757d23e8661cad90288f10462bc1..c72882e7e892c05e580a7d45d3dee18213505029 100644 (file)
@@ -9,19 +9,19 @@ Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.
 
 =head1 VERSION
 
-Version 1.02
+Version 1.12
 
 =cut
 
-our $VERSION = '1.02';
+our $VERSION = '1.12';
 
 =head1 DESCRIPTION
 
-This tool parses the XML output of a C<memcheck> run with L<XML::Twig>.
+This class contains the information required by the session for running the C<memcheck> tool.
 
 =cut
 
-use base qw/Test::Valgrind::Tool/;
+use base qw<Test::Valgrind::Tool>;
 
 =head1 METHODS
 
@@ -58,8 +58,6 @@ sub new {
 
  $self->{callers} = $callers;
 
- $self->{twig} = Test::Valgrind::Tool::memcheck::Twig->new(tool => $self);
-
  $self;
 }
 
@@ -73,23 +71,39 @@ Read-only accessor for the C<callers> option.
 
 sub callers { $_[0]->{callers} }
 
-=head2 C<twig>
+sub suppressions_tag { 'memcheck-' . $_[1]->version }
+
+=head2 C<parser_class $session>
 
-Read-only accessor for the underlying L<XML::Twig> parser.
+This tool uses a L<Test::Valgrind::Parser::XML::Twig> parser in analysis mode, and a L<Test::Valgrind::Parser::Suppressions::Text> parser in suppressions mode.
 
 =cut
 
-sub twig { $_[0]->{twig} }
+sub parser_class {
+ my ($self, $session) = @_;
 
-sub suppressions_tag { 'memcheck-' . $_[1]->version }
+ my $class = $session->do_suppressions
+           ? 'Test::Valgrind::Parser::Suppressions::Text'
+           : 'Test::Valgrind::Parser::XML::Twig';
+
+ local $@;
+ eval "require $class";
+
+ return $class;
+}
 
-=head2 C<report_class_analysis $session>
+=head2 C<report_class $session>
 
-This tool emits C<Test::Valgrind::Tool::memcheck::Report> object reports in analysis mode.
+This tool emits C<Test::Valgrind::Tool::memcheck::Report> object reports in analysis mode, and C<Test::Valgrind::Report::Suppressions> object reports in suppressions mode.
 
 =cut
 
-sub report_class_analysis { 'Test::Valgrind::Tool::memcheck::Report' }
+sub report_class {
+ my ($self, $session) = @_;
+
+ $session->do_suppressions ? 'Test::Valgrind::Report::Suppressions'
+                           : 'Test::Valgrind::Tool::memcheck::Report'
+}
 
 sub args {
  my $self = shift;
@@ -104,55 +118,18 @@ sub args {
   '--error-limit=yes',
  );
 
- unless ($sess->do_suppressions) {
-  push @args, '--track-origins=yes' if $sess->version ge '3.4.0';
-  push @args, '--xml=yes';
- }
+ push @args, '--track-origins=yes' if  $sess->version ge '3.4.0'
+                                   and not $sess->do_suppressions;
 
  push @args, $self->SUPER::args(@_);
 
  return @args;
 }
 
-# We must store the session in ourselves because it's only possible to pass
-# arguments to XML::Twig objects by a global stash.
-
-sub _session { @_ <= 1 ? $_[0]->{_session} : ($_[0]->{_session} = $_[1]) }
-
-sub start {
- my ($self, $sess) = @_;
-
- $self->SUPER::start($sess);
- $self->_session($sess);
-
- return;
-}
-
-sub parse_analysis {
- my ($self, $sess, $fh) = @_;
-
- my $twig = $self->twig;
- $twig->parse($fh);
- $twig->purge;
-
- return;
-}
-
-sub finish {
- my ($self, $sess) = @_;
-
- $self->_session(undef);
- $self->SUPER::finish($sess);
-
- return;
-}
-
 =head1 SEE ALSO
 
 L<Test::Valgrind>, L<Test::Valgrind::Tool>.
 
-L<XML::Twig>.
-
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
@@ -172,7 +149,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2009 Vincent Pit, all rights reserved.
+Copyright 2009,2010,2011 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.
 
@@ -182,11 +159,11 @@ This program is free software; you can redistribute it and/or modify it under th
 
 package Test::Valgrind::Tool::memcheck::Report;
 
-use base qw/Test::Valgrind::Report/;
+use base qw<Test::Valgrind::Report>;
 
-our $VERSION = '1.02';
+our $VERSION = '1.12';
 
-my @kinds = qw/
+my @kinds = qw<
  InvalidFree
  MismatchedFree
  InvalidRead
@@ -202,7 +179,7 @@ my @kinds = qw/
  Leak_IndirectlyLost
  Leak_PossiblyLost
  Leak_StillReachable
-/;
+>;
 push @kinds, __PACKAGE__->SUPER::kinds();
 
 my %kinds_hashed = map { $_ => 1 } @kinds;
@@ -239,9 +216,9 @@ sub dump {
    my ($ip, $obj, $fn, $dir, $file, $line) = map { (defined) ? $_ : '?' } @$_;
    my $frame;
    if ($fn eq '?' and $obj eq '?') {
-    $ip =~ s/^0x//g;
-    $ip = hex $ip;
-    $frame = sprintf "0x%0${pad}X", $ip;
+    $ip =~ s/^0x//gi;
+    my $l = length $ip;
+    $frame = '0x' . ($l < $pad ? ('0' x ($pad - $l)) : '') . uc($ip);
    } else {
     $frame = sprintf '%s (%s) [%s:%s]', $fn, $obj, $file, $line;
    }