initialized itself.
Next, it checks the C<PERLDB_OPTS> environment variable and treats its
-contents as the argument of a debugger <C<O> command.
+contents as the argument of a debugger <C<o> command.
=head2 STARTUP-ONLY OPTIONS
use IO::Handle;
# Debugger for Perl 5.00x; perl5db.pl patch level:
-$VERSION = 1.23;
+$VERSION = 1.24;
$header = "perl5db.pl version $VERSION";
# wise to read the perldebguts man page or risk the ire of dragons.
#
# (It should be noted that perldebguts will tell you a lot about
-# the uderlying mechanics of how the debugger interfaces into the
+# the underlying mechanics of how the debugger interfaces into the
# Perl interpreter, but not a lot about the debugger itself. The new
# comments in this code try to address this problem.)
# + Flush stdout/stderr before the debugger prompt is printed.
# Changes: 1.23: Dec 21, 2003 Dominique Quatravaux
# + Fix a side-effect of bug #24674 in the perl debugger ("odd taint bug")
-
+# Changes: 1.24: Mar 03, 2004 Richard Foley <richard.foley@rfi.net>
+# + Added command to save all debugger commands for sourcing later.
+# + Added command to display parent inheritence tree of given class.
+# + Fixed minor newline in history bug.
####################################################################
=head1 DEBUGGER INITIALIZATION
# Empty input means repeat the last command.
$cmd =~ /^$/ && ($cmd = $laststep);
+ chomp($cmd); # get rid of the annoying extra newline
push (@hist, $cmd) if length($cmd) > 1;
-
+ push (@truehist, $cmd);
# This is a restart point for commands that didn't arrive
# via direct user input. It allows us to 'redo PIPE' to
# All of these commands were remapped in perl 5.8.0;
# we send them off to the secondary dispatcher (see below).
- $cmd =~ /^([aAbBhlLMoOvwW]\b|[<>\{]{1,2})\s*(.*)/so && do {
+ $cmd =~ /^([aAbBhilLMoOvwW]\b|[<>\{]{1,2})\s*(.*)/so && do {
&cmd_wrapper($1, $2, $line);
next CMD;
};
next CMD;
};
+=head4 C<save> - send current history to a file
+
+Takes the complete history, (not the shrunken version you see with C<H>),
+and saves it to the given filename, so it can be replayed using C<source>.
+
+Note that all C<^(save|source)>'s are commented out with a view to minimise recursion.
+
+=cut
+
+ # save source - write commands to a file for later use
+ $cmd =~ /^save\s*(.*)$/ && do {
+ my $file = $1 || '.perl5dbrc'; # default?
+ if (open my $fh, "> $file") {
+ # chomp to remove extraneous newlines from source'd files
+ chomp(my @truelist = map { m/^\s*(save|source)/ ? "#$_": $_ } @truehist);
+ print $fh join("\n", @truelist);
+ print "commands saved in $file\n";
+ } else {
+ &warn("Can't save debugger commands in '$1': $!\n");
+ }
+ next CMD;
+ };
+
=head4 C<|, ||> - pipe output through the pager.
FOR C<|>, we save C<OUT> (the debugger's output filehandle) and C<STDOUT>
}
} ## end sub cmd_h
+=head3 C<cmd_i> - inheritance display
+
+Display the (nested) parentage of the module or object given.
+
+=cut
+
+sub cmd_i {
+ my $cmd = shift;
+ my $line = shift;
+ eval { require Class::ISA };
+ if ($@) {
+ &warn($@ =~ /locate/ ? "Class::ISA module not found - please install\n" : $@);
+ } else {
+ ISA:
+ foreach my $isa (split(/\s+/, $line)) {
+ no strict 'refs';
+ print join(', ', map { # snaffled unceremoniously from Class::ISA
+ "$_".(defined(${"$_\::VERSION"}) ? ' '.${"$_\::VERSION"} : undef)
+ } Class::ISA::self_and_super_path($isa));
+ print "\n";
+ }
+ }
+} ## end sub cmd_i
+
=head3 C<cmd_l> - list lines (command)
Most of the command is taken up with transforming all the different line
on the first element of the result.
B<m> I<class> Prints methods callable via the given class.
B<M> Show versions of loaded modules.
+B<i> I<class> Prints nested parents of given class.
B<y> [I<n> [I<Vars>]] List lexicals in higher scope <n>. Vars same as B<V>.
B<<> ? List Perl commands to run before each prompt.
. "
See 'B<O> I<shellBang>' too.
B<source> I<file> Execute I<file> containing debugger commands (may nest).
+B<save> I<file> Save current debugger session (actual history) to I<file>.
B<H> I<-number> Display last number commands (default all).
B<p> I<expr> Same as \"I<print {DB::OUT} expr>\" in current package.
B<|>I<dbcmd> Run debugger command, piping DB::OUT to current pager.
B<p> I<expr> Print expression (uses script's current package).
B<S> [[B<!>]I<pat>] List subroutine names [not] matching pattern
B<V> [I<Pk> [I<Vars>]] List Variables in Package. Vars can be ~pattern or !pattern.
- B<X> [I<Vars>] Same as \"B<V> I<current_package> [I<Vars>]\".
+ B<X> [I<Vars>] Same as \"B<V> I<current_package> [I<Vars>]\". B<i> I<class> inheritance tree.
B<y> [I<n> [I<Vars>]] List lexicals in higher scope <n>. Vars same as B<V>.
For more help, type B<h> I<cmd_letter>, or run B<$doccmd perldebug> for all docs.
END_SUM
$sh = '!'; # Shell escape (does not work)
$rc = ','; # Recall command (does not work)
@hist = ('?'); # Show history (does not work)
+ @truehist=(); # Can be saved for replay (per session)
# This defines the point at which you get the 'deep recursion'
# warning. It MUST be defined or the debugger will not load.