/usr/share/perl5/Test/Valgrind/Parser/XML/Twig.pm is in libtest-valgrind-perl 1.14-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | package Test::Valgrind::Parser::XML::Twig;
use strict;
use warnings;
=head1 NAME
Test::Valgrind::Parser::XML::Twig - Parse valgrind XML output with XML::Twig.
=head1 VERSION
Version 1.14
=cut
our $VERSION = '1.14';
=head1 DESCRIPTION
This subclass of L<XML::Twig> and L<Test::Valgrind::Parser::XML> encapsulates an L<XML::Twig> parser inside the L<Test::Valgrind::Parser> framework.
It is able to parse the XML output from C<valgrind> up to protocol version 4 and to generate the appropriate reports accordingly.
=cut
use Scalar::Util ();
use base qw<Test::Valgrind::Parser::XML Test::Valgrind::Carp XML::Twig>;
BEGIN { XML::Twig->add_options('Stash'); }
my %handlers = (
'/valgrindoutput/protocolversion' => \&handle_version,
'/valgrindoutput/error' => \&handle_error,
);
=head1 METHODS
=cut
sub new {
my $class = shift;
$class = ref($class) || $class;
my %args = @_;
my $stash = delete $args{stash} || { };
bless $class->XML::Twig::new(
elt_class => __PACKAGE__ . '::Elt',
stash => $stash,
twig_roots => { map { $_ => 1 } keys %handlers },
twig_handlers => { map { $_ => $handlers{$_} } keys %handlers },
), $class;
}
sub stash { shift->{Stash} }
=head2 C<protocol_version>
The version of the protocol that the current stream is conforming to.
It is reset before and after the parsing phase, so it's effectively only available from inside C<parse>.
=cut
eval "sub $_ { \@_ <= 1 ? \$_[0]->{$_} : (\$_[0]->{$_} = \$_[1]) }"
for qw<_session protocol_version>;
# We must store the session in ourselves because it's only possible to pass
# arguments to XML::Twig objects by a global stash.
sub start {
my ($self, $sess) = @_;
$self->SUPER::start($sess);
$self->_session($sess);
return;
}
sub parse {
my ($self, $sess, $fh) = @_;
$self->protocol_version(undef);
$self->XML::Twig::parse($fh);
$self->purge;
$self->protocol_version(undef);
return;
}
sub finish {
my ($self, $sess) = @_;
$self->_session(undef);
$self->SUPER::finish($sess);
return;
}
sub handle_version {
my ($twig, $node) = @_;
$twig->protocol_version($node->text);
$twig->purge;
}
sub handle_error {
my ($twig, $node) = @_;
my $id = $node->kid('unique')->text;
my $kind = $node->kid('kind')->text;
my $data;
my ($what, $xwhat);
if ($twig->protocol_version >= 4) {
$xwhat = $node->first_child('xwhat');
$what = $xwhat->kid('text')->text if defined $xwhat;
}
$what = $node->kid('what')->text unless defined $what;
$data->{what} = $what;
$data->{stack} = [ map $_->listify_frame,
$node->kid('stack')->children('frame') ];
for (qw<leakedbytes leakedblocks>) {
my $kid = ($xwhat || $node)->first_child($_);
next unless $kid;
$data->{$_} = int $kid->text;
}
if (my $auxwhat = $node->first_child('auxwhat')) {
if (my $stack = $auxwhat->next_sibling('stack')) {
$data->{auxstack} = [ map $_->listify_frame, $stack->children('frame') ];
}
$data->{auxwhat} = $auxwhat->text;
}
if (my $origin = $node->first_child('origin')) {
$data->{origwhat} = $origin->kid('what')->text;
$data->{origstack} = [ map $_->listify_frame,
$origin->kid('stack')->children('frame') ];
}
my $sess = $twig->_session;
$sess->report($sess->report_class($sess)->new(
kind => $kind,
id => $id,
data => $data,
));
$twig->purge;
}
=head1 SEE ALSO
L<Test::Valgrind>, L<Test::Valgrind::Parser>, L<Test::Valgrind::Parser::XML>.
L<XML::Twig>.
=head1 AUTHOR
Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
You can contact me by mail or on C<irc.perl.org> (vincent).
=head1 BUGS
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>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Test::Valgrind::Parser::XML::Twig
=head1 COPYRIGHT & LICENSE
Copyright 2009,2010,2011,2013 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.
=cut
# End of Test::Valgrind::Parser::XML::Twig
package Test::Valgrind::Parser::XML::Twig::Elt;
our $VERSION = '1.14';
BEGIN { require XML::Twig; }
use base qw<XML::Twig::Elt Test::Valgrind::Carp>;
sub kid {
my ($self, $what) = @_;
my $node = $self->first_child($what);
$self->_croak("Couldn't get first $what child node") unless $node;
return $node;
}
sub listify_frame {
my ($frame) = @_;
return unless $frame->tag eq 'frame';
return [
map {
my $x = $frame->first_child($_);
$x ? $x->text : undef
} qw<ip obj fn dir file line>
];
}
1; # End of Test::Valgrind::Parser::XML::Twig::Elt
|