X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FTest%2FValgrind%2FTool%2Fmemcheck.pm;h=27a2a62eed0abe2d820f151d5ff77fc1849959e6;hb=f2071d95aaaa4817e91cc33530deedc8d701d44d;hp=e75f0c0dd0dda9492d35666052f1d588dbd952f5;hpb=08f451d35014a7f8587fba4bc20103a018487653;p=perl%2Fmodules%2FTest-Valgrind.git diff --git a/lib/Test/Valgrind/Tool/memcheck.pm b/lib/Test/Valgrind/Tool/memcheck.pm index e75f0c0..27a2a62 100644 --- a/lib/Test/Valgrind/Tool/memcheck.pm +++ b/lib/Test/Valgrind/Tool/memcheck.pm @@ -9,19 +9,21 @@ Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool. =head1 VERSION -Version 1.02 +Version 1.19 =cut -our $VERSION = '1.02'; +our $VERSION = '1.19'; =head1 DESCRIPTION -This tool parses the XML output of a C run with L. +This class contains the information required by the session for running the C tool. =cut -use base qw/Test::Valgrind::Tool/; +use Scalar::Util (); + +use base qw; =head1 METHODS @@ -29,13 +31,20 @@ This class inherits L. =head2 C + my $required_version = $tvt->requires_version; + This tool requires C C<3.1.0>. =cut sub requires_version { '3.1.0' } -=head2 C<< new callers => $callers, ... >> +=head2 C + + my $tvtm = Test::Valgrind::Tool::memcheck->new( + callers => $callers, + %extra_args, + ); Your usual constructor. @@ -51,8 +60,11 @@ sub new { my %args = @_; - my $callers = delete $args{callers} || 12; - $callers =~ s/\D//g; + my $callers = delete $args{callers}; + $callers = 24 unless $callers; + die 'Invalid number of callers' + unless Scalar::Util::looks_like_number($callers) and $callers > 0 + and $callers <= 24; my $self = bless $class->Test::Valgrind::Tool::new(%args), $class; @@ -61,10 +73,12 @@ sub new { $self; } -sub new_trainer { shift->new(callers => 50) } +sub new_trainer { shift->new(callers => 24) } =head2 C + my $callers = $tvtm->callers; + Read-only accessor for the C option. =cut @@ -73,13 +87,47 @@ sub callers { $_[0]->{callers} } sub suppressions_tag { 'memcheck-' . $_[1]->version } -=head2 C +=head2 C + + my $parser_class = $tvtm->parser_class($session); -This tool emits C object reports in analysis mode. +This tool uses a L parser in analysis mode, and a L parser in suppressions mode. =cut -sub report_class_analysis { 'Test::Valgrind::Tool::memcheck::Report' } +sub parser_class { + my ($self, $session) = @_; + + my $class = $session->do_suppressions + ? 'Test::Valgrind::Parser::Suppressions::Text' + : 'Test::Valgrind::Parser::XML::Twig'; + + { + local $@; + eval "require $class; 1" or die $@; + } + + return $class; +} + +=head2 C + + my $report_class = $tvtm->report_class($session); + +This tool emits C object reports in analysis mode, and C object reports in suppressions mode. + +=cut + +sub report_class { + my ($self, $session) = @_; + + if ($session->do_suppressions) { + require Test::Valgrind::Parser::Suppressions::Text; + return 'Test::Valgrind::Report::Suppressions'; + } else { + return 'Test::Valgrind::Tool::memcheck::Report'; + } +} sub args { my $self = shift; @@ -94,10 +142,8 @@ 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 >= '3.4.0' + and not $sess->do_suppressions; push @args, $self->SUPER::args(@_); @@ -108,8 +154,6 @@ sub args { L, L. -L. - =head1 AUTHOR Vincent Pit, C<< >>, L. @@ -129,7 +173,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,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. @@ -139,11 +183,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; -our $VERSION = '1.02'; +our $VERSION = '1.19'; -my @kinds = qw/ +my @kinds = qw< InvalidFree MismatchedFree InvalidRead @@ -159,7 +203,7 @@ my @kinds = qw/ Leak_IndirectlyLost Leak_PossiblyLost Leak_StillReachable -/; +>; push @kinds, __PACKAGE__->SUPER::kinds(); my %kinds_hashed = map { $_ => 1 } @kinds; @@ -196,9 +240,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; }