« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Frame.pm
↑ Summary
blib/lib/Devel/Trepan/CmdProcessor/Validate.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2012, 2014, 2017 Rocky Bernstein <rocky@cpan.org> | ||
| 3 | use warnings; use utf8; | ||
| 4 | use rlib '../../../../..'; | ||
| 5 | package Devel::Trepan::CmdProcessor::Command::Info::Line; | ||
| 6 | |||
| 7 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use vars qw(@ISA @SUBCMD_VARS); | ||
| 11 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 12 | # Values inherited from parent | ||
| 13 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 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 pc>|Devel::Trepan::CmdProcessor::Command::Info::PC> and C<info program|Devel::Trepan::CmdProcessor::Command::Info::Program>. | ||
| 39 | =cut | ||
| 40 | HELP | ||
| 41 | |||
| 42 | no warnings 'redefine'; | ||
| 43 | sub run($$) | ||
| 44 | { | ||
| 45 | my ($self, $args) = @_; | ||
| 46 | my @args = @$args; shift @args; shift @args; | ||
| 47 | my $proc = $self->{proc}; | ||
| 48 | my $frame = $proc->{frame}; | ||
| 49 | my $filename = $proc->filename(); | ||
| 50 | my ($line, $first_arg, $end_line); | ||
| 51 | |||
| 52 | my $arg_count = scalar @args; | ||
| 53 | if ($arg_count == 0) { | ||
| 54 | $line = $frame->{line}; | ||
| 55 | } else { | ||
| 56 | $first_arg = $args[0]; | ||
| 57 | if ($first_arg =~ /\d+/) { | ||
| 58 | $line = $first_arg; | ||
| 59 | } else { | ||
| 60 | my @matches = $proc->{dbgr}->subs($first_arg); | ||
| 61 | unless (scalar(@matches)) { | ||
| 62 | # Try with current package name | ||
| 63 | $first_arg = $proc->{frame}{pkg} . '::' . $first_arg; | ||
| 64 | @matches = $proc->{dbgr}->subs($first_arg); | ||
| 65 | } | ||
| 66 | if (scalar(@matches) == 1) { | ||
| 67 | $filename = $matches[0][0]; | ||
| 68 | $line = $matches[0][1]; | ||
| 69 | $end_line = $matches[0][2]; | ||
| 70 | } else { | ||
| 71 | $proc->msg("Expecting a line number or function; got ${args[0]}"); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | my $m; | ||
| 77 | my $canonic = $proc->canonic_file($filename); | ||
| 78 | if (defined $end_line) { | ||
| 79 | $m = sprintf("Function %s in file %s lines %d..%d", | ||
| 80 | $args[0], $canonic, $line, $end_line); | ||
| 81 | } else { | ||
| 82 | $m = sprintf "Line %d, file %s", $line, $canonic; | ||
| 83 | } | ||
| 84 | $proc->msg($m); | ||
| 85 | local(*DB::dbline) = "::_<$filename"; | ||
| 86 | if (defined($DB::dbline[$line]) && 0 != $DB::dbline[$line]) { | ||
| 87 | my $cop = 0; | ||
| 88 | no warnings 'once'; | ||
| 89 | if ($DB::HAVE_MODULE{'Devel::Callsite'} eq 'call_level_param') { | ||
| 90 | $cop = Devel::Callsite::callsite($proc->{frame_index}); | ||
| 91 | } else { | ||
| 92 | $cop = 0 + $DB::dbline[$line]; | ||
| 93 | } | ||
| 94 | $proc->msg(sprintf "OP address: 0x%x.", $cop); | ||
| 95 | } else { | ||
| 96 | $proc->msg("Line not showing as associated with code\n") | ||
| 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; |