1 package Test::Valgrind::Tool::memcheck;
8 Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.
16 our $VERSION = '1.15';
20 This class contains the information required by the session for running the C<memcheck> tool.
24 use base qw<Test::Valgrind::Tool>;
28 This class inherits L<Test::Valgrind::Tool>.
30 =head2 C<requires_version>
32 my $required_version = $tvt->requires_version;
34 This tool requires C<valgrind> C<3.1.0>.
38 sub requires_version { '3.1.0' }
42 my $tvtm = Test::Valgrind::Tool::memcheck->new(
47 Your usual constructor.
49 C<$callers> specifies the number of stack frames to inspect for errors : the bigger you set it, the more granular the analysis is.
51 Other arguments are passed straight to C<< Test::Valgrind::Tool->new >>.
57 $class = ref($class) || $class;
61 my $callers = delete $args{callers} || 12;
64 my $self = bless $class->Test::Valgrind::Tool::new(%args), $class;
66 $self->{callers} = $callers;
71 sub new_trainer { shift->new(callers => 50) }
75 my $callers = $tvtm->callers;
77 Read-only accessor for the C<callers> option.
81 sub callers { $_[0]->{callers} }
83 sub suppressions_tag { 'memcheck-' . $_[1]->version }
85 =head2 C<parser_class>
87 my $parser_class = $tvtm->parser_class($session);
89 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.
94 my ($self, $session) = @_;
96 my $class = $session->do_suppressions
97 ? 'Test::Valgrind::Parser::Suppressions::Text'
98 : 'Test::Valgrind::Parser::XML::Twig';
102 eval "require $class; 1" or die $@;
108 =head2 C<report_class>
110 my $report_class = $tvtm->report_class($session);
112 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.
117 my ($self, $session) = @_;
119 if ($session->do_suppressions) {
120 require Test::Valgrind::Parser::Suppressions::Text;
121 return 'Test::Valgrind::Report::Suppressions';
123 return 'Test::Valgrind::Tool::memcheck::Report';
134 '--leak-resolution=high',
135 '--show-reachable=yes',
136 '--num-callers=' . $self->callers,
140 push @args, '--track-origins=yes' if $sess->version ge '3.4.0'
141 and not $sess->do_suppressions;
143 push @args, $self->SUPER::args(@_);
150 L<Test::Valgrind>, L<Test::Valgrind::Tool>.
154 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
156 You can contact me by mail or on C<irc.perl.org> (vincent).
160 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
161 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
165 You can find documentation for this module with the perldoc command.
167 perldoc Test::Valgrind::Tool::memcheck
169 =head1 COPYRIGHT & LICENSE
171 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
173 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
177 # End of Test::Valgrind::Tool::memcheck
179 package Test::Valgrind::Tool::memcheck::Report;
181 use base qw<Test::Valgrind::Report>;
183 our $VERSION = '1.15';
202 push @kinds, __PACKAGE__->SUPER::kinds();
204 my %kinds_hashed = map { $_ => 1 } @kinds;
208 sub valid_kind { exists $kinds_hashed{$_[1]} }
210 sub is_leak { $_[0]->kind =~ /^Leak_/ ? 1 : '' }
215 $pad = 2 * ($Config::Config{ptrsize} || 4);
221 my $data = $self->data;
225 for ([ '', 2, 4 ], [ 'aux', 4, 6 ], [ 'orig', 4, 6 ]) {
226 my ($prefix, $wind, $sind) = @$_;
228 my ($what, $stack) = @{$data}{"${prefix}what", "${prefix}stack"};
229 next unless defined $what and defined $stack;
231 $_ = ' ' x $_ for $wind, $sind;
233 $desc .= "$wind$what\n";
235 my ($ip, $obj, $fn, $dir, $file, $line) = map { (defined) ? $_ : '?' } @$_;
237 if ($fn eq '?' and $obj eq '?') {
240 $frame = '0x' . ($l < $pad ? ('0' x ($pad - $l)) : '') . uc($ip);
242 $frame = sprintf '%s (%s) [%s:%s]', $fn, $obj, $file, $line;
244 $desc .= "$sind$frame\n";
251 # End of Test::Valgrind::Tool::memcheck::Report