File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Line.pm
Criterion Covered Total %
statement 54 130 41.5
branch 0 32 0.0
condition 0 6 0.0
subroutine 18 20 90.0
pod n/a
total 72 188 38.3


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 12     12   106 use warnings; use utf8;
  12     12   34  
  12     1   440  
  12     1   81  
  12         35  
  12         91  
  1         12  
  1         4  
  1         41  
  1         12  
  1         4  
  1         7  
4 12     12   367 use rlib '../../../../..';
  12     1   33  
  12         75  
  1         49  
  1         5  
  1         7  
5             package Devel::Trepan::CmdProcessor::Command::Info::Line;
6              
7 12     12   5284 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
  12     1   35  
  12         284  
  1         691  
  1         4  
  1         40  
8              
9 12     12   66 use strict;
  12     1   27  
  12         333  
  1         10  
  1         3  
  1         42  
10 12     12   73 use vars qw(@ISA @SUBCMD_VARS);
  12     1   31  
  12         877  
  1         10  
  1         9  
  1         98  
11             @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
12             # Values inherited from parent
13 12     12   79 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
  12     1   35  
  12         2013  
  1         10  
  1         4  
  1         260  
14              
15             unless (@ISA) {
16             eval <<"EOE";
17             use constant MAX_ARGS => 1;
18             EOE
19             }
20              
21             our $SHORT_HELP = 'Line Information about debugged program';
22             our $MIN_ABBREV = length('li');
23              
24             =pod
25              
26             =head2 Synopsis:
27              
28             =cut
29             our $HELP = <<'HELP';
30             =pod
31              
32             B<info line>
33              
34             Show line information about the selected frame of debugged program.
35              
36             =head2 See also:
37              
38             L<C<info line>|Devel::Trepan::CmdProcessor::Command::Info::Line> and C<info program|Devel::Trepan::CmdProcessor::Command::Info::Program>.
39             =cut
40             HELP
41              
42 12     12   82 no warnings 'redefine';
  12     1   36  
  12         3970  
  1         11  
  1         4  
  1         472  
43             sub run($$)
44             {
45 0     0     my ($self, $args) = @_;
  0     0      
46 0           my @args = @$args; shift @args; shift @args;
  0            
  0            
  0            
  0            
  0            
47 0           my $proc = $self->{proc};
  0            
48 0           my $frame = $proc->{frame};
  0            
49 0           my $filename = $proc->filename();
  0            
50 0           my ($line, $first_arg, $end_line);
  0            
51              
52 0           my $arg_count = scalar @args;
  0            
53 0 0         if ($arg_count == 0) {
  0 0          
54 0           $line = $frame->{line};
  0            
55             } else {
56 0           $first_arg = $args[0];
  0            
57 0 0         if ($first_arg =~ /\d+/) {
  0 0          
58 0           $line = $first_arg;
  0            
59             } else {
60 0           my @matches = $proc->{dbgr}->subs($first_arg);
  0            
61 0 0         unless (scalar(@matches)) {
  0 0          
62             # Try with current package name
63 0           $first_arg = $proc->{frame}{pkg} . '::' . $first_arg;
  0            
64 0           @matches = $proc->{dbgr}->subs($first_arg);
  0            
65             }
66 0 0         if (scalar(@matches) == 1) {
  0 0          
67 0           $filename = $matches[0][0];
  0            
68 0           $line = $matches[0][1];
  0            
69 0           $end_line = $matches[0][2];
  0            
70             } else {
71 0           $proc->msg("Expecting a line number or function; got ${args[0]}");
  0            
72 0           return;
  0            
73             }
74             }
75             }
76 0           my $m;
  0            
77 0           my $canonic = $proc->canonic_file($filename);
  0            
78 0 0         if (defined $end_line) {
  0 0          
79 0           $m = sprintf("Function %s in file %s lines %d..%d",
  0            
80             $args[0], $canonic, $line, $end_line);
81             } else {
82 0           $m = sprintf "Line %d, file %s", $line, $canonic;
  0            
83             }
84 0           $proc->msg($m);
  0            
85 0           local(*DB::dbline) = "::_<$filename";
  0            
86 0 0 0       if (defined($DB::dbline[$line]) && 0 != $DB::dbline[$line]) {
  0 0 0        
87 0           my $cop = 0;
  0            
88 12     12   100 no warnings 'once';
  12     1   41  
  12         2562  
  1         8  
  1         3  
  1         188  
89 0 0         if ($DB::HAVE_MODULE{'Devel::Callsite'} eq 'call_level_param') {
  0 0          
90 0           $cop = Devel::Callsite::callsite($proc->{frame_index});
  0            
91             } else {
92 0           $cop = 0 + $DB::dbline[$line];
  0            
93             }
94 0           $proc->msg(sprintf "OP address: 0x%x.", $cop);
  0            
95             } else {
96 0 0         $proc->msg("Line not showing as associated with code\n")
  0 0          
97             unless $end_line;
98             }
99             }
100              
101             unless (caller) {
102             require Devel::Trepan;
103             # Demo it.
104             # require_relative '../../mock'
105             # my($dbgr, $parent_cmd) = MockDebugger::setup('show');
106             # $cmd = __PACKAGE__->new(parent_cmd);
107             # $cmd->run(@$cmd->prefix);
108             }
109              
110             # Suppress a "used-once" warning;
111             $HELP || scalar @SUBCMD_VARS;