« lib/Devel/Trepan/CmdProcessor/Command/Show.pm
↑ Summary
blib/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Substitute_Subcmd/Path.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2012, 2014 Rocky Bernstein <rocky@cpan.org> | ||
| 3 | use warnings; no warnings 'redefine'; no warnings 'once'; | ||
| 4 | use rlib '../../../../..'; | ||
| 5 | |||
| 6 | package Devel::Trepan::CmdProcessor::Command::Load::Source; | ||
| 7 | use English qw( -no_match_vars ); | ||
| 8 | use Cwd 'abs_path'; | ||
| 9 | |||
| 10 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 11 | # use Devel::Trepan::DB::LineCache qw(file_list); | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | our (@ISA, @SUBCMD_VARS); | ||
| 15 | # Values inherited from parent | ||
| 16 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 17 | |||
| 18 | ## FIXME: do automatically. | ||
| 19 | our $CMD = "load source"; | ||
| 20 | |||
| 21 | unless (@ISA) { | ||
| 22 | eval <<"EOE"; | ||
| 23 | use constant MAX_ARGS => 0; # Need at most this many - undef -> unlimited. | ||
| 24 | use constant NEED_STACK => 0; | ||
| 25 | EOE | ||
| 26 | } | ||
| 27 | |||
| 28 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 29 | |||
| 30 | =pod | ||
| 31 | |||
| 32 | =head2 Synopsis: | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | our $HELP = <<'HELP'; | ||
| 37 | =pod | ||
| 38 | |||
| 39 | B<load source> {I<Perl-source-file>} | ||
| 40 | |||
| 41 | Read source lines of {I<Perl-source-file>}. | ||
| 42 | |||
| 43 | This simulates what Perl does in reading a file when debugging is | ||
| 44 | turned on, somewhat. A description of what this means is below. | ||
| 45 | |||
| 46 | The file contents are read in as a list of strings in | ||
| 47 | I<_E<lt>$filename> for the debugger to refer to; I<$filename> contains | ||
| 48 | the name I<Perl-source-file>. In addition, each entry of this list is | ||
| 49 | a dual variable. In a non-numeric context, an entry is a string of the | ||
| 50 | line contents including the trailing C<\n>. | ||
| 51 | |||
| 52 | But in numeric context, an entry of the list is I<true> if that line | ||
| 53 | is traceable or has a COP instruction in it which allows the debugger | ||
| 54 | to take control. | ||
| 55 | =cut | ||
| 56 | HELP | ||
| 57 | |||
| 58 | our $SHORT_HELP = 'Read Perl source file(s)'; | ||
| 59 | our $MIN_ABBREV = length('so'); | ||
| 60 | |||
| 61 | sub complete($$) | ||
| 62 | { | ||
| 63 | my ($self, $prefix) = @_; | ||
| 64 | $self->{proc}->filename_complete($prefix); | ||
| 65 | } | ||
| 66 | |||
| 67 | sub run($$) | ||
| 68 | { | ||
| 69 | my ($self, $args) = @_; | ||
| 70 | my $proc = $self->{proc}; | ||
| 71 | my @args = @$args; shift @args; shift @args; | ||
| 72 | foreach my $source (@args) { | ||
| 73 | if (-r $source) { | ||
| 74 | ## FIXME put into a common routine and use in bin/trepan.pl as | ||
| 75 | ## well | ||
| 76 | # Check that the debugged Perl program is syntactically valid. | ||
| 77 | my $cmd = "$EXECUTABLE_NAME -c $source 2>&1"; | ||
| 78 | my $output = `$cmd`; | ||
| 79 | my $rc = $? >>8; | ||
| 80 | if ($rc) { | ||
| 81 | $proc->errmsg("$output"); | ||
| 82 | } else { | ||
| 83 | |||
| 84 | # FIXME: These two things should be one routine. Also change | ||
| 85 | # 10test-linecache.t | ||
| 86 | Devel::Trepan::DB::LineCache::load_file($source); | ||
| 87 | Devel::Trepan::DB::LineCache::update_cache($source, | ||
| 88 | {use_perl_d_file => 1}); | ||
| 89 | |||
| 90 | $proc->msg("Read in lines of Perl source file $source"); | ||
| 91 | } | ||
| 92 | } else { | ||
| 93 | $proc->errmsg("Don't see ${source} for reading"); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | unless (caller) { | ||
| 99 | require Devel::Trepan; | ||
| 100 | # Demo it. | ||
| 101 | # require_relative '../../mock' | ||
| 102 | # my($dbgr, $parent_cmd) = MockDebugger::setup('show'); | ||
| 103 | # $cmd = __PACKAGE__->new(parent_cmd); | ||
| 104 | # $cmd->run(@$cmd->prefix); | ||
| 105 | } | ||
| 106 | |||
| 107 | # Suppress a "used-once" warning; | ||
| 108 | $HELP || scalar @SUBCMD_VARS; |