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

filter: Statementstmt 57.5% 80 / 139 Branchbran 25.0% 4 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.3% 22 / 30 Podpod 0.0% 0 / 8 totaltotal 54.9% 106 / 193 CC 10 SCAR 15.0
CC
10
Cov
54%
run
12.1
run
12.1
run
12.1
CRAP 4.5
« lib/Devel/Trepan/CmdProcessor/Command/Frame.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/Set.pm »
1 # Copyright (C) 2011-2012, 2014-2015, 2018 Rocky Bernstein <rocky@cpan.org>
2 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
3  
4 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Devel::Trepan::CmdProcessor::Command::Backtrace;
7 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 0 1 1
12 0 ▶ 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
Subroutine BEGIN: called CC=1 SCAR=0.0
13 use constant ALIASES => qw(bt where T);
14 use constant CATEGORY => 'stack';
15 use constant SHORT_HELP => 'Print backtrace of stack frames';
16 use constant MIN_ARGS => 0; # Need at least this many
17 use constant MAX_ARGS => 4; # Need at most this many - undef -> unlimited.
18 use constant NEED_STACK => 1;
19 EOE
20 }
21  
22 12 ▶use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
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
23 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
24  
25 1 our $NAME = set_name();
26 =pod
27  
28 =head2 Synopsis:
29  
30 =cut
31 1 our $HELP = <<'HELP';
32 =pod
33  
34 B<backtrace> [I<options>] [I<count>]
35  
36 Print backtrace of all stack frames, or innermost *count* frames.
37  
38 With a negative argument, print outermost -I<count> frames.
39  
40 In the listing produced, an arrow, C<--E<gt>>, indicates the 'current
41 frame'. The current frame determines the context used for many
42 debugger commands such as source-line listing
43 (L<C<list>|Devel::Trepan::CmdProcessor::Command::List>) or the
44 L<C<edit>|Devel::Trepan::CmdProcessor::Command::Edit> command.
45  
46 I<optionss> are:
47  
48 -d | --deparse - show deparsed call position
49 -s | --source - show source code line
50 -f | --full - locals of each frame
51 -h | --help - give this help
52  
53 =head2 Examples:
54  
55 backtrace # Print a full stack trace
56 backtrace 2 # Print only the top two entries
57 backtrace -1 # Print a stack trace except the initial (least recent) call.
58 backtrace -s # show source lines in listing
59 backtrace -d # show deparsed source lines in listing
60 backtrace -f # show with locals
61 backtrace -df # show with deparsed calls and locals
62 backtrace --deparse --full # same as above
63  
64 =head2 See also:
65  
66 L<C<up>|Devel::Trepan::CmdProcessor::Command::Up>,
67 L<C<down>|Devel::Trepan::CmdProcessor::Command::Down>, and
68 L<C<frame>|Devel::Trepan::CmdProcessor::Command::Frame>,
69  
70 =cut
71 HELP
72  
73 sub complete($$)
74 0 ▶{
Subroutine complete: not called CC=1 SCAR=6.9
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
75 0 ▶ my ($self, $prefix) = @_;
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
76 0 $self->{proc}->frame_complete($prefix);
77 }
78  
79 1 my $DEFAULT_OPTIONS = {
80 help => 0, # show source line in backtrace?
81 deparse => 0, # show deparse in backtrace?
82 full => 0, # show "locals"?
83 source => 0, # show source line in backtrace?
84  
85 };
86  
87 sub parse_options($$)
88 0 ▶{
Subroutine parse_options: not called CC=1 SCAR=6.9
Subroutine parse_options: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
89 0 ▶ my ($self, $args) = @_;
Subroutine parse_options: not called CC=1 SCAR=6.9
Pod undocumented
90 0 $Getopt::Long::autoabbrev = 1;
91 0 my %opts = %{$DEFAULT_OPTIONS};
92 my $result = &GetOptionsFromArray($args,
93 'h|help' => \$opts{help},
94 'd|deparse' => \$opts{deparse},
95 's|source' => \$opts{source},
96 'f|full' => \$opts{full},
97 0 );
98 0 %opts;
99 }
100  
101 # This method runs the command
102 sub run($$)
103 0 ▶{
Subroutine run: not called CC=4 SCAR=24.9
Subroutine run: not called CC=4 SCAR=24.9
Pod undocumented
Pod undocumented
104 0 my ($self, $args) = @_;
105 0 my $proc = $self->{proc};
106 0 my %cmd_opts = $self->parse_options($args);
107 my $opts = {
108 basename => $proc->{settings}{basename},
109 current_pos => $proc->{frame_index},
110 maxstack => $proc->{settings}{maxstack},
111 maxwidth => $proc->{settings}{maxwidth},
112 displayop => $proc->{settings}{displayop},
113 deparse => $cmd_opts{deparse},
114 source => $cmd_opts{source},
115 full => $cmd_opts{full},
116 0 };
117 0 ▶ if ($cmd_opts{help}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd_opts{"help"}) 0 0 0
if ($cmd_opts{"help"}) 11 0 11
118 0 my $help_cmd = $proc->{commands}{help};
119 0 $help_cmd->run( ['help', 'backtrace'] );
120 return
121 0 }
122  
123 0 my $stack_size = $proc->{stack_size};
124 0 my $count = $stack_size;
125 0 ▶ if (scalar @$args > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$args > 1) 0 0 0
if (scalar @$args > 1) 0 11 11
126 0 $count =
127 $proc->get_an_int($args->[1],
128 {cmdname => $self->name,
129 min_value => -$stack_size,
130 });
131 0 ▶ return unless defined $count;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $count 0 0 0
unless defined $count 0 0 0
132 }
133 0 $opts->{count} = $count;
134 0 my @frames = $self->{dbgr}->tbacktrace($count-1);
135 0 $self->{proc}->print_stack_trace(\@frames, $opts);
136 }
137  
138 1 ▶unless(caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
139 # FIXME: DRY this code by putting in common location.
140 0 require Devel::Trepan::DB;
141 0 require Devel::Trepan::Core;
142 0 my $db = Devel::Trepan::Core->new;
143 0 my $intf = Devel::Trepan::Interface::User->new(undef, undef, {readline => 0});
144 0 my $proc = Devel::Trepan::CmdProcessor->new([$intf], $db);
145  
146 0 $proc->{stack_size} = 0;
147 0 my $cmd = __PACKAGE__->new($proc);
148 0 $cmd->run([$NAME]);
149 0 $cmd->run([$NAME, 1000]);
150 }
151  
152 1 1;
« lib/Devel/Trepan/CmdProcessor/Command/Frame.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/Set.pm »