From a7b657eec5c9a956f5411ffb5c1dacbd8d5b6c1b Mon Sep 17 00:00:00 2001 From: Peter Scott Date: Tue, 19 Mar 2002 04:28:52 -0800 Subject: [PATCH] List lexicals from debugger Message-id: <4.3.2.7.2.20020319101746.00aa7aa0@shell2.webquarry.com> p4raw-id: //depot/perl@15363 --- lib/dumpvar.pl | 37 +++++++++++++++++++++++++++++++++++++ lib/perl5db.pl | 2 ++ pod/perldebug.pod | 10 ++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/dumpvar.pl b/lib/dumpvar.pl index 2fb1f69..12c9e91 100644 --- a/lib/dumpvar.pl +++ b/lib/dumpvar.pl @@ -250,6 +250,13 @@ sub unwrap { } } +sub matchlex { + (my $var = $_[0]) =~ s/.//; + $var eq $_[1] or + ($_[1] =~ /^([!~])(.)([\x00-\xff]*)/) and + ($1 eq '!') ^ (eval { $var =~ /$2$3/ }); +} + sub matchvar { $_[0] eq $_[1] or ($_[1] =~ /^([!~])(.)([\x00-\xff]*)/) and @@ -326,6 +333,36 @@ sub dumpglob { } } +sub dumplex { + return if $DB::signal; + my ($key, $val, $m, @vars) = @_; + return if @vars && !grep( matchlex($key, $_), @vars ); + local %address; + my $off = 0; # It reads better this way + my $fileno; + if (UNIVERSAL::isa($val,'ARRAY')) { + print( (' ' x $off) . "$key = (\n" ); + unwrap($val,3+$off,$m) ; + print( (' ' x $off) . ")\n" ); + } + elsif (UNIVERSAL::isa($val,'HASH')) { + print( (' ' x $off) . "$key = (\n" ); + unwrap($val,3+$off,$m) ; + print( (' ' x $off) . ")\n" ); + } + elsif (UNIVERSAL::isa($val,'IO')) { + print( (' ' x $off) . "FileHandle($key) => fileno($fileno)\n" ); + } + # No lexical subroutines yet... + # elsif (UNIVERSAL::isa($val,'CODE')) { + # dumpsub($off, $$val); + # } + else { + print( (' ' x $off) . &unctrl($key), " = " ); + DumpElem $$val, 3+$off, $m; + } +} + sub CvGV_name_or_bust { my $in = shift; return if $skipCvGV; # Backdoor to avoid problems if XS broken... diff --git a/lib/perl5db.pl b/lib/perl5db.pl index 158510d..fd925b5 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -2809,6 +2809,7 @@ I B Execute perl code, also see: B,B,B B [[B]I] List subroutine names [not] matching pattern B [I [I]] List Variables in Package. Vars can be ~pattern or !pattern. B [I] Same as \"B I [I]\". + B [I [I]] List lexicals in higher scope . Vars same as B. For more help, type B I, or run B<$doccmd perldebug> for all docs. END_SUM # ')}}; # Fix balance of vi % matching @@ -2976,6 +2977,7 @@ I B Execute perl code, also see: B,B,B B [[B]I] List subroutine names [not] matching pattern B [I [I]] List Variables in Package. Vars can be ~pattern or !pattern. B [I] Same as \"B I [I]\". + B [I [I]] List lexicals in higher scope . Vars same as B. For more help, type B I, or run B<$doccmd perldebug> for all docs. END_SUM # ')}}; # Fix balance of vi % matching diff --git a/pod/perldebug.pod b/pod/perldebug.pod index 5d0ef3f..45c2420 100644 --- a/pod/perldebug.pod +++ b/pod/perldebug.pod @@ -114,6 +114,16 @@ This is similar to calling the C command on each applicable var. Same as C. +=item y [level [vars]] + +Display all (or some) lexical variables (mnemonic: C variables) +in the current scope or I scopes higher. You can limit the +variables that you see with I which works exactly as it does +for the C and C commands. Requires the C module +version 0.08 or higher; will warn if this isn't installed. Output +is pretty-printed in the same style as for C and the format is +controlled by the same options. + =item T Produce a stack backtrace. See below for details on its output. -- 2.7.4