blib/lib/Sys/Ptrace.pm

filter: Statementstmt 87.5% 42 / 48 Branchbran 42.8% 6 / 14 Conditioncond 60.0% 9 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 70.9% 66 / 93 CC 13 SCAR 23.8
CC
13
Cov
74%
ptrace
19.1
AUTOLOAD
5.5
BEGIN
1.0
CRAP 10.8
↑ Summary Ptrace.xs »
1 package Sys::Ptrace;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 $VERSION = '0.06';
10 4 @ISA = qw(Exporter DynaLoader);
11  
12 4 @EXPORT_OK = qw(
13 ptrace
14 PT_ATTACH
15 PT_CONTINUE
16 PT_DETACH
17 PT_GETFPREGS
18 PT_GETFPXREGS
19 PT_GETREGS
20 PT_KILL
21 PT_READ_D
22 PT_READ_I
23 PT_READ_U
24 PT_SETFPREGS
25 PT_SETFPXREGS
26 PT_SETREGS
27 PT_STEP
28 PT_SYSCALL
29 PT_TRACE_ME
30 PT_WRITE_D
31 PT_WRITE_I
32 PT_WRITE_U
33 );
34  
35 4 @EXPORT = qw( ptrace );
36  
37 # THE FOLLOWING HASHREF WAS GENERATED BY:
38 # perl -n -e 'print "$2 => '"'"'$1'"'"',\n" if /define\s+(PT_\w+)\s+(PTRACE_\w+)/;' /usr/include/sys/ptrace.h
39 4 my $PTRACE_CONSTANT = {
40 PTRACE_TRACEME => 'PT_TRACE_ME',
41 PTRACE_PEEKTEXT => 'PT_READ_I',
42 PTRACE_PEEKDATA => 'PT_READ_D',
43 PTRACE_PEEKUSER => 'PT_READ_U',
44 PTRACE_POKETEXT => 'PT_WRITE_I',
45 PTRACE_POKEDATA => 'PT_WRITE_D',
46 PTRACE_POKEUSER => 'PT_WRITE_U',
47 PTRACE_CONT => 'PT_CONTINUE',
48 PTRACE_KILL => 'PT_KILL',
49 PTRACE_SINGLESTEP => 'PT_STEP',
50 PTRACE_GETREGS => 'PT_GETREGS',
51 PTRACE_SETREGS => 'PT_SETREGS',
52 PTRACE_GETFPREGS => 'PT_GETFPREGS',
53 PTRACE_SETFPREGS => 'PT_SETFPREGS',
54 PTRACE_ATTACH => 'PT_ATTACH',
55 PTRACE_DETACH => 'PT_DETACH',
56 PTRACE_GETFPXREGS => 'PT_GETFPXREGS',
57 PTRACE_SETFPXREGS => 'PT_SETFPXREGS',
58 PTRACE_SYSCALL => 'PT_SYSCALL',
59 };
60  
61 # Allow export for all of them
62 4 foreach ( keys %{$PTRACE_CONSTANT} ) {
63 76 push @EXPORT_OK, $_;
64 }
65  
66 4 foreach (@EXPORT_OK) {
67  
68 # Prototype constants to prepare
69 # for correct entry into the AUTOLOAD
70 156 ▶ eval "sub $_ ();" if /^PT(RACE)?_/;
Branch: 1 branch
BranchTrueFalseTotal
if /^PT(RACE)?_/ 152 4 156
71 }
72  
73 46 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=5 SCAR=17.1
74  
75 # This AUTOLOAD is used to 'autoload' constants from the constant()
76 # XS function. If a constant is not found then control is passed
77 # to the AUTOLOAD in AutoLoader.
78  
79 46 my $constname;
80 46 ( $constname = $AUTOLOAD ) =~ s/.*:://;
81 46 ▶ croak "& not defined" if $constname eq 'constant';
Branch: 1 branch
BranchTrueFalseTotal
if $constname eq "constant" 0 46 46
82 46 ▶ my $function_name = $PTRACE_CONSTANT->{$constname} || $constname;
Condition66%2/3
$PTRACE_CONSTANT->{$constname} || $constname
l!l&&r!l&&!r
21250
MC/DC0%0/2
$PTRACE_CONSTANT->{$constname} || $constname
$PTRACE_CONSTANT->{$constname} $constname
Truth table66%2/3
A || B
A= $PTRACE_CONSTANT->{$constname}B= $constname
ABresult
1X1
011
000
83 46 ▶ my $val = constant( $function_name, @_ ? $_[0] : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 46 46
84 46 ▶ if ( $! != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! != 0) 0 46 46
85 0 croak "Your vendor has not defined Sys::Ptrace macro $constname";
86 }
87 46 eval "sub $constname () { $val; }";
88 46 goto &$AUTOLOAD;
89 }
90  
91 4 bootstrap Sys::Ptrace $VERSION;
92  
93 # Preloaded methods go here.
94  
95 # Dumb wrapper function to call the internal ptrace C function.
96 # Returns true on success and sets $! on failure.
97 2 ▶sub ptrace {
Subroutine ptrace: called CC=9 SCAR=29.5
Pod undocumented
98 2 my ( $request, $pid, $addr, $data ) = @_;
99 2 ▶ $pid ||= 0;
Condition100%2/2
$pid ||= 0
l!l
11
MC/DC100%1/1
$pid ||= 0
$pid
Truth table100%2/2
A
A= $pid
Aresult
11
00
100 2 ▶ $addr ||= 0;
Condition100%2/2
$addr ||= 0
l!l
11
MC/DC100%1/1
$addr ||= 0
$addr
Truth table100%2/2
A
A= $addr
Aresult
11
00
101 2 ▶ $data ||= 0;
Condition50%1/2
$data ||= 0
l!l
02
MC/DC0%0/1
$data ||= 0
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
102 2 my $result = _ptrace( $request, $pid, $addr, $data );
103 2 ▶ if ( $request == PT_READ_I()
Branch: 1 branch
BranchTrueFalseTotal
if ($request == &PT_READ_I() or $request == &PT_READ_D() or $request == &PT_READ_U()) 0 2 2
Condition33%2/6
$request == &PT_READ_I() or $request == &PT_READ_D() or $request == &PT_READ_U()
l!l&&r!l&&!r
002
$request == &PT_READ_I() or $request == &PT_READ_D()
l!l&&r!l&&!r
002
MC/DC0%0/3
$request == &PT_READ_I() or $request == &PT_READ_D() or $request == &PT_READ_U()
$request == &PT_READ_I() $request == &PT_READ_D() $request == &PT_READ_U()
Truth table25%1/4
A or B or C
A= $request == &PT_READ_I()B= $request == &PT_READ_D()C= $request == &PT_READ_U()
ABCresult
1XX1
01X1
0011
0000
104 || $request == PT_READ_D()
105 || $request == PT_READ_U() ) {
106 0 ▶ if ( ref $data eq "SCALAR" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'SCALAR') { } 0 0 0
elsif (@_ > 3) { } 0 0 0
107 0 $$data = $result;
108 }
109 elsif ( @_ > 3 ) {
110 0 $_[3] = $result;
111 }
112 else {
113 0 croak 'PTRACE_PEEK* requires $data to store into';
114 }
115 0 $result = 0;
116 }
117 2 return !$result;
118 }
119  
120 4 1;
121 __END__
↑ Summary Ptrace.xs »