1 package Test::Valgrind::Tool::memcheck;
8 Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.
16 our $VERSION = '1.13';
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';
101 eval "require $class";
106 =head2 C<report_class>
108 my $report_class = $tvtm->report_class($session);
110 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.
115 my ($self, $session) = @_;
117 $session->do_suppressions ? 'Test::Valgrind::Report::Suppressions'
118 : 'Test::Valgrind::Tool::memcheck::Report'
128 '--leak-resolution=high',
129 '--show-reachable=yes',
130 '--num-callers=' . $self->callers,
134 push @args, '--track-origins=yes' if $sess->version ge '3.4.0'
135 and not $sess->do_suppressions;
137 push @args, $self->SUPER::args(@_);
144 L<Test::Valgrind>, L<Test::Valgrind::Tool>.
148 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
150 You can contact me by mail or on C<irc.perl.org> (vincent).
154 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>.
155 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
159 You can find documentation for this module with the perldoc command.
161 perldoc Test::Valgrind::Tool::memcheck
163 =head1 COPYRIGHT & LICENSE
165 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
167 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
171 # End of Test::Valgrind::Tool::memcheck
173 package Test::Valgrind::Tool::memcheck::Report;
175 use base qw<Test::Valgrind::Report>;
177 our $VERSION = '1.13';
196 push @kinds, __PACKAGE__->SUPER::kinds();
198 my %kinds_hashed = map { $_ => 1 } @kinds;
202 sub valid_kind { exists $kinds_hashed{$_[1]} }
204 sub is_leak { $_[0]->kind =~ /^Leak_/ ? 1 : '' }
209 $pad = 2 * ($Config::Config{ptrsize} || 4);
215 my $data = $self->data;
219 for ([ '', 2, 4 ], [ 'aux', 4, 6 ], [ 'orig', 4, 6 ]) {
220 my ($prefix, $wind, $sind) = @$_;
222 my ($what, $stack) = @{$data}{"${prefix}what", "${prefix}stack"};
223 next unless defined $what and defined $stack;
225 $_ = ' ' x $_ for $wind, $sind;
227 $desc .= "$wind$what\n";
229 my ($ip, $obj, $fn, $dir, $file, $line) = map { (defined) ? $_ : '?' } @$_;
231 if ($fn eq '?' and $obj eq '?') {
234 $frame = '0x' . ($l < $pad ? ('0' x ($pad - $l)) : '') . uc($ip);
236 $frame = sprintf '%s (%s) [%s:%s]', $fn, $obj, $file, $line;
238 $desc .= "$sind$frame\n";
245 # End of Test::Valgrind::Tool::memcheck::Report