lib/Devel/Trepan/CmdProcessor/Command/Kill.pm

filter: Statementstmt 57.7% 86 / 149 Branchbran 25.0% 9 / 36 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 84.6% 22 / 26 Podpod 0.0% 0 / 5 totaltotal 46.0% 117 / 254 CC 34 SCAR 39.6
CC
34
Cov
45%
run
94.4
run
94.4
run
94.4
CRAP 52.5
« blib/lib/Devel/Trepan/SigHandler.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Program.pm »
1 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
2 # -*- coding: utf-8 -*-
3 12 ▶use warnings; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # FIXME: Complete doesn't work if in package.
7 12 ▶use Devel::Trepan::Complete;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 package Devel::Trepan::CmdProcessor::Command::Kill;
9  
10 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 1 1 2
15 12 ▶ eval <<'EOE';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
16 use constant ALIASES => ('kill!');
17 use constant CATEGORY => 'running';
18 use constant SHORT_HELP => 'Send this process a POSIX signal';
19 use constant MIN_ARGS => 0; # Need at least this many
20 use constant MAX_ARGS => 1; # Need at most this many - undef -> unlimited.
21 EOE
22 }
23 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 12 @ISA = @CMD_ISA;
26 12 ▶use vars @CMD_VARS; # Value inherited from parent
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 our $NAME = set_name();
29 =pod
30  
31 =head2 Synopsis:
32  
33 =cut
34 2 our $HELP = <<'HELP';
35 =pod
36  
37 B<kill>[B<!>] [I<signal-number>|I<signal-name>]
38  
39 Kill execution of program being debugged.
40  
41 Equivalent of C<kill('KILL', $$)>. This is an unmaskable
42 signal. Use this when all else fails, e.g. in thread code, use this.
43  
44 If you are in interactive mode, you are prompted to confirm killing.
45 However when this command is aliased from a command ending in C<!>, no
46 questions are asked.
47  
48 =head2 Examples:
49  
50 kill
51 kill KILL # same as above
52 kill kill # same as above
53 kill -9 # same as above
54 kill 9 # same as above
55 kill! 9 # same as above, but no questions asked
56 kill unconditionally # same as above
57 kill TERM # Send "TERM" signal
58  
59 =head2 See also:
60  
61 See also L<C<set
62 confirm>|Devel::Trepan::CmdProcessor::Command::Set::Confirm> and
63 L<C<quit>|Devel::Trepan::CmdProcessor::Command::Quit>.
64  
65 =cut
66 HELP
67  
68 0 ▶sub complete($$) {
Subroutine complete: not called CC=2 SCAR=8.5
Subroutine complete: called CC=2 SCAR=8.5
Pod undocumented
Pod undocumented
69 0 ▶ my ($self, $prefix) = @_;
Subroutine complete: not called CC=2 SCAR=8.5
Pod undocumented
70 0 my @matches = Devel::Trepan::Complete::signal_complete($prefix);
71 0 ▶ push @matches, 'unconditionally' if 0 == index('unconditionally', $prefix);
Branch: 3 branches
BranchTrueFalseTotal
if 0 == index("unconditionally", $prefix) 0 0 0
if 0 == index("unconditionally", $prefix) 1 1 2
if 0 == index("unconditionally", $prefix) 0 1 1
72 0 sort @matches;
73 }
74  
75 # This method runs the command
76 0 ▶sub run($$) {
Subroutine run: not called CC=11 SCAR=45.5
Subroutine run: not called CC=11 SCAR=45.5
Pod undocumented
Pod undocumented
77 0 my ($self, $args) = @_;
78 0 my $unconditional = substr($args->[0], -1, 1) eq '!';
79 0 my $sig;
80 0 ▶ if (scalar(@$args) > 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @$args > 1) { } 0 0 0
if (scalar @$args > 1) { } 10 0 10
if (scalar @$args > 1) { } 0 1 1
81 0 $sig = uc($args->[1]);
82 0 ▶ unless ( ($sig =~ /[+-]?\d+/) || exists $SIG{$sig} ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($sig =~ /[+-]?\d+/ or exists $SIG{$sig}) 0 0 0
unless ($sig =~ /[+-]?\d+/ or exists $SIG{$sig}) 0 10 10
Condition0%0/6
$sig =~ /[+-]?\d+/ or exists $SIG{$sig}
l!l&&r!l&&!r
000
$sig =~ /[+-]?\d+/ or exists $SIG{$sig}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig =~ /[+-]?\d+/ or exists $SIG{$sig}
$sig =~ /[+-]?\d+/ exists $SIG{$sig}
MC/DC0%0/2
$sig =~ /[+-]?\d+/ or exists $SIG{$sig}
$sig =~ /[+-]?\d+/ exists $SIG{$sig}
Truth table0%0/3
A or B
A= $sig =~ /[+-]?\d+/B= exists $SIG{$sig}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $sig =~ /[+-]?\d+/B= exists $SIG{$sig}
ABresult
1X1
011
000
83 0 $self->errmsg("Signal name '${sig}' is not a signal I know about.");
84 0 return;
85 }
86 } else {
87 0 ▶ if ($unconditional || $self->{proc}->confirm('Really quit?', 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unconditional or $self->{'proc'}->confirm('Really quit?', 0)) { } 0 0 0
if ($unconditional or $self->{'proc'}->confirm('Really quit?', 0)) { } 0 0 0
Condition0%0/6
$unconditional or $self->{"proc"}->confirm("Really quit?", 0)
l!l&&r!l&&!r
000
$unconditional or $self->{"proc"}->confirm("Really quit?", 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$unconditional or $self->{"proc"}->confirm("Really quit?", 0)
$unconditional $self->{"proc"}->confirm("Really quit?", 0)
MC/DC0%0/2
$unconditional or $self->{"proc"}->confirm("Really quit?", 0)
$unconditional $self->{"proc"}->confirm("Really quit?", 0)
Truth table0%0/3
A or B
A= $unconditionalB= $self->{"proc"}->confirm("Really quit?", 0)
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $unconditionalB= $self->{"proc"}->confirm("Really quit?", 0)
ABresult
1X1
011
000
88 0 $sig = 'KILL';
89 } else {
90 0 $self->msg('Kill not confirmed.');
91 0 return;
92 }
93 }
94 0 ▶ if (kill(0, $$)) {
Branch: 2 branches
BranchTrueFalseTotal
if (kill 0, $$) { } 0 0 0
if (kill 0, $$) { } 0 0 0
95 # Force finalization on interface.
96 0 ▶ $self->{proc}{interfaces} = [] if
Branch: 2 branches
BranchTrueFalseTotal
if "KILL" eq $sig or 9 eq $sig or -9 eq $sig 0 0 0
if "KILL" eq $sig or 9 eq $sig or -9 eq $sig 0 0 0
Condition0%0/12
"KILL" eq $sig or 9 eq $sig or -9 eq $sig
l!l&&r!l&&!r
000
"KILL" eq $sig or 9 eq $sig
l!l&&r!l&&!r
000
"KILL" eq $sig or 9 eq $sig or -9 eq $sig
l!l&&r!l&&!r
000
"KILL" eq $sig or 9 eq $sig
l!l&&r!l&&!r
000
MC/DC0%0/3
"KILL" eq $sig or 9 eq $sig or -9 eq $sig
"KILL" eq $sig 9 eq $sig -9 eq $sig
MC/DC0%0/3
"KILL" eq $sig or 9 eq $sig or -9 eq $sig
"KILL" eq $sig 9 eq $sig -9 eq $sig
Truth table0%0/4
A or B or C
A= "KILL" eq $sigB= 9 eq $sigC= -9 eq $sig
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= "KILL" eq $sigB= 9 eq $sigC= -9 eq $sig
ABCresult
1XX1
01X1
0011
0000
97 'KILL' eq $sig || 9 eq $sig || -9 eq $sig;
98 0 ▶ if (kill($sig, $$)) {
Branch: 2 branches
BranchTrueFalseTotal
if (kill $sig, $$) { } 0 0 0
if (kill $sig, $$) { } 0 0 0
99 0 $self->msg("kill ${sig} successfully sent to process $$");
100 } else {
101 0 $self->errmsg("Kill ${sig} to process $$ not accepted: $!")
102 }
103 } else {
104 0 $self->errmsg(["Unable kill ${sig} to process $$",
105 "Different uid and not super-user?"]);
106 }
107 }
108  
109 2 ▶unless (caller()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller()) 0 2 2
110 0 require Devel::Trepan::CmdProcessor;
111 0 my $proc = Devel::Trepan::CmdProcessor->new;
112 0 my $cmd = __PACKAGE__->new($proc);
113 0 print $cmd->{help}, "\n";
114 0 print join(', ', @{$cmd->{aliases}}), "\n";
115 0 print "min args: ", eval('$' . __PACKAGE__ . "::MIN_ARGS"), "\n";
116 0 for my $arg ('hu', 'HU', '', 1, '-9') {
117 0 printf "complete($arg) => %s\n", join(", ", $cmd->complete($arg));
118 }
119 0 for my $arg (qw(fooo 100 1 -1 HUP -9)) {
120 0 print "$NAME ${arg}\n";
121 0 $cmd->run([$NAME, $arg]);
122 0 my $sep = '=' x 40 . "\n";
123 0 print $sep;
124 }
125 }
126  
127 2 1;
« blib/lib/Devel/Trepan/SigHandler.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Program.pm »