« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Display.pm
↑ Summary
lib/Devel/Trepan/IO/Input.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2011-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::Info::Functions; | ||
| 7 | |||
| 8 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | our (@ISA, @SUBCMD_VARS); | ||
| 12 | # Values inherited from parent | ||
| 13 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 14 | |||
| 15 | ## FIXME: do automatically. | ||
| 16 | our $CMD = "info functions"; | ||
| 17 | |||
| 18 | unless (@ISA) { | ||
| 19 | eval <<"EOE"; | ||
| 20 | use constant MAX_ARGS => 1; # Need at most this many - undef -> unlimited. | ||
| 21 | EOE | ||
| 22 | } | ||
| 23 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 24 | =pod | ||
| 25 | |||
| 26 | =head2 Synopsis: | ||
| 27 | |||
| 28 | =cut | ||
| 29 | our $HELP = <<'HELP'; | ||
| 30 | =pod | ||
| 31 | |||
| 32 | B<info functions> [I<regexp>] | ||
| 33 | |||
| 34 | Give functions names or those matching I<regexp>. If no regular | ||
| 35 | expresion is given, list all functions. | ||
| 36 | =cut | ||
| 37 | HELP | ||
| 38 | |||
| 39 | our $SHORT_HELP = 'All function names, or those matching REGEXP'; | ||
| 40 | our $MIN_ABBREV = length('fu'); | ||
| 41 | |||
| 42 | sub complete($$) | ||
| 43 | { | ||
| 44 | my ($self, $prefix) = @_; | ||
| 45 | Devel::Trepan::Complete::complete_subs($prefix); | ||
| 46 | } | ||
| 47 | |||
| 48 | sub run($$) | ||
| 49 | { | ||
| 50 | my ($self, $args) = @_; | ||
| 51 | my $proc = $self->{proc}; | ||
| 52 | my $regexp = undef; | ||
| 53 | |||
| 54 | if (@$args == 3) { | ||
| 55 | $regexp = $args->[2]; | ||
| 56 | } | ||
| 57 | |||
| 58 | my @functions = keys %DB::sub; | ||
| 59 | @functions = grep /$regexp/, @functions if defined $regexp; | ||
| 60 | if (scalar @functions) { | ||
| 61 | my %FILES = (); | ||
| 62 | for my $function (sort @functions) { | ||
| 63 | my $file_range = $DB::sub{$function}; | ||
| 64 | if ($file_range =~ /^(.+):(\d+-\d+)/) { | ||
| 65 | my ($filename, $range) = ($1, $2); | ||
| 66 | $FILES{$filename} ||= []; | ||
| 67 | push @{$FILES{$filename}}, [$function, $range]; | ||
| 68 | } else { | ||
| 69 | $FILES{$file_range} ||= []; | ||
| 70 | push @{$FILES{$file_range}}, [$function]; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | # FIXME: make output more like gdb's. | ||
| 74 | for my $filename (sort keys %FILES) { | ||
| 75 | $proc->section($filename); | ||
| 76 | for my $entry (@{$FILES{$filename}}) { | ||
| 77 | $proc->msg("\t" . join(' is at ', @$entry)); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } else { | ||
| 81 | my @fns = Devel::Trepan::Complete::complete_builtins($regexp); | ||
| 82 | if (@fns) { | ||
| 83 | for my $entry (@fns) { | ||
| 84 | $proc->msg($entry . ' is a built-in function'); | ||
| 85 | } | ||
| 86 | } else { | ||
| 87 | $proc->msg("No matching functions"); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | unless (caller) { | ||
| 93 | require Devel::Trepan; | ||
| 94 | # Demo it. | ||
| 95 | # require_relative '../../mock' | ||
| 96 | # my($dbgr, $parent_cmd) = MockDebugger::setup('show'); | ||
| 97 | # $cmd = __PACKAGE__->new(parent_cmd); | ||
| 98 | # $cmd->run(@$cmd->prefix); | ||
| 99 | } | ||
| 100 | |||
| 101 | # Suppress a "used-once" warning; | ||
| 102 | $HELP || scalar @SUBCMD_VARS; |