Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.


Test-Valgrind documentation Contained in the Test-Valgrind distribution.

Index


Code Index:

NAME

Top

Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.

VERSION

Top

Version 1.12

DESCRIPTION

Top

This class contains the information required by the session for running the memcheck tool.

METHODS

Top

This class inherits Test::Valgrind::Tool.

requires_version

This tool requires valgrind 3.1.0.

new callers => $callers, ...

Your usual constructor.

$callers specifies the number of stack frames to inspect for errors : the bigger you set it, the more granular the analysis is.

Other arguments are passed straight to Test::Valgrind::Tool->new.

callers

Read-only accessor for the callers option.

parser_class $session

This tool uses a Test::Valgrind::Parser::XML::Twig parser in analysis mode, and a Test::Valgrind::Parser::Suppressions::Text parser in suppressions mode.

report_class $session

This tool emits Test::Valgrind::Tool::memcheck::Report object reports in analysis mode, and Test::Valgrind::Report::Suppressions object reports in suppressions mode.

SEE ALSO

Top

Test::Valgrind, Test::Valgrind::Tool.

AUTHOR

Top

Vincent Pit, <perl at profvince.com>, http://www.profvince.com.

You can contact me by mail or on irc.perl.org (vincent).

BUGS

Top

Please report any bugs or feature requests to bug-test-valgrind at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Test::Valgrind::Tool::memcheck

COPYRIGHT & LICENSE

Top


Test-Valgrind documentation Contained in the Test-Valgrind distribution.
package Test::Valgrind::Tool::memcheck;

use strict;
use warnings;

our $VERSION = '1.12';

use base qw/Test::Valgrind::Tool/;

sub requires_version { '3.1.0' }

sub new {
 my $class = shift;
 $class = ref($class) || $class;

 my %args = @_;

 my $callers = delete $args{callers} || 12;
 $callers =~ s/\D//g;

 my $self = bless $class->Test::Valgrind::Tool::new(%args), $class;

 $self->{callers} = $callers;

 $self;
}

sub new_trainer { shift->new(callers => 50) }

sub callers { $_[0]->{callers} }

sub suppressions_tag { 'memcheck-' . $_[1]->version }

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";

 return $class;
}

sub report_class {
 my ($self, $session) = @_;

 $session->do_suppressions ? 'Test::Valgrind::Report::Suppressions'
                           : 'Test::Valgrind::Tool::memcheck::Report'
}

sub args {
 my $self = shift;
 my ($sess) = @_;

 my @args = (
  '--tool=memcheck',
  '--leak-check=full',
  '--leak-resolution=high',
  '--show-reachable=yes',
  '--num-callers=' . $self->callers,
  '--error-limit=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;
}

# End of Test::Valgrind::Tool::memcheck

package Test::Valgrind::Tool::memcheck::Report;

use base qw/Test::Valgrind::Report/;

our $VERSION = '1.12';

my @kinds = qw/
 InvalidFree
 MismatchedFree
 InvalidRead
 InvalidWrite
 InvalidJump
 Overlap
 InvalidMemPool
 UninitCondition
 UninitValue
 SyscallParam
 ClientCheck
 Leak_DefinitelyLost
 Leak_IndirectlyLost
 Leak_PossiblyLost
 Leak_StillReachable
/;
push @kinds, __PACKAGE__->SUPER::kinds();

my %kinds_hashed = map { $_ => 1 } @kinds;

sub kinds      { @kinds }

sub valid_kind { exists $kinds_hashed{$_[1]} }

sub is_leak    { $_[0]->kind =~ /^Leak_/ ? 1 : '' }

my $pad;
BEGIN {
 require Config;
 $pad = 2 * ($Config::Config{ptrsize} || 4);
}

sub dump {
 my ($self) = @_;

 my $data = $self->data;

 my $desc = '';

 for ([ '', 2, 4 ], [ 'aux', 4, 6 ], [ 'orig', 4, 6 ]) {
  my ($prefix, $wind, $sind) = @$_;

  my ($what, $stack) = @{$data}{"${prefix}what", "${prefix}stack"};
  next unless defined $what and defined $stack;

  $_ = ' ' x $_ for $wind, $sind;

  $desc .= "$wind$what\n";
  for (@$stack) {
   my ($ip, $obj, $fn, $dir, $file, $line) = map { (defined) ? $_ : '?' } @$_;
   my $frame;
   if ($fn eq '?' and $obj eq '?') {
    $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;
   }
   $desc .= "$sind$frame\n";
  }
 }

 return $desc;
}

# End of Test::Valgrind::Tool::memcheck::Report