This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactoring the /Can't return (?:array|hash) to scalar context/ croak
[perl5.git] / lib / perl5db.pl
index 855e275..2167f78 100644 (file)
@@ -1,6 +1,7 @@
+
 =head1 NAME 
 
-C<perl5db.pl> - the perl debugger
+perl5db.pl - the perl debugger
 
 =head1 SYNOPSIS
 
@@ -39,7 +40,7 @@ Unfortunately, though the variables are accessible, they're not well
 documented, so it's generally been a decision that hasn't made a lot of
 difference to most users. Where appropriate, comments have been added to
 make variables more accessible and usable, with the understanding that these
-i<are> debugger internals, and are therefore subject to change. Future
+I<are> debugger internals, and are therefore subject to change. Future
 development should probably attempt to replace the globals with a well-defined
 API, but for now, the variables are what we've got.
 
@@ -103,7 +104,7 @@ Boolean algebra states that the truth table for XOR looks like this:
 =back
 
 As you can see, the first pair applies when C<!> isn't supplied, and
-the second pair applies when it isn't. The XOR simply allows us to
+the second pair applies when it is. The XOR simply allows us to
 compact a more complicated if-then-elseif-else into a more elegant 
 (but perhaps overly clever) single test. After all, it needed this
 explanation...
@@ -111,7 +112,7 @@ explanation...
 =head2 FLAGS, FLAGS, FLAGS
 
 There is a certain C programming legacy in the debugger. Some variables,
-such as C<$single>, C<$trace>, and C<$frame>, have "magical" values composed
+such as C<$single>, C<$trace>, and C<$frame>, have I<magical> values composed
 of 1, 2, 4, etc. (powers of 2) OR'ed together. This allows several pieces
 of state to be stored independently in a single scalar. 
 
@@ -131,22 +132,27 @@ it?
 
 =over 4
 
+=item *
 
-=item * First, doing an arithmetical or bitwise operation on a scalar is
+First, doing an arithmetical or bitwise operation on a scalar is
 just about the fastest thing you can do in Perl: C<use constant> actually
-creates a subroutine call, and array hand hash lookups are much slower. Is
+creates a subroutine call, and array and hash lookups are much slower. Is
 this over-optimization at the expense of readability? Possibly, but the 
 debugger accesses these  variables a I<lot>. Any rewrite of the code will
 probably have to benchmark alternate implementations and see which is the
 best balance of readability and speed, and then document how it actually 
 works.
 
-=item * Second, it's very easy to serialize a scalar number. This is done in 
+=item *
+
+Second, it's very easy to serialize a scalar number. This is done in 
 the restart code; the debugger state variables are saved in C<%ENV> and then
 restored when the debugger is restarted. Having them be just numbers makes
 this trivial. 
 
-=item * Third, some of these variables are being shared with the Perl core 
+=item *
+
+Third, some of these variables are being shared with the Perl core 
 smack in the middle of the interpreter's execution loop. It's much faster for 
 a C program (like the interpreter) to check a bit in a scalar than to access 
 several different variables (or a Perl array).
@@ -175,10 +181,13 @@ The hash C<%{'_<'.$filename}> (aliased locally to C<%dbline> via glob
 assignment) contains breakpoints and actions.  The keys are line numbers; 
 you can set individual values, but not the whole hash. The Perl interpreter 
 uses this hash to determine where breakpoints have been set. Any true value is
-considered to be a breakpoint; C<perl5db.pl> uses "$break_condition\0$action".
+considered to be a breakpoint; C<perl5db.pl> uses C<$break_condition\0$action>.
 Values are magical in numeric context: 1 if the line is breakable, 0 if not.
 
-The scalar ${'_<'.$filename} contains $filename  XXX What?
+The scalar C<${"_<$filename"}> simply contains the string C<_<$filename>.
+This is also the case for evaluated strings that contain subroutines, or
+which are currently being executed.  The $filename for C<eval>ed strings looks
+like C<(eval 34)> or C<(re_eval 19)>.
 
 =head1 DEBUGGER STARTUP
 
@@ -189,7 +198,7 @@ that will be executed (in the debugger's context) after the debugger has
 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 C<o> command in the debugger.
 
 =head2 STARTUP-ONLY OPTIONS
 
@@ -206,13 +215,13 @@ the TTY to use for debugging i/o.
 =item * noTTY 
 
 if set, goes in NonStop mode.  On interrupt, if TTY is not set,
-uses the value of noTTY or "/tmp/perldbtty$$" to find TTY using
+uses the value of noTTY or F<$HOME/.perldbtty$$> to find TTY using
 Term::Rendezvous.  Current variant is to have the name of TTY in this
 file.
 
 =item * ReadLine 
 
-If false, a dummy  ReadLine is used, so you can debug
+if false, a dummy ReadLine is used, so you can debug
 ReadLine applications.
 
 =item * NonStop 
@@ -228,6 +237,16 @@ pipe, a short "emacs like" message is used.
 
 host:port to connect to on remote host for remote debugging.
 
+=item * HistFile
+
+file to store session history to. There is no default and so no
+history file is written unless this variable is explicitly set.
+
+=item * HistSize
+
+number of commands to store to the file specified in C<HistFile>.
+Default is 100.
+
 =back
 
 =head3 SAMPLE RCFILE
@@ -237,14 +256,14 @@ host:port to connect to on remote host for remote debugging.
 
 The script will run without human intervention, putting trace
 information into C<db.out>.  (If you interrupt it, you had better
-reset C<LineInfo> to something "interactive"!)
+reset C<LineInfo> to something I<interactive>!)
 
 =head1 INTERNALS DESCRIPTION
 
 =head2 DEBUGGER INTERFACE VARIABLES
 
 Perl supplies the values for C<%sub>.  It effectively inserts
-a C<&DB'DB();> in front of each place that can have a
+a C<&DB::DB();> in front of each place that can have a
 breakpoint. At each subroutine call, it calls C<&DB::sub> with
 C<$DB::sub> set to the called subroutine. It also inserts a C<BEGIN
 {require 'perl5db.pl'}> before the first line.
@@ -289,11 +308,11 @@ is entered or exited.
 
 =item * 0 -  No enter/exit messages
 
-=item * 1 - Print "entering" messages on subroutine entry
+=item * 1 - Print I<entering> messages on subroutine entry
 
 =item * 2 - Adds exit messages on subroutine exit. If no other flag is on, acts like 1+2.
 
-=item * 4 - Extended messages: C<in|out> I<context>=I<fully-qualified sub name> from I<file>:I<line>>. If no other flag is on, acts like 1+4.
+=item * 4 - Extended messages: C<< <in|out> I<context>=I<fully-qualified sub name> from I<file>:I<line> >>. If no other flag is on, acts like 1+4.
 
 =item * 8 - Adds parameter information to messages, and overloaded stringify and tied FETCH is enabled on the printed arguments. Ignored if C<4> is not on.
 
@@ -301,7 +320,7 @@ is entered or exited.
 
 =back
 
-To get everything, use C<$frame=30> (or C<o f-30> as a debugger command).
+To get everything, use C<$frame=30> (or C<o f=30> as a debugger command).
 The debugger internally juggles the value of C<$frame> during execution to
 protect external modules that the debugger uses from getting traced.
 
@@ -329,7 +348,7 @@ expression.
 
 =head4 C<$onetimeDumpDepth>
 
-Controls how far down C<dumpvar.pl> will go before printing '...' while
+Controls how far down C<dumpvar.pl> will go before printing C<...> while
 dumping a structure. Numeric. If C<undef>, print all levels.
 
 =head4 C<$signal>
@@ -347,12 +366,12 @@ each subroutine; popped again at the end of each subroutine.
 
 =item * 0 - run continuously.
 
-=item * 1 - single-step, go into subs. The 's' command.
+=item * 1 - single-step, go into subs. The C<s> command.
 
-=item * 2 - single-step, don't go into subs. The 'n' command.
+=item * 2 - single-step, don't go into subs. The C<n> command.
 
-=item * 4 - print current sub depth (turned on to force this when "too much
-recursion" occurs.
+=item * 4 - print current sub depth (turned on to force this when C<too much
+recursion> occurs.
 
 =back
 
@@ -421,7 +440,7 @@ Keys are file names, values are 1 (break when this file is loaded) or undef
 
 =head4 C<%dbline>
 
-Keys are line numbers, values are "condition\0action". If used in numeric
+Keys are line numbers, values are C<condition\0action>. If used in numeric
 context, values are 0 if not breakable, 1 if breakable, no matter what is
 in the actual hash entry.
 
@@ -450,9 +469,9 @@ Keys are subroutine names, values are:
 
 =over 4
 
-=item * 'compile' - break when this sub is compiled
+=item * C<compile> - break when this sub is compiled
 
-=item * 'break +0 if <condition>' - break (conditionally) at the start of this routine. The condition will be '1' if no condition was specified.
+=item * C<< break +0 if <condition> >> - break (conditionally) at the start of this routine. The condition will be '1' if no condition was specified.
 
 =back
 
@@ -461,7 +480,7 @@ Keys are subroutine names, values are:
 This hash keeps track of breakpoints that need to be set for files that have
 not yet been compiled. Keys are filenames; values are references to hashes.
 Each of these hashes is keyed by line number, and its values are breakpoint
-definitions ("condition\0action").
+definitions (C<condition\0action>).
 
 =head1 DEBUGGER INITIALIZATION
 
@@ -489,9 +508,12 @@ where it has to go.
 
 package DB;
 
+BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl
+
 # Debugger for Perl 5.00x; perl5db.pl patch level:
-$VERSION = 1.21;
-$header  = "perl5db.pl version $VERSION";
+$VERSION = 1.30;
+
+$header = "perl5db.pl version $VERSION";
 
 =head1 DEBUGGER ROUTINES
 
@@ -503,20 +525,20 @@ the process of evaluating code in the user's context.
 The code to be evaluated is passed via the package global variable 
 C<$DB::evalarg>; this is done to avoid fiddling with the contents of C<@_>.
 
-We preserve the current settings of X<C<$trace>>, X<C<$single>>, and X<C<$^D>>;
-add the X<C<$usercontext>> (that's the preserved values of C<$@>, C<$!>,
-C<$^E>, C<$,>, C<$/>, C<$\>, and C<$^W>, grabbed when C<DB::DB> got control,
-and the user's current package) and a add a newline before we do the C<eval()>.
-This causes the proper context to be used when the eval is actually done.
-Afterward, we restore C<$trace>, C<$single>, and C<$^D>.
+Before we do the C<eval()>, we preserve the current settings of C<$trace>,
+C<$single>, C<$^D> and C<$usercontext>.  The latter contains the
+preserved values of C<$@>, C<$!>, C<$^E>, C<$,>, C<$/>, C<$\>, C<$^W> and the
+user's current package, grabbed when C<DB::DB> got control.  This causes the
+proper context to be used when the eval is actually done.  Afterward, we
+restore C<$trace>, C<$single>, and C<$^D>.
 
 Next we need to handle C<$@> without getting confused. We save C<$@> in a
 local lexical, localize C<$saved[0]> (which is where C<save()> will put 
 C<$@>), and then call C<save()> to capture C<$@>, C<$!>, C<$^E>, C<$,>, 
 C<$/>, C<$\>, and C<$^W>) and set C<$,>, C<$/>, C<$\>, and C<$^W> to values
 considered sane by the debugger. If there was an C<eval()> error, we print 
-it on the debugger's output. If X<C<$onetimedump>> is defined, we call 
-X<C<dumpit>> if it's set to 'dump', or X<C<methods>> if it's set to 
+it on the debugger's output. If C<$onetimedump> is defined, we call 
+C<dumpit> if it's set to 'dump', or C<methods> if it's set to 
 'methods'. Setting it to something else causes the debugger to do the eval 
 but not print the result - handy if you want to do something else with it 
 (the "watch expressions" code does this to get the value of the watch
@@ -536,9 +558,9 @@ The variables listed below influence C<DB::eval()>'s execution directly.
 
 =item C<$evalarg> - the thing to actually be eval'ed
 
-=item C<$trace> - Current state of execution tracing (see X<$trace>)
+=item C<$trace> - Current state of execution tracing
 
-=item C<$single> - Current state of single-stepping (see X<$single>)        
+=item C<$single> - Current state of single-stepping
 
 =item C<$onetimeDump> - what is to be displayed after the evaluation 
 
@@ -593,27 +615,27 @@ context, so we can use C<my> freely.
 sub eval {
 
     # 'my' would make it visible from user code
-    #    but so does local! --tchrist  
+    #    but so does local! --tchrist
     # Remember: this localizes @DB::res, not @main::res.
     local @res;
     {
-        # Try to keep the user code from messing  with us. Save these so that 
-        # even if the eval'ed code changes them, we can put them back again. 
-        # Needed because the user could refer directly to the debugger's 
+
+        # Try to keep the user code from messing  with us. Save these so that
+        # even if the eval'ed code changes them, we can put them back again.
+        # Needed because the user could refer directly to the debugger's
         # package globals (and any 'my' variables in this containing scope)
         # inside the eval(), and we want to try to stay safe.
-        local $otrace  = $trace; 
+        local $otrace  = $trace;
         local $osingle = $single;
         local $od      = $^D;
 
         # Untaint the incoming eval() argument.
         { ($evalarg) = $evalarg =~ /(.*)/s; }
 
-        # $usercontext built in DB::DB near the comment 
+        # $usercontext built in DB::DB near the comment
         # "set up the context for DB::eval ..."
         # Evaluate and save any results.
-        @res =
-          eval "$usercontext $evalarg;\n";    # '\n' for nice recursive debug
+        @res = eval "$usercontext $evalarg;\n";  # '\n' for nice recursive debug
 
         # Restore those old values.
         $trace  = $otrace;
@@ -627,7 +649,7 @@ sub eval {
 
     # Since we're only saving $@, we only have to localize the array element
     # that it will be stored in.
-    local $saved[0];                          # Preserve the old value of $@
+    local $saved[0];    # Preserve the old value of $@
     eval { &DB::save };
 
     # Now see whether we need to report an error back to the user.
@@ -639,13 +661,13 @@ sub eval {
     # Display as required by the caller. $onetimeDump and $onetimedumpDepth
     # are package globals.
     elsif ($onetimeDump) {
-        if ($onetimeDump eq 'dump') {
+        if ( $onetimeDump eq 'dump' ) {
             local $option{dumpDepth} = $onetimedumpDepth
               if defined $onetimedumpDepth;
-            dumpit($OUT, \@res);
+            dumpit( $OUT, \@res );
         }
-        elsif ($onetimeDump eq 'methods') {
-            methods($res[0]);
+        elsif ( $onetimeDump eq 'methods' ) {
+            methods( $res[0] );
         }
     } ## end elsif ($onetimeDump)
     @res;
@@ -654,29 +676,27 @@ sub eval {
 ############################################## End lexical danger zone
 
 # After this point it is safe to introduce lexicals.
-# The code being debugged will be executing in its own context, and 
+# The code being debugged will be executing in its own context, and
 # can't see the inside of the debugger.
 #
-# However, one should not overdo it: leave as much control from outside as    
+# However, one should not overdo it: leave as much control from outside as
 # possible. If you make something a lexical, it's not going to be addressable
 # from outside the debugger even if you know its name.
 
 # This file is automatically included if you do perl -d.
 # It's probably not useful to include this yourself.
 #
-# Before venturing further into these twisty passages, it is 
+# Before venturing further into these twisty passages, it is
 # 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.)
 
 # Note that no subroutine call is possible until &DB::sub is defined
 # (for subroutines defined outside of the package DB). In fact the same is
 # true if $deep is not defined.
-#
-# $Log:        perldb.pl,v $
 
 # Enhanced by ilya@math.ohio-state.edu (Ilya Zakharevich)
 
@@ -705,7 +725,7 @@ sub eval {
 # Changes: 0.95
 #   + `v' command shows versions.
 #
-# Changes: 0.96 
+# Changes: 0.96
 #   + `v' command shows version of readline.
 #     primitive completion works (dynamic variables, subs for `b' and `l',
 #     options). Can `p %var'
@@ -722,7 +742,7 @@ sub eval {
 #   + `b postpone subr' implemented.
 #   + now only `q' exits debugger (overwritable on $inhibit_exit).
 #   + When restarting debugger breakpoints/actions persist.
-#   + Buglet: When restarting debugger only one breakpoint/action per 
+#   + Buglet: When restarting debugger only one breakpoint/action per
 #             autoloaded function persists.
 #
 # Changes: 0.97: NonStop will not stop in at_exit().
@@ -755,12 +775,12 @@ sub eval {
 #     They are not used in print_help if they will hurt.  Strip pod
 #     if we're paging to less.
 #   + Fixed mis-formatting of help messages caused by ornaments
-#     to restore Larry's original formatting.  
-#   + Fixed many other formatting errors.  The code is still suboptimal, 
+#     to restore Larry's original formatting.
+#   + Fixed many other formatting errors.  The code is still suboptimal,
 #     and needs a lot of work at restructuring.  It's also misindented
 #     in many places.
 #   + Fixed bug where trying to look at an option like your pager
-#     shows "1".  
+#     shows "1".
 #   + Fixed some $? processing.  Note: if you use csh or tcsh, you will
 #     lose.  You should consider shell escapes not using their shell,
 #     or else not caring about detailed status.  This should really be
@@ -803,7 +823,7 @@ sub eval {
 #     unconditionally, or if started as a kid of another debugger session;
 #   + New `O'ption CreateTTY
 #       I<CreateTTY>      bits control attempts to create a new TTY on events:
-#                         1: on fork()   
+#                         1: on fork()
 #                         2: debugger is started inside debugger
 #                         4: on startup
 #   + Code to auto-create a new TTY window on OS/2 (currently one
@@ -831,11 +851,11 @@ sub eval {
 #      breakable_line_in_filename($name, $from [, $to])
 #                                           # First breakable line in the
 #                                           # range $from .. $to.  $to defaults
-#                                           # to $from, and may be less than 
+#                                           # to $from, and may be less than
 #                                           # $to
 #      breakable_line($from [, $to])        # Same for the current file
 #      break_on_filename_line($name, $lineno [, $cond])
-#                                           # Set breakpoint,$cond defaults to 
+#                                           # Set breakpoint,$cond defaults to
 #                                           # 1
 #      break_on_filename_line_range($name, $from, $to [, $cond])
 #                                           # As above, on the first
@@ -859,7 +879,7 @@ sub eval {
 #   + Fixed warnings generated by "O" (Show debugger options)
 #   + Fixed warnings generated by "p 42" (Print expression)
 # Changes: 1.13: Jun 19, 2001 Scott.L.Miller@compaq.com
-#   + Added windowSize option 
+#   + Added windowSize option
 # Changes: 1.14: Oct  9, 2001 multiple
 #   + Clean up after itself on VMS (Charles Lane in 12385)
 #   + Adding "@ file" syntax (Peter Scott in 12014)
@@ -874,12 +894,12 @@ sub eval {
 #   + $onetimeDump improvements
 # Changes: 1.17: Feb 20, 2002 Richard Foley <richard.foley@rfi.net>
 #   Moved some code to cmd_[.]()'s for clarity and ease of handling,
-#   rationalised the following commands and added cmd_wrapper() to 
-#   enable switching between old and frighteningly consistent new 
+#   rationalised the following commands and added cmd_wrapper() to
+#   enable switching between old and frighteningly consistent new
 #   behaviours for diehards: 'o CommandSet=pre580' (sigh...)
 #     a(add),       A(del)            # action expr   (added del by line)
 #   + b(add),       B(del)            # break  [line] (was b,D)
-#   + w(add),       W(del)            # watch  expr   (was W,W) 
+#   + w(add),       W(del)            # watch  expr   (was W,W)
 #                                     # added del by expr
 #   + h(summary), h h(long)           # help (hh)     (was h h,h)
 #   + m(methods),   M(modules)        # ...           (was m,v)
@@ -892,11 +912,36 @@ sub eval {
 # Changes: 1.20: Feb 17, 2003 Richard Foley <richard.foley@rfi.net>
 #   + pre'n'post commands no longer trashed with no args
 #   + watch val joined out of eval()
-# Changes: 1.21: Jun 04, 2002 Joe McMahon (mcmahon@ibiblio.org)
+# Changes: 1.21: Jun 04, 2003 Joe McMahon <mcmahon@ibiblio.org>
 #   + Added comments and reformatted source. No bug fixes/enhancements.
 #   + Includes cleanup by Robin Barker and Jarkko Hietaniemi.
-
-####################################################################
+# Changes: 1.22  Jun 09, 2003 Alex Vandiver <alexmv@MIT.EDU>
+#   + 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 inheritance tree of given class.
+#   + Fixed minor newline in history bug.
+# Changes: 1.25: Apr 17, 2004 Richard Foley <richard.foley@rfi.net>
+#   + Fixed option bug (setting invalid options + not recognising valid short forms)
+# Changes: 1.26: Apr 22, 2004 Richard Foley <richard.foley@rfi.net>
+#   + unfork the 5.8.x and 5.9.x debuggers.
+#   + whitespace and assertions call cleanup across versions 
+#   + H * deletes (resets) history
+#   + i now handles Class + blessed objects
+# Changes: 1.27: May 09, 2004 Richard Foley <richard.foley@rfi.net>
+#   + updated pod page references - clunky.
+#   + removed windowid restriction for forking into an xterm.
+#   + more whitespace again.
+#   + wrapped restart and enabled rerun [-n] (go back n steps) command.
+# Changes: 1.28: Oct 12, 2004 Richard Foley <richard.foley@rfi.net>
+#   + Added threads support (inc. e and E commands)
+# Changes: 1.29: Nov 28, 2006 Bo Lindbergh <blgl@hagernas.com> 
+#   + Added macosx_get_fork_TTY support 
+# Changes: 1.30: Mar 06, 2007 Andreas Koenig <andk@cpan.org>
+#   + Added HistFile, HistSize
+########################################################################
 
 =head1 DEBUGGER INITIALIZATION
 
@@ -924,6 +969,51 @@ BEGIN {
 
 local ($^W) = 0;    # Switch run-time warnings off during init.
 
+=head2 THREADS SUPPORT
+
+If we are running under a threaded Perl, we require threads and threads::shared
+if the environment variable C<PERL5DB_THREADED> is set, to enable proper
+threaded debugger control.  C<-dt> can also be used to set this.
+
+Each new thread will be announced and the debugger prompt will always inform
+you of each new thread created.  It will also indicate the thread id in which
+we are currently running within the prompt like this:
+
+       [tid] DB<$i>
+
+Where C<[tid]> is an integer thread id and C<$i> is the familiar debugger
+command prompt.  The prompt will show: C<[0]> when running under threads, but
+not actually in a thread.  C<[tid]> is consistent with C<gdb> usage.
+
+While running under threads, when you set or delete a breakpoint (etc.), this
+will apply to all threads, not just the currently running one.  When you are 
+in a currently executing thread, you will stay there until it completes.  With
+the current implementation it is not currently possible to hop from one thread
+to another.
+
+The C<e> and C<E> commands are currently fairly minimal - see C<h e> and C<h E>.
+
+Note that threading support was built into the debugger as of Perl version
+C<5.8.6> and debugger version C<1.2.8>.
+
+=cut
+
+BEGIN {
+  # ensure we can share our non-threaded variables or no-op
+  if ($ENV{PERL5DB_THREADED}) {
+       require threads;
+       require threads::shared;
+       import threads::shared qw(share);
+       $DBGR;
+       share(\$DBGR);
+       lock($DBGR);
+       print "Threads support enabled\n";
+  } else {
+       *lock  = sub(*) {};
+       *share = sub(*) {};
+  }
+}
+
 # This would probably be better done with "use vars", but that wasn't around
 # when this code was originally written. (Neither was "use strict".) And on
 # the principle of not fiddling with something that was working, this was
@@ -955,6 +1045,10 @@ warn(               # Do not ;-)
   )
   if 0;
 
+foreach my $k (keys (%INC)) {
+       &share(\$main::{'_<'.$filename});
+};
+
 # Command-line + PERLLIB:
 # Save the contents of @INC before they are modified elsewhere.
 @ini_INC = @INC;
@@ -965,8 +1059,8 @@ warn(               # Do not ;-)
 
 # We set these variables to safe values. We don't want to blindly turn
 # off warnings, because other packages may still want them.
-$trace = $signal = $single = 0;   # Uninitialized warning suppression
-                                  # (local $^W cannot help - other packages!).
+$trace = $signal = $single = 0;    # Uninitialized warning suppression
+                                   # (local $^W cannot help - other packages!).
 
 # Default to not exiting when program finishes; print the return
 # value when the 'r' command is used to return from a subroutine.
@@ -986,20 +1080,23 @@ are to be accepted.
 =cut
 
 @options = qw(
-             CommandSet
-             hashDepth    arrayDepth    dumpDepth
-             DumpDBFiles  DumpPackages  DumpReused
-             compactDump  veryCompact   quote
-             HighBit      undefPrint    globPrint 
-             PrintRet     UsageOnly     frame
-             AutoTrace    TTY           noTTY 
-             ReadLine     NonStop       LineInfo 
-             maxTraceLen  recallCommand ShellBang
-             pager        tkRunning     ornaments
-             signalLevel  warnLevel     dieLevel 
-             inhibit_exit ImmediateStop bareStringify 
-             CreateTTY    RemotePort    windowSize
-           );
+  CommandSet   HistFile      HistSize
+  hashDepth    arrayDepth    dumpDepth
+  DumpDBFiles  DumpPackages  DumpReused
+  compactDump  veryCompact   quote
+  HighBit      undefPrint    globPrint
+  PrintRet     UsageOnly     frame
+  AutoTrace    TTY           noTTY
+  ReadLine     NonStop       LineInfo
+  maxTraceLen  recallCommand ShellBang
+  pager        tkRunning     ornaments
+  signalLevel  warnLevel     dieLevel
+  inhibit_exit ImmediateStop bareStringify
+  CreateTTY    RemotePort    windowSize
+  DollarCaretP
+);
+
+@RememberOnROptions = qw(DollarCaretP);
 
 =pod
 
@@ -1028,7 +1125,9 @@ state.
     ImmediateStop => \$ImmediateStop,
     RemotePort    => \$remoteport,
     windowSize    => \$window,
-    );
+    HistFile      => \$histfile,
+    HistSize      => \$histsize,
+);
 
 =pod
 
@@ -1055,7 +1154,8 @@ option.
     tkRunning     => \&tkRunning,
     ornaments     => \&ornaments,
     RemotePort    => \&RemotePort,
-    );
+    DollarCaretP  => \&DollarCaretP,
+);
 
 =pod
 
@@ -1073,7 +1173,7 @@ option is used.
     compactDump => 'dumpvar.pl',
     veryCompact => 'dumpvar.pl',
     quote       => 'dumpvar.pl',
-    );
+);
 
 =pod
 
@@ -1116,6 +1216,17 @@ $pretype     = []    unless defined $pretype;
 $CreateTTY   = 3     unless defined $CreateTTY;
 $CommandSet  = '580' unless defined $CommandSet;
 
+share($rl);
+share($warnLevel);
+share($dieLevel);
+share($signalLevel);
+share($pre);
+share($post);
+share($pretype);
+share($rl);
+share($CreateTTY);
+share($CommandSet);
+
 =pod
 
 The default C<die>, C<warn>, and C<signal> handlers are set up.
@@ -1129,7 +1240,7 @@ signalLevel($signalLevel);
 =pod
 
 The pager to be used is needed next. We try to get it from the
-environment first.  if it's not defined there, we try to find it in
+environment first.  If it's not defined there, we try to find it in
 the Perl C<Config.pm>.  If it's not there, we default to C<more>. We
 then call the C<pager()> function to save the pager name.
 
@@ -1137,24 +1248,26 @@ then call the C<pager()> function to save the pager name.
 
 # This routine makes sure $pager is set up so that '|' can use it.
 pager(
+
     # If PAGER is defined in the environment, use it.
-    defined $ENV{PAGER} 
-      ? $ENV{PAGER}
+    defined $ENV{PAGER}
+    ? $ENV{PAGER}
 
       # If not, see if Config.pm defines it.
-      : eval { require Config } && defined $Config::Config{pager} 
-        ? $Config::Config{pager}
+    : eval { require Config }
+      && defined $Config::Config{pager}
+    ? $Config::Config{pager}
 
       # If not, fall back to 'more'.
-        : 'more'
+    : 'more'
   )
   unless defined $pager;
 
 =pod
 
 We set up the command to be used to access the man pages, the command
-recall character ("!" unless otherwise defined) and the shell escape
-character ("!" unless otherwise defined). Yes, these do conflict, and
+recall character (C<!> unless otherwise defined) and the shell escape
+character (C<!> unless otherwise defined). Yes, these do conflict, and
 neither works in the debugger at the moment.
 
 =cut
@@ -1182,7 +1295,7 @@ $maxtrace = 400 unless defined $maxtrace;
 
 =head2 SETTING UP THE DEBUGGER GREETING
 
-The debugger 'greeting'  helps to inform the user how many debuggers are
+The debugger I<greeting> helps to inform the user how many debuggers are
 running, and whether the current debugger is the primary or a child.
 
 If we are the primary, we just hang onto our pid so we'll have it when
@@ -1200,31 +1313,45 @@ yet so the parent will give them one later via C<resetterm()>.
 
 =cut
 
-# Save the current contents of the environment; we're about to 
+# Save the current contents of the environment; we're about to
 # much with it. We'll need this if we have to restart.
 $ini_pids = $ENV{PERLDB_PIDS};
 
-if (defined $ENV{PERLDB_PIDS}) { 
+if ( defined $ENV{PERLDB_PIDS} ) {
+
     # We're a child. Make us a label out of the current PID structure
-    # recorded in PERLDB_PIDS plus our (new) PID. Mark us as not having 
+    # recorded in PERLDB_PIDS plus our (new) PID. Mark us as not having
     # a term yet so the parent will give us one later via resetterm().
-    $pids = "[$ENV{PERLDB_PIDS}]";
-    $ENV{PERLDB_PIDS} .= "->$$";
-    $term_pid = -1;
+
+    my $env_pids = $ENV{PERLDB_PIDS};
+    $pids = "[$env_pids]";
+
+    # Unless we are on OpenVMS, all programs under the DCL shell run under
+    # the same PID.
+
+    if (($^O eq 'VMS') && ($env_pids =~ /\b$$\b/)) {
+        $term_pid         = $$;
+    }
+    else {
+        $ENV{PERLDB_PIDS} .= "->$$";
+        $term_pid = -1;
+    }
+
 } ## end if (defined $ENV{PERLDB_PIDS...
 else {
-    # We're the parent PID. Initialize PERLDB_PID in case we end up with a 
+
+    # We're the parent PID. Initialize PERLDB_PID in case we end up with a
     # child debugger, and mark us as the parent, so we'll know to set up
     # more TTY's is we have to.
     $ENV{PERLDB_PIDS} = "$$";
-    $pids     = "{pid=$$}";
-    $term_pid = $$;
+    $pids             = "[pid=$$]";
+    $term_pid         = $$;
 }
 
 $pidprompt = '';
 
 # Sets up $emacs as a synonym for $slave_editor.
-*emacs     = $slave_editor if $slave_editor;   # May be used in afterinit()...
+*emacs = $slave_editor if $slave_editor;    # May be used in afterinit()...
 
 =head2 READING THE RC FILE
 
@@ -1235,7 +1362,8 @@ running interactively, this is C<.perldb>; if not, it's C<perldb.ini>.
 
 # As noted, this test really doesn't check accurately that the debugger
 # is running at a terminal or not.
-if (-e "/dev/tty") {                           # this is the wrong metric!
+
+if ( -e "/dev/tty" ) {                      # this is the wrong metric!
     $rcfile = ".perldb";
 }
 else {
@@ -1263,7 +1391,7 @@ sub safe_do {
     local $SIG{__WARN__};
     local $SIG{__DIE__};
 
-    unless (is_safe_file($file)) {
+    unless ( is_safe_file($file) ) {
         CORE::warn <<EO_GRIPE;
 perldb: Must not source insecure rcfile $file.
         You or the superuser must be the owner, and it must not 
@@ -1282,12 +1410,12 @@ EO_GRIPE
 # one but owner may write to it.  This function is of limited use
 # when called on a path instead of upon a handle, because there are
 # no guarantees that filename (by dirent) whose file (by ino) is
-# eventually accessed is the same as the one tested. 
+# eventually accessed is the same as the one tested.
 # Assumes that the file's existence is not in doubt.
 sub is_safe_file {
     my $path = shift;
     stat($path) || return;    # mysteriously vaporized
-    my ($dev, $ino, $mode, $nlink, $uid, $gid) = stat(_);
+    my ( $dev, $ino, $mode, $nlink, $uid, $gid ) = stat(_);
 
     return 0 if $uid != 0 && $uid != $<;
     return 0 if $mode & 022;
@@ -1295,53 +1423,67 @@ sub is_safe_file {
 } ## end sub is_safe_file
 
 # If the rcfile (whichever one we decided was the right one to read)
-# exists, we safely do it. 
-if (-f $rcfile) {
+# exists, we safely do it.
+if ( -f $rcfile ) {
     safe_do("./$rcfile");
 }
+
 # If there isn't one here, try the user's home directory.
-elsif (defined $ENV{HOME} && -f "$ENV{HOME}/$rcfile") {
+elsif ( defined $ENV{HOME} && -f "$ENV{HOME}/$rcfile" ) {
     safe_do("$ENV{HOME}/$rcfile");
 }
+
 # Else try the login directory.
-elsif (defined $ENV{LOGDIR} && -f "$ENV{LOGDIR}/$rcfile") {
+elsif ( defined $ENV{LOGDIR} && -f "$ENV{LOGDIR}/$rcfile" ) {
     safe_do("$ENV{LOGDIR}/$rcfile");
 }
 
 # If the PERLDB_OPTS variable has options in it, parse those out next.
-if (defined $ENV{PERLDB_OPTS}) {
-    parse_options($ENV{PERLDB_OPTS});
+if ( defined $ENV{PERLDB_OPTS} ) {
+    parse_options( $ENV{PERLDB_OPTS} );
 }
 
 =pod
 
 The last thing we do during initialization is determine which subroutine is
 to be used to obtain a new terminal when a new debugger is started. Right now,
-the debugger only handles X Windows and OS/2.
+the debugger only handles X Windows, OS/2, and Mac OS X (darwin).
 
 =cut
 
 # Set up the get_fork_TTY subroutine to be aliased to the proper routine.
 # Works if you're running an xterm or xterm-like window, or you're on
-# OS/2. This may need some expansion: for instance, this doesn't handle
-# OS X Terminal windows.       
-
-if (not defined &get_fork_TTY                        # no routine exists,
-    and defined $ENV{TERM}                           # and we know what kind
-                                                     # of terminal this is,
-    and $ENV{TERM} eq 'xterm'                        # and it's an xterm,
-    and defined $ENV{WINDOWID}                       # and we know what
-                                                     # window this is,
-    and defined $ENV{DISPLAY})                       # and what display it's
-                                                     # on,
+# OS/2, or on Mac OS X. This may need some expansion.
+
+if (not defined &get_fork_TTY)       # only if no routine exists
 {
-    *get_fork_TTY = \&xterm_get_fork_TTY;            # use the xterm version
+    if (defined $ENV{TERM}                       # If we know what kind
+                                                 # of terminal this is,
+        and $ENV{TERM} eq 'xterm'                # and it's an xterm,
+        and defined $ENV{DISPLAY}                # and what display it's on,
+      )
+    {
+        *get_fork_TTY = \&xterm_get_fork_TTY;    # use the xterm version
+    }
+    elsif ( $^O eq 'os2' ) {                     # If this is OS/2,
+        *get_fork_TTY = \&os2_get_fork_TTY;      # use the OS/2 version
+    }
+    elsif ( $^O eq 'darwin'                      # If this is Mac OS X
+            and defined $ENV{TERM_PROGRAM}       # and we're running inside
+            and $ENV{TERM_PROGRAM}
+                eq 'Apple_Terminal'              # Terminal.app
+            )
+    {
+        *get_fork_TTY = \&macosx_get_fork_TTY;   # use the Mac OS X version
+    }
 } ## end if (not defined &get_fork_TTY...
-elsif ($^O eq 'os2') {                               # If this is OS/2,
-    *get_fork_TTY = \&os2_get_fork_TTY;              # use the OS/2 version
-}
 
-# "Here begin the unreadable code.  It needs fixing." 
+# untaint $^O, which may have been tainted by the last statement.
+# see bug [perl #24674]
+$^O =~ m/^(.*)\z/;
+$^O = $1;
+
+# Here begin the unreadable code.  It needs fixing.
 
 =head2 RESTART PROCESSING
 
@@ -1369,38 +1511,45 @@ back into the appropriate spots in the debugger.
 
 =cut
 
-if (exists $ENV{PERLDB_RESTART}) {
+if ( exists $ENV{PERLDB_RESTART} ) {
+
     # We're restarting, so we don't need the flag that says to restart anymore.
     delete $ENV{PERLDB_RESTART};
+
     # $restart = 1;
     @hist          = get_list('PERLDB_HIST');
     %break_on_load = get_list("PERLDB_ON_LOAD");
     %postponed     = get_list("PERLDB_POSTPONE");
 
+       share(@hist);
+       share(@truehist);
+       share(%break_on_load);
+       share(%postponed);
+
     # restore breakpoints/actions
     my @had_breakpoints = get_list("PERLDB_VISITED");
-    for (0 .. $#had_breakpoints) {
+    for ( 0 .. $#had_breakpoints ) {
         my %pf = get_list("PERLDB_FILE_$_");
         $postponed_file{ $had_breakpoints[$_] } = \%pf if %pf;
     }
 
     # restore options
     my %opt = get_list("PERLDB_OPT");
-    my ($opt, $val);
-    while (($opt, $val) = each %opt) {
+    my ( $opt, $val );
+    while ( ( $opt, $val ) = each %opt ) {
         $val =~ s/[\\\']/\\$1/g;
         parse_options("$opt'$val'");
     }
 
     # restore original @INC
-    @INC       = get_list("PERLDB_INC");
-    @ini_INC   = @INC;
+    @INC     = get_list("PERLDB_INC");
+    @ini_INC = @INC;
 
     # return pre/postprompt actions and typeahead buffer
-    $pretype   = [get_list("PERLDB_PRETYPE")];
-    $pre       = [get_list("PERLDB_PRE")];
-    $post      = [get_list("PERLDB_POST")];
-    @typeahead = get_list("PERLDB_TYPEAHEAD", @typeahead);
+    $pretype   = [ get_list("PERLDB_PRETYPE") ];
+    $pre       = [ get_list("PERLDB_PRE") ];
+    $post      = [ get_list("PERLDB_POST") ];
+    @typeahead = get_list( "PERLDB_TYPEAHEAD", @typeahead );
 } ## end if (exists $ENV{PERLDB_RESTART...
 
 =head2 SETTING UP THE TERMINAL
@@ -1413,6 +1562,7 @@ to be anyone there to enter commands.
 
 if ($notty) {
     $runnonstop = 1;
+       share($runnonstop);
 }
 
 =pod
@@ -1425,11 +1575,13 @@ set C<$rl> to 0 (XXX ostensibly to do straight reads).
 =cut
 
 else {
+
     # Is Perl being run from a slave editor or graphical debugger?
     # If so, don't use readline, and set $slave_editor = 1.
     $slave_editor =
-      ((defined $main::ARGV[0]) and ($main::ARGV[0] eq '-emacs'));
-    $rl = 0, shift (@main::ARGV) if $slave_editor;
+      ( ( defined $main::ARGV[0] ) and ( $main::ARGV[0] eq '-emacs' ) );
+    $rl = 0, shift(@main::ARGV) if $slave_editor;
+
     #require Term::ReadLine;
 
 =pod
@@ -1442,8 +1594,8 @@ We then determine what the console should be on various systems:
 
 =cut
 
+    if ( $^O eq 'cygwin' ) {
 
-    if ($^O eq 'cygwin') {
         # /dev/tty is binary. use stdin for textmode
         undef $console;
     }
@@ -1452,7 +1604,7 @@ We then determine what the console should be on various systems:
 
 =cut
 
-    elsif (-e "/dev/tty") {
+    elsif ( -e "/dev/tty" ) {
         $console = "/dev/tty";
     }
 
@@ -1460,17 +1612,19 @@ We then determine what the console should be on various systems:
 
 =cut
 
-    elsif ($^O eq 'dos' or -e "con" or $^O eq 'MSWin32') {
+    elsif ( $^O eq 'dos' or -e "con" or $^O eq 'MSWin32' ) {
         $console = "con";
     }
 
 =item * MacOS - use C<Dev:Console:Perl Debug> if this is the MPW version; C<Dev:
-Console> if not. (Note that Mac OS X returns 'darwin', not 'MacOS'. Also note that the debugger doesn't do anything special for 'darwin'. Maybe it should.)
+Console> if not.
+
+Note that Mac OS X returns C<darwin>, not C<MacOS>. Also note that the debugger doesn't do anything special for C<darwin>. Maybe it should.
 
 =cut
 
-    elsif ($^O eq 'MacOS') {
-        if ($MacPerl::Version !~ /MPW/) {
+    elsif ( $^O eq 'MacOS' ) {
+        if ( $MacPerl::Version !~ /MPW/ ) {
             $console =
               "Dev:Console:Perl Debug";    # Separate window for application
         }
@@ -1484,6 +1638,7 @@ Console> if not. (Note that Mac OS X returns 'darwin', not 'MacOS'. Also note th
 =cut
 
     else {
+
         # everything else is ...
         $console = "sys\$command";
     }
@@ -1498,24 +1653,27 @@ with a slave editor, Epoc).
 
 =cut
 
-    if (($^O eq 'MSWin32') and ($slave_editor or defined $ENV{EMACS})) {
+    if ( ( $^O eq 'MSWin32' ) and ( $slave_editor or defined $ENV{EMACS} ) ) {
+
         # /dev/tty is binary. use stdin for textmode
         $console = undef;
     }
 
-    if ($^O eq 'NetWare') {
+    if ( $^O eq 'NetWare' ) {
+
         # /dev/tty is binary. use stdin for textmode
         $console = undef;
     }
 
     # In OS/2, we need to use STDIN to get textmode too, even though
     # it pretty much looks like Unix otherwise.
-    if (defined $ENV{OS2_SHELL} and ($slave_editor or $ENV{WINDOWID}))
+    if ( defined $ENV{OS2_SHELL} and ( $slave_editor or $ENV{WINDOWID} ) )
     {    # In OS/2
         $console = undef;
     }
+
     # EPOC also falls into the 'got to use STDIN' camp.
-    if ($^O eq 'epoc') {
+    if ( $^O eq 'epoc' ) {
         $console = undef;
     }
 
@@ -1539,7 +1697,9 @@ and then tries to connect the input and output filehandles to it.
 =cut
 
     # Handle socket stuff.
-    if (defined $remoteport) {
+
+    if ( defined $remoteport ) {
+
         # If RemotePort was defined in the options, connect input and output
         # to the socket.
         require IO::Socket;
@@ -1547,8 +1707,8 @@ and then tries to connect the input and output filehandles to it.
             Timeout  => '10',
             PeerAddr => $remoteport,
             Proto    => 'tcp',
-            );
-        if (!$OUT) { die "Unable to connect to remote host: $remoteport\n"; }
+        );
+        if ( !$OUT ) { die "Unable to connect to remote host: $remoteport\n"; }
         $IN = $OUT;
     } ## end if (defined $remoteport)
 
@@ -1564,38 +1724,41 @@ and if we can.
 
     # Non-socket.
     else {
+
         # Two debuggers running (probably a system or a backtick that invokes
         # the debugger itself under the running one). create a new IN and OUT
-        # filehandle, and do the necessary mojo to create a new tty if we 
+        # filehandle, and do the necessary mojo to create a new tty if we
         # know how, and we can.
         create_IN_OUT(4) if $CreateTTY & 4;
         if ($console) {
+
             # If we have a console, check to see if there are separate ins and
-            # outs to open. (They are assumed identiical if not.)
-            my ($i, $o) = split /,/, $console;
+            # outs to open. (They are assumed identical if not.)
+
+            my ( $i, $o ) = split /,/, $console;
             $o = $i unless defined $o;
 
             # read/write on in, or just read, or read on STDIN.
-            open(IN, "+<$i") || 
-             open(IN, "<$i") || 
-              open(IN, "<&STDIN");
+            open( IN,      "+<$i" )
+              || open( IN, "<$i" )
+              || open( IN, "<&STDIN" );
 
             # read/write/create/clobber out, or write/create/clobber out,
             # or merge with STDERR, or merge with STDOUT.
-            open(OUT,   "+>$o")     ||
-              open(OUT, ">$o")      ||
-              open(OUT, ">&STDERR") ||
-              open(OUT, ">&STDOUT");    # so we don't dongle stdout
+                 open( OUT, "+>$o" )
+              || open( OUT, ">$o" )
+              || open( OUT, ">&STDERR" )
+              || open( OUT, ">&STDOUT" );    # so we don't dongle stdout
 
         } ## end if ($console)
-        elsif (not defined $console) {
-           # No console. Open STDIN.
-            open(IN,    "<&STDIN");
+        elsif ( not defined $console ) {
 
-           # merge with STDERR, or with STDOUT.
-            open(OUT,   ">&STDERR") ||
-              open(OUT, ">&STDOUT");     # so we don't dongle stdout
+            # No console. Open STDIN.
+            open( IN, "<&STDIN" );
 
+            # merge with STDERR, or with STDOUT.
+            open( OUT,      ">&STDERR" )
+              || open( OUT, ">&STDOUT" );    # so we don't dongle stdout
             $console = 'STDIN/OUT';
         } ## end elsif (not defined $console)
 
@@ -1604,17 +1767,19 @@ and if we can.
         $IN = \*IN, $OUT = \*OUT if $console or not defined $console;
     } ## end elsif (from if(defined $remoteport))
 
-    # Unbuffer DB::OUT. We need to see responses right away. 
+    # Unbuffer DB::OUT. We need to see responses right away.
     my $previous = select($OUT);
-    $| = 1;                              # for DB::OUT
+    $| = 1;                                  # for DB::OUT
     select($previous);
 
     # Line info goes to debugger output unless pointed elsewhere.
     # Pointing elsewhere makes it possible for slave editors to
-    # keep track of file and position. We have both a filehandle 
+    # keep track of file and position. We have both a filehandle
     # and a I/O description to keep track of.
     $LINEINFO = $OUT     unless defined $LINEINFO;
     $lineinfo = $console unless defined $lineinfo;
+       # share($LINEINFO); # <- unable to share globs
+       share($lineinfo);   # 
 
 =pod
 
@@ -1628,7 +1793,7 @@ and then call the C<afterinit()> subroutine if there is one.
     unless ($runnonstop) {
         local $\ = '';
         local $, = '';
-        if ($term_pid eq '-1') {
+        if ( $term_pid eq '-1' ) {
             print $OUT "\nDaughter DB session started...\n";
         }
         else {
@@ -1636,7 +1801,7 @@ and then call the C<afterinit()> subroutine if there is one.
             print $OUT (
                 "Editor support ",
                 $slave_editor ? "enabled" : "available", ".\n"
-                );
+            );
             print $OUT
 "\nEnter h or `h h' for help, or `$doccmd perldebug' for more help.\n\n";
         } ## end else [ if ($term_pid eq '-1')
@@ -1649,15 +1814,16 @@ and then call the C<afterinit()> subroutine if there is one.
 for (@args) {
     # Make sure backslashes before single quotes are stripped out, and
     # keep args unless they are numeric (XXX why?)
-    s/\'/\\\'/g;
-    s/(.*)/'$1'/ unless /^-?[\d.]+$/;
+    # s/\'/\\\'/g;                      # removed while not justified understandably
+    # s/(.*)/'$1'/ unless /^-?[\d.]+$/; # ditto
 }
 
-# If there was an afterinit() sub defined, call it. It will get 
+# If there was an afterinit() sub defined, call it. It will get
 # executed in our scope, so it can fiddle with debugger globals.
-if (defined &afterinit) {    # May be defined in $rcfile
+if ( defined &afterinit ) {    # May be defined in $rcfile
     &afterinit();
 }
+
 # Inform us about "Stack dump during die enabled ..." in dieLevel().
 $I_m_init = 1;
 
@@ -1674,7 +1840,7 @@ them, and hen send execution off to the next statement.
 
 Note that the order in which the commands are processed is very important;
 some commands earlier in the loop will actually alter the C<$cmd> variable
-to create other commands to be executed later. This is all highly "optimized"
+to create other commands to be executed later. This is all highly I<optimized>
 but can be confusing. Check the comments for each C<$cmd ... && do {}> to
 see what's happening in any given command.
 
@@ -1682,29 +1848,39 @@ see what's happening in any given command.
 
 sub DB {
 
+    # lock the debugger and get the thread id for the prompt
+       lock($DBGR);
+       my $tid;
+       if ($ENV{PERL5DB_THREADED}) {
+               $tid = eval { "[".threads->tid."]" };
+       }
+
     # Check for whether we should be running continuously or not.
     # _After_ the perl program is compiled, $single is set to 1:
-    if ($single and not $second_time++) {
+    if ( $single and not $second_time++ ) {
+
         # Options say run non-stop. Run until we get an interrupt.
         if ($runnonstop) {    # Disable until signal
-            # If there's any call stack in place, turn off single
-            # stepping into subs throughout the stack.
-            for ($i = 0 ; $i <= $stack_depth ;) {
-                $stack[$i++] &= ~1;
+                # If there's any call stack in place, turn off single
+                # stepping into subs throughout the stack.
+            for ( $i = 0 ; $i <= $stack_depth ; ) {
+                $stack[ $i++ ] &= ~1;
             }
+
             # And we are now no longer in single-step mode.
             $single = 0;
 
             # If we simply returned at this point, we wouldn't get
             # the trace info. Fall on through.
-            # return; 
+            # return;
         } ## end if ($runnonstop)
 
         elsif ($ImmediateStop) {
-            # We are supposed to stop here; XXX probably a break. 
-            $ImmediateStop = 0;               # We've processed it; turn it off
-            $signal        = 1;               # Simulate an interrupt to force
-                                              # us into the command loop
+
+            # We are supposed to stop here; XXX probably a break.
+            $ImmediateStop = 0;    # We've processed it; turn it off
+            $signal        = 1;    # Simulate an interrupt to force
+                                   # us into the command loop
         }
     } ## end if ($single and not $second_time...
 
@@ -1718,17 +1894,16 @@ sub DB {
 
     # Since DB::DB gets called after every line, we can use caller() to
     # figure out where we last were executing. Sneaky, eh? This works because
-    # caller is returning all the extra information when called from the 
+    # caller is returning all the extra information when called from the
     # debugger.
-    local ($package, $filename, $line) = caller;
+    local ( $package, $filename, $line ) = caller;
     local $filename_ini = $filename;
 
     # set up the context for DB::eval, so it can properly execute
     # code on behalf of the user. We add the package in so that the
     # code is eval'ed in the proper package (not in the debugger!).
-    local $usercontext  =
-      '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
-      "package $package;"; 
+    local $usercontext =
+      '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' . "package $package;";
 
     # Create an alias to the active file magical array to simplify
     # the code here.
@@ -1736,7 +1911,7 @@ sub DB {
 
     # we need to check for pseudofiles on Mac OS (these are files
     # not attached to a filename, but instead stored in Dev:Pseudo)
-    if ($^O eq 'MacOS' && $#dbline < 0) {
+    if ( $^O eq 'MacOS' && $#dbline < 0 ) {
         $filename_ini = $filename = 'Dev:Pseudo';
         *dbline = $main::{ '_<' . $filename };
     }
@@ -1745,11 +1920,15 @@ sub DB {
     local $max = $#dbline;
 
     # if we have something here, see if we should break.
-    if ($dbline{$line} && (($stop, $action) = split (/\0/, $dbline{$line}))) {
+    if ( $dbline{$line}
+        && ( ( $stop, $action ) = split( /\0/, $dbline{$line} ) ) )
+    {
+
         # Stop if the stop criterion says to just stop.
-        if ($stop eq '1') {
+        if ( $stop eq '1' ) {
             $signal |= 1;
         }
+
         # It's a conditional stop; eval it in the user's context and
         # see if we should stop. If so, remove the one-time sigil.
         elsif ($stop) {
@@ -1764,25 +1943,25 @@ sub DB {
     my $was_signal = $signal;
 
     # If we have any watch expressions ...
-    if ($trace & 2) {
-        for (my $n = 0 ; $n <= $#to_watch ; $n++) {
+    if ( $trace & 2 ) {
+        for ( my $n = 0 ; $n <= $#to_watch ; $n++ ) {
             $evalarg = $to_watch[$n];
             local $onetimeDump;    # Tell DB::eval() to not output results
 
             # Fix context DB::eval() wants to return an array, but
             # we need a scalar here.
-            my ($val) =
-              join ( "', '", &eval );
-            $val = ((defined $val) ? "'$val'" : 'undef');
+            my ($val) = join( "', '", &eval );
+            $val = ( ( defined $val ) ? "'$val'" : 'undef' );
 
             # Did it change?
-            if ($val ne $old_watch[$n]) {
+            if ( $val ne $old_watch[$n] ) {
+
                 # Yep! Show the difference, and fake an interrupt.
                 $signal = 1;
                 print $OUT <<EOP;
 Watchpoint $n:\t$to_watch[$n] changed:
-       old value:\t$old_watch[$n]
-       new value:\t$val
+    old value:\t$old_watch[$n]
+    new value:\t$val
 EOP
                 $old_watch[$n] = $val;
             } ## end if ($val ne $old_watch...
@@ -1805,13 +1984,21 @@ C<watchfunction()> executes:
 
 =over 4 
 
-=item * Returning a false value from the C<watchfunction()> itself.
+=item *
+
+Returning a false value from the C<watchfunction()> itself.
+
+=item *
 
-=item * Altering C<$single> to a false value.
+Altering C<$single> to a false value.
 
-=item * Altering C<$signal> to a false value.
+=item *
 
-=item *  Turning off the '4' bit in C<$trace> (this also disables the
+Altering C<$signal> to a false value.
+
+=item *
+
+Turning off the C<4> bit in C<$trace> (this also disables the
 check for C<watchfunction()>. This can be done with
 
     $trace &= ~4;
@@ -1820,19 +2007,18 @@ check for C<watchfunction()>. This can be done with
 
 =cut
 
-    # If there's a user-defined DB::watchfunction, call it with the 
+    # If there's a user-defined DB::watchfunction, call it with the
     # current package, filename, and line. The function executes in
     # the DB:: package.
-    if ($trace & 4) {    # User-installed watch
+    if ( $trace & 4 ) {    # User-installed watch
         return
-          if watchfunction($package, $filename, $line)
+          if watchfunction( $package, $filename, $line )
           and not $single
           and not $was_signal
-          and not($trace & ~4);
+          and not( $trace & ~4 );
     } ## end if ($trace & 4)
 
-
-    # Pick up any alteration to $signal in the watchfunction, and 
+    # Pick up any alteration to $signal in the watchfunction, and
     # turn off the signal now.
     $was_signal = $signal;
     $signal     = 0;
@@ -1848,9 +2034,11 @@ won't cause trouble, and we say that the program is over.
 
     # Check to see if we should grab control ($single true,
     # trace set appropriately, or we got a signal).
-    if ($single || ($trace & 1) || $was_signal) {
+    if ( $single || ( $trace & 1 ) || $was_signal ) {
+
         # Yes, grab control.
         if ($slave_editor) {
+
             # Tell the editor to update its position.
             $position = "\032\032$filename:$line:0\n";
             print_lineinfo($position);
@@ -1864,20 +2052,21 @@ to enter commands and have a valid context to be in.
 
 =cut
 
-        elsif ($package eq 'DB::fake') {
+        elsif ( $package eq 'DB::fake' ) {
+
             # Fallen off the end already.
             $term || &setterm;
             print_help(<<EOP);
 Debugged program terminated.  Use B<q> to quit or B<R> to restart,
-  use B<O> I<inhibit_exit> to avoid stopping after program termination,
-  B<h q>, B<h R> or B<h O> to get additional info.  
+  use B<o> I<inhibit_exit> to avoid stopping after program termination,
+  B<h q>, B<h R> or B<h o> to get additional info.  
 EOP
 
             # Set the DB::eval context appropriately.
             $package     = 'main';
             $usercontext =
-              '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
-              "package $package;";    # this won't let them modify, alas
+                '($@, $!, $^E, $,, $/, $\, $^W) = @saved;'
+              "package $package;";    # this won't let them modify, alas
         } ## end elsif ($package eq 'DB::fake')
 
 =pod
@@ -1889,18 +2078,19 @@ number information, and print that.
 =cut
 
         else {
+
             # Still somewhere in the midst of execution. Set up the
             #  debugger prompt.
             $sub =~ s/\'/::/;    # Swap Perl 4 package separators (') to
-                                 # Perl 5 ones (sorry, we don't print Klingon 
+                                 # Perl 5 ones (sorry, we don't print Klingon
                                  #module names)
 
             $prefix = $sub =~ /::/ ? "" : "${'package'}::";
             $prefix .= "$sub($filename:";
-            $after = ($dbline[$line] =~ /\n$/ ? '' : "\n");
+            $after = ( $dbline[$line] =~ /\n$/ ? '' : "\n" );
 
             # Break up the prompt if it's really long.
-            if (length($prefix) > 30) {
+            if ( length($prefix) > 30 ) {
                 $position = "$prefix$line):\n$line:\t$dbline[$line]$after";
                 $prefix   = "";
                 $infix    = ":\t";
@@ -1912,8 +2102,8 @@ number information, and print that.
 
             # Print current line info, indenting if necessary.
             if ($frame) {
-                print_lineinfo(' ' x $stack_depth,
-                    "$line:\t$dbline[$line]$after");
+                print_lineinfo( ' ' x $stack_depth,
+                    "$line:\t$dbline[$line]$after" );
             }
             else {
                 print_lineinfo($position);
@@ -1921,7 +2111,7 @@ number information, and print that.
 
             # Scan forward, stopping at either the end or the next
             # unbreakable line.
-            for ($i = $line + 1 ; $i <= $max && $dbline[$i] == 0 ; ++$i)
+            for ( $i = $line + 1 ; $i <= $max && $dbline[$i] == 0 ; ++$i )
             {    #{ vi
 
                 # Drop out on null statements, block closers, and comments.
@@ -1929,18 +2119,19 @@ number information, and print that.
 
                 # Drop out if the user interrupted us.
                 last if $signal;
-               
+
                 # Append a newline if the line doesn't have one. Can happen
                 # in eval'ed text, for instance.
-                $after = ($dbline[$i] =~ /\n$/ ? '' : "\n");
+                $after = ( $dbline[$i] =~ /\n$/ ? '' : "\n" );
 
                 # Next executable line.
                 $incr_pos = "$prefix$i$infix$dbline[$i]$after";
                 $position .= $incr_pos;
                 if ($frame) {
+
                     # Print it indented if tracing is on.
-                    print_lineinfo(' ' x $stack_depth,
-                        "$i:\t$dbline[$i]$after");
+                    print_lineinfo( ' ' x $stack_depth,
+                        "$i:\t$dbline[$i]$after" );
                 }
                 else {
                     print_lineinfo($incr_pos);
@@ -1961,7 +2152,8 @@ If there are any preprompt actions, execute those as well.
 
     # Are we nested another level (e.g., did we evaluate a function
     # that had a breakpoint in it at the debugger prompt)?
-    if ($single || $was_signal) {
+    if ( $single || $was_signal ) {
+
         # Yes, go down a level.
         local $level = $level + 1;
 
@@ -1976,11 +2168,11 @@ If there are any preprompt actions, execute those as well.
 
         # The line we're currently on. Set $incr to -1 to stay here
         # until we get a command that tells us to advance.
-        $start     = $line;
-        $incr      = -1;                        # for backward motion.
+        $start = $line;
+        $incr  = -1;      # for backward motion.
 
         # Tack preprompt debugger actions ahead of any actual input.
-        @typeahead = (@$pretype, @typeahead);
+        @typeahead = ( @$pretype, @typeahead );
 
 =head2 WHERE ARE WE?
 
@@ -1990,11 +2182,11 @@ The debugger normally shows the line corresponding to the current line of
 execution. Sometimes, though, we want to see the next line, or to move elsewhere
 in the file. This is done via the C<$incr>, C<$start>, and C<$max> variables.
 
-C<$incr> controls by how many lines the "current" line should move forward
-after a command is executed. If set to -1, this indicates that the "current"
+C<$incr> controls by how many lines the I<current> line should move forward
+after a command is executed. If set to -1, this indicates that the I<current>
 line shouldn't change.
 
-C<$start> is the "current" line. It is used for things like knowing where to
+C<$start> is the I<current> line. It is used for things like knowing where to
 move forwards or backwards from when doing an C<L> or C<-> command.
 
 C<$max> tells the debugger where the last line of the current file is. It's
@@ -2007,10 +2199,14 @@ in two parts:
 
 =over 4
 
-=item * The outer part of the loop, starting at the C<CMD> label. This loop
+=item *
+
+The outer part of the loop, starting at the C<CMD> label. This loop
 reads a command and then executes it.
 
-=item * The inner part of the loop, starting at the C<PIPE> label. This part
+=item *
+
+The inner part of the loop, starting at the C<PIPE> label. This part
 is wholly contained inside the C<CMD> block and only executes a command.
 Used to handle commands running inside a pager.
 
@@ -2029,19 +2225,26 @@ the new command. This is faster, but perhaps a bit more convoluted.
         # from readline(), keep on processing.
       CMD:
         while (
+
             # We have a terminal, or can get one ...
-            ($term || &setterm),
+            ( $term || &setterm ),
+
             # ... and it belogs to this PID or we get one for this PID ...
-            ($term_pid == $$ or resetterm(1)),
+            ( $term_pid == $$ or resetterm(1) ),
+
             # ... and we got a line of command input ...
             defined(
                 $cmd = &readline(
-                    "$pidprompt  DB" . ('<' x $level) . ($#hist + 1) .
-                      ('>' x $level) . " "
+                        "$pidprompt $tid DB"
+                      . ( '<' x $level )
+                      . ( $#hist + 1 )
+                      . ( '>' x $level ) . " "
                 )
             )
           )
         {
+
+                       share($cmd);
             # ... try to execute the input as debugger commands.
 
             # Don't stop running.
@@ -2058,7 +2261,7 @@ the new command. This is faster, but perhaps a bit more convoluted.
 
 =head4 The null command
 
-A newline entered by itself means "re-execute the last command". We grab the
+A newline entered by itself means I<re-execute the last command>. We grab the
 command out of C<$laststep> (where it was recorded previously), and copy it
 back into C<$cmd> to be executed below. If there wasn't any previous command,
 we'll do nothing below (no command will match). If there was, we also save it
@@ -2068,17 +2271,20 @@ it up.
 =cut
 
             # Empty input means repeat the last command.
-            $cmd =~ /^$/ && ($cmd = $laststep);
-            push (@hist, $cmd) if length($cmd) > 1;
-
-
-          # This is a restart point for commands that didn't arrive
-          # via direct user input. It allows us to 'redo PIPE' to
-          # re-execute command processing without reading a new command.
+            $cmd =~ /^$/ && ( $cmd = $laststep );
+            chomp($cmd);    # get rid of the annoying extra newline
+            push( @hist, $cmd ) if length($cmd) > 1;
+            push( @truehist, $cmd );
+                       share(@hist);
+                       share(@truehist);
+
+            # This is a restart point for commands that didn't arrive
+            # via direct user input. It allows us to 'redo PIPE' to
+            # re-execute command processing without reading a new command.
           PIPE: {
                 $cmd =~ s/^\s+//s;    # trim annoying leading whitespace
                 $cmd =~ s/\s+$//s;    # trim annoying trailing whitespace
-                ($i) = split (/\s+/, $cmd);
+                ($i) = split( /\s+/, $cmd );
 
 =head3 COMMAND ALIASES
 
@@ -2090,7 +2296,8 @@ completely replacing it.
 =cut
 
                 # See if there's an alias for the command, and set it up if so.
-                if ($alias{$i}) {
+                if ( $alias{$i} ) {
+
                     # Squelch signal handling; we want to keep control here
                     # if something goes loco during the alias eval.
                     local $SIG{__DIE__};
@@ -2136,8 +2343,8 @@ Turn tracing on or off. Inverts the appropriate bit in C<$trace> (q.v.).
                 $cmd =~ /^t$/ && do {
                     $trace ^= 1;
                     local $\ = '';
-                    print $OUT "Trace = " . (($trace & 1) ? "on" : "off") .
-                      "\n";
+                    print $OUT "Trace = "
+                      . ( ( $trace & 1 ) ? "on" : "off" ) . "\n";
                     next CMD;
                 };
 
@@ -2149,7 +2356,7 @@ Walks through C<%sub>, checking to see whether or not to print the name.
 
                 $cmd =~ /^S(\s+(!)?(.+))?$/ && do {
 
-                    $Srev     = defined $2;     # Reverse scan? 
+                    $Srev     = defined $2;     # Reverse scan?
                     $Spatt    = $3;             # The pattern (if any) to use.
                     $Snocheck = !defined $1;    # No args - print all subs.
 
@@ -2161,8 +2368,8 @@ Walks through C<%sub>, checking to see whether or not to print the name.
                     # If $nocheck is true, just print the sub name.
                     # Otherwise, check it against the pattern. We then use
                     # the XOR trick to reverse the condition as required.
-                    foreach $subname (sort(keys %sub)) {
-                        if ($Snocheck or $Srev ^ ($subname =~ /$Spatt/)) {
+                    foreach $subname ( sort( keys %sub ) ) {
+                        if ( $Snocheck or $Srev ^ ( $subname =~ /$Spatt/ ) ) {
                             print $OUT $subname, "\n";
                         }
                     }
@@ -2190,9 +2397,9 @@ Uses C<dumpvar.pl> to dump out the current values for selected variables.
                     $cmd = "V $package";
                 };
 
-
                 # V - show variables in package.
                 $cmd =~ /^V\b\s*(\S+)\s*(.*)/ && do {
+
                     # Save the currently selected filehandle and
                     # force output to debugger's filehandle (dumpvar
                     # just does "print" for output).
@@ -2200,13 +2407,14 @@ Uses C<dumpvar.pl> to dump out the current values for selected variables.
 
                     # Grab package name and variables to dump.
                     $packname = $1;
-                    @vars = split (' ', $2);
+                    @vars     = split( ' ', $2 );
 
                     # If main::dumpvar isn't here, get it.
-                    do 'dumpvar.pl' unless defined &main::dumpvar;
-                    if (defined &main::dumpvar) {
+                    do 'dumpvar.pl' || die $@ unless defined &main::dumpvar;
+                    if ( defined &main::dumpvar ) {
+
                         # We got it. Turn off subroutine entry/exit messages
-                        # for the moment. XXX Why do this to doret?
+                        # for the moment, along with return values.
                         local $frame = 0;
                         local $doret = -2;
 
@@ -2217,21 +2425,23 @@ Uses C<dumpvar.pl> to dump out the current values for selected variables.
                                 $packname,
                                 defined $option{dumpDepth}
                                 ? $option{dumpDepth}
-                                : -1,          # assume -1 unless specified
+                                : -1,    # assume -1 unless specified
                                 @vars
-                                );
+                            );
                         };
 
-                        # The die doesn't need to include the $@, because 
+                        # The die doesn't need to include the $@, because
                         # it will automatically get propagated for us.
                         if ($@) {
                             die unless $@ =~ /dumpvar print failed/;
                         }
                     } ## end if (defined &main::dumpvar)
                     else {
+
                         # Couldn't load dumpvar.
                         print $OUT "dumpvar.pl not available.\n";
                     }
+
                     # Restore the output filehandle, and go round again.
                     select($savout);
                     next CMD;
@@ -2244,12 +2454,12 @@ via C<dumpvar.pl> instead of just printing it directly.
 
 =cut
 
-                $cmd =~ s/^x\b/ / && do {   # Remainder gets done by DB::eval()
-                    $onetimeDump = 'dump';  # main::dumpvar shows the output
+                $cmd =~ s/^x\b/ / && do {    # Remainder gets done by DB::eval()
+                    $onetimeDump = 'dump';    # main::dumpvar shows the output
 
                     # handle special  "x 3 blah" syntax XXX propagate
                     # doc back to special variables.
-                    if ($cmd =~ s/^\s*(\d+)(?=\s)/ /) {
+                    if ( $cmd =~ s/^\s*(\d+)(?=\s)/ / ) {
                         $onetimedumpDepth = $1;
                     }
                 };
@@ -2266,8 +2476,8 @@ Just uses C<DB::methods> to determine what methods are available.
                 };
 
                 # m expr - set up DB::eval to do the work
-                $cmd =~ s/^m\b/ / && do {     # Rest gets done by DB::eval()
-                    $onetimeDump = 'methods'; #  method output gets used there
+                $cmd =~ s/^m\b/ / && do {    # Rest gets done by DB::eval()
+                    $onetimeDump = 'methods';   #  method output gets used there
                 };
 
 =head4 C<f> - switch files
@@ -2279,33 +2489,32 @@ Just uses C<DB::methods> to determine what methods are available.
                     $file =~ s/\s+$//;
 
                     # help for no arguments (old-style was return from sub).
-                    if (!$file) {
+                    if ( !$file ) {
                         print $OUT
-                          "The old f command is now the r command.\n";  # hint
+                          "The old f command is now the r command.\n";    # hint
                         print $OUT "The new f command switches filenames.\n";
                         next CMD;
                     } ## end if (!$file)
 
                     # if not in magic file list, try a close match.
-                    if (!defined $main::{ '_<' . $file }) {
-                        if (($try) = grep(m#^_<.*$file#, keys %main::)) {
+                    if ( !defined $main::{ '_<' . $file } ) {
+                        if ( ($try) = grep( m#^_<.*$file#, keys %main:: ) ) {
                             {
-                                $try = substr($try, 2);
-                                print $OUT
-                                  "Choosing $try matching `$file':\n";
+                                $try = substr( $try, 2 );
+                                print $OUT "Choosing $try matching `$file':\n";
                                 $file = $try;
                             }
                         } ## end if (($try) = grep(m#^_<.*$file#...
                     } ## end if (!defined $main::{ ...
 
                     # If not successfully switched now, we failed.
-                    if (!defined $main::{ '_<' . $file }) {
+                    if ( !defined $main::{ '_<' . $file } ) {
                         print $OUT "No file matching `$file' is loaded.\n";
                         next CMD;
                     }
 
                     # We switched, so switch the debugger internals around.
-                    elsif ($file ne $filename) {
+                    elsif ( $file ne $filename ) {
                         *dbline   = $main::{ '_<' . $file };
                         $max      = $#dbline;
                         $filename = $file;
@@ -2329,13 +2538,13 @@ and then we look up the line in the magical C<%dbline> hash.
 
                 # . command.
                 $cmd =~ /^\.$/ && do {
-                    $incr     = -1;              # stay at current line
+                    $incr = -1;    # stay at current line
 
                     # Reset everything to the old location.
                     $start    = $line;
                     $filename = $filename_ini;
-                    *dbline = $main::{ '_<' . $filename };
-                    $max    = $#dbline;
+                    *dbline   = $main::{ '_<' . $filename };
+                    $max      = $#dbline;
 
                     # Now where are we?
                     print_lineinfo($position);
@@ -2353,10 +2562,11 @@ C<$start>) in C<$cmd> to be executed later.
 
                 # - - back a window.
                 $cmd =~ /^-$/ && do {
+
                     # back up by a window; go to 1 if back too far.
                     $start -= $incr + $window + 1;
                     $start = 1 if $start <= 0;
-                    $incr = $window - 1;
+                    $incr  = $window - 1;
 
                     # Generate and execute a "l +" command (handled below).
                     $cmd = 'l ' . ($start) . '+';
@@ -2374,9 +2584,9 @@ deal with them instead of processing them in-line.
 =cut
 
                 # 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_wrapper($1, $2, $line);
+                # we send them off to the secondary dispatcher (see below).
+                $cmd =~ /^([aAbBeEhilLMoOPvwW]\b|[<>\{]{1,2})\s*(.*)/so && do {
+                    &cmd_wrapper( $1, $2, $line );
                     next CMD;
                 };
 
@@ -2399,16 +2609,16 @@ above the current one and then displays then using C<dumpvar.pl>.
                       and next CMD;
 
                     # Load up dumpvar if we don't have it. If we can, that is.
-                    do 'dumpvar.pl' unless defined &main::dumpvar;
+                    do 'dumpvar.pl' || die $@ unless defined &main::dumpvar;
                     defined &main::dumpvar
                       or print $OUT "dumpvar.pl not available.\n"
                       and next CMD;
 
                     # Got all the modules we need. Find them and print them.
-                    my @vars = split (' ', $2 || '');
+                    my @vars = split( ' ', $2 || '' );
 
                     # Find the pad.
-                    my $h = eval { PadWalker::peek_my(($1 || 0) + 1) };
+                    my $h = eval { PadWalker::peek_my( ( $1 || 0 ) + 1 ) };
 
                     # Oops. Can't find it.
                     $@ and $@ =~ s/ at .*//, &warn($@), next CMD;
@@ -2417,12 +2627,10 @@ above the current one and then displays then using C<dumpvar.pl>.
                     my $savout = select($OUT);
 
                     # Have dumplex dump the lexicals.
-                    dumpvar::dumplex(
-                        $_,
-                        $h->{$_},
+                    dumpvar::dumplex( $_, $h->{$_},
                         defined $option{dumpDepth} ? $option{dumpDepth} : -1,
-                        @vars
-                    ) for sort keys %$h;
+                        @vars )
+                      for sort keys %$h;
                     select($savout);
                     next CMD;
                 };
@@ -2438,16 +2646,18 @@ they can't.
 =head4 C<n> - single step, but don't trace down into subs
 
 Done by setting C<$single> to 2, which forces subs to execute straight through
-when entered (see X<DB::sub>). We also save the C<n> command in C<$laststep>,
+when entered (see C<DB::sub>). We also save the C<n> command in C<$laststep>,
 so a null command knows what to re-execute. 
 
 =cut
 
-                # n - next 
+                # n - next
                 $cmd =~ /^n$/ && do {
                     end_report(), next CMD if $finished and $level <= 1;
+
                     # Single step, but don't enter subs.
-                    $single   = 2;
+                    $single = 2;
+
                     # Save for empty command (repeat last).
                     $laststep = $cmd;
                     last CMD;
@@ -2455,18 +2665,21 @@ so a null command knows what to re-execute.
 
 =head4 C<s> - single-step, entering subs
 
-Sets C<$single> to 1, which causes X<DB::sub> to continue tracing inside     
+Sets C<$single> to 1, which causes C<DB::sub> to continue tracing inside     
 subs. Also saves C<s> as C<$lastcmd>.
 
 =cut
 
                 # s - single step.
                 $cmd =~ /^s$/ && do {
+
                     # Get out and restart the command loop if program
                     # has finished.
                     end_report(), next CMD if $finished and $level <= 1;
+
                     # Single step should enter subs.
-                    $single   = 1;
+                    $single = 1;
+
                     # Save for empty command (repeat last).
                     $laststep = $cmd;
                     last CMD;
@@ -2483,6 +2696,7 @@ in this and all call levels above this one.
 
                 # c - start continuous execution.
                 $cmd =~ /^c\b\s*([\w:]*)\s*$/ && do {
+
                     # Hey, show's over. The debugged program finished
                     # executing already.
                     end_report(), next CMD if $finished and $level <= 1;
@@ -2501,28 +2715,32 @@ in this and all call levels above this one.
 
                     # If the "subname" isn't all digits, we'll assume it
                     # is a subroutine name, and try to find it.
-                    if ($subname =~ /\D/) {    # subroutine name
-                        # Qualify it to the current package unless it's
-                        # already qualified.
+                    if ( $subname =~ /\D/ ) {    # subroutine name
+                            # Qualify it to the current package unless it's
+                            # already qualified.
                         $subname = $package . "::" . $subname
                           unless $subname =~ /::/;
+
                         # find_sub will return "file:line_number" corresponding
                         # to where the subroutine is defined; we call find_sub,
-                        # break up the return value, and assign it in one 
+                        # break up the return value, and assign it in one
                         # operation.
-                        ($file, $i) = (find_sub($subname) =~ /^(.*):(.*)$/);
+                        ( $file, $i ) = ( find_sub($subname) =~ /^(.*):(.*)$/ );
 
                         # Force the line number to be numeric.
                         $i += 0;
 
                         # If we got a line number, we found the sub.
                         if ($i) {
+
                             # Switch all the debugger's internals around so
                             # we're actually working with that file.
                             $filename = $file;
                             *dbline   = $main::{ '_<' . $filename };
+
                             # Mark that there's a breakpoint in this file.
                             $had_breakpoints{$filename} |= 1;
+
                             # Scan forward to the first executable line
                             # after the 'sub whatever' line.
                             $max = $#dbline;
@@ -2542,14 +2760,14 @@ in this and all call levels above this one.
                     # for an executable, which we may or may not have found.
                     #
                     # If $i (which we set $subname from) is non-zero, we
-                    # got a request to break at some line somewhere. On 
-                    # one hand, if there wasn't any real subroutine name 
-                    # involved, this will be a request to break in the current 
-                    # file at the specified line, so we have to check to make 
+                    # got a request to break at some line somewhere. On
+                    # one hand, if there wasn't any real subroutine name
+                    # involved, this will be a request to break in the current
+                    # file at the specified line, so we have to check to make
                     # sure that the line specified really is breakable.
                     #
                     # On the other hand, if there was a subname supplied, the
-                    # preceeding block has moved us to the proper file and
+                    # preceding block has moved us to the proper file and
                     # location within that file, and then scanned forward
                     # looking for the next executable line. We have to make
                     # sure that one was found.
@@ -2558,19 +2776,20 @@ in this and all call levels above this one.
                     # current value of $i points to a valid breakable line.
                     # Check that.
                     if ($i) {
+
                         # Breakable?
-                        if ($dbline[$i] == 0) {
+                        if ( $dbline[$i] == 0 ) {
                             print $OUT "Line $i not breakable.\n";
                             next CMD;
                         }
+
                         # Yes. Set up the one-time-break sigil.
-                        $dbline{$i} =~
-                          s/($|\0)/;9$1/;    # add one-time-only b.p.
+                        $dbline{$i} =~ s/($|\0)/;9$1/;  # add one-time-only b.p.
                     } ## end if ($i)
 
                     # Turn off stack tracing from here up.
-                    for ($i = 0 ; $i <= $stack_depth ;) {
-                        $stack[$i++] &= ~1;
+                    for ( $i = 0 ; $i <= $stack_depth ; ) {
+                        $stack[ $i++ ] &= ~1;
                     }
                     last CMD;
                 };
@@ -2587,209 +2806,15 @@ appropriately, and force us out of the command loop.
 
                 # r - return from the current subroutine.
                 $cmd =~ /^r$/ && do {
+
                     # Can't do anythign if the program's over.
                     end_report(), next CMD if $finished and $level <= 1;
+
                     # Turn on stack trace.
                     $stack[$stack_depth] |= 1;
-                    # XXX weird stack fram management? 
-                    $doret = $option{PrintRet} ? $stack_depth - 1 : -2;
-                    last CMD;
-                };
-
-=head4 C<R> - restart
 
-Restarting the debugger is a complex operation that occurs in several phases.
-First, we try to reconstruct the command line that was used to invoke Perl
-and the debugger.
-
-=cut
-
-                # R - restart execution.
-                $cmd =~ /^R$/ && do {
-                    # I may not be able to resurrect you, but here goes ...
-                    print $OUT
-"Warning: some settings and command-line options may be lost!\n";
-                    my (@script, @flags, $cl);
-
-                    # If warn was on before, turn it on again.
-                    push @flags, '-w' if $ini_warn;
-
-                    # Rebuild the -I flags that were on the initial
-                    # command line.
-                    for (@ini_INC) {
-                        push @flags, '-I', $_;
-                    }
-
-                    # Turn on taint if it was on before.
-                    push @flags, '-T' if ${^TAINT};
-
-                    # Arrange for setting the old INC:
-                    # Save the current @init_INC in the environment.
-                    set_list("PERLDB_INC", @ini_INC);
-
-                    # If this was a perl one-liner, go to the "file"
-                    # corresponding to the one-liner read all the lines
-                    # out of it (except for the first one, which is going
-                    # to be added back on again when 'perl -d' runs: that's
-                    # the 'require perl5db.pl;' line), and add them back on
-                    # to the command line to be executed.
-                    if ($0 eq '-e') {
-                        for (1 .. $#{'::_<-e'}) {  # The first line is PERL5DB
-                            chomp($cl = ${'::_<-e'}[$_]);
-                            push @script, '-e', $cl;
-                        }
-                    } ## end if ($0 eq '-e')
-
-                    # Otherwise we just reuse the original name we had 
-                    # before.
-                    else {
-                        @script = $0;
-                    }
-
-=pod
-
-After the command line  has been reconstructed, the next step is to save
-the debugger's status in environment variables. The C<DB::set_list> routine
-is used to save aggregate variables (both hashes and arrays); scalars are
-just popped into environment variables directly.
-
-=cut
-
-                    # If the terminal supported history, grab it and
-                    # save that in the environment.
-                    set_list("PERLDB_HIST",
-                        $term->Features->{getHistory}
-                        ? $term->GetHistory
-                        : @hist);
-                    # Find all the files that were visited during this
-                    # session (i.e., the debugger had magic hashes
-                    # corresponding to them) and stick them in the environment.
-                    my @had_breakpoints = keys %had_breakpoints;
-                    set_list("PERLDB_VISITED", @had_breakpoints);
-
-                    # Save the debugger options we chose.
-                    set_list("PERLDB_OPT",     %option);
-
-                    # Save the break-on-loads.
-                    set_list("PERLDB_ON_LOAD", %break_on_load);
-
-=pod 
-
-The most complex part of this is the saving of all of the breakpoints. They
-can live in an awful lot of places, and we have to go through all of them,
-find the breakpoints, and then save them in the appropriate environment
-variable via C<DB::set_list>.
-
-=cut
-
-                    # Go through all the breakpoints and make sure they're
-                    # still valid.
-                    my @hard;
-                    for (0 .. $#had_breakpoints) {
-                        # We were in this file.
-                        my $file = $had_breakpoints[$_];
-
-                        # Grab that file's magic line hash.
-                        *dbline = $main::{ '_<' . $file };
-
-                        # Skip out if it doesn't exist, or if the breakpoint
-                        # is in a postponed file (we'll do postponed ones 
-                        # later).
-                        next unless %dbline or $postponed_file{$file};
-
-                        # In an eval. This is a little harder, so we'll
-                        # do more processing on that below.
-                        (push @hard, $file), next
-                          if $file =~ /^\(\w*eval/;
-                        # XXX I have no idea what this is doing. Yet. 
-                        my @add;
-                        @add = %{ $postponed_file{$file} }
-                          if $postponed_file{$file};
-
-                        # Save the list of all the breakpoints for this file.
-                        set_list("PERLDB_FILE_$_", %dbline, @add);
-                    } ## end for (0 .. $#had_breakpoints)
-
-                    # The breakpoint was inside an eval. This is a little
-                    # more difficult. XXX and I don't understand it.
-                    for (@hard) {    
-                        # Get over to the eval in question.
-                        *dbline = $main::{ '_<' . $_ };
-                        my ($quoted, $sub, %subs, $line) = quotemeta $_;
-                        for $sub (keys %sub) {
-                            next unless $sub{$sub} =~ /^$quoted:(\d+)-(\d+)$/;
-                            $subs{$sub} = [$1, $2];
-                        }
-                        unless (%subs) {
-                            print $OUT
-                              "No subroutines in $_, ignoring breakpoints.\n";
-                            next;
-                        }
-                      LINES: for $line (keys %dbline) {
-
-                            # One breakpoint per sub only:
-                            my ($offset, $sub, $found);
-                          SUBS: for $sub (keys %subs) {
-                                if (
-                                    $subs{$sub}->[1] >=
-                                    $line    # Not after the subroutine
-                                    and (
-                                        not defined $offset    # Not caught
-                                        or $offset < 0
-                                    )
-                                  )
-                                {    # or badly caught
-                                    $found  = $sub;
-                                    $offset = $line - $subs{$sub}->[0];
-                                    $offset = "+$offset", last SUBS
-                                      if $offset >= 0;
-                                } ## end if ($subs{$sub}->[1] >=...
-                            } ## end for $sub (keys %subs)
-                            if (defined $offset) {
-                                $postponed{$found} =
-                                  "break $offset if $dbline{$line}";
-                            }
-                            else {
-                                print $OUT
-"Breakpoint in $_:$line ignored: after all the subroutines.\n";
-                            }
-                        } ## end for $line (keys %dbline)
-                    } ## end for (@hard)
-
-                    # Save the other things that don't need to be 
-                    # processed.
-                    set_list("PERLDB_POSTPONE",  %postponed);
-                    set_list("PERLDB_PRETYPE",   @$pretype);
-                    set_list("PERLDB_PRE",       @$pre);
-                    set_list("PERLDB_POST",      @$post);
-                    set_list("PERLDB_TYPEAHEAD", @typeahead);
-
-                    # We are oficially restarting.
-                    $ENV{PERLDB_RESTART} = 1;
-
-                    # We are junking all child debuggers.
-                    delete $ENV{PERLDB_PIDS};    # Restore ini state
-
-                    # Set this back to the initial pid.
-                    $ENV{PERLDB_PIDS} = $ini_pids if defined $ini_pids;
-
-=pod 
-
-After all the debugger status has been saved, we take the command we built
-up and then C<exec()> it. The debugger will spot the C<PERLDB_RESTART>
-environment variable and realize it needs to reload its state from the
-environment.
-
-=cut
-
-                    # And run Perl again. Add the "-d" flag, all the 
-                    # flags we built up, the script (whether a one-liner
-                    # or a file), add on the -emacs flag for a slave editor,
-                    # and then the old arguments. We use exec() to keep the
-                    # PID stable (and that way $ini_pids is still valid).
-                    exec($^X, '-d', @flags, @script,
-                        ($slave_editor ? '-emacs' : ()), @ARGS) ||
-                      print $OUT "exec failed: $!\n";
+                    # Print return value unless the stack is empty.
+                    $doret = $option{PrintRet} ? $stack_depth - 1 : -2;
                     last CMD;
                 };
 
@@ -2800,7 +2825,7 @@ Just calls C<DB::print_trace>.
 =cut
 
                 $cmd =~ /^T$/ && do {
-                    print_trace($OUT, 1);        # skip DB
+                    print_trace( $OUT, 1 );    # skip DB
                     next CMD;
                 };
 
@@ -2810,7 +2835,7 @@ Just calls C<DB::cmd_w>.
 
 =cut
 
-                $cmd =~ /^w\b\s*(.*)/s && do { &cmd_w('w', $1); next CMD; };
+                $cmd =~ /^w\b\s*(.*)/s && do { &cmd_w( 'w', $1 ); next CMD; };
 
 =head4 C<W> - watch-expression processing.
 
@@ -2818,7 +2843,7 @@ Just calls C<DB::cmd_W>.
 
 =cut
 
-                $cmd =~ /^W\b\s*(.*)/s && do { &cmd_W('W', $1); next CMD; };
+                $cmd =~ /^W\b\s*(.*)/s && do { &cmd_W( 'W', $1 ); next CMD; };
 
 =head4 C</> - search forward for a string in the source
 
@@ -2829,7 +2854,7 @@ mess us up.
 
 =cut
 
-                $cmd =~ /^\/(.*)$/     && do {
+                $cmd =~ /^\/(.*)$/ && do {
 
                     # The pattern as a string.
                     $inpat = $1;
@@ -2838,7 +2863,7 @@ mess us up.
                     $inpat =~ s:([^\\])/$:$1:;
 
                     # If the pattern isn't null ...
-                    if ($inpat ne "") {
+                    if ( $inpat ne "" ) {
 
                         # Turn of warn and die procesing for a bit.
                         local $SIG{__DIE__};
@@ -2846,9 +2871,10 @@ mess us up.
 
                         # Create the pattern.
                         eval '$inpat =~ m' . "\a$inpat\a";
-                        if ($@ ne "") {
+                        if ( $@ ne "" ) {
+
                             # Oops. Bad pattern. No biscuit.
-                            # Print the eval error and go back for more 
+                            # Print the eval error and go back for more
                             # commands.
                             print $OUT "$@";
                             next CMD;
@@ -2857,7 +2883,7 @@ mess us up.
                     } ## end if ($inpat ne "")
 
                     # Set up to stop on wrap-around.
-                    $end  = $start;
+                    $end = $start;
 
                     # Don't move off the current line.
                     $incr = -1;
@@ -2892,8 +2918,9 @@ mess us up.
                                 last;
                             }
                          } ';
+
                     # If we wrapped, there never was a match.
-                    print $OUT "/$pat/: not found\n" if ($start == $end);
+                    print $OUT "/$pat/: not found\n" if ( $start == $end );
                     next CMD;
                 };
 
@@ -2911,14 +2938,15 @@ Same as for C</>, except the loop runs backwards.
                     $inpat =~ s:([^\\])\?$:$1:;
 
                     # If we've got one ...
-                    if ($inpat ne "") {
+                    if ( $inpat ne "" ) {
 
                         # Turn off die & warn handlers.
                         local $SIG{__DIE__};
                         local $SIG{__WARN__};
                         eval '$inpat =~ m' . "\a$inpat\a";
 
-                        if ($@ ne "") {
+                        if ( $@ ne "" ) {
+
                             # Ouch. Not good. Print the error.
                             print $OUT $@;
                             next CMD;
@@ -2927,7 +2955,7 @@ Same as for C</>, except the loop runs backwards.
                     } ## end if ($inpat ne "")
 
                     # Where we are now is where to stop after wraparound.
-                    $end  = $start;
+                    $end = $start;
 
                     # Don't move away from this line.
                     $incr = -1;
@@ -2940,6 +2968,7 @@ Same as for C</>, except the loop runs backwards.
                             --$start;
 
                             # Wrap if we pass the first line.
+
                             $start = $max if ($start <= 0);
 
                             # Quit if we get back where we started,
@@ -2962,7 +2991,7 @@ Same as for C</>, except the loop runs backwards.
                         } ';
 
                     # Say we failed if the loop never found anything,
-                    print $OUT "?$pat?: not found\n" if ($start == $end);
+                    print $OUT "?$pat?: not found\n" if ( $start == $end );
                     next CMD;
                 };
 
@@ -2974,17 +3003,17 @@ into C<$cmd>, and redoes the loop to execute it.
 
 =cut
 
-                # $rc - recall command. 
+                # $rc - recall command.
                 $cmd =~ /^$rc+\s*(-)?(\d+)?$/ && do {
 
                     # No arguments, take one thing off history.
-                    pop (@hist) if length($cmd) > 1;
+                    pop(@hist) if length($cmd) > 1;
 
-                    # Relative (- found)? 
+                    # Relative (- found)?
                     #  Y - index back from most recent (by 1 if bare minus)
-                    #  N - go to that particular command slot or the last 
+                    #  N - go to that particular command slot or the last
                     #      thing if nothing following.
-                    $i = $1 ? ($#hist - ($2 || 1)) : ($2 || $#hist);
+                    $i = $1 ? ( $#hist - ( $2 || 1 ) ) : ( $2 || $#hist );
 
                     # Pick out the command desired.
                     $cmd = $hist[$i];
@@ -3005,6 +3034,7 @@ C<STDOUT> from getting messed up.
                 # $sh$sh - run a shell command (if it's all ASCII).
                 # Can't run shell commands with Unicode in the debugger, hmm.
                 $cmd =~ /^$sh$sh\s*([\x00-\xff]*)/ && do {
+
                     # System it.
                     &system($1);
                     next CMD;
@@ -3013,25 +3043,28 @@ C<STDOUT> from getting messed up.
 =head4 C<$rc I<pattern> $rc> - Search command history
 
 Another command to manipulate C<@hist>: this one searches it with a pattern.
-If a command is found, it is placed in C<$cmd> and executed via <redo>.
+If a command is found, it is placed in C<$cmd> and executed via C<redo>.
 
 =cut
 
-                # $rc pattern $rc - find a command in the history. 
+                # $rc pattern $rc - find a command in the history.
                 $cmd =~ /^$rc([^$rc].*)$/ && do {
+
                     # Create the pattern to use.
                     $pat = "^$1";
 
                     # Toss off last entry if length is >1 (and it always is).
-                    pop (@hist) if length($cmd) > 1;
+                    pop(@hist) if length($cmd) > 1;
 
                     # Look backward through the history.
-                    for ($i = $#hist ; $i ; --$i) {
+                    for ( $i = $#hist ; $i ; --$i ) {
+
                         # Stop if we find it.
                         last if $hist[$i] =~ /$pat/;
                     }
 
-                    if (!$i) {
+                    if ( !$i ) {
+
                         # Never found it.
                         print $OUT "No such command!\n\n";
                         next CMD;
@@ -3051,9 +3084,10 @@ Uses C<DB::system> to invoke a shell.
 
                 # $sh - start a shell.
                 $cmd =~ /^$sh$/ && do {
+
                     # Run the user's shell. If none defined, run Bourne.
                     # We resume execution when the shell terminates.
-                    &system($ENV{SHELL} || "/bin/sh");
+                    &system( $ENV{SHELL} || "/bin/sh" );
                     next CMD;
                 };
 
@@ -3066,11 +3100,12 @@ C<DB::system> to avoid problems with C<STDIN> and C<STDOUT>.
 
                 # $sh command - start a shell and run a command in it.
                 $cmd =~ /^$sh\s*([\x00-\xff]*)/ && do {
+
                     # XXX: using csh or tcsh destroys sigint retvals!
                     #&system($1);  # use this instead
 
                     # use the user's shell, or Bourne if none defined.
-                    &system($ENV{SHELL} || "/bin/sh", "-c", $1);
+                    &system( $ENV{SHELL} || "/bin/sh", "-c", $1 );
                     next CMD;
                 };
 
@@ -3080,18 +3115,25 @@ Prints the contents of C<@hist> (if any).
 
 =cut
 
+                $cmd =~ /^H\b\s*\*/ && do {
+                    @hist = @truehist = ();
+                    print $OUT "History cleansed\n";
+                    next CMD;
+                };
+
                 $cmd =~ /^H\b\s*(-(\d+))?/ && do {
-                    # Anything other than negative numbers is ignored by 
+
+                    # Anything other than negative numbers is ignored by
                     # the (incorrect) pattern, so this test does nothing.
-                    $end = $2 ? ($#hist - $2) : 0;
+                    $end = $2 ? ( $#hist - $2 ) : 0;
 
                     # Set to the minimum if less than zero.
                     $hist = 0 if $hist < 0;
 
-                    # Start at the end of the array. 
+                    # Start at the end of the array.
                     # Stay in while we're still above the ending value.
                     # Tick back by one each time around the loop.
-                    for ($i = $#hist ; $i > $end ; $i--) {
+                    for ( $i = $#hist ; $i > $end ; $i-- ) {
 
                         # Print the command  unless it has no arguments.
                         print $OUT "$i: ", $hist[$i], "\n"
@@ -3106,7 +3148,7 @@ Just calls C<runman()> to print the appropriate document.
 
 =cut
 
-                # man, perldoc, doc - show manual pages.               
+                # man, perldoc, doc - show manual pages.
                 $cmd =~ /^(?:man|(?:perl)?doc)\b(?:\s+([^(]*))?$/ && do {
                     runman($1);
                     next CMD;
@@ -3131,25 +3173,28 @@ Manipulates C<%alias> to add or list command aliases.
 
 =cut
 
-                 # = - set up a command alias.
+                # = - set up a command alias.
                 $cmd =~ s/^=\s*// && do {
                     my @keys;
-                    if (length $cmd == 0) {
+                    if ( length $cmd == 0 ) {
+
                         # No args, get current aliases.
                         @keys = sort keys %alias;
                     }
-                    elsif (my ($k, $v) = ($cmd =~ /^(\S+)\s+(\S.*)/)) {
+                    elsif ( my ( $k, $v ) = ( $cmd =~ /^(\S+)\s+(\S.*)/ ) ) {
+
                         # Creating a new alias. $k is alias name, $v is
                         # alias value.
 
                         # can't use $_ or kill //g state
-                        for my $x ($k, $v) { 
-                          # Escape "alarm" characters.
-                          $x =~ s/\a/\\a/g 
+                        for my $x ( $k, $v ) {
+
+                            # Escape "alarm" characters.
+                            $x =~ s/\a/\\a/g;
                         }
 
                         # Substitute key for value, using alarm chars
-                        # as separators (which is why we escaped them in 
+                        # as separators (which is why we escaped them in
                         # the command).
                         $alias{$k} = "s\a$k\a$v\a";
 
@@ -3158,12 +3203,14 @@ Manipulates C<%alias> to add or list command aliases.
                         local $SIG{__WARN__};
 
                         # Is it valid Perl?
-                        unless (eval "sub { s\a$k\a$v\a }; 1") {
+                        unless ( eval "sub { s\a$k\a$v\a }; 1" ) {
+
                             # Nope. Bad alias. Say so and get out.
                             print $OUT "Can't alias $k to $v: $@\n";
                             delete $alias{$k};
                             next CMD;
                         }
+
                         # We'll only list the new one.
                         @keys = ($k);
                     } ## end elsif (my ($k, $v) = ($cmd...
@@ -3175,18 +3222,22 @@ Manipulates C<%alias> to add or list command aliases.
 
                     # List aliases.
                     for my $k (@keys) {
+
                         # Messy metaquoting: Trim the substiution code off.
                         # We use control-G as the delimiter because it's not
                         # likely to appear in the alias.
-                        if ((my $v = $alias{$k}) =~ s\as\a$k\a(.*)\a$\a1\a) {
+                        if ( ( my $v = $alias{$k} ) =~ s\as\a$k\a(.*)\a$\a1\a ) {
+
                             # Print the alias.
                             print $OUT "$k\t= $1\n";
                         }
-                        elsif (defined $alias{$k}) {
+                        elsif ( defined $alias{$k} ) {
+
                             # Couldn't trim it off; just print the alias code.
                             print $OUT "$k\t$alias{$k}\n";
                         }
                         else {
+
                             # No such, dude.
                             print "No alias for $k\n";
                         }
@@ -3201,22 +3252,91 @@ pick it up.
 
 =cut
 
-                # source - read commands from a file (or pipe!) and execute. 
+                # source - read commands from a file (or pipe!) and execute.
                 $cmd =~ /^source\s+(.*\S)/ && do {
-                    if (open my $fh, $1) {
+                    if ( open my $fh, $1 ) {
+
                         # Opened OK; stick it in the list of file handles.
                         push @cmdfhs, $fh;
                     }
                     else {
-                        # Couldn't open it. 
+
+                        # Couldn't open it.
                         &warn("Can't execute `$1': $!\n");
                     }
                     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<R> - restart
+
+Restart the debugger session. 
+
+=head4 C<rerun> - rerun the current session
+
+Return to any given position in the B<true>-history list
+
+=cut
+
+                # R - restart execution.
+                # rerun - controlled restart execution.
+                $cmd =~ /^(R|rerun\s*(.*))$/ && do {
+                    my @args = ($1 eq 'R' ? restart() : rerun($2));
+
+                    # Close all non-system fds for a clean restart.  A more
+                    # correct method would be to close all fds that were not
+                    # open when the process started, but this seems to be
+                    # hard.  See "debugger 'R'estart and open database
+                    # connections" on p5p.
+
+                    my $max_fd = 1024; # default if POSIX can't be loaded
+                    if (eval { require POSIX }) {
+                        $max_fd = POSIX::sysconf(POSIX::_SC_OPEN_MAX());
+                    }
+
+                    if (defined $max_fd) {
+                        foreach ($^F+1 .. $max_fd-1) {
+                            next unless open FD_TO_CLOSE, "<&=$_";
+                            close(FD_TO_CLOSE);
+                        }
+                    }
+
+                    # And run Perl again.  We use exec() to keep the
+                    # PID stable (and that way $ini_pids is still valid).
+                    exec(@args) || print $OUT "exec failed: $!\n";
+
+                    last CMD;
+                };
+
 =head4 C<|, ||> - pipe output through the pager.
 
-FOR C<|>, we save C<OUT> (the debugger's output filehandle) and C<STDOUT>
+For C<|>, we save C<OUT> (the debugger's output filehandle) and C<STDOUT>
 (the program's standard output). For C<||>, we only save C<OUT>. We open a
 pipe to the pager (restoring the output filehandles if this fails). If this
 is the C<|> command, we also set up a C<SIGPIPE> handler which will simply 
@@ -3230,35 +3350,40 @@ reading another.
 
                 # || - run command in the pager, with output to DB::OUT.
                 $cmd =~ /^\|\|?\s*[^|]/ && do {
-                    if ($pager =~ /^\|/) {
+                    if ( $pager =~ /^\|/ ) {
+
                         # Default pager is into a pipe. Redirect I/O.
-                        open(SAVEOUT, ">&STDOUT") ||
-                          &warn("Can't save STDOUT");
-                        open(STDOUT, ">&OUT") ||
-                          &warn("Can't redirect STDOUT");
+                        open( SAVEOUT, ">&STDOUT" )
+                          || &warn("Can't save STDOUT");
+                        open( STDOUT, ">&OUT" )
+                          || &warn("Can't redirect STDOUT");
                     } ## end if ($pager =~ /^\|/)
                     else {
+
                         # Not into a pipe. STDOUT is safe.
-                        open(SAVEOUT, ">&OUT") || &warn("Can't save DB::OUT");
+                        open( SAVEOUT, ">&OUT" ) || &warn("Can't save DB::OUT");
                     }
 
                     # Fix up environment to record we have less if so.
                     fix_less();
 
-                    unless ($piped = open(OUT, $pager)) {
+                    unless ( $piped = open( OUT, $pager ) ) {
+
                         # Couldn't open pipe to pager.
                         &warn("Can't pipe output to `$pager'");
-                        if ($pager =~ /^\|/) {
+                        if ( $pager =~ /^\|/ ) {
+
                             # Redirect I/O back again.
-                            open(OUT, ">&STDOUT")    # XXX: lost message
+                            open( OUT, ">&STDOUT" )    # XXX: lost message
                               || &warn("Can't restore DB::OUT");
-                            open(STDOUT, ">&SAVEOUT") ||
-                              &warn("Can't restore STDOUT");
+                            open( STDOUT, ">&SAVEOUT" )
+                              || &warn("Can't restore STDOUT");
                             close(SAVEOUT);
                         } ## end if ($pager =~ /^\|/)
                         else {
+
                             # Redirect I/O. STDOUT already safe.
-                            open(OUT, ">&STDOUT")    # XXX: lost message
+                            open( OUT, ">&STDOUT" )    # XXX: lost message
                               || &warn("Can't restore DB::OUT");
                         }
                         next CMD;
@@ -3266,8 +3391,8 @@ reading another.
 
                     # Set up broken-pipe handler if necessary.
                     $SIG{PIPE} = \&DB::catch
-                      if $pager =~ /^\|/ &&
-                      ("" eq $SIG{PIPE} || "DEFAULT" eq $SIG{PIPE});
+                      if $pager =~ /^\|/
+                      && ( "" eq $SIG{PIPE} || "DEFAULT" eq $SIG{PIPE} );
 
                     # Save current filehandle, unbuffer out, and put it back.
                     $selected = select(OUT);
@@ -3281,7 +3406,6 @@ reading another.
                     redo PIPE;
                 };
 
-
 =head3 END OF COMMAND PARSING
 
 Anything left in C<$cmd> at this point is a Perl expression that we want to 
@@ -3302,7 +3426,7 @@ any variables we might want to address in the C<DB> package.
 
             }    # PIPE:
 
-            # Make sure the flag that says "the debugger's running" is 
+            # Make sure the flag that says "the debugger's running" is
             # still on, to make sure we get control again.
             $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd";
 
@@ -3314,7 +3438,12 @@ any variables we might want to address in the C<DB> package.
                 $onetimeDump      = undef;
                 $onetimedumpDepth = undef;
             }
-            elsif ($term_pid == $$) {
+            elsif ( $term_pid == $$ ) {
+               eval {          # May run under miniperl, when not available...
+                    STDOUT->flush();
+                    STDERR->flush();
+               };
+
                 # XXX If this is the master pid, print a newline.
                 print $OUT "\n";
             }
@@ -3332,8 +3461,10 @@ our standard filehandles for input and output.
 
             # At the end of every command:
             if ($piped) {
+
                 # Unhook the pipe mechanism now.
-                if ($pager =~ /^\|/) {
+                if ( $pager =~ /^\|/ ) {
+
                     # No error from the child.
                     $? = 0;
 
@@ -3344,24 +3475,24 @@ our standard filehandles for input and output.
                     # $? is explicitly set to 0, so this never runs.
                     if ($?) {
                         print SAVEOUT "Pager `$pager' failed: ";
-                        if ($? == -1) {
+                        if ( $? == -1 ) {
                             print SAVEOUT "shell returned -1\n";
                         }
-                        elsif ($? >> 8) {
-                            print SAVEOUT ($? & 127)
-                              ? " (SIG#" . ($? & 127) . ")"
-                              : "", ($? & 128) ? " -- core dumped" : "", "\n";
+                        elsif ( $? >> 8 ) {
+                            print SAVEOUT ( $? & 127 )
+                              ? " (SIG#" . ( $? & 127 ) . ")"
+                              : "", ( $? & 128 ) ? " -- core dumped" : "", "\n";
                         }
                         else {
-                            print SAVEOUT "status ", ($? >> 8), "\n";
+                            print SAVEOUT "status ", ( $? >> 8 ), "\n";
                         }
                     } ## end if ($?)
 
-                    # Reopen filehandle for our output (if we can) and 
+                    # Reopen filehandle for our output (if we can) and
                     # restore STDOUT (if we can).
-                    open(OUT, ">&STDOUT") || &warn("Can't restore DB::OUT");
-                    open(STDOUT, ">&SAVEOUT") ||
-                      &warn("Can't restore STDOUT");
+                    open( OUT, ">&STDOUT" ) || &warn("Can't restore DB::OUT");
+                    open( STDOUT, ">&SAVEOUT" )
+                      || &warn("Can't restore STDOUT");
 
                     # Turn off pipe exception handler if necessary.
                     $SIG{PIPE} = "DEFAULT" if $SIG{PIPE} eq \&DB::catch;
@@ -3370,8 +3501,9 @@ our standard filehandles for input and output.
                     # does SIGINT but Perl doesn't give us a choice.
                 } ## end if ($pager =~ /^\|/)
                 else {
+
                     # Non-piped "pager". Just restore STDOUT.
-                    open(OUT, ">&SAVEOUT") || &warn("Can't restore DB::OUT");
+                    open( OUT, ">&SAVEOUT" ) || &warn("Can't restore DB::OUT");
                 }
 
                 # Close filehandle pager was using, restore the normal one
@@ -3405,7 +3537,7 @@ again.
     }    # if ($single || $signal)
 
     # Put the user's globals back where you found them.
-    ($@, $!, $^E, $,, $/, $\, $^W) = @saved;
+    ( $@, $!, $^E, $,, $/, $\, $^W ) = @saved;
     ();
 } ## end sub DB
 
@@ -3434,7 +3566,7 @@ the 16 bit is set in C<$frame>).
 It also tracks the subroutine call depth by saving the current setting of
 C<$single> in the C<@stack> package global; if this exceeds the value in
 C<$deep>, C<sub> automatically turns on printing of the current depth by
-setting the 4 bit in C<$single>. In any case, it keeps the current setting
+setting the C<4> bit in C<$single>. In any case, it keeps the current setting
 of stop/don't stop on entry to subs set as it currently is set.
 
 =head3 C<caller()> support
@@ -3458,7 +3590,7 @@ The line number it was defined on
 
 =item * C<$subroutine>
 
-The subroutine name; C<'(eval)'> if an C<eval>().
+The subroutine name; C<(eval)> if an C<eval>().
 
 =item * C<$hasargs>
 
@@ -3482,7 +3614,7 @@ pragma information; subject to change between versions
 
 =item * C<$bitmask>
 
-pragma information: subject to change between versions
+pragma information; subject to change between versions
 
 =item * C<@DB::args>
 
@@ -3494,15 +3626,21 @@ arguments with which the subroutine was invoked
 
 sub sub {
 
+       # lock ourselves under threads
+       lock($DBGR);
+
     # Whether or not the autoloader was running, a scalar to put the
     # sub's return value in (if needed), and an array to put the sub's
     # return value in (if needed).
-    my ($al, $ret, @ret) = "";
+    my ( $al, $ret, @ret ) = "";
+       if ($sub =~ /^threads::new$/ && $ENV{PERL5DB_THREADED}) {
+               print "creating new thread\n"; 
+       }
 
-    # If the last ten characters are C'::AUTOLOAD', note we've traced
+    # If the last ten characters are '::AUTOLOAD', note we've traced
     # into AUTOLOAD for $sub.
-    if (length($sub) > 10 && substr($sub, -10, 10) eq '::AUTOLOAD') {
-        $al = " for $$sub";
+    if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
+        $al = " for $$sub" if defined $$sub;
     }
 
     # We stack the stack pointer and then increment it to protect us
@@ -3517,7 +3655,7 @@ sub sub {
     # Save current single-step setting.
     $stack[-1] = $single;
 
-    # Turn off all flags except single-stepping. 
+    # Turn off all flags except single-stepping.
     $single &= 1;
 
     # If we've gotten really deeply recursed, turn on the flag that will
@@ -3528,100 +3666,106 @@ sub sub {
     (
         $frame & 4    # Extended frame entry message
         ? (
-            print_lineinfo(' ' x ($stack_depth - 1), "in  "),
+            print_lineinfo( ' ' x ( $stack_depth - 1 ), "in  " ),
 
             # Why -1? But it works! :-(
             # Because print_trace will call add 1 to it and then call
             # dump_trace; this results in our skipping -1+1 = 0 stack frames
             # in dump_trace.
-            print_trace($LINEINFO, -1, 1, 1, "$sub$al")
+            print_trace( $LINEINFO, -1, 1, 1, "$sub$al" )
           )
-        : print_lineinfo(' ' x ($stack_depth - 1), "entering $sub$al\n")
+        : print_lineinfo( ' ' x ( $stack_depth - 1 ), "entering $sub$al\n" )
+
           # standard frame entry message
       )
       if $frame;
 
     # Determine the sub's return type,and capture approppriately.
     if (wantarray) {
+
         # Called in array context. call sub and capture output.
         # DB::DB will recursively get control again if appropriate; we'll come
         # back here when the sub is finished.
-        @ret = &$sub;
+       @ret = &$sub;
 
         # Pop the single-step value back off the stack.
-        $single |= $stack[$stack_depth--];
+        $single |= $stack[ $stack_depth-- ];
 
         # Check for exit trace messages...
         (
-            $frame & 4         # Extended exit message
+            $frame & 4    # Extended exit message
             ? (
-                print_lineinfo(' ' x $stack_depth, "out "),
-                print_trace($LINEINFO, -1, 1, 1, "$sub$al")
+                print_lineinfo( ' ' x $stack_depth, "out " ),
+                print_trace( $LINEINFO, -1, 1, 1, "$sub$al" )
               )
-            : print_lineinfo(' ' x $stack_depth, "exited $sub$al\n")
+            : print_lineinfo( ' ' x $stack_depth, "exited $sub$al\n" )
+
               # Standard exit message
           )
           if $frame & 2;
 
         # Print the return info if we need to.
-        if ($doret eq $stack_depth or $frame & 16) {
+        if ( $doret eq $stack_depth or $frame & 16 ) {
+
             # Turn off output record separator.
             local $\ = '';
-            my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
+            my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
 
             # Indent if we're printing because of $frame tracing.
             print $fh ' ' x $stack_depth if $frame & 16;
 
             # Print the return value.
             print $fh "list context return from $sub:\n";
-            dumpit($fh, \@ret);
+            dumpit( $fh, \@ret );
 
             # And don't print it again.
             $doret = -2;
         } ## end if ($doret eq $stack_depth...
-        # And we have to return the return value now.
+            # And we have to return the return value now.
         @ret;
-
     } ## end if (wantarray)
 
     # Scalar context.
     else {
-        if (defined wantarray) {
-            # Save the value if it's wanted at all. 
-            $ret = &$sub;
-        }
-        else {
-            # Void return, explicitly.
-            &$sub;
-            undef $ret;
-        }
+       if ( defined wantarray ) {
+
+           # Save the value if it's wanted at all.
+           $ret = &$sub;
+       }
+       else {
+
+           # Void return, explicitly.
+           &$sub;
+           undef $ret;
+       }
 
         # Pop the single-step value off the stack.
-        $single |= $stack[$stack_depth--];
+        $single |= $stack[ $stack_depth-- ];
 
         # If we're doing exit messages...
         (
-            $frame & 4                        # Extended messsages
+            $frame & 4    # Extended messsages
             ? (
-                print_lineinfo(' ' x $stack_depth, "out "),
-                print_trace($LINEINFO, -1, 1, 1, "$sub$al")
+                print_lineinfo( ' ' x $stack_depth, "out " ),
+                print_trace( $LINEINFO, -1, 1, 1, "$sub$al" )
               )
-            : print_lineinfo(' ' x $stack_depth, "exited $sub$al\n")
-                                              # Standard messages
+            : print_lineinfo( ' ' x $stack_depth, "exited $sub$al\n" )
+
+              # Standard messages
           )
           if $frame & 2;
 
         # If we are supposed to show the return value... same as before.
-        if ($doret eq $stack_depth or $frame & 16 and defined wantarray) {
+        if ( $doret eq $stack_depth or $frame & 16 and defined wantarray ) {
             local $\ = '';
-            my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
-            print $fh (' ' x $stack_depth) if $frame & 16;
+            my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
+            print $fh ( ' ' x $stack_depth ) if $frame & 16;
             print $fh (
                 defined wantarray
                 ? "scalar context return from $sub: "
                 : "void context return from $sub\n"
-                );
-            dumpit($fh, $ret) if defined wantarray;
+            );
+            dumpit( $fh, $ret ) if defined wantarray;
             $doret = -2;
         } ## end if ($doret eq $stack_depth...
 
@@ -3655,8 +3799,8 @@ The C<%set> hash defines the mapping from command letter to subroutine
 name suffix. 
 
 C<%set> is a two-level hash, indexed by set name and then by command name.
-Note that trying to set the CommandSet to 'foobar' simply results in the
-5.8.0 command set being used, since there's no top-level entry for 'foobar'.
+Note that trying to set the CommandSet to C<foobar> simply results in the
+5.8.0 command set being used, since there's no top-level entry for C<foobar>.
 
 =cut 
 
@@ -3686,14 +3830,14 @@ my %set = (    #
         '{'  => 'pre590_prepost',
         '{{' => 'pre590_prepost',
     },
-  );
+);
 
 =head2 C<cmd_wrapper()> (API)
 
 C<cmd_wrapper()> allows the debugger to switch command sets 
 depending on the value of the C<CommandSet> option. 
 
-It tries to look up the command in the X<C<%set>> package-level I<lexical>
+It tries to look up the command in the C<%set> package-level I<lexical>
 (which means external entities can't fiddle with it) and create the name of 
 the sub to call based on the value found in the hash (if it's there). I<All> 
 of the commands to be handled in a set have to be added to C<%set>; if they 
@@ -3708,7 +3852,7 @@ sub cmd_wrapper {
     my $line     = shift;
     my $dblineno = shift;
 
-    # Assemble the command subroutine's name by looking up the 
+    # Assemble the command subroutine's name by looking up the
     # command set and command name in %set. If we can't find it,
     # default to the older version of the command.
     my $call = 'cmd_'
@@ -3716,7 +3860,7 @@ sub cmd_wrapper {
           || ( $cmd =~ /^[<>{]+/o ? 'prepost' : $cmd ) );
 
     # Call the command subroutine, call it by name.
-    return &$call($cmd, $line, $dblineno);
+    return &$call( $cmd, $line, $dblineno );
 } ## end sub cmd_wrapper
 
 =head3 C<cmd_a> (command)
@@ -3728,25 +3872,27 @@ line if none is specified.
 =cut
 
 sub cmd_a {
-    my $cmd  = shift;
-    my $line = shift || '';    # [.|line] expr
+    my $cmd    = shift;
+    my $line   = shift || '';    # [.|line] expr
     my $dbline = shift;
 
     # If it's dot (here), or not all digits,  use the current line.
     $line =~ s/^(\.|(?:[^\d]))/$dbline/;
 
-    # Should be a line number followed by an expression. 
-    if ($line =~ /^\s*(\d*)\s*(\S.+)/) {
-        my ($lineno, $expr) = ($1, $2);
+    # Should be a line number followed by an expression.
+    if ( $line =~ /^\s*(\d*)\s*(\S.+)/ ) {
+        my ( $lineno, $expr ) = ( $1, $2 );
 
         # If we have an expression ...
-        if (length $expr) {
+        if ( length $expr ) {
+
             # ... but the line isn't breakable, complain.
-            if ($dbline[$lineno] == 0) {
+            if ( $dbline[$lineno] == 0 ) {
                 print $OUT
                   "Line $lineno($dbline[$lineno]) does not have an action?\n";
             }
             else {
+
                 # It's executable. Record that the line has an action.
                 $had_breakpoints{$filename} |= 2;
 
@@ -3759,6 +3905,7 @@ sub cmd_a {
         } ## end if (length $expr)
     } ## end if ($line =~ /^\s*(\d*)\s*(\S.+)/)
     else {
+
         # Syntax wrong.
         print $OUT
           "Adding an action requires an optional lineno and an expression\n"
@@ -3774,8 +3921,8 @@ subroutine, C<delete_action>.
 =cut
 
 sub cmd_A {
-    my $cmd  = shift;
-    my $line = shift || '';
+    my $cmd    = shift;
+    my $line   = shift || '';
     my $dbline = shift;
 
     # Dot is this line.
@@ -3785,21 +3932,20 @@ sub cmd_A {
     # The '1' forces the eval to be true. It'll be false only
     # if delete_action blows up for some reason, in which case
     # we print $@ and get out.
-    if ($line eq '*') {
+    if ( $line eq '*' ) {
         eval { &delete_action(); 1 } or print $OUT $@ and return;
     }
 
     # There's a real line  number. Pass it to delete_action.
     # Error trapping is as above.
-    elsif ($line =~ /^(\S.*)/) {
+    elsif ( $line =~ /^(\S.*)/ ) {
         eval { &delete_action($1); 1 } or print $OUT $@ and return;
     }
 
     # Swing and a miss. Bad syntax.
     else {
         print $OUT
-          "Deleting an action requires a line number, or '*' for all\n"
-          ;    # hint
+          "Deleting an action requires a line number, or '*' for all\n" ; # hint
     }
 } ## end sub cmd_A
 
@@ -3814,7 +3960,8 @@ will get any kind of an action, including breakpoints).
 
 sub delete_action {
     my $i = shift;
-    if (defined($i)) {
+    if ( defined($i) ) {
+
         # Can there be one?
         die "Line $i has no action .\n" if $dbline[$i] == 0;
 
@@ -3824,16 +3971,16 @@ sub delete_action {
     }
     else {
         print $OUT "Deleting all actions...\n";
-        for my $file (keys %had_breakpoints) {
+        for my $file ( keys %had_breakpoints ) {
             local *dbline = $main::{ '_<' . $file };
             my $max = $#dbline;
             my $was;
-            for ($i = 1 ; $i <= $max ; $i++) {
-                if (defined $dbline{$i}) {
+            for ( $i = 1 ; $i <= $max ; $i++ ) {
+                if ( defined $dbline{$i} ) {
                     $dbline{$i} =~ s/\0[^\0]*//;
                     delete $dbline{$i} if $dbline{$i} eq '';
                 }
-                unless ($had_breakpoints{$file} &= ~2) {
+                unless ( $had_breakpoints{$file} &= ~2 ) {
                     delete $had_breakpoints{$file};
                 }
             } ## end for ($i = 1 ; $i <= $max...
@@ -3859,28 +4006,29 @@ sub cmd_b {
     # Make . the current line number if it's there..
     $line =~ s/^\./$dbline/;
 
-    # No line number, no condition. Simple break on current line. 
-    if ($line =~ /^\s*$/) {
-        &cmd_b_line($dbline, 1);
+    # No line number, no condition. Simple break on current line.
+    if ( $line =~ /^\s*$/ ) {
+        &cmd_b_line( $dbline, 1 );
     }
 
     # Break on load for a file.
-    elsif ($line =~ /^load\b\s*(.*)/) {
+    elsif ( $line =~ /^load\b\s*(.*)/ ) {
         my $file = $1;
         $file =~ s/\s+$//;
         &cmd_b_load($file);
     }
 
     # b compile|postpone <some sub> [<condition>]
-    # The interpreter actually traps this one for us; we just put the 
+    # The interpreter actually traps this one for us; we just put the
     # necessary condition in the %postponed hash.
-    elsif ($line =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/) {
+    elsif ( $line =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/ ) {
+
         # Capture the condition if there is one. Make it true if none.
         my $cond = length $3 ? $3 : '1';
 
         # Save the sub name and set $break to 1 if $1 was 'postpone', 0
         # if it was 'compile'.
-        my ($subname, $break) = ($2, $1 eq 'postpone');
+        my ( $subname, $break ) = ( $2, $1 eq 'postpone' );
 
         # De-Perl4-ify the name - ' separators to ::.
         $subname =~ s/\'/::/g;
@@ -3889,22 +4037,24 @@ sub cmd_b {
         $subname = "${'package'}::" . $subname unless $subname =~ /::/;
 
         # Add main if it starts with ::.
-        $subname = "main" . $subname if substr($subname, 0, 2) eq "::";
+        $subname = "main" . $subname if substr( $subname, 0, 2 ) eq "::";
 
         # Save the break type for this sub.
         $postponed{$subname} = $break ? "break +0 if $cond" : "compile";
     } ## end elsif ($line =~ ...
 
     # b <sub name> [<condition>]
-    elsif ($line =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/) {
-        # 
+    elsif ( $line =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/ ) {
+
+        #
         $subname = $1;
         $cond = length $2 ? $2 : '1';
-        &cmd_b_sub($subname, $cond);
+        &cmd_b_sub( $subname, $cond );
     }
 
     # b <line> [<condition>].
-    elsif ($line =~ /^(\d*)\s*(.*)/) {
+    elsif ( $line =~ /^(\d*)\s*(.*)/ ) {
+
         # Capture the line. If none, it's the current line.
         $line = $1 || $dbline;
 
@@ -3912,7 +4062,7 @@ sub cmd_b {
         $cond = length $2 ? $2 : '1';
 
         # Break on line.
-        &cmd_b_line($line, $cond);
+        &cmd_b_line( $line, $cond );
     }
 
     # Line didn't make sense.
@@ -3962,11 +4112,12 @@ sub cmd_b_load {
     # This is a block because that way we can use a redo inside it
     # even without there being any looping structure at all outside it.
     {
+
         # Save short name and full path if found.
         push @files, $file;
         push @files, $::INC{$file} if $::INC{$file};
 
-        # Tack on .pm and do it again unless there was a '.' in the name 
+        # Tack on .pm and do it again unless there was a '.' in the name
         # already.
         $file .= '.pm', redo unless $file =~ /\./;
     }
@@ -3992,24 +4143,31 @@ worked on (if it's not the current one).
 
 We can now build functions in pairs: the basic function works on the current
 file, and uses C<$filename_error> as part of its error message. Since this is
-initialized to C<''>, no filename will appear when we are working on the
+initialized to C<"">, no filename will appear when we are working on the
 current file.
 
 The second function is a wrapper which does the following:
 
 =over 4 
 
-=item * Localizes C<$filename_error> and sets it to the name of the file to be processed.
+=item *
+
+Localizes C<$filename_error> and sets it to the name of the file to be processed.
 
-=item * Localizes the C<*dbline> glob and reassigns it to point to the file we want to process. 
+=item *
 
-=item * Calls the first function
+Localizes the C<*dbline> glob and reassigns it to point to the file we want to process
 
-The first function works on the "current" (i.e., the one we changed to) file,
+=item *
+
+Calls the first function. 
+
+The first function works on the I<current> file (i.e., the one we changed to),
 and prints C<$filename_error> in the error message (the name of the other file)
-if it needs to. When the functions return, C<*dbline> is restored to point to the actual current file (the one we're executing in) and C<$filename_error> is 
-restored to C<''>. This restores everything to the way it was before the 
-second function was called at all.
+if it needs to. When the functions return, C<*dbline> is restored to point
+to the actual current file (the one we're executing in) and
+C<$filename_error> is restored to C<"">. This restores everything to
+the way it was before the second function was called at all.
 
 See the comments in C<breakable_line> and C<breakable_line_in_file> for more
 details.
@@ -4020,7 +4178,7 @@ details.
 
 $filename_error = '';
 
-=head3 breakable_line($from, $to) (API)
+=head3 breakable_line(from, to) (API)
 
 The subroutine decides whether or not a line in the current file is breakable.
 It walks through C<@dbline> within the range of lines specified, looking for
@@ -4035,14 +4193,14 @@ first line I<before> C<$to> that's breakable, if there is one.
 =cut
 
 sub breakable_line {
-    
-    my ($from, $to) = @_;
+
+    my ( $from, $to ) = @_;
 
     # $i is the start point. (Where are the FORTRAN programs of yesteryear?)
     my $i = $from;
 
     # If there are at least 2 arguments, we're trying to search a range.
-    if (@_ >= 2) {
+    if ( @_ >= 2 ) {
 
         # $delta is positive for a forward search, negative for a backward one.
         my $delta = $from < $to ? +1 : -1;
@@ -4055,39 +4213,39 @@ sub breakable_line {
         # If $delta is positive (going forward), $limit will be $#dbline.
         #    If $to is less than $limit, ($limit - $to) will be positive, times
         #    $delta of 1 (positive), so the result is > 0 and we should use $to
-        #    as the stopping point. 
+        #    as the stopping point.
         #
         #    If $to is greater than $limit, ($limit - $to) is negative,
-        #    times $delta of 1 (positive), so the result is < 0 and we should 
+        #    times $delta of 1 (positive), so the result is < 0 and we should
         #    use $limit ($#dbline) as the stopping point.
         #
-        # If $delta is negative (going backward), $limit will be 1. 
+        # If $delta is negative (going backward), $limit will be 1.
         #    If $to is zero, ($limit - $to) will be 1, times $delta of -1
         #    (negative) so the result is > 0, and we use $to as the stopping
         #    point.
         #
         #    If $to is less than zero, ($limit - $to) will be positive,
-        #    times $delta of -1 (negative), so the result is not > 0, and 
-        #    we use $limit (1) as the stopping point. 
+        #    times $delta of -1 (negative), so the result is not > 0, and
+        #    we use $limit (1) as the stopping point.
         #
         #    If $to is 1, ($limit - $to) will zero, times $delta of -1
-        #    (negative), still giving zero; the result is not > 0, and 
+        #    (negative), still giving zero; the result is not > 0, and
         #    we use $limit (1) as the stopping point.
         #
         #    if $to is >1, ($limit - $to) will be negative, times $delta of -1
         #    (negative), giving a positive (>0) value, so we'll set $limit to
         #    $to.
-        
-        $limit = $to if ($limit - $to) * $delta > 0;
+
+        $limit = $to if ( $limit - $to ) * $delta > 0;
 
         # The real search loop.
         # $i starts at $from (the point we want to start searching from).
         # We move through @dbline in the appropriate direction (determined
-        # by $delta: either -1 (back) or +1 (ahead). 
-        # We stay in as long as we haven't hit an executable line 
+        # by $delta: either -1 (back) or +1 (ahead).
+        # We stay in as long as we haven't hit an executable line
         # ($dbline[$i] == 0 means not executable) and we haven't reached
         # the limit yet (test similar to the above).
-        $i += $delta while $dbline[$i] == 0 and ($limit - $i) * $delta > 0;
+        $i += $delta while $dbline[$i] == 0 and ( $limit - $i ) * $delta > 0;
 
     } ## end if (@_ >= 2)
 
@@ -4095,26 +4253,27 @@ sub breakable_line {
     return $i unless $dbline[$i] == 0;
 
     # Format the message and print it: no breakable lines in range.
-    my ($pl, $upto) = ('', '');
-    ($pl, $upto) = ('s', "..$to") if @_ >= 2 and $from != $to;
+    my ( $pl, $upto ) = ( '', '' );
+    ( $pl, $upto ) = ( 's', "..$to" ) if @_ >= 2 and $from != $to;
 
     # If there's a filename in filename_error, we'll see it.
     # If not, not.
     die "Line$pl $from$upto$filename_error not breakable\n";
 } ## end sub breakable_line
 
-=head3 breakable_line_in_filename($file, $from, $to) (API)
+=head3 breakable_line_in_filename(file, from, to) (API)
 
 Like C<breakable_line>, but look in another file.
 
 =cut
 
 sub breakable_line_in_filename {
+
     # Capture the file name.
     my ($f) = shift;
 
     # Swap the magic line array over there temporarily.
-    local *dbline         = $main::{ '_<' . $f };
+    local *dbline = $main::{ '_<' . $f };
 
     # If there's an error, it's in this other file.
     local $filename_error = " of `$f'";
@@ -4134,7 +4293,7 @@ specified) to the specified line. Dies if it can't.
 =cut
 
 sub break_on_line {
-    my ($i, $cond) = @_;
+    my ( $i, $cond ) = @_;
 
     # Always true if no condition supplied.
     $cond = 1 unless @_ >= 2;
@@ -4150,14 +4309,16 @@ sub break_on_line {
     # Mark this file as having breakpoints in it.
     $had_breakpoints{$filename} |= 1;
 
-    # If there is an action or condition here already ... 
-    if ($dbline{$i}) { 
+    # If there is an action or condition here already ...
+    if ( $dbline{$i} ) {
+
         # ... swap this condition for the existing one.
-        $dbline{$i} =~ s/^[^\0]*/$cond/; 
+        $dbline{$i} =~ s/^[^\0]*/$cond/;
     }
-    else { 
+    else {
+
         # Nothing here - just add the condition.
-        $dbline{$i} = $cond; 
+        $dbline{$i} = $cond;
     }
 } ## end sub break_on_line
 
@@ -4183,20 +4344,20 @@ the breakpoint.
 =cut
 
 sub break_on_filename_line {
-    my ($f, $i, $cond) = @_;
+    my ( $f, $i, $cond ) = @_;
 
     # Always true if condition left off.
     $cond = 1 unless @_ >= 3;
 
     # Switch the magical hash temporarily.
-    local *dbline         = $main::{ '_<' . $f };
+    local *dbline = $main::{ '_<' . $f };
 
     # Localize the variables that break_on_line uses to make its message.
     local $filename_error = " of `$f'";
     local $filename       = $f;
 
     # Add the breakpoint.
-    break_on_line($i, $cond);
+    break_on_line( $i, $cond );
 } ## end sub break_on_filename_line
 
 =head3 break_on_filename_line_range(file, from, to, [condition]) (API)
@@ -4207,16 +4368,16 @@ executable one, and put a breakpoint on the first one you find.
 =cut
 
 sub break_on_filename_line_range {
-    my ($f, $from, $to, $cond) = @_;
+    my ( $f, $from, $to, $cond ) = @_;
 
     # Find a breakable line if there is one.
-    my $i = breakable_line_in_filename($f, $from, $to);
+    my $i = breakable_line_in_filename( $f, $from, $to );
 
     # Always true if missing.
     $cond = 1 unless @_ >= 3;
 
     # Add the breakpoint.
-    break_on_filename_line($f, $i, $cond);
+    break_on_filename_line( $f, $i, $cond );
 } ## end sub break_on_filename_line_range
 
 =head3 subroutine_filename_lines(subname, [condition]) (API)
@@ -4227,7 +4388,7 @@ Uses C<find_sub> to locate the desired subroutine.
 =cut
 
 sub subroutine_filename_lines {
-    my ($subname, $cond) = @_;
+    my ( $subname, $cond ) = @_;
 
     # Returned value from find_sub() is fullpathname:startline-endline.
     # The match creates the list (fullpathname, start, end). Falling off
@@ -4247,7 +4408,7 @@ sub break_subroutine {
     my $subname = shift;
 
     # Get filename, start, and end.
-    my ($file, $s, $e) = subroutine_filename_lines($subname)
+    my ( $file, $s, $e ) = subroutine_filename_lines($subname)
       or die "Subroutine $subname not found.\n";
 
     # Null condition changes to '1' (always true).
@@ -4255,7 +4416,7 @@ sub break_subroutine {
 
     # Put a break the first place possible in the range of lines
     # that make up this subroutine.
-    break_on_filename_line_range($file, $s, $e, @_);
+    break_on_filename_line_range( $file, $s, $e, @_ );
 } ## end sub break_subroutine
 
 =head3 cmd_b_sub(subname, [condition]) (command)
@@ -4280,14 +4441,15 @@ breakpoint.
 =cut
 
 sub cmd_b_sub {
-    my ($subname, $cond) = @_;
+    my ( $subname, $cond ) = @_;
 
     # Add always-true condition if we have none.
     $cond = 1 unless @_ >= 2;
 
-    # If the subname isn't a code reference, qualify it so that 
+    # If the subname isn't a code reference, qualify it so that
     # break_subroutine() will work right.
-    unless (ref $subname eq 'CODE') {
+    unless ( ref $subname eq 'CODE' ) {
+
         # Not Perl4.
         $subname =~ s/\'/::/g;
         my $s = $subname;
@@ -4305,12 +4467,12 @@ sub cmd_b_sub {
           and defined &{"CORE::GLOBAL::$s"};
 
         # Put it in package 'main' if it has a leading ::.
-        $subname = "main" . $subname if substr($subname, 0, 2) eq "::";
+        $subname = "main" . $subname if substr( $subname, 0, 2 ) eq "::";
 
     } ## end unless (ref $subname eq 'CODE')
 
     # Try to set the breakpoint.
-    eval { break_subroutine($subname, $cond); 1 } or do {
+    eval { break_subroutine( $subname, $cond ); 1 } or do {
         local $\ = '';
         print $OUT $@ and return;
       }
@@ -4328,30 +4490,30 @@ thereby deleting all the breakpoints.
 =cut
 
 sub cmd_B {
-    my $cmd  = shift;
+    my $cmd = shift;
 
-    # No line spec? Use dbline. 
+    # No line spec? Use dbline.
     # If there is one, use it if it's non-zero, or wipe it out if it is.
-    my $line = ($_[0] =~ /^\./) ? $dbline : shift || '';
+    my $line   = ( $_[0] =~ /^\./ ) ? $dbline : shift || '';
     my $dbline = shift;
 
     # If the line was dot, make the line the current one.
     $line =~ s/^\./$dbline/;
 
     # If it's * we're deleting all the breakpoints.
-    if ($line eq '*') {
+    if ( $line eq '*' ) {
         eval { &delete_breakpoint(); 1 } or print $OUT $@ and return;
     }
 
     # If there is a line spec, delete the breakpoint on that line.
-    elsif ($line =~ /^(\S.*)/) {
-        eval { &delete_breakpoint($line || $dbline); 1 } or do {
+    elsif ( $line =~ /^(\S.*)/ ) {
+        eval { &delete_breakpoint( $line || $dbline ); 1 } or do {
             local $\ = '';
             print $OUT $@ and return;
         };
     } ## end elsif ($line =~ /^(\S.*)/)
 
-    # No line spec. 
+    # No line spec.
     else {
         print $OUT
           "Deleting a breakpoint requires a line number, or '*' for all\n"
@@ -4388,7 +4550,7 @@ sub delete_breakpoint {
     my $i = shift;
 
     # If we got a line, delete just that one.
-    if (defined($i)) {
+    if ( defined($i) ) {
 
         # Woops. This line wasn't breakable at all.
         die "Line $i not breakable.\n" if $dbline[$i] == 0;
@@ -4406,7 +4568,8 @@ sub delete_breakpoint {
 
         # %had_breakpoints lists every file that had at least one
         # breakpoint in it.
-        for my $file (keys %had_breakpoints) {
+        for my $file ( keys %had_breakpoints ) {
+
             # Switch to the desired file temporarily.
             local *dbline = $main::{ '_<' . $file };
 
@@ -4414,12 +4577,15 @@ sub delete_breakpoint {
             my $was;
 
             # For all lines in this file ...
-            for ($i = 1 ; $i <= $max ; $i++) {
+            for ( $i = 1 ; $i <= $max ; $i++ ) {
+
                 # If there's a breakpoint or action on this line ...
-                if (defined $dbline{$i}) {
+                if ( defined $dbline{$i} ) {
+
                     # ... remove the breakpoint.
                     $dbline{$i} =~ s/^[^\0]+//;
-                    if ($dbline{$i} =~ s/^\0?$//) {
+                    if ( $dbline{$i} =~ s/^\0?$// ) {
+
                         # Remove the entry altogether if no action is there.
                         delete $dbline{$i};
                     }
@@ -4427,9 +4593,9 @@ sub delete_breakpoint {
             } ## end for ($i = 1 ; $i <= $max...
 
             # If, after we turn off the "there were breakpoints in this file"
-            # bit, the entry in %had_breakpoints for this file is zero, 
+            # bit, the entry in %had_breakpoints for this file is zero,
             # we should remove this file from the hash.
-            if (not $had_breakpoints{$file} &= ~1) {
+            if ( not $had_breakpoints{$file} &= ~1 ) {
                 delete $had_breakpoints{$file};
             }
         } ## end for my $file (keys %had_breakpoints)
@@ -4454,51 +4620,107 @@ sub cmd_stop {    # As on ^C, but not signal-safy.
     $signal = 1;
 }
 
+=head3 C<cmd_e> - threads
+
+Display the current thread id:
+
+       e
+
+This could be how (when implemented) to send commands to this thread id (e cmd)
+or that thread id (e tid cmd).
+
+=cut
+
+sub cmd_e {
+    my $cmd  = shift;
+    my $line = shift;
+       unless (exists($INC{'threads.pm'})) {
+               print "threads not loaded($ENV{PERL5DB_THREADED})
+               please run the debugger with PERL5DB_THREADED=1 set in the environment\n";
+       } else {
+               my $tid = threads->tid;
+               print "thread id: $tid\n";
+       }
+} ## end sub cmd_e
+
+=head3 C<cmd_E> - list of thread ids
+
+Display the list of available thread ids:
+
+       E
+
+This could be used (when implemented) to send commands to all threads (E cmd).
+
+=cut
+
+sub cmd_E {
+    my $cmd  = shift;
+    my $line = shift;
+       unless (exists($INC{'threads.pm'})) { 
+               print "threads not loaded($ENV{PERL5DB_THREADED})
+               please run the debugger with PERL5DB_THREADED=1 set in the environment\n";
+       } else {
+               my $tid = threads->tid;
+               print "thread ids: ".join(', ', 
+                       map { ($tid == $_->tid ? '<'.$_->tid.'>' : $_->tid) } threads->list
+               )."\n"; 
+       }
+} ## end sub cmd_E
+
 =head3 C<cmd_h> - help command (command)
 
 Does the work of either
 
 =over 4
 
-=item * Showing all the debugger help
+=item *
+
+Showing all the debugger help
 
-=item * Showing help for a specific command
+=item *
+
+Showing help for a specific command
 
 =back
 
 =cut
 
 sub cmd_h {
-    my $cmd  = shift;
+    my $cmd = shift;
 
     # If we have no operand, assume null.
     my $line = shift || '';
 
     # 'h h'. Print the long-format help.
-    if ($line =~ /^h\s*/) {
+    if ( $line =~ /^h\s*/ ) {
         print_help($help);
     }
 
     # 'h <something>'. Search for the command and print only its help.
-    elsif ($line =~ /^(\S.*)$/) {
+    elsif ( $line =~ /^(\S.*)$/ ) {
 
         # support long commands; otherwise bogus errors
         # happen when you ask for h on <CR> for example
-        my $asked  = $1;                   # the command requested
-                                           # (for proper error message)
+        my $asked = $1;    # the command requested
+                           # (for proper error message)
 
         my $qasked = quotemeta($asked);    # for searching; we don't
                                            # want to use it as a pattern.
                                            # XXX: finds CR but not <CR>
 
         # Search the help string for the command.
-        if ($help =~ /^                    # Start of a line
+        if (
+            $help =~ /^                    # Start of a line
                       <?                   # Optional '<'
                       (?:[IB]<)            # Optional markup
                       $qasked              # The requested command
-                     /mx) {
+                     /mx
+          )
+        {
+
             # It's there; pull it out and print it.
-            while ($help =~ /^
+            while (
+                $help =~ /^
                               (<?            # Optional '<'
                                  (?:[IB]<)   # Optional markup
                                  $qasked     # The command
@@ -4506,7 +4728,9 @@ sub cmd_h {
                               \n)            # End of last description line
                               (?!\s)         # Next line not starting with 
                                              # whitespace
-                             /mgx) {
+                             /mgx
+              )
+            {
                 print_help($1);
             }
         }
@@ -4523,6 +4747,42 @@ sub cmd_h {
     }
 } ## 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 ) ) {
+            $evalarg = $isa;
+            ($isa) = &eval;
+            no strict 'refs';
+            print join(
+                ', ',
+                map {    # snaffled unceremoniously from Class::ISA
+                    "$_"
+                      . (
+                        defined( ${"$_\::VERSION"} )
+                        ? ' ' . ${"$_\::VERSION"}
+                        : undef )
+                  } Class::ISA::self_and_super_path(ref($isa) || $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
@@ -4538,34 +4798,36 @@ later.
 =cut
 
 sub cmd_l {
-    my $current_line  = shift;
-    my $line          = shift;
+    my $current_line = $line;
+    my $cmd  = shift;
+    my $line = shift;
 
     # If this is '-something', delete any spaces after the dash.
     $line =~ s/^-\s*$/-/;
 
-    # If the line is '$something', assume this is a scalar containing a 
+    # If the line is '$something', assume this is a scalar containing a
     # line number.
-    if ($line =~ /^(\$.*)/s) {
+    if ( $line =~ /^(\$.*)/s ) {
 
         # Set up for DB::eval() - evaluate in *user* context.
-        $evalarg = $2;
+        $evalarg = $1;
+        # $evalarg = $2;
         my ($s) = &eval;
 
         # Ooops. Bad scalar.
-        print($OUT "Error: $@\n"), next CMD if $@;
+        print( $OUT "Error: $@\n" ), next CMD if $@;
 
         # Good scalar. If it's a reference, find what it points to.
         $s = CvGV_name($s);
-        print($OUT "Interpreted as: $1 $s\n");
+        print( $OUT "Interpreted as: $1 $s\n" );
         $line = "$1 $s";
 
         # Call self recursively to really do the command.
-        &cmd_l('l', $s);
+        &cmd_l( 'l', $s );
     } ## end if ($line =~ /^(\$.*)/s)
 
-    # l name. Try to find a sub by that name. 
-    elsif ($line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s) {
+    # l name. Try to find a sub by that name.
+    elsif ( $line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s ) {
         my $s = $subname = $1;
 
         # De-Perl4.
@@ -4582,21 +4844,21 @@ sub cmd_l {
           and defined &{"CORE::GLOBAL::$s"};
 
         # Put leading '::' names into 'main::'.
-        $subname = "main" . $subname if substr($subname, 0, 2) eq "::";
+        $subname = "main" . $subname if substr( $subname, 0, 2 ) eq "::";
 
-        # Get name:start-stop from find_sub, and break this up at 
+        # Get name:start-stop from find_sub, and break this up at
         # colons.
-        @pieces = split (/:/, find_sub($subname) || $sub{$subname});
+        @pieces = split( /:/, find_sub($subname) || $sub{$subname} );
 
         # Pull off start-stop.
         $subrange = pop @pieces;
 
         # If the name contained colons, the split broke it up.
         # Put it back together.
-        $file     = join (':', @pieces);
+        $file = join( ':', @pieces );
 
         # If we're not in that file, switch over to it.
-        if ($file ne $filename) {
+        if ( $file ne $filename ) {
             print $OUT "Switching to file '$file'.\n"
               unless $slave_editor;
 
@@ -4609,12 +4871,13 @@ sub cmd_l {
         # Subrange is 'start-stop'. If this is less than a window full,
         # swap it to 'start+', which will list a window from the start point.
         if ($subrange) {
-            if (eval($subrange) < -$window) {
+            if ( eval($subrange) < -$window ) {
                 $subrange =~ s/-.*/+/;
             }
+
             # Call self recursively to list the range.
             $line = $subrange;
-            &cmd_l('l', $subrange);
+            &cmd_l( 'l', $subrange );
         } ## end if ($subrange)
 
         # Couldn't find it.
@@ -4624,16 +4887,19 @@ sub cmd_l {
     } ## end elsif ($line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s)
 
     # Bare 'l' command.
-    elsif ($line =~ /^\s*$/) {
+    elsif ( $line =~ /^\s*$/ ) {
+
         # Compute new range to list.
         $incr = $window - 1;
-        $line = $start . '-' . ($start + $incr);
+        $line = $start . '-' . ( $start + $incr );
+
         # Recurse to do it.
-        &cmd_l('l', $line);
+        &cmd_l( 'l', $line );
     }
 
     # l [start]+number_of_lines
-    elsif ($line =~ /^(\d*)\+(\d*)$/) {
+    elsif ( $line =~ /^(\d*)\+(\d*)$/ ) {
+
         # Don't reset start for 'l +nnn'.
         $start = $1 if $1;
 
@@ -4643,23 +4909,23 @@ sub cmd_l {
         $incr = $window - 1 unless $incr;
 
         # Create a line range we'll understand, and recurse to do it.
-        $line = $start . '-' . ($start + $incr);
-        &cmd_l('l', $line);
+        $line = $start . '-' . ( $start + $incr );
+        &cmd_l( 'l', $line );
     } ## end elsif ($line =~ /^(\d*)\+(\d*)$/)
 
     # l start-stop or l start,stop
-    elsif ($line =~ /^((-?[\d\$\.]+)([-,]([\d\$\.]+))?)?/) {
+    elsif ( $line =~ /^((-?[\d\$\.]+)([-,]([\d\$\.]+))?)?/ ) {
 
         # Determine end point; use end of file if not specified.
-        $end = (!defined $2) ? $max : ($4 ? $4 : $2);
+        $end = ( !defined $2 ) ? $max : ( $4 ? $4 : $2 );
 
         # Go on to the end, and then stop.
         $end = $max if $end > $max;
 
-        # Determine start line.  
-        $i = $2;
-        $i = $line if $i eq '.';
-        $i = 1 if $i < 1;
+        # Determine start line.
+        $i    = $2;
+        $i    = $line if $i eq '.';
+        $i    = 1 if $i < 1;
         $incr = $end - $i;
 
         # If we're running under a slave editor, force it to show the lines.
@@ -4670,23 +4936,24 @@ sub cmd_l {
 
         # We're doing it ourselves. We want to show the line and special
         # markers for:
-        # - the current line in execution 
+        # - the current line in execution
         # - whether a line is breakable or not
         # - whether a line has a break or not
         # - whether a line has an action or not
         else {
-            for (; $i <= $end ; $i++) {
+            for ( ; $i <= $end ; $i++ ) {
+
                 # Check for breakpoints and actions.
-                my ($stop, $action);
-                ($stop, $action) = split (/\0/, $dbline{$i})
+                my ( $stop, $action );
+                ( $stop, $action ) = split( /\0/, $dbline{$i} )
                   if $dbline{$i};
 
                 # ==> if this is the current line in execution,
                 # : if it's breakable.
                 $arrow =
-                  ($i == $current_line and $filename eq $filename_ini)
+                  ( $i == $current_line and $filename eq $filename_ini )
                   ? '==>'
-                  : ($dbline[$i] + 0 ? ':' : ' ');
+                  : ( $dbline[$i] + 0 ? ':' : ' ' );
 
                 # Add break and action indicators.
                 $arrow .= 'b' if $stop;
@@ -4701,7 +4968,7 @@ sub cmd_l {
 
             # Line the prompt up; print a newline if the last line listed
             # didn't have a newline.
-            print $OUT "\n" unless $dbline[$i - 1] =~ /\n$/;
+            print $OUT "\n" unless $dbline[ $i - 1 ] =~ /\n$/;
         } ## end else [ if ($slave_editor)
 
         # Save the point we last listed to in case another relative 'l'
@@ -4729,33 +4996,37 @@ Watchpoints are simpler: we just list the entries in C<@to_watch>.
 sub cmd_L {
     my $cmd = shift;
 
-    # If no argument, list everything. Pre-5.8.0 version always lists 
+    # If no argument, list everything. Pre-5.8.0 version always lists
     # everything
     my $arg = shift || 'abw';
     $arg = 'abw' unless $CommandSet eq '580';    # sigh...
 
     # See what is wanted.
-    my $action_wanted = ($arg =~ /a/) ? 1 : 0;
-    my $break_wanted  = ($arg =~ /b/) ? 1 : 0;
-    my $watch_wanted  = ($arg =~ /w/) ? 1 : 0;
+    my $action_wanted = ( $arg =~ /a/ ) ? 1 : 0;
+    my $break_wanted  = ( $arg =~ /b/ ) ? 1 : 0;
+    my $watch_wanted  = ( $arg =~ /w/ ) ? 1 : 0;
 
     # Breaks and actions are found together, so we look in the same place
     # for both.
-    if ($break_wanted or $action_wanted) {
+    if ( $break_wanted or $action_wanted ) {
+
         # Look in all the files with breakpoints...
-        for my $file (keys %had_breakpoints) {
+        for my $file ( keys %had_breakpoints ) {
+
             # Temporary switch to this file.
             local *dbline = $main::{ '_<' . $file };
 
             # Set up to look through the whole file.
             my $max = $#dbline;
-            my $was;                         # Flag: did we print something
-                                             # in this file?
+            my $was;    # Flag: did we print something
+                        # in this file?
 
             # For each line in the file ...
-            for ($i = 1 ; $i <= $max ; $i++) {
+            for ( $i = 1 ; $i <= $max ; $i++ ) {
+
                 # We've got something on this line.
-                if (defined $dbline{$i}) {
+                if ( defined $dbline{$i} ) {
+
                     # Print the header if we haven't.
                     print $OUT "$file:\n" unless $was++;
 
@@ -4763,7 +5034,7 @@ sub cmd_L {
                     print $OUT " $i:\t", $dbline[$i];
 
                     # Pull out the condition and the action.
-                    ($stop, $action) = split (/\0/, $dbline{$i});
+                    ( $stop, $action ) = split( /\0/, $dbline{$i} );
 
                     # Print the break if there is one and it's wanted.
                     print $OUT "   break if (", $stop, ")\n"
@@ -4783,10 +5054,10 @@ sub cmd_L {
     } ## end if ($break_wanted or $action_wanted)
 
     # Look for breaks in not-yet-compiled subs:
-    if (%postponed and $break_wanted) {
+    if ( %postponed and $break_wanted ) {
         print $OUT "Postponed breakpoints in subroutines:\n";
         my $subname;
-        for $subname (keys %postponed) {
+        for $subname ( keys %postponed ) {
             print $OUT " $subname\t$postponed{$subname}\n";
             last if $signal;
         }
@@ -4798,16 +5069,16 @@ sub cmd_L {
     } keys %postponed_file;
 
     # If there are any, list them.
-    if (@have and ($break_wanted or $action_wanted)) {
+    if ( @have and ( $break_wanted or $action_wanted ) ) {
         print $OUT "Postponed breakpoints in files:\n";
-        my ($file, $line);
+        my ( $file, $line );
 
-        for $file (keys %postponed_file) {
+        for $file ( keys %postponed_file ) {
             my $db = $postponed_file{$file};
             print $OUT " $file:\n";
-            for $line (sort { $a <=> $b } keys %$db) {
+            for $line ( sort { $a <=> $b } keys %$db ) {
                 print $OUT "  $line:\n";
-                my ($stop, $action) = split (/\0/, $$db{$line});
+                my ( $stop, $action ) = split( /\0/, $$db{$line} );
                 print $OUT "    break if (", $stop, ")\n"
                   if $stop
                   and $break_wanted;
@@ -4819,16 +5090,16 @@ sub cmd_L {
             last if $signal;
         } ## end for $file (keys %postponed_file)
     } ## end if (@have and ($break_wanted...
-    if (%break_on_load and $break_wanted) {
+    if ( %break_on_load and $break_wanted ) {
         print $OUT "Breakpoints on load:\n";
         my $file;
-        for $file (keys %break_on_load) {
+        for $file ( keys %break_on_load ) {
             print $OUT " $file\n";
             last if $signal;
         }
     } ## end if (%break_on_load and...
     if ($watch_wanted) {
-        if ($trace & 2) {
+        if ( $trace & 2 ) {
             print $OUT "Watch-expressions:\n" if @to_watch;
             for my $expr (@to_watch) {
                 print $OUT " $expr\n";
@@ -4861,7 +5132,7 @@ sub cmd_o {
     my $opt = shift || '';    # opt[=val]
 
     # Nonblank. Try to parse and process.
-    if ($opt =~ /^(\S.*)/) {
+    if ( $opt =~ /^(\S.*)/ ) {
         &parse_options($1);
     }
 
@@ -4901,21 +5172,22 @@ sub cmd_v {
     # this pattern will match whether or not a numeric line is specified,
     # which means that we'll always enter this loop (though a non-numeric
     # argument results in no action at all)).
-    if ($line =~ /^(\d*)$/) {
+    if ( $line =~ /^(\d*)$/ ) {
+
         # Total number of lines to list (a windowful).
         $incr = $window - 1;
 
         # Set the start to the argument given (if there was one).
-       $start = $1 if $1;
+        $start = $1 if $1;
 
         # Back up by the context amount.
         $start -= $preview;
 
         # Put together a linespec that cmd_l will like.
-        $line = $start . '-' . ($start + $incr);
+        $line = $start . '-' . ( $start + $incr );
 
         # List the lines.
-        &cmd_l('l', $line);
+        &cmd_l( 'l', $line );
     } ## end if ($line =~ /^(\d*)$/)
 } ## end sub cmd_v
 
@@ -4932,13 +5204,14 @@ of any of the expressions changes.
 =cut
 
 sub cmd_w {
-    my $cmd  = shift;
+    my $cmd = shift;
 
     # Null expression if no arguments.
     my $expr = shift || '';
 
     # If expression is not null ...
-    if ($expr =~ /^(\S.*)/) {
+    if ( $expr =~ /^(\S.*)/ ) {
+
         # ... save it.
         push @to_watch, $expr;
 
@@ -4946,8 +5219,8 @@ sub cmd_w {
         # in the user's context. This version can handle expressions which
         # return a list value.
         $evalarg = $expr;
-        my ($val) = join(' ', &eval);
-        $val = (defined $val) ? "'$val'" : 'undef';
+        my ($val) = join( ' ', &eval );
+        $val = ( defined $val ) ? "'$val'" : 'undef';
 
         # Save the current value of the expression.
         push @old_watch, $val;
@@ -4958,8 +5231,7 @@ sub cmd_w {
 
     # You have to give one to get one.
     else {
-        print $OUT
-          "Adding a watch-expression requires an expression\n";    # hint
+        print $OUT "Adding a watch-expression requires an expression\n";  # hint
     }
 } ## end sub cmd_w
 
@@ -4975,7 +5247,7 @@ watch expressions.
 If an expression (or partial expression) is specified, we pattern-match
 through the expressions and remove the ones that match. We also discard
 the corresponding values. If no watch expressions are left, we turn off 
-the 'watching expressions' bit.
+the I<watching expressions> bit.
 
 =cut
 
@@ -4984,7 +5256,8 @@ sub cmd_W {
     my $expr = shift || '';
 
     # Delete them all.
-    if ($expr eq '*') {
+    if ( $expr eq '*' ) {
+
         # Not watching now.
         $trace &= ~2;
 
@@ -4995,7 +5268,8 @@ sub cmd_W {
     }
 
     # Delete one of them.
-    elsif ($expr =~ /^(\S.*)/) {
+    elsif ( $expr =~ /^(\S.*)/ ) {
+
         # Where we are in the list.
         my $i_cnt = 0;
 
@@ -5004,26 +5278,25 @@ sub cmd_W {
             my $val = $to_watch[$i_cnt];
 
             # Does this one match the command argument?
-            if ($val eq $expr) {    # =~ m/^\Q$i$/) {
-                # Yes. Turn it off.
-                splice(@to_watch, $i_cnt, 1);
-                # We ought to kill the value too, oughtn't we?
-                # But we don't. XXX This is a bug.
+            if ( $val eq $expr ) {    # =~ m/^\Q$i$/) {
+                                      # Yes. Turn it off, and its value too.
+                splice( @to_watch,  $i_cnt, 1 );
+                splice( @old_watch, $i_cnt, 1 );
             }
             $i_cnt++;
         } ## end foreach (@to_watch)
 
-        # We probably should see if they're all gone. But we don't.
-        # No bug shows up for this because the 'check watch expressions'
-        # code iterates over the @to_watch array. Since it's empty, nothing
-        # untoward happens.
+        # We don't bother to turn watching off because
+        #  a) we don't want to stop calling watchfunction() it it exists
+        #  b) foreach over a null list doesn't do anything anyway
+
     } ## end elsif ($expr =~ /^(\S.*)/)
 
     # No command arguments entered.
     else {
         print $OUT
-"Deleting a watch-expression requires an expression, or '*' for all\n"
-          ;                         # hint
+          "Deleting a watch-expression requires an expression, or '*' for all\n"
+          ;    # hint
     }
 } ## end sub cmd_W
 
@@ -5042,15 +5315,16 @@ and installs the versions we like better.
 =cut
 
 sub save {
-    # Save eval failure, command failure, extended OS error, output field 
-    # separator, input record separator, output record separator and 
+
+    # Save eval failure, command failure, extended OS error, output field
+    # separator, input record separator, output record separator and
     # the warning setting.
-    @saved = ($@, $!, $^E, $,, $/, $\, $^W);
+    @saved = ( $@, $!, $^E, $,, $/, $\, $^W );
 
-    $,     = "";             # output field separator is null string
-    $/     = "\n";           # input record separator is newline
-    $\     = "";             # output record separator is null string
-    $^W    = 0;              # warnings are off
+    $,  = "";      # output field separator is null string
+    $/  = "\n";    # input record separator is newline
+    $\  = "";      # output record separator is null string
+    $^W = 0;       # warnings are off
 } ## end sub save
 
 =head2 C<print_lineinfo> - show where we are now
@@ -5063,6 +5337,7 @@ debugger output.
 =cut
 
 sub print_lineinfo {
+
     # Make the terminal sensible if we're not the primary debugger.
     resetterm(1) if $LINEINFO eq $OUT and $term_pid != $$;
     local $\ = '';
@@ -5084,19 +5359,22 @@ we set the breakpoint on it, deleting the breakpoint from C<%postponed>.
 # The following takes its argument via $evalarg to preserve current @_
 
 sub postponed_sub {
+
     # Get the subroutine name.
     my $subname = shift;
 
     # If this is a 'break +<n> if <condition>' ...
-    if ($postponed{$subname} =~ s/^break\s([+-]?\d+)\s+if\s//) {
+    if ( $postponed{$subname} =~ s/^break\s([+-]?\d+)\s+if\s// ) {
+
         # If there's no offset, use '+0'.
         my $offset = $1 || 0;
 
         # find_sub's value is 'fullpath-filename:start-stop'. It's
         # possible that the filename might have colons in it too.
-        my ($file, $i) = (find_sub($subname) =~ /^(.*):(\d+)-.*$/);
+        my ( $file, $i ) = ( find_sub($subname) =~ /^(.*):(\d+)-.*$/ );
         if ($i) {
-            # We got the start line. Add the offset '+<n>' from 
+
+            # We got the start line. Add the offset '+<n>' from
             # $postponed{subname}.
             $i += $offset;
 
@@ -5104,7 +5382,7 @@ sub postponed_sub {
             local *dbline = $main::{ '_<' . $file };
 
             # No warnings, please.
-            local $^W     = 0;                         # != 0 is magical below
+            local $^W = 0;    # != 0 is magical below
 
             # This file's got a breakpoint in it.
             $had_breakpoints{$file} |= 1;
@@ -5127,7 +5405,7 @@ sub postponed_sub {
         }
         return;
     } ## end if ($postponed{$subname...
-    elsif ($postponed{$subname} eq 'compile') { $signal = 1 }
+    elsif ( $postponed{$subname} eq 'compile' ) { $signal = 1 }
 
     #print $OUT "In postponed_sub for `$subname'.\n";
 } ## end sub postponed_sub
@@ -5147,13 +5425,15 @@ If it's a subroutine, the incoming parameter is the subroutine name.
 =cut
 
 sub postponed {
+
     # If there's a break, process it.
     if ($ImmediateStop) {
+
         # Right, we've stopped. Turn it off.
         $ImmediateStop = 0;
 
         # Enter the command loop when DB::DB gets called.
-        $signal        = 1;
+        $signal = 1;
     }
 
     # If this is a subroutine, let postponed_sub() deal with it.
@@ -5166,7 +5446,7 @@ sub postponed {
     local $\ = '';
     $signal = 1, print $OUT "'$filename' loaded...\n"
       if $break_on_load{$filename};
-    print_lineinfo(' ' x $stack_depth, "Package $filename.\n") if $frame;
+    print_lineinfo( ' ' x $stack_depth, "Package $filename.\n" ) if $frame;
 
     # Do we have any breakpoints to put in this file?
     return unless $postponed_file{$filename};
@@ -5178,12 +5458,13 @@ sub postponed {
     # breakpoints saved in %postponed_file into %dbline by assigning
     # the whole hash; we have to do it one item at a time for the
     # breakpoints to be set properly.
-    #%dbline = %{$postponed_file{$filename}}; 
+    #%dbline = %{$postponed_file{$filename}};
 
     # Set the breakpoints, one at a time.
     my $key;
 
-    for $key (keys %{ $postponed_file{$filename} }) {
+    for $key ( keys %{ $postponed_file{$filename} } ) {
+
         # Stash the saved breakpoint into the current file's magic line array.
         $dbline{$key} = ${ $postponed_file{$filename} }{$key};
     }
@@ -5211,7 +5492,7 @@ prevent return values from being shown.
 
 C<dumpit()> then checks to see if it needs to load C<dumpvar.pl> and 
 tries to load it (note: if you have a C<dumpvar.pl>  ahead of the 
-installed version in @INC, yours will be used instead. Possible security 
+installed version in C<@INC>, yours will be used instead. Possible security 
 problem?).
 
 It then checks to see if the subroutine C<main::dumpValue> is now defined
@@ -5233,6 +5514,7 @@ and we then return to the caller.
 =cut
 
 sub dumpit {
+
     # Save the current output filehandle and switch to the one
     # passed in as the first parameter.
     local ($savout) = select(shift);
@@ -5247,20 +5529,20 @@ sub dumpit {
     local $doret = -2;
 
     # Load dumpvar.pl unless we've already got the sub we need from it.
-    unless (defined &main::dumpValue) {
-        do 'dumpvar.pl';
+    unless ( defined &main::dumpValue ) {
+        do 'dumpvar.pl' or die $@;
     }
 
     # If the load succeeded (or we already had dumpvalue()), go ahead
     # and dump things.
-    if (defined &main::dumpValue) {
+    if ( defined &main::dumpValue ) {
         local $\ = '';
         local $, = '';
         local $" = ' ';
         my $v = shift;
         my $maxdepth = shift || $option{dumpDepth};
         $maxdepth = -1 unless defined $maxdepth;    # -1 means infinite depth
-        &main::dumpValue($v, $maxdepth);
+        &main::dumpValue( $v, $maxdepth );
     } ## end if (defined &main::dumpValue)
 
     # Oops, couldn't load dumpvar.pl.
@@ -5288,13 +5570,21 @@ Parameters:
 
 =over 4
 
-=item * The filehandle to print to.
+=item *
+
+The filehandle to print to.
 
-=item * How many frames to skip before starting trace.
+=item *
 
-=item * How many frames to print.
+How many frames to skip before starting trace.
 
-=item * A flag: if true, print a "short" trace without filenames, line numbers, or arguments
+=item *
+
+How many frames to print.
+
+=item *
+
+A flag: if true, print a I<short> trace without filenames, line numbers, or arguments
 
 =back
 
@@ -5308,27 +5598,29 @@ correct if this routine is called in a tied method.
 sub print_trace {
     local $\ = '';
     my $fh = shift;
+
     # If this is going to a slave editor, but we're not the primary
     # debugger, reset it first.
     resetterm(1)
-      if $fh eq $LINEINFO          # slave editor
-      and $LINEINFO eq $OUT        # normal output
-      and $term_pid != $$;         # not the primary
+      if $fh        eq $LINEINFO    # slave editor
+      and $LINEINFO eq $OUT         # normal output
+      and $term_pid != $$;          # not the primary
 
     # Collect the actual trace information to be formatted.
     # This is an array of hashes of subroutine call info.
-    my @sub = dump_trace($_[0] + 1, $_[1]);
+    my @sub = dump_trace( $_[0] + 1, $_[1] );
 
     # Grab the "short report" flag from @_.
-    my $short = $_[2];    # Print short report, next one for sub name
+    my $short = $_[2];              # Print short report, next one for sub name
 
     # Run through the traceback info, format it, and print it.
     my $s;
-    for ($i = 0 ; $i <= $#sub ; $i++) {
+    for ( $i = 0 ; $i <= $#sub ; $i++ ) {
+
         # Drop out if the user has lost interest and hit control-C.
         last if $signal;
 
-        # Set the separator so arrys print nice. 
+        # Set the separator so arrys print nice.
         local $" = ', ';
 
         # Grab and stringify the arguments if they are there.
@@ -5336,8 +5628,9 @@ sub print_trace {
           defined $sub[$i]{args}
           ? "(@{ $sub[$i]{args} })"
           : '';
+
         # Shorten them up if $maxtrace says they're too long.
-        $args = (substr $args, 0, $maxtrace - 3) . '...'
+        $args = ( substr $args, 0, $maxtrace - 3 ) . '...'
           if length $args > $maxtrace;
 
         # Get the file name.
@@ -5348,19 +5641,19 @@ sub print_trace {
 
         # Get the actual sub's name, and shorten to $maxtrace's requirement.
         $s = $sub[$i]{sub};
-        $s = (substr $s, 0, $maxtrace - 3) . '...' if length $s > $maxtrace;
+        $s = ( substr $s, 0, $maxtrace - 3 ) . '...' if length $s > $maxtrace;
 
         # Short report uses trimmed file and sub names.
         if ($short) {
             my $sub = @_ >= 4 ? $_[3] : $s;
-            print $fh
-              "$sub[$i]{context}=$sub$args from $file:$sub[$i]{line}\n";
+            print $fh "$sub[$i]{context}=$sub$args from $file:$sub[$i]{line}\n";
         } ## end if ($short)
 
         # Non-short report includes full names.
         else {
-            print $fh "$sub[$i]{context} = $s$args" . " called from $file" .
-              " line $sub[$i]{line}\n";
+            print $fh "$sub[$i]{context} = $s$args"
+              . " called from $file"
+              . " line $sub[$i]{line}\n";
         }
     } ## end for ($i = 0 ; $i <= $#sub...
 } ## end sub print_trace
@@ -5406,19 +5699,19 @@ sub dump_trace {
     my $count = shift || 1e9;
 
     # We increment skip because caller(1) is the first level *back* from
-    # the current one.  Add $skip to the count of frames so we have a 
+    # the current one.  Add $skip to the count of frames so we have a
     # simple stop criterion, counting from $skip to $count+$skip.
     $skip++;
     $count += $skip;
 
     # These variables are used to capture output from caller();
-    my ($p, $file, $line, $sub, $h, $context);
+    my ( $p, $file, $line, $sub, $h, $context );
 
-    my ($e, $r, @a, @sub, $args);
+    my ( $e, $r, @a, @sub, $args );
 
     # XXX Okay... why'd we do that?
     my $nothard = not $frame & 8;
-    local $frame = 0;    
+    local $frame = 0;
 
     # Do not want to trace this.
     my $otrace = $trace;
@@ -5433,7 +5726,7 @@ sub dump_trace {
     for (
         $i = $skip ;
         $i < $count
-        and ($p, $file, $line, $sub, $h, $context, $e, $r) = caller($i) ;
+        and ( $p, $file, $line, $sub, $h, $context, $e, $r ) = caller($i) ;
         $i++
       )
     {
@@ -5442,17 +5735,17 @@ sub dump_trace {
         @a = ();
         for $arg (@args) {
             my $type;
-            if (not defined $arg) {                    # undefined parameter
+            if ( not defined $arg ) {    # undefined parameter
                 push @a, "undef";
             }
 
-            elsif ($nothard and tied $arg) {           # tied parameter
+            elsif ( $nothard and tied $arg ) {    # tied parameter
                 push @a, "tied";
             }
-            elsif ($nothard and $type = ref $arg) {    # reference
+            elsif ( $nothard and $type = ref $arg ) {    # reference
                 push @a, "ref($type)";
             }
-            else {                                     # can be stringified
+            else {                                       # can be stringified
                 local $_ =
                   "$arg";    # Safe to stringify now - should not call f().
 
@@ -5470,15 +5763,15 @@ sub dump_trace {
                 # Turn control characters into ^-whatever.
                 s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
 
-                push (@a, $_);
+                push( @a, $_ );
             } ## end else [ if (not defined $arg)
         } ## end for $arg (@args)
 
         # If context is true, this is array (@)context.
         # If context is false, this is scalar ($) context.
-        # If neither, context isn't defined. (This is apparently a 'can't 
+        # If neither, context isn't defined. (This is apparently a 'can't
         # happen' trap.)
-        $context = $context ? '@' : (defined $context ? "\$" : '.');
+        $context = $context ? '@' : ( defined $context ? "\$" : '.' );
 
         # if the sub has args ($h true), make an anonymous array of the
         # dumped args.
@@ -5486,7 +5779,7 @@ sub dump_trace {
 
         # remove trailing newline-whitespace-semicolon-end of line sequence
         # from the eval text, if any.
-        $e =~ s/\n\s*\;\s*\Z//  if $e;
+        $e =~ s/\n\s*\;\s*\Z// if $e;
 
         # Escape backslashed single-quotes again if necessary.
         $e =~ s/([\\\'])/\\$1/g if $e;
@@ -5495,19 +5788,20 @@ sub dump_trace {
         if ($r) {
             $sub = "require '$e'";
         }
+
         # if it's false, the eval text is really from an eval.
-        elsif (defined $r) {
+        elsif ( defined $r ) {
             $sub = "eval '$e'";
         }
 
         # If the sub is '(eval)', this is a block eval, meaning we don't
         # know what the eval'ed text actually was.
-        elsif ($sub eq '(eval)') {
+        elsif ( $sub eq '(eval)' ) {
             $sub = "eval {...}";
         }
 
         # Stick the collected information into @sub as an anonymous hash.
-        push (
+        push(
             @sub,
             {
                 context => $context,
@@ -5516,7 +5810,7 @@ sub dump_trace {
                 file    => $file,
                 line    => $line
             }
-            );
+        );
 
         # Stop processing frames if the user hit control-C.
         last if $signal;
@@ -5539,7 +5833,8 @@ without a trailing backslash.
 sub action {
     my $action = shift;
 
-    while ($action =~ s/\\$//) {
+    while ( $action =~ s/\\$// ) {
+
         # We have a backslash on the end. Read more.
         $action .= &gets;
     } ## end while ($action =~ s/\\$//)
@@ -5554,7 +5849,7 @@ This routine mostly just packages up a regular expression to be used
 to check that the thing it's being matched against has properly-matched
 curly braces.
 
-Of note is the definition of the $balanced_brace_re global via ||=, which
+Of note is the definition of the C<$balanced_brace_re> global via C<||=>, which
 speeds things up by only creating the qr//'ed expression once; if it's 
 already defined, we don't try to define it again. A speed hack.
 
@@ -5579,7 +5874,7 @@ sub unbalanced {
 
 C<gets()> is a primitive (very primitive) routine to read continuations.
 It was devised for reading continuations for actions.
-it just reads more input with X<C<readline()>> and returns it.
+it just reads more input with C<readline()> and returns it.
 
 =cut
 
@@ -5603,29 +5898,29 @@ sub system {
 
     # We save, change, then restore STDIN and STDOUT to avoid fork() since
     # some non-Unix systems can do system() but have problems with fork().
-    open(SAVEIN,  "<&STDIN")  || &warn("Can't save STDIN");
-    open(SAVEOUT, ">&STDOUT") || &warn("Can't save STDOUT");
-    open(STDIN,   "<&IN")     || &warn("Can't redirect STDIN");
-    open(STDOUT,  ">&OUT")    || &warn("Can't redirect STDOUT");
+    open( SAVEIN,  "<&STDIN" )  || &warn("Can't save STDIN");
+    open( SAVEOUT, ">&STDOUT" ) || &warn("Can't save STDOUT");
+    open( STDIN,   "<&IN" )     || &warn("Can't redirect STDIN");
+    open( STDOUT,  ">&OUT" )    || &warn("Can't redirect STDOUT");
 
     # XXX: using csh or tcsh destroys sigint retvals!
     system(@_);
-    open(STDIN,  "<&SAVEIN")  || &warn("Can't restore STDIN");
-    open(STDOUT, ">&SAVEOUT") || &warn("Can't restore STDOUT");
+    open( STDIN,  "<&SAVEIN" )  || &warn("Can't restore STDIN");
+    open( STDOUT, ">&SAVEOUT" ) || &warn("Can't restore STDOUT");
     close(SAVEIN);
     close(SAVEOUT);
 
     # most of the $? crud was coping with broken cshisms
-    if ($? >> 8) {
-        &warn("(Command exited ", ($? >> 8), ")\n");
+    if ( $? >> 8 ) {
+        &warn( "(Command exited ", ( $? >> 8 ), ")\n" );
     }
     elsif ($?) {
         &warn(
             "(Command died of SIG#",
-            ($? & 127),
-            (($? & 128) ? " -- core dumped" : ""),
+            ( $? & 127 ),
+            ( ( $? & 128 ) ? " -- core dumped" : "" ),
             ")", "\n"
-            );
+        );
     } ## end elsif ($?)
 
     return $?;
@@ -5653,6 +5948,7 @@ the appropriate attributes. We then
 =cut
 
 sub setterm {
+
     # Load Term::Readline, but quietly; don't debug it and don't trace it.
     local $frame = 0;
     local $doret = -2;
@@ -5661,10 +5957,10 @@ sub setterm {
     # If noTTY is set, but we have a TTY name, go ahead and hook up to it.
     if ($notty) {
         if ($tty) {
-            my ($i, $o) = split $tty, /,/;
+            my ( $i, $o ) = split $tty, /,/;
             $o = $i unless defined $o;
-            open(IN,  "<$i") or die "Cannot open TTY `$i' for read: $!";
-            open(OUT, ">$o") or die "Cannot open TTY `$o' for write: $!";
+            open( IN,  "<$i" ) or die "Cannot open TTY `$i' for read: $!";
+            open( OUT, ">$o" ) or die "Cannot open TTY `$o' for write: $!";
             $IN  = \*IN;
             $OUT = \*OUT;
             my $sel = select($OUT);
@@ -5675,9 +5971,10 @@ sub setterm {
         # We don't have a TTY - try to find one via Term::Rendezvous.
         else {
             eval "require Term::Rendezvous;" or die;
+
             # See if we have anything to pass to Term::Rendezvous.
-            # Use /tmp/perldbtty$$ if not.
-            my $rv = $ENV{PERLDB_NOTTY} || "/tmp/perldbtty$$";
+            # Use $HOME/.perldbtty$$ if not.
+            my $rv = $ENV{PERLDB_NOTTY} || "$ENV{HOME}/.perldbtty$$";
 
             # Rendezvous and get the filehandles.
             my $term_rv = new Term::Rendezvous $rv;
@@ -5686,14 +5983,13 @@ sub setterm {
         } ## end else [ if ($tty)
     } ## end if ($notty)
 
-
     # We're a daughter debugger. Try to fork off another TTY.
-    if ($term_pid eq '-1') {    # In a TTY with another debugger
+    if ( $term_pid eq '-1' ) {    # In a TTY with another debugger
         resetterm(2);
     }
 
     # If we shouldn't use Term::ReadLine, don't.
-    if (!$rl) {
+    if ( !$rl ) {
         $term = new Term::ReadLine::Stub 'perldb', $IN, $OUT;
     }
 
@@ -5704,7 +6000,7 @@ sub setterm {
         $rl_attribs = $term->Attribs;
         $rl_attribs->{basic_word_break_characters} .= '-:+/*,[])}'
           if defined $rl_attribs->{basic_word_break_characters}
-          and index($rl_attribs->{basic_word_break_characters}, ":") == -1;
+          and index( $rl_attribs->{basic_word_break_characters}, ":" ) == -1;
         $rl_attribs->{special_prefixes} = '$@&%';
         $rl_attribs->{completer_word_break_characters} .= '$@&%';
         $rl_attribs->{completion_function} = \&db_complete;
@@ -5716,7 +6012,9 @@ sub setterm {
 
     $term->MinLine(2);
 
-    if ($term->Features->{setHistory} and "@hist" ne "?") {
+    &load_hist();
+
+    if ( $term->Features->{setHistory} and "@hist" ne "?" ) {
         $term->SetHistory(@hist);
     }
 
@@ -5726,6 +6024,34 @@ sub setterm {
     $term_pid = $$;
 } ## end sub setterm
 
+sub load_hist {
+    $histfile //= option_val("HistFile", undef);
+    return unless defined $histfile;
+    open my $fh, "<", $histfile or return;
+    local $/ = "\n";
+    @hist = ();
+    while (<$fh>) {
+        chomp;
+        push @hist, $_;
+    }
+    close $fh;
+}
+
+sub save_hist {
+    return unless defined $histfile;
+    eval { require File::Path } or return;
+    eval { require File::Basename } or return;
+    File::Path::mkpath(File::Basename::dirname($histfile));
+    open my $fh, ">", $histfile or die "Could not open '$histfile': $!";
+    $histsize //= option_val("HistSize",100);
+    my @copy = grep { $_ ne '?' } @hist;
+    my $start = scalar(@copy) > $histsize ? scalar(@copy)-$histsize : 0;
+    for ($start .. $#copy) {
+        print $fh "$copy[$_]\n";
+    }
+    close $fh or die "Could not write '$histfile': $!";
+}
+
 =head1 GET_FORK_TTY EXAMPLE FUNCTIONS
 
 When the process being debugged forks, or the process invokes a command
@@ -5739,9 +6065,10 @@ is tasked with doing all the necessary operating system mojo to get a new
 TTY (and probably another window) and to direct the new debugger to read and
 write there.
 
-The debugger provides C<get_fork_TTY> functions which work for X Windows and
-OS/2. Other systems are not supported. You are encouraged to write 
-C<get_fork_TTY> functions which work for I<your> platform and contribute them.
+The debugger provides C<get_fork_TTY> functions which work for X Windows,
+OS/2, and Mac OS X. Other systems are not supported. You are encouraged
+to write C<get_fork_TTY> functions which work for I<your> platform
+and contribute them.
 
 =head3 C<xterm_get_fork_TTY>
 
@@ -5762,7 +6089,7 @@ properly set up.
 =cut
 
 sub xterm_get_fork_TTY {
-    (my $name = $0) =~ s,^.*[/\\],,s;
+    ( my $name = $0 ) =~ s,^.*[/\\],,s;
     open XT,
 qq[3>&1 xterm -title "Daughter Perl debugger $pids $name" -e sh -c 'tty 1>&3;\
  sleep 10000000' |];
@@ -5784,67 +6111,108 @@ XXX It behooves an OS/2 expert to write the necessary documentation for this!
 =cut
 
 # This example function resets $IN, $OUT itself
-sub os2_get_fork_TTY {
-    local $^F = 40;     # XXXX Fixme!
+my $c_pipe = 0;
+sub os2_get_fork_TTY { # A simplification of the following (and works without):
     local $\  = '';
-    my ($in1, $out1, $in2, $out2);
-
-    # Having -d in PERL5OPT would lead to a disaster...
-    local $ENV{PERL5OPT} = $ENV{PERL5OPT} if $ENV{PERL5OPT};
-    $ENV{PERL5OPT} =~ s/(?:^|(?<=\s))-d\b//  if $ENV{PERL5OPT};
-    $ENV{PERL5OPT} =~ s/(?:^|(?<=\s))-d\B/-/ if $ENV{PERL5OPT};
-    print $OUT "Making kid PERL5OPT->`$ENV{PERL5OPT}'.\n" if $ENV{PERL5OPT};
-    local $ENV{PERL5LIB} = $ENV{PERL5LIB} ? $ENV{PERL5LIB} : $ENV{PERLLIB};
-    $ENV{PERL5LIB} = '' unless defined $ENV{PERL5LIB};
-    $ENV{PERL5LIB} = join ';', @ini_INC, split /;/, $ENV{PERL5LIB};
-    (my $name = $0) =~ s,^.*[/\\],,s;
-    my @args;
-
-    if (
-            pipe $in1, $out1
-        and pipe $in2, $out2
-
-        # system P_SESSION will fail if there is another process
-        # in the same session with a "dependent" asynchronous child session.
-        and @args = (
-            $rl, fileno $in1, fileno $out2,
-            "Daughter Perl debugger $pids $name"
-        )
-        and (
-            ($kpid = CORE::system 4, $^X, '-we',
-                <<'ES', @args) >= 0    # P_SESSION
-END {sleep 5 unless $loaded}
-BEGIN {open STDIN,  '</dev/con' or warn "reopen stdin: $!"}
-use OS2::Process;
-
-my ($rl, $in) = (shift, shift);        # Read from $in and pass through
-set_title pop;
-system P_NOWAIT, $^X, '-we', <<EOS or die "Cannot start a grandkid";
-  open IN, '<&=$in' or die "open <&=$in: \$!";
-  \$| = 1; print while sysread IN, \$_, 1<<16;
-EOS
-
-my $out = shift;
-open OUT, ">&=$out" or die "Cannot open &=$out for writing: $!";
-select OUT;    $| = 1;
-require Term::ReadKey if $rl;
-Term::ReadKey::ReadMode(4) if $rl; # Nodelay on kbd.  Pipe is automatically nodelay...
-print while sysread STDIN, $_, 1<<($rl ? 16 : 0);
-ES
-            or warn "system P_SESSION: $!, $^E" and 0
-        )
-        and close $in1
-        and close $out2
-      )
-    {
-        $pidprompt = '';    # Shown anyway in titlebar
-        reset_IN_OUT($in2, $out1);
-        $tty = '*reset*';
-        return '';          # Indicate that reset_IN_OUT is called
-    } ## end if (pipe $in1, $out1 and...
-    return;
+    ( my $name = $0 ) =~ s,^.*[/\\],,s;
+    my %opt = (        title => "Daughter Perl debugger $pids $name",
+               ($rl ? (read_by_key => 1) : ()) );
+    require OS2::Process;
+    my ($in, $out, $pid) = eval { OS2::Process::io_term(related => 0, %opt) }
+      or return;
+    $pidprompt = '';    # Shown anyway in titlebar
+    reset_IN_OUT($in, $out);
+    $tty = '*reset*';
+    return '';          # Indicate that reset_IN_OUT is called
 } ## end sub os2_get_fork_TTY
 
+=head3 C<macosx_get_fork_TTY>
+
+The Mac OS X version uses AppleScript to tell Terminal.app to create
+a new window.
+
+=cut
+
+# Notes about Terminal.app's AppleScript support,
+# (aka things that might break in future OS versions).
+#
+# The "do script" command doesn't return a reference to the new window
+# it creates, but since it appears frontmost and windows are enumerated
+# front to back, we can use "first window" === "window 1".
+#
+# Since "do script" is implemented by supplying the argument (plus a
+# return character) as terminal input, there's a potential race condition
+# where the debugger could beat the shell to reading the command.
+# To prevent this, we wait for the screen to clear before proceeding.
+#
+# 10.3 and 10.4:
+# There's no direct accessor for the tty device name, so we fiddle
+# with the window title options until it says what we want.
+#
+# 10.5:
+# There _is_ a direct accessor for the tty device name, _and_ there's
+# a new possible component of the window title (the name of the settings
+# set).  A separate version is needed.
+
+my @script_versions=
+
+    ([237, <<'__LEOPARD__'],
+tell application "Terminal"
+    do script "clear;exec sleep 100000"
+    tell first tab of first window
+        copy tty to thetty
+        set custom title to "forked perl debugger"
+        set title displays custom title to true
+        repeat while (length of first paragraph of (get contents)) > 0
+            delay 0.1
+        end repeat
+    end tell
+end tell
+thetty
+__LEOPARD__
+
+     [100, <<'__JAGUAR_TIGER__'],
+tell application "Terminal"
+    do script "clear;exec sleep 100000"
+    tell first window
+        set title displays shell path to false
+        set title displays window size to false
+        set title displays file name to false
+        set title displays device name to true
+        set title displays custom title to true
+        set custom title to ""
+        copy "/dev/" & name to thetty
+        set custom title to "forked perl debugger"
+        repeat while (length of first paragraph of (get contents)) > 0
+            delay 0.1
+        end repeat
+    end tell
+end tell
+thetty
+__JAGUAR_TIGER__
+
+);
+
+sub macosx_get_fork_TTY
+{
+    my($version,$script,$pipe,$tty);
+
+    return unless $version=$ENV{TERM_PROGRAM_VERSION};
+    foreach my $entry (@script_versions) {
+       if ($version>=$entry->[0]) {
+           $script=$entry->[1];
+           last;
+       }
+    }
+    return unless defined($script);
+    return unless open($pipe,'-|','/usr/bin/osascript','-e',$script);
+    $tty=readline($pipe);
+    close($pipe);
+    return unless defined($tty) && $tty =~ m(^/dev/);
+    chomp $tty;
+    return $tty;
+}
+
 =head2 C<create_IN_OUT($flags)>
 
 Create a new pair of filehandles, pointing to a new TTY. If impossible,
@@ -5870,10 +6238,10 @@ sub create_IN_OUT {    # Create a window with IN/OUT handles redirected there
     # the TTY name if get_fork_TTY works.
     my $in = &get_fork_TTY if defined &get_fork_TTY;
 
-    # It used to be that 
+    # It used to be that
     $in = $fork_TTY if defined $fork_TTY;    # Backward compatibility
 
-    if (not defined $in) {
+    if ( not defined $in ) {
         my $why = shift;
 
         # We don't know how.
@@ -5893,16 +6261,17 @@ EOP
 
 EOP
         print_help(<<EOP);
-  I know how to switch the output to a different window in xterms
-  and OS/2 consoles only.  For a manual switch, put the name of the created I<TTY>
-  in B<\$DB::fork_TTY>, or define a function B<DB::get_fork_TTY()> returning this.
+  I know how to switch the output to a different window in xterms, OS/2
+  consoles, and Mac OS X Terminal.app only.  For a manual switch, put the name
+  of the created I<TTY> in B<\$DB::fork_TTY>, or define a function
+  B<DB::get_fork_TTY()> returning this.
 
   On I<UNIX>-like systems one can get the name of a I<TTY> for the given window
   by typing B<tty>, and disconnect the I<shell> from I<TTY> by B<sleep 1000000>.
 
 EOP
     } ## end if (not defined $in)
-    elsif ($in ne '') {
+    elsif ( $in ne '' ) {
         TTY($in);
     }
     else {
@@ -5930,7 +6299,7 @@ and try to do that.
 
 =cut
 
-sub resetterm {           # We forked, so we need a different TTY
+sub resetterm {    # We forked, so we need a different TTY
 
     # Needs to be passed to create_IN_OUT() as well.
     my $in = shift;
@@ -5953,7 +6322,7 @@ sub resetterm {           # We forked, so we need a different TTY
     $pidprompt = $pids;
 
     # We now 0wnz this terminal.
-    $term_pid  = $$;
+    $term_pid = $$;
 
     # Just return if we're not supposed to try to create a new TTY.
     return unless $CreateTTY & $in;
@@ -5986,11 +6355,12 @@ sub readline {
 
     # Pull a line out of the typeahead if there's stuff there.
     if (@typeahead) {
+
         # How many lines left.
         my $left = @typeahead;
 
         # Get the next line.
-        my $got  = shift @typeahead;
+        my $got = shift @typeahead;
 
         # Print a message saying we got input from the typeahead.
         local $\ = '';
@@ -6003,30 +6373,37 @@ sub readline {
         return $got;
     } ## end if (@typeahead)
 
-    # We really need to read some input. Turn off entry/exit trace and 
+    # We really need to read some input. Turn off entry/exit trace and
     # return value printing.
     local $frame = 0;
     local $doret = -2;
 
     # If there are stacked filehandles to read from ...
     while (@cmdfhs) {
+
         # Read from the last one in the stack.
-        my $line = CORE::readline($cmdfhs[-1]);
+        my $line = CORE::readline( $cmdfhs[-1] );
+
         # If we got a line ...
         defined $line
-          ? (print $OUT ">> $line" and return $line)  # Echo and return
-          : close pop @cmdfhs;                        # Pop and close
+          ? ( print $OUT ">> $line" and return $line )    # Echo and return
+          : close pop @cmdfhs;                            # Pop and close
     } ## end while (@cmdfhs)
 
     # Nothing on the filehandle stack. Socket?
-    if (ref $OUT and UNIVERSAL::isa($OUT, 'IO::Socket::INET')) {
+    if ( ref $OUT and UNIVERSAL::isa( $OUT, 'IO::Socket::INET' ) ) {
+
         # Send anyting we have to send.
-        $OUT->write(join ('', @_));
+        $OUT->write( join( '', @_ ) );
 
         # Receive anything there is to receive.
-        my $stuff;
-        $IN->recv($stuff, 2048);    # XXX "what's wrong with sysread?"
-                                    # XXX Don't know. You tell me.
+        $stuff;
+        my $stuff = '';
+        my $buf;
+        do {
+            $IN->recv( $buf = '', 2048 );   # XXX "what's wrong with sysread?"
+                                            # XXX Don't know. You tell me.
+        } while length $buf and ($stuff .= $buf) !~ /\n/;
 
         # What we got.
         $stuff;
@@ -6051,12 +6428,19 @@ its value.
 =cut
 
 sub dump_option {
-    my ($opt, $val) = @_;
-    $val = option_val($opt, 'N/A');
+    my ( $opt, $val ) = @_;
+    $val = option_val( $opt, 'N/A' );
     $val =~ s/([\\\'])/\\$1/g;
     printf $OUT "%20s = '%s'\n", $opt, $val;
 } ## end sub dump_option
 
+sub options2remember {
+    foreach my $k (@RememberOnROptions) {
+        $option{$k} = option_val( $k, 'N/A' );
+    }
+    return %option;
+}
+
 =head2 C<option_val> - find the current value of an option
 
 This can't just be a simple hash lookup because of the indirect way that
@@ -6068,13 +6452,14 @@ You must supply a default value to be used in case the option isn't set.
 =cut
 
 sub option_val {
-    my ($opt, $default) = @_;
+    my ( $opt, $default ) = @_;
     my $val;
 
     # Does this option exist, and is it a variable?
     # If so, retrieve the value via the value in %optionVars.
     if (    defined $optionVars{$opt}
-        and defined ${ $optionVars{$opt} }) {
+        and defined ${ $optionVars{$opt} } )
+    {
         $val = ${ $optionVars{$opt} };
     }
 
@@ -6082,14 +6467,15 @@ sub option_val {
     # If so, call the subroutine via the ref in %optionAction
     # and capture the value.
     elsif ( defined $optionAction{$opt}
-        and defined &{ $optionAction{$opt} }) {
+        and defined &{ $optionAction{$opt} } )
+    {
         $val = &{ $optionAction{$opt} }();
     }
 
     # If there's an action or variable for the supplied option,
     # but no value was set, use the default.
     elsif (defined $optionAction{$opt} and not defined $option{$opt}
-        or defined $optionVars{$opt} and not defined ${ $optionVars{$opt} })
+        or defined $optionVars{$opt} and not defined ${ $optionVars{$opt} } )
     {
         $val = $default;
     }
@@ -6109,11 +6495,11 @@ sub option_val {
 
 Handles the parsing and execution of option setting/displaying commands.
 
-An option entered by itself is assumed to be 'set me to 1' (the default value)
+An option entered by itself is assumed to be I<set me to 1> (the default value)
 if the option is a boolean one. If not, the user is prompted to enter a valid
-value or to query the current value (via 'option? ').
+value or to query the current value (via C<option? >).
 
-If 'option=value' is entered, we try to extract a quoted string from the
+If C<option=value> is entered, we try to extract a quoted string from the
 value (if it is quoted). If it's not, we just use the whole value as-is.
 
 We load any modules required to service this option, and then we set it: if
@@ -6131,10 +6517,10 @@ sub parse_options {
     local $\ = '';
 
     # These options need a value. Don't allow them to be clobbered by accident.
-    my %opt_needs_val = map { ($_ => 1) } qw{
+    my %opt_needs_val = map { ( $_ => 1 ) } qw{
       dumpDepth arrayDepth hashDepth LineInfo maxTraceLen ornaments windowSize
-      pager quote ReadLine recallCommand RemotePort ShellBang TTY
-      };
+      pager quote ReadLine recallCommand RemotePort ShellBang TTY CommandSet
+    };
 
     while (length) {
         my $val_defaulted;
@@ -6144,14 +6530,20 @@ sub parse_options {
 
         # Options are always all word characters, followed by a non-word
         # separator.
-        s/^(\w+)(\W?)// or print($OUT "Invalid option `$_'\n"), last;
-        my ($opt, $sep) = ($1, $2);
+        s/^(\w+)(\W?)// or print( $OUT "Invalid option `$_'\n" ), last;
+        my ( $opt, $sep ) = ( $1, $2 );
 
+        # Make sure that such an option exists.
+        my $matches = grep( /^\Q$opt/ && ( $option = $_ ), @options )
+          || grep( /^\Q$opt/i && ( $option = $_ ), @options );
+
+        print( $OUT "Unknown option `$opt'\n" ), next unless $matches;
+        print( $OUT "Ambiguous option `$opt'\n" ), next if $matches > 1;
         my $val;
 
         # '?' as separator means query, but must have whitespace after it.
-        if ("?" eq $sep) {
-            print($OUT "Option query `$opt?' followed by non-space `$_'\n"),
+        if ( "?" eq $sep ) {
+            print( $OUT "Option query `$opt?' followed by non-space `$_'\n" ),
               last
               if /^\S/;
 
@@ -6160,22 +6552,21 @@ sub parse_options {
 
         # Separator is whitespace (or just a carriage return).
         # They're going for a default, which we assume is 1.
-        elsif ($sep !~ /\S/) {
+        elsif ( $sep !~ /\S/ ) {
             $val_defaulted = 1;
-            $val           = "1"; #  this is an evil default; make 'em set it!
+            $val           = "1";   #  this is an evil default; make 'em set it!
         }
 
         # Separator is =. Trying to set a value.
-        elsif ($sep eq "=") {
+        elsif ( $sep eq "=" ) {
+
             # If quoted, extract a quoted string.
             if (s/ (["']) ( (?: \\. | (?! \1 ) [^\\] )* ) \1 //x) {
                 my $quote = $1;
-                ($val = $2) =~ s/\\([$quote\\])/$1/g;
+                ( $val = $2 ) =~ s/\\([$quote\\])/$1/g;
             }
 
             # Not quoted. Use the whole thing. Warn about 'option='.
-            # XXX Spurious messages about clearing nonexistent options
-            # XXX can be created, e.g., 'o googleWhack='. 
             else {
                 s/^(\S*)//;
                 $val = $1;
@@ -6185,26 +6576,18 @@ sub parse_options {
 
         } ## end elsif ($sep eq "=")
 
-        # "Quoted" with [], <>, or {}.  
+        # "Quoted" with [], <>, or {}.
         else {    #{ to "let some poor schmuck bounce on the % key in B<vi>."
-            my ($end) = "\\" . substr(")]>}$sep", index("([<{", $sep), 1);  #}
+            my ($end) =
+              "\\" . substr( ")]>}$sep", index( "([<{", $sep ), 1 );    #}
             s/^(([^\\$end]|\\[\\$end])*)$end($|\s+)//
-              or print($OUT "Unclosed option value `$opt$sep$_'\n"), last;
-            ($val = $1) =~ s/\\([\\$end])/$1/g;
+              or print( $OUT "Unclosed option value `$opt$sep$_'\n" ), last;
+            ( $val = $1 ) =~ s/\\([\\$end])/$1/g;
         } ## end else [ if ("?" eq $sep)
 
-        my $option;
-
-        # Make sure that such an option exists.
-        my $matches = grep(/^\Q$opt/ && ($option = $_), @options) ||
-          grep(/^\Q$opt/i && ($option = $_), @options);
-
-        print($OUT "Unknown option `$opt'\n"), next unless $matches;
-        print($OUT "Ambiguous option `$opt'\n"), next if $matches > 1;
-
         # Exclude non-booleans from getting set to 1 by default.
-        if ($opt_needs_val{$option} && $val_defaulted) {
-            my $cmd = ($CommandSet eq '580') ? 'o' : 'O';
+        if ( $opt_needs_val{$option} && $val_defaulted ) {
+            my $cmd = ( $CommandSet eq '580' ) ? 'o' : 'O';
             print $OUT
 "Option `$opt' is non-boolean.  Use `$cmd $option=VAL' to set, `$cmd $option?' to query\n";
             next;
@@ -6220,20 +6603,20 @@ sub parse_options {
                 require '$optionRequire{$option}';
                 1;
                } || die    # XXX: shouldn't happen
-          if defined $optionRequire{$option} &&
-             defined $val;
+          if defined $optionRequire{$option}
+          && defined $val;
 
-        # Set it. 
+        # Set it.
         # Stick it in the proper variable if it goes in a variable.
         ${ $optionVars{$option} } = $val
-          if defined $optionVars{$option} &&
-          defined $val;
+          if defined $optionVars{$option}
+          && defined $val;
 
         # Call the appropriate sub if it gets set via sub.
         &{ $optionAction{$option} }($val)
-          if defined $optionAction{$option} &&
-          defined &{ $optionAction{$option} } &&
-          defined $val;
+          if defined $optionAction{$option}
+          && defined &{ $optionAction{$option} }
+          && defined $val;
 
         # Not initialization - echo the value we set it to.
         dump_option($option) unless $OUT eq \*STDERR;
@@ -6255,7 +6638,7 @@ then as hexadecimal values.
 =cut
 
 sub set_list {
-    my ($stem, @list) = @_;
+    my ( $stem, @list ) = @_;
     my $val;
 
     # VAR_n: how many we have. Scalar assignment gets the number of items.
@@ -6263,7 +6646,7 @@ sub set_list {
 
     # Grab each item in the list, escape the backslashes, encode the non-ASCII
     # as hex, and then save in the appropriate VAR_0, VAR_1, etc.
-    for $i (0 .. $#list) {
+    for $i ( 0 .. $#list ) {
         $val = $list[$i];
         $val =~ s/\\/\\\\/g;
         $val =~ s/([\0-\37\177\200-\377])/"\\0x" . unpack('H2',$1)/eg;
@@ -6283,7 +6666,7 @@ sub get_list {
     my @list;
     my $n = delete $ENV{"${stem}_n"};
     my $val;
-    for $i (0 .. $n - 1) {
+    for $i ( 0 .. $n - 1 ) {
         $val = delete $ENV{"${stem}_$i"};
         $val =~ s/\\((\\)|0x(..))/ $2 ? $2 : pack('H2', $3) /ge;
         push @list, $val;
@@ -6298,7 +6681,7 @@ sub get_list {
 The C<catch()> subroutine is the essence of fast and low-impact. We simply
 set an already-existing global scalar variable to a constant value. This 
 avoids allocating any memory possibly in the middle of something that will
-get all confused if we do.
+get all confused if we do, particularly under I<unsafe signals>.
 
 =cut
 
@@ -6320,7 +6703,7 @@ assumptions about what filehandles are available.
 =cut
 
 sub warn {
-    my ($msg) = join ("", @_);
+    my ($msg) = join( "", @_ );
     $msg .= ": $!\n" unless $msg =~ /\n$/;
     local $\ = '';
     print $OUT $msg;
@@ -6340,9 +6723,9 @@ sub reset_IN_OUT {
     my $switch_li = $LINEINFO eq $OUT;
 
     # If there's a term and it's able to get a new tty, try to get one.
-    if ($term and $term->Features->{newTTY}) {
-        ($IN, $OUT) = (shift, shift);
-        $term->newTTY($IN, $OUT);
+    if ( $term and $term->Features->{newTTY} ) {
+        ( $IN, $OUT ) = ( shift, shift );
+        $term->newTTY( $IN, $OUT );
     }
 
     # This term can't get a new tty now. Better luck later.
@@ -6352,7 +6735,7 @@ sub reset_IN_OUT {
 
     # Set the filehndles up as they were.
     else {
-        ($IN, $OUT) = (shift, shift);
+        ( $IN, $OUT ) = ( shift, shift );
     }
 
     # Unbuffer the output filehandle.
@@ -6382,27 +6765,43 @@ we go ahead and set C<$console> and C<$tty> to the file indicated.
 =cut
 
 sub TTY {
-    if (@_ and $term and $term->Features->{newTTY}) {
+
+    # With VMS we can get here with $term undefined, so we do not
+    # switch to this terminal.  There may be a better place to make
+    # sure that $term is defined on VMS
+    if ( @_ and ($^O eq 'VMS') and !defined($term) ) {
+       eval { require Term::ReadLine } or die $@;
+        if ( !$rl ) {
+           $term = new Term::ReadLine::Stub 'perldb', $IN, $OUT;
+       }
+       else {
+           $term = new Term::ReadLine 'perldb', $IN, $OUT;
+       }
+    }
+    if ( @_ and $term and $term->Features->{newTTY} ) {
+
         # This terminal supports switching to a new TTY.
         # Can be a list of two files, or on string containing both names,
         # comma-separated.
         # XXX Should this perhaps be an assignment from @_?
-        my ($in, $out) = shift; 
-        if ($in =~ /,/) {
+        my ( $in, $out ) = shift;
+        if ( $in =~ /,/ ) {
+
             # Split list apart if supplied.
-            ($in, $out) = split /,/, $in, 2;
+            ( $in, $out ) = split /,/, $in, 2;
         }
         else {
+
             # Use the same file for both input and output.
             $out = $in;
         }
 
         # Open file onto the debugger's filehandles, if you can.
-        open IN, $in or die "cannot open `$in' for read: $!";
+        open IN,  $in     or die "cannot open `$in' for read: $!";
         open OUT, ">$out" or die "cannot open `$out' for write: $!";
 
         # Swap to the new filehandles.
-        reset_IN_OUT(\*IN, \*OUT);
+        reset_IN_OUT( \*IN, \*OUT );
 
         # Save the setting for later.
         return $tty = $in;
@@ -6411,7 +6810,7 @@ sub TTY {
     # Terminal doesn't support new TTY, or doesn't support readline.
     # Can't do it now, try restarting.
     &warn("Too late to set TTY, enabled on next `R'!\n") if $term and @_;
-    
+
     # Useful if done through PERLDB_OPTS:
     $console = $tty = shift if @_;
 
@@ -6438,7 +6837,7 @@ sub noTTY {
 =head2 C<ReadLine>
 
 Sets the C<$rl> option variable. If 0, we use C<Term::ReadLine::Stub> 
-(essentially, no C<readline> processing on this "terminal"). Otherwise, we
+(essentially, no C<readline> processing on this I<terminal>). Otherwise, we
 use C<Term::ReadLine>. Can't be changed after a terminal's in place; we save
 the value in case a restart is done so we can change it then.
 
@@ -6476,7 +6875,7 @@ false. Returns false if the current terminal doesn't support C<readline>.
 =cut
 
 sub tkRunning {
-    if (${ $term->Features }{tkRunning}) {
+    if ( ${ $term->Features }{tkRunning} ) {
         return $term->tkRunning(@_);
     }
     else {
@@ -6502,6 +6901,15 @@ sub NonStop {
     $runnonstop;
 } ## end sub NonStop
 
+sub DollarCaretP {
+    if ($term) {
+        &warn("Some flag changes could not take effect until next 'R'!\n")
+          if @_;
+    }
+    $^P = parse_DollarCaretP_flags(shift) if @_;
+    expand_DollarCaretP_flags($^P);
+}
+
 =head2 C<pager>
 
 Set up the C<$pager> variable. Adds a pipe to the front unless there's one
@@ -6534,10 +6942,10 @@ sub shellBang {
     }
 
     # Generate the printable version for the help:
-    $psh = $sh;                       # copy it
-    $psh =~ s/\\b$//;                 # Take off trailing \b if any
-    $psh =~ s/\\(.)/$1/g;             # De-escape
-    $psh;                             # return the printable version
+    $psh = $sh;    # copy it
+    $psh =~ s/\\b$//;        # Take off trailing \b if any
+    $psh =~ s/\\(.)/$1/g;    # De-escape
+    $psh;                    # return the printable version
 } ## end sub shellBang
 
 =head2 C<ornaments>
@@ -6549,9 +6957,10 @@ ornaments.)
 =cut 
 
 sub ornaments {
-    if (defined $term) {
+    if ( defined $term ) {
+
         # We don't want to show warning backtraces, but we do want die() ones.
-        local ($warnLevel, $dieLevel) = (0, 1);
+        local ( $warnLevel, $dieLevel ) = ( 0, 1 );
 
         # No ornaments if the terminal doesn't support them.
         return '' unless $term->Features->{ornaments};
@@ -6581,10 +6990,10 @@ sub recallCommand {
     }
 
     # Build it into a printable version.
-    $prc = $rc;                             # Copy it
-    $prc =~ s/\\b$//;                       # Remove trailing \b
-    $prc =~ s/\\(.)/$1/g;                   # Remove escapes
-    $prc;                                   # Return the printable version
+    $prc = $rc;    # Copy it
+    $prc =~ s/\\b$//;        # Remove trailing \b
+    $prc =~ s/\\(.)/$1/g;    # Remove escapes
+    $prc;                    # Return the printable version
 } ## end sub recallCommand
 
 =head2 C<LineInfo> - where the line number information goes
@@ -6601,15 +7010,15 @@ sub LineInfo {
     return $lineinfo unless @_;
     $lineinfo = shift;
 
-    #  If this is a valid "thing to be opened for output", tack a 
+    #  If this is a valid "thing to be opened for output", tack a
     # '>' onto the front.
-    my $stream = ($lineinfo =~ /^(\+?\>|\|)/) ? $lineinfo : ">$lineinfo";
+    my $stream = ( $lineinfo =~ /^(\+?\>|\|)/ ) ? $lineinfo : ">$lineinfo";
 
     # If this is a pipe, the stream points to a slave editor.
-    $slave_editor = ($stream =~ /^\|/);
+    $slave_editor = ( $stream =~ /^\|/ );
 
     # Open it up and unbuffer it.
-    open(LINEINFO, "$stream") || &warn("Cannot open `$stream' for write");
+    open( LINEINFO, "$stream" ) || &warn("Cannot open `$stream' for write");
     $LINEINFO = \*LINEINFO;
     my $save = select($LINEINFO);
     $| = 1;
@@ -6626,18 +7035,19 @@ These subroutines provide functionality for various commands.
 =head2 C<list_modules>
 
 For the C<M> command: list modules loaded and their versions.
-Essentially just runs through the keys in %INC, picks up the 
-$VERSION package globals from each package, gets the file name, and formats the
-information for output.
+Essentially just runs through the keys in %INC, picks each package's
+C<$VERSION> variable, gets the file name, and formats the information
+for output.
 
 =cut
 
 sub list_modules {    # versions
     my %version;
     my $file;
+
     # keys are the "as-loaded" name, values are the fully-qualified path
     # to the file itself.
-    for (keys %INC) {
+    for ( keys %INC ) {
         $file = $_;                                # get the module name
         s,\.p[lm]$,,i;                             # remove '.pl' or '.pm'
         s,/,::,g;                                  # change '/' to '::'
@@ -6647,7 +7057,7 @@ sub list_modules {    # versions
 
         # If the package has a $VERSION package global (as all good packages
         # should!) decode it and save as partial message.
-        if (defined ${ $_ . '::VERSION' }) {
+        if ( defined ${ $_ . '::VERSION' } ) {
             $version{$file} = "${ $_ . '::VERSION' } from ";
         }
 
@@ -6656,7 +7066,7 @@ sub list_modules {    # versions
     } ## end for (keys %INC)
 
     # Hey, dumpit() formats a hash nicely, so why not use it?
-    dumpit($OUT, \%version);
+    dumpit( $OUT, \%version );
 } ## end sub list_modules
 
 =head2 C<sethelp()>
@@ -6665,14 +7075,15 @@ Sets up the monster string used to format and print the help.
 
 =head3 HELP MESSAGE FORMAT
 
-The help message is a peculiar format unto itself; it mixes C<pod> 'ornaments'
-(BE<lt>E<gt>, IE<gt>E<lt>) with tabs to come up with a format that's fairly
+The help message is a peculiar format unto itself; it mixes C<pod> I<ornaments>
+(C<< B<> >> C<< I<> >>) with tabs to come up with a format that's fairly
 easy to parse and portable, but which still allows the help to be a little
 nicer than just plain text.
 
-Essentially, you define the command name (usually marked up with BE<gt>E<lt>
-and IE<gt>E<lt>), followed by a tab, and then the descriptive text, ending in a newline. The descriptive text can also be marked up in the same way. If you 
-need to continue the descriptive text to another line, start that line with 
+Essentially, you define the command name (usually marked up with C<< B<> >>
+and C<< I<> >>), followed by a tab, and then the descriptive text, ending in a
+newline. The descriptive text can also be marked up in the same way. If you
+need to continue the descriptive text to another line, start that line with
 just tabs and then enter the marked-up text.
 
 If you are modifying the help text, I<be careful>. The help-string parser is 
@@ -6692,152 +7103,159 @@ Help is currently only available for the new 5.8 command set.
 No help is available for the old command set. 
 We assume you know what you're doing if you switch to it.
 
-B<T>           Stack trace.
-B<s> [I<expr>] Single step [in I<expr>].
-B<n> [I<expr>] Next, steps over subroutine calls [in I<expr>].
-<B<CR>>                Repeat last B<n> or B<s> command.
-B<r>           Return from current subroutine.
-B<c> [I<line>|I<sub>]  Continue; optionally inserts a one-time-only breakpoint
-               at the specified position.
-B<l> I<min>B<+>I<incr> List I<incr>+1 lines starting at I<min>.
-B<l> I<min>B<->I<max>  List lines I<min> through I<max>.
-B<l> I<line>           List single I<line>.
-B<l> I<subname>        List first window of lines from subroutine.
-B<l> I<\$var>          List first window of lines from subroutine referenced by I<\$var>.
-B<l>           List next window of lines.
-B<->           List previous window of lines.
-B<v> [I<line>] View window around I<line>.
-B<.>           Return to the executed line.
-B<f> I<filename>       Switch to viewing I<filename>. File must be already loaded.
-               I<filename> may be either the full name of the file, or a regular
-               expression matching the full file name:
-               B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
-               Evals (with saved bodies) are considered to be filenames:
-               B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
-               (in the order of execution).
-B</>I<pattern>B</>     Search forwards for I<pattern>; final B</> is optional.
-B<?>I<pattern>B<?>     Search backwards for I<pattern>; final B<?> is optional.
-B<L> [I<a|b|w>]                List actions and or breakpoints and or watch-expressions.
-B<S> [[B<!>]I<pattern>]        List subroutine names [not] matching I<pattern>.
-B<t>           Toggle trace mode.
-B<t> I<expr>           Trace through execution of I<expr>.
-B<b>           Sets breakpoint on current line)
+B<T>        Stack trace.
+B<s> [I<expr>]    Single step [in I<expr>].
+B<n> [I<expr>]    Next, steps over subroutine calls [in I<expr>].
+<B<CR>>        Repeat last B<n> or B<s> command.
+B<r>        Return from current subroutine.
+B<c> [I<line>|I<sub>]    Continue; optionally inserts a one-time-only breakpoint
+        at the specified position.
+B<l> I<min>B<+>I<incr>    List I<incr>+1 lines starting at I<min>.
+B<l> I<min>B<->I<max>    List lines I<min> through I<max>.
+B<l> I<line>        List single I<line>.
+B<l> I<subname>    List first window of lines from subroutine.
+B<l> I<\$var>        List first window of lines from subroutine referenced by I<\$var>.
+B<l>        List next window of lines.
+B<->        List previous window of lines.
+B<v> [I<line>]    View window around I<line>.
+B<.>        Return to the executed line.
+B<f> I<filename>    Switch to viewing I<filename>. File must be already loaded.
+        I<filename> may be either the full name of the file, or a regular
+        expression matching the full file name:
+        B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
+        Evals (with saved bodies) are considered to be filenames:
+        B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
+        (in the order of execution).
+B</>I<pattern>B</>    Search forwards for I<pattern>; final B</> is optional.
+B<?>I<pattern>B<?>    Search backwards for I<pattern>; final B<?> is optional.
+B<L> [I<a|b|w>]        List actions and or breakpoints and or watch-expressions.
+B<S> [[B<!>]I<pattern>]    List subroutine names [not] matching I<pattern>.
+B<t>        Toggle trace mode.
+B<t> I<expr>        Trace through execution of I<expr>.
+B<b>        Sets breakpoint on current line)
 B<b> [I<line>] [I<condition>]
-               Set breakpoint; I<line> defaults to the current execution line;
-               I<condition> breaks if it evaluates to true, defaults to '1'.
+        Set breakpoint; I<line> defaults to the current execution line;
+        I<condition> breaks if it evaluates to true, defaults to '1'.
 B<b> I<subname> [I<condition>]
-               Set breakpoint at first line of subroutine.
-B<b> I<\$var>          Set breakpoint at first line of subroutine referenced by I<\$var>.
+        Set breakpoint at first line of subroutine.
+B<b> I<\$var>        Set breakpoint at first line of subroutine referenced by I<\$var>.
 B<b> B<load> I<filename> Set breakpoint on 'require'ing the given file.
 B<b> B<postpone> I<subname> [I<condition>]
-               Set breakpoint at first line of subroutine after 
-               it is compiled.
+        Set breakpoint at first line of subroutine after 
+        it is compiled.
 B<b> B<compile> I<subname>
-               Stop after the subroutine is compiled.
-B<B> [I<line>] Delete the breakpoint for I<line>.
+        Stop after the subroutine is compiled.
+B<B> [I<line>]    Delete the breakpoint for I<line>.
 B<B> I<*>             Delete all breakpoints.
 B<a> [I<line>] I<command>
-               Set an action to be done before the I<line> is executed;
-               I<line> defaults to the current execution line.
-               Sequence is: check for breakpoint/watchpoint, print line
-               if necessary, do action, prompt user if necessary,
-               execute line.
-B<a>           Does nothing
-B<A> [I<line>] Delete the action for I<line>.
+        Set an action to be done before the I<line> is executed;
+        I<line> defaults to the current execution line.
+        Sequence is: check for breakpoint/watchpoint, print line
+        if necessary, do action, prompt user if necessary,
+        execute line.
+B<a>        Does nothing
+B<A> [I<line>]    Delete the action for I<line>.
 B<A> I<*>             Delete all actions.
-B<w> I<expr>           Add a global watch-expression.
-B<w>                   Does nothing
-B<W> I<expr>           Delete a global watch-expression.
+B<w> I<expr>        Add a global watch-expression.
+B<w>             Does nothing
+B<W> I<expr>        Delete a global watch-expression.
 B<W> I<*>             Delete all watch-expressions.
-B<V> [I<pkg> [I<vars>]]        List some (default all) variables in package (default current).
-               Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
-B<X> [I<vars>] Same as \"B<V> I<currentpackage> [I<vars>]\".
-B<x> I<expr>           Evals expression in list context, dumps the result.
-B<m> I<expr>           Evals expression in list context, prints methods callable
-               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<V> [I<pkg> [I<vars>]]    List some (default all) variables in package (default current).
+        Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
+B<X> [I<vars>]    Same as \"B<V> I<currentpackage> [I<vars>]\".
+B<x> I<expr>        Evals expression in list context, dumps the result.
+B<m> I<expr>        Evals expression in list context, prints methods callable
+        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<e>         Display current thread id.
+B<E>         Display all thread ids the current one will be identified: <n>.
 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.
-B<<> I<expr>           Define Perl command to run before each prompt.
-B<<<> I<expr>          Add to the list of Perl commands to run before each prompt.
-B<< *>                         Delete the list of perl commands to run before each prompt.
-B<>> ?                 List Perl commands to run after each prompt.
-B<>> I<expr>           Define Perl command to run after each prompt.
-B<>>B<>> I<expr>               Add to the list of Perl commands to run after each prompt.
-B<>>B< *>              Delete the list of Perl commands to run after each prompt.
-B<{> I<db_command>     Define debugger command to run before each prompt.
-B<{> ?                 List debugger commands to run before each prompt.
-B<{ *>                         Delete the list of debugger commands to run before each prompt.
-B<{{> I<db_command>    Add to the list of debugger commands to run before each prompt.
-B<$prc> I<number>      Redo a previous command (default previous command).
-B<$prc> I<-number>     Redo number'th-to-last command.
-B<$prc> I<pattern>     Redo last command that started with I<pattern>.
-               See 'B<O> I<recallCommand>' too.
-B<$psh$psh> I<cmd>     Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
+B<<> ?            List Perl commands to run before each prompt.
+B<<> I<expr>        Define Perl command to run before each prompt.
+B<<<> I<expr>        Add to the list of Perl commands to run before each prompt.
+B<< *>                Delete the list of perl commands to run before each prompt.
+B<>> ?            List Perl commands to run after each prompt.
+B<>> I<expr>        Define Perl command to run after each prompt.
+B<>>B<>> I<expr>        Add to the list of Perl commands to run after each prompt.
+B<>>B< *>        Delete the list of Perl commands to run after each prompt.
+B<{> I<db_command>    Define debugger command to run before each prompt.
+B<{> ?            List debugger commands to run before each prompt.
+B<{{> I<db_command>    Add to the list of debugger commands to run before each prompt.
+B<{ *>             Delete the list of debugger commands to run before each prompt.
+B<$prc> I<number>    Redo a previous command (default previous command).
+B<$prc> I<-number>    Redo number'th-to-last command.
+B<$prc> I<pattern>    Redo last command that started with I<pattern>.
+        See 'B<O> I<recallCommand>' too.
+B<$psh$psh> I<cmd>      Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
       . (
         $rc eq $sh
         ? ""
         : "
-B<$psh> [I<cmd>]       Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")."
-      ) 
-      . "
-               See 'B<O> I<shellBang>' too.
-B<source> I<file>              Execute I<file> containing debugger commands (may nest).
-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<||>I<dbcmd>          Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
-B<\=> [I<alias> I<value>]      Define a command alias, or list current aliases.
-I<command>             Execute as a perl statement in current package.
-B<R>           Pure-man-restart of debugger, some of debugger state
-               and command-line options may be lost.
-               Currently the following settings are preserved:
-               history, breakpoints and actions, debugger B<O>ptions 
-               and the following command-line options: I<-w>, I<-I>, I<-e>.
-
-B<o> [I<opt>] ...      Set boolean option to true
-B<o> [I<opt>B<?>]      Query options
+B<$psh> [I<cmd>] Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")."
+      ) . "
+        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<rerun>           Rerun session to current position.
+B<rerun> I<n>         Rerun session to numbered command.
+B<rerun> I<-n>        Rerun session to number'th-to-last command.
+B<H> I<-number>    Display last number commands (default all).
+B<H> I<*>          Delete complete history.
+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<||>I<dbcmd>        Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
+B<\=> [I<alias> I<value>]    Define a command alias, or list current aliases.
+I<command>        Execute as a perl statement in current package.
+B<R>        Pure-man-restart of debugger, some of debugger state
+        and command-line options may be lost.
+        Currently the following settings are preserved:
+        history, breakpoints and actions, debugger B<O>ptions 
+        and the following command-line options: I<-w>, I<-I>, I<-e>.
+
+B<o> [I<opt>] ...    Set boolean option to true
+B<o> [I<opt>B<?>]    Query options
 B<o> [I<opt>B<=>I<val>] [I<opt>=B<\">I<val>B<\">] ... 
-               Set options.  Use quotes in spaces in value.
-    I<recallCommand>, I<ShellBang>     chars used to recall command or spawn shell;
-    I<pager>                   program for output of \"|cmd\";
-    I<tkRunning>                       run Tk while prompting (with ReadLine);
-    I<signalLevel> I<warnLevel> I<dieLevel>    level of verbosity;
-    I<inhibit_exit>            Allows stepping off the end of the script.
-    I<ImmediateStop>           Debugger should stop as early as possible.
-    I<RemotePort>                      Remote hostname:port for remote debugging
+        Set options.  Use quotes if spaces in value.
+    I<recallCommand>, I<ShellBang>    chars used to recall command or spawn shell;
+    I<pager>            program for output of \"|cmd\";
+    I<tkRunning>            run Tk while prompting (with ReadLine);
+    I<signalLevel> I<warnLevel> I<dieLevel>    level of verbosity;
+    I<inhibit_exit>        Allows stepping off the end of the script.
+    I<ImmediateStop>        Debugger should stop as early as possible.
+    I<RemotePort>            Remote hostname:port for remote debugging
   The following options affect what happens with B<V>, B<X>, and B<x> commands:
-    I<arrayDepth>, I<hashDepth>        print only first N elements ('' for all);
-    I<compactDump>, I<veryCompact>     change style of array and hash dump;
-    I<globPrint>                       whether to print contents of globs;
-    I<DumpDBFiles>             dump arrays holding debugged files;
-    I<DumpPackages>            dump symbol tables of packages;
-    I<DumpReused>                      dump contents of \"reused\" addresses;
-    I<quote>, I<HighBit>, I<undefPrint>        change style of string dump;
-    I<bareStringify>           Do not print the overload-stringified value;
+    I<arrayDepth>, I<hashDepth>     print only first N elements ('' for all);
+    I<compactDump>, I<veryCompact>     change style of array and hash dump;
+    I<globPrint>             whether to print contents of globs;
+    I<DumpDBFiles>         dump arrays holding debugged files;
+    I<DumpPackages>         dump symbol tables of packages;
+    I<DumpReused>             dump contents of \"reused\" addresses;
+    I<quote>, I<HighBit>, I<undefPrint>     change style of string dump;
+    I<bareStringify>         Do not print the overload-stringified value;
   Other options include:
-    I<PrintRet>                affects printing of return value after B<r> command,
-    I<frame>           affects printing messages on subroutine entry/exit.
-    I<AutoTrace>       affects printing messages on possible breaking points.
-    I<maxTraceLen>     gives max length of evals/args listed in stack trace.
-    I<ornaments>       affects screen appearance of the command line.
-    I<CreateTTY>       bits control attempts to create a new TTY on events:
-                       1: on fork()    2: debugger is started inside debugger
-                       4: on startup
-       During startup options are initialized from \$ENV{PERLDB_OPTS}.
-       You can put additional initialization options I<TTY>, I<noTTY>,
-       I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
-       `B<R>' after you set them).
-
-B<q> or B<^D>          Quit. Set B<\$DB::finished = 0> to debug global destruction.
-B<h>           Summary of debugger commands.
-B<h> [I<db_command>]   Get help [on a specific debugger command], enter B<|h> to page.
-B<h h>         Long help for debugger commands
-B<$doccmd> I<manpage>  Runs the external doc viewer B<$doccmd> command on the 
-               named Perl I<manpage>, or on B<$doccmd> itself if omitted.
-               Set B<\$DB::doccmd> to change viewer.
+    I<PrintRet>        affects printing of return value after B<r> command,
+    I<frame>        affects printing messages on subroutine entry/exit.
+    I<AutoTrace>    affects printing messages on possible breaking points.
+    I<maxTraceLen>    gives max length of evals/args listed in stack trace.
+    I<ornaments>     affects screen appearance of the command line.
+    I<CreateTTY>     bits control attempts to create a new TTY on events:
+            1: on fork()    2: debugger is started inside debugger
+            4: on startup
+    During startup options are initialized from \$ENV{PERLDB_OPTS}.
+    You can put additional initialization options I<TTY>, I<noTTY>,
+    I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
+    `B<R>' after you set them).
+
+B<q> or B<^D>        Quit. Set B<\$DB::finished = 0> to debug global destruction.
+B<h>        Summary of debugger commands.
+B<h> [I<db_command>]    Get help [on a specific debugger command], enter B<|h> to page.
+B<h h>        Long help for debugger commands
+B<$doccmd> I<manpage>    Runs the external doc viewer B<$doccmd> command on the 
+        named Perl I<manpage>, or on B<$doccmd> itself if omitted.
+        Set B<\$DB::doccmd> to change viewer.
 
 Type `|h h' for a paged display if this was too hard to read.
 
@@ -6867,8 +7285,9 @@ I<Data Examination:>     B<expr>     Execute perl code, also see: B<s>,B<n>,B<t>
   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>.
+  B<e>     Display thread id     B<E> Display all thread ids.
 For more help, type B<h> I<cmd_letter>, or run B<$doccmd perldebug> for all docs.
 END_SUM
 
@@ -6876,143 +7295,142 @@ END_SUM
 
     # and this is really numb...
     $pre580_help = "
-B<T>           Stack trace.
-B<s> [I<expr>] Single step [in I<expr>].
-B<n> [I<expr>] Next, steps over subroutine calls [in I<expr>].
-B<CR>>                 Repeat last B<n> or B<s> command.
-B<r>           Return from current subroutine.
-B<c> [I<line>|I<sub>]  Continue; optionally inserts a one-time-only breakpoint
-               at the specified position.
-B<l> I<min>B<+>I<incr> List I<incr>+1 lines starting at I<min>.
-B<l> I<min>B<->I<max>  List lines I<min> through I<max>.
-B<l> I<line>           List single I<line>.
-B<l> I<subname>        List first window of lines from subroutine.
-B<l> I<\$var>          List first window of lines from subroutine referenced by I<\$var>.
-B<l>           List next window of lines.
-B<->           List previous window of lines.
-B<w> [I<line>] List window around I<line>.
-B<.>           Return to the executed line.
-B<f> I<filename>       Switch to viewing I<filename>. File must be already loaded.
-               I<filename> may be either the full name of the file, or a regular
-               expression matching the full file name:
-               B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
-               Evals (with saved bodies) are considered to be filenames:
-               B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
-               (in the order of execution).
-B</>I<pattern>B</>     Search forwards for I<pattern>; final B</> is optional.
-B<?>I<pattern>B<?>     Search backwards for I<pattern>; final B<?> is optional.
-B<L>           List all breakpoints and actions.
-B<S> [[B<!>]I<pattern>]        List subroutine names [not] matching I<pattern>.
-B<t>           Toggle trace mode.
-B<t> I<expr>           Trace through execution of I<expr>.
+B<T>        Stack trace.
+B<s> [I<expr>]    Single step [in I<expr>].
+B<n> [I<expr>]    Next, steps over subroutine calls [in I<expr>].
+B<CR>>        Repeat last B<n> or B<s> command.
+B<r>        Return from current subroutine.
+B<c> [I<line>|I<sub>]    Continue; optionally inserts a one-time-only breakpoint
+        at the specified position.
+B<l> I<min>B<+>I<incr>    List I<incr>+1 lines starting at I<min>.
+B<l> I<min>B<->I<max>    List lines I<min> through I<max>.
+B<l> I<line>        List single I<line>.
+B<l> I<subname>    List first window of lines from subroutine.
+B<l> I<\$var>        List first window of lines from subroutine referenced by I<\$var>.
+B<l>        List next window of lines.
+B<->        List previous window of lines.
+B<w> [I<line>]    List window around I<line>.
+B<.>        Return to the executed line.
+B<f> I<filename>    Switch to viewing I<filename>. File must be already loaded.
+        I<filename> may be either the full name of the file, or a regular
+        expression matching the full file name:
+        B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
+        Evals (with saved bodies) are considered to be filenames:
+        B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
+        (in the order of execution).
+B</>I<pattern>B</>    Search forwards for I<pattern>; final B</> is optional.
+B<?>I<pattern>B<?>    Search backwards for I<pattern>; final B<?> is optional.
+B<L>        List all breakpoints and actions.
+B<S> [[B<!>]I<pattern>]    List subroutine names [not] matching I<pattern>.
+B<t>        Toggle trace mode.
+B<t> I<expr>        Trace through execution of I<expr>.
 B<b> [I<line>] [I<condition>]
-               Set breakpoint; I<line> defaults to the current execution line;
-               I<condition> breaks if it evaluates to true, defaults to '1'.
+        Set breakpoint; I<line> defaults to the current execution line;
+        I<condition> breaks if it evaluates to true, defaults to '1'.
 B<b> I<subname> [I<condition>]
-               Set breakpoint at first line of subroutine.
-B<b> I<\$var>          Set breakpoint at first line of subroutine referenced by I<\$var>.
+        Set breakpoint at first line of subroutine.
+B<b> I<\$var>        Set breakpoint at first line of subroutine referenced by I<\$var>.
 B<b> B<load> I<filename> Set breakpoint on `require'ing the given file.
 B<b> B<postpone> I<subname> [I<condition>]
-               Set breakpoint at first line of subroutine after 
-               it is compiled.
+        Set breakpoint at first line of subroutine after 
+        it is compiled.
 B<b> B<compile> I<subname>
-               Stop after the subroutine is compiled.
-B<d> [I<line>] Delete the breakpoint for I<line>.
-B<D>           Delete all breakpoints.
+        Stop after the subroutine is compiled.
+B<d> [I<line>]    Delete the breakpoint for I<line>.
+B<D>        Delete all breakpoints.
 B<a> [I<line>] I<command>
-               Set an action to be done before the I<line> is executed;
-               I<line> defaults to the current execution line.
-               Sequence is: check for breakpoint/watchpoint, print line
-               if necessary, do action, prompt user if necessary,
-               execute line.
-B<a> [I<line>] Delete the action for I<line>.
-B<A>           Delete all actions.
-B<W> I<expr>           Add a global watch-expression.
-B<W>           Delete all watch-expressions.
-B<V> [I<pkg> [I<vars>]]        List some (default all) variables in package (default current).
-               Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
-B<X> [I<vars>] Same as \"B<V> I<currentpackage> [I<vars>]\".
-B<x> I<expr>           Evals expression in list context, dumps the result.
-B<m> I<expr>           Evals expression in list context, prints methods callable
-               on the first element of the result.
-B<m> I<class>          Prints methods callable via the given class.
-
-B<<> ?                 List Perl commands to run before each prompt.
-B<<> I<expr>           Define Perl command to run before each prompt.
-B<<<> I<expr>          Add to the list of Perl commands to run before each prompt.
-B<>> ?                 List Perl commands to run after each prompt.
-B<>> I<expr>           Define Perl command to run after each prompt.
-B<>>B<>> I<expr>               Add to the list of Perl commands to run after each prompt.
-B<{> I<db_command>     Define debugger command to run before each prompt.
-B<{> ?                 List debugger commands to run before each prompt.
-B<{{> I<db_command>    Add to the list of debugger commands to run before each prompt.
-B<$prc> I<number>      Redo a previous command (default previous command).
-B<$prc> I<-number>     Redo number'th-to-last command.
-B<$prc> I<pattern>     Redo last command that started with I<pattern>.
-               See 'B<O> I<recallCommand>' too.
-B<$psh$psh> I<cmd>     Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
+        Set an action to be done before the I<line> is executed;
+        I<line> defaults to the current execution line.
+        Sequence is: check for breakpoint/watchpoint, print line
+        if necessary, do action, prompt user if necessary,
+        execute line.
+B<a> [I<line>]    Delete the action for I<line>.
+B<A>        Delete all actions.
+B<W> I<expr>        Add a global watch-expression.
+B<W>        Delete all watch-expressions.
+B<V> [I<pkg> [I<vars>]]    List some (default all) variables in package (default current).
+        Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
+B<X> [I<vars>]    Same as \"B<V> I<currentpackage> [I<vars>]\".
+B<x> I<expr>        Evals expression in list context, dumps the result.
+B<m> I<expr>        Evals expression in list context, prints methods callable
+        on the first element of the result.
+B<m> I<class>        Prints methods callable via the given class.
+
+B<<> ?            List Perl commands to run before each prompt.
+B<<> I<expr>        Define Perl command to run before each prompt.
+B<<<> I<expr>        Add to the list of Perl commands to run before each prompt.
+B<>> ?            List Perl commands to run after each prompt.
+B<>> I<expr>        Define Perl command to run after each prompt.
+B<>>B<>> I<expr>        Add to the list of Perl commands to run after each prompt.
+B<{> I<db_command>    Define debugger command to run before each prompt.
+B<{> ?            List debugger commands to run before each prompt.
+B<{{> I<db_command>    Add to the list of debugger commands to run before each prompt.
+B<$prc> I<number>    Redo a previous command (default previous command).
+B<$prc> I<-number>    Redo number'th-to-last command.
+B<$prc> I<pattern>    Redo last command that started with I<pattern>.
+        See 'B<O> I<recallCommand>' too.
+B<$psh$psh> I<cmd>      Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
       . (
         $rc eq $sh
         ? ""
         : "
-B<$psh> [I<cmd>]       Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")."
-      ) .
-      "
-               See 'B<O> I<shellBang>' too.
-B<source> I<file>              Execute I<file> containing debugger commands (may nest).
-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<||>I<dbcmd>          Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
-B<\=> [I<alias> I<value>]      Define a command alias, or list current aliases.
-I<command>             Execute as a perl statement in current package.
-B<v>           Show versions of loaded modules.
-B<R>           Pure-man-restart of debugger, some of debugger state
-               and command-line options may be lost.
-               Currently the following settings are preserved:
-               history, breakpoints and actions, debugger B<O>ptions 
-               and the following command-line options: I<-w>, I<-I>, I<-e>.
-
-B<O> [I<opt>] ...      Set boolean option to true
-B<O> [I<opt>B<?>]      Query options
+B<$psh> [I<cmd>]     Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")."
+      ) . "
+        See 'B<O> I<shellBang>' too.
+B<source> I<file>        Execute I<file> containing debugger commands (may nest).
+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<||>I<dbcmd>        Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
+B<\=> [I<alias> I<value>]    Define a command alias, or list current aliases.
+I<command>        Execute as a perl statement in current package.
+B<v>        Show versions of loaded modules.
+B<R>        Pure-man-restart of debugger, some of debugger state
+        and command-line options may be lost.
+        Currently the following settings are preserved:
+        history, breakpoints and actions, debugger B<O>ptions 
+        and the following command-line options: I<-w>, I<-I>, I<-e>.
+
+B<O> [I<opt>] ...    Set boolean option to true
+B<O> [I<opt>B<?>]    Query options
 B<O> [I<opt>B<=>I<val>] [I<opt>=B<\">I<val>B<\">] ... 
-               Set options.  Use quotes in spaces in value.
-    I<recallCommand>, I<ShellBang>     chars used to recall command or spawn shell;
-    I<pager>                   program for output of \"|cmd\";
-    I<tkRunning>                       run Tk while prompting (with ReadLine);
-    I<signalLevel> I<warnLevel> I<dieLevel>    level of verbosity;
-    I<inhibit_exit>            Allows stepping off the end of the script.
-    I<ImmediateStop>           Debugger should stop as early as possible.
-    I<RemotePort>                      Remote hostname:port for remote debugging
+        Set options.  Use quotes if spaces in value.
+    I<recallCommand>, I<ShellBang>    chars used to recall command or spawn shell;
+    I<pager>            program for output of \"|cmd\";
+    I<tkRunning>            run Tk while prompting (with ReadLine);
+    I<signalLevel> I<warnLevel> I<dieLevel>    level of verbosity;
+    I<inhibit_exit>        Allows stepping off the end of the script.
+    I<ImmediateStop>        Debugger should stop as early as possible.
+    I<RemotePort>            Remote hostname:port for remote debugging
   The following options affect what happens with B<V>, B<X>, and B<x> commands:
-    I<arrayDepth>, I<hashDepth>        print only first N elements ('' for all);
-    I<compactDump>, I<veryCompact>     change style of array and hash dump;
-    I<globPrint>                       whether to print contents of globs;
-    I<DumpDBFiles>             dump arrays holding debugged files;
-    I<DumpPackages>            dump symbol tables of packages;
-    I<DumpReused>                      dump contents of \"reused\" addresses;
-    I<quote>, I<HighBit>, I<undefPrint>        change style of string dump;
-    I<bareStringify>           Do not print the overload-stringified value;
+    I<arrayDepth>, I<hashDepth>     print only first N elements ('' for all);
+    I<compactDump>, I<veryCompact>     change style of array and hash dump;
+    I<globPrint>             whether to print contents of globs;
+    I<DumpDBFiles>         dump arrays holding debugged files;
+    I<DumpPackages>         dump symbol tables of packages;
+    I<DumpReused>             dump contents of \"reused\" addresses;
+    I<quote>, I<HighBit>, I<undefPrint>     change style of string dump;
+    I<bareStringify>         Do not print the overload-stringified value;
   Other options include:
-    I<PrintRet>                affects printing of return value after B<r> command,
-    I<frame>           affects printing messages on subroutine entry/exit.
-    I<AutoTrace>       affects printing messages on possible breaking points.
-    I<maxTraceLen>     gives max length of evals/args listed in stack trace.
-    I<ornaments>       affects screen appearance of the command line.
-    I<CreateTTY>       bits control attempts to create a new TTY on events:
-                       1: on fork()    2: debugger is started inside debugger
-                       4: on startup
-       During startup options are initialized from \$ENV{PERLDB_OPTS}.
-       You can put additional initialization options I<TTY>, I<noTTY>,
-       I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
-       `B<R>' after you set them).
-
-B<q> or B<^D>          Quit. Set B<\$DB::finished = 0> to debug global destruction.
-B<h> [I<db_command>]   Get help [on a specific debugger command], enter B<|h> to page.
-B<h h>         Summary of debugger commands.
-B<$doccmd> I<manpage>  Runs the external doc viewer B<$doccmd> command on the 
-               named Perl I<manpage>, or on B<$doccmd> itself if omitted.
-               Set B<\$DB::doccmd> to change viewer.
+    I<PrintRet>        affects printing of return value after B<r> command,
+    I<frame>        affects printing messages on subroutine entry/exit.
+    I<AutoTrace>    affects printing messages on possible breaking points.
+    I<maxTraceLen>    gives max length of evals/args listed in stack trace.
+    I<ornaments>     affects screen appearance of the command line.
+    I<CreateTTY>     bits control attempts to create a new TTY on events:
+            1: on fork()    2: debugger is started inside debugger
+            4: on startup
+    During startup options are initialized from \$ENV{PERLDB_OPTS}.
+    You can put additional initialization options I<TTY>, I<noTTY>,
+    I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
+    `B<R>' after you set them).
+
+B<q> or B<^D>        Quit. Set B<\$DB::finished = 0> to debug global destruction.
+B<h> [I<db_command>]    Get help [on a specific debugger command], enter B<|h> to page.
+B<h h>        Summary of debugger commands.
+B<$doccmd> I<manpage>    Runs the external doc viewer B<$doccmd> command on the 
+        named Perl I<manpage>, or on B<$doccmd> itself if omitted.
+        Set B<\$DB::doccmd> to change viewer.
 
 Type `|h' for a paged display if this was too hard to read.
 
@@ -7055,7 +7473,7 @@ END_SUM
 Most of what C<print_help> does is just text formatting. It finds the
 C<B> and C<I> ornaments, cleans them off, and substitutes the proper
 terminal control characters to simulate them (courtesy of 
-<Term::ReadLine::TermCap>).
+C<Term::ReadLine::TermCap>).
 
 =cut
 
@@ -7124,16 +7542,17 @@ sub fix_less {
 
     # Pager is less for sure.
     my $is_less = $pager =~ /\bless\b/;
-    if ($pager =~ /\bmore\b/) {
+    if ( $pager =~ /\bmore\b/ ) {
+
         # Nope, set to more. See what's out there.
         my @st_more = stat('/usr/bin/more');
         my @st_less = stat('/usr/bin/less');
 
         # is it really less, pretending to be more?
-        $is_less = @st_more &&
-          @st_less &&
-          $st_more[0] == $st_less[0] &&
-          $st_more[1] == $st_less[1];
+             $is_less = @st_more
+          && @st_less
+          && $st_more[0] == $st_less[0]
+          && $st_more[1] == $st_less[1];
     } ## end if ($pager =~ /\bmore\b/)
 
     # changes environment!
@@ -7154,6 +7573,7 @@ program, debugger, and everything to die.
 =cut
 
 sub diesignal {
+
     # No entry/exit messages.
     local $frame = 0;
 
@@ -7168,16 +7588,17 @@ sub diesignal {
     kill 'ABRT', $$ if $panic++;
 
     # If we can show detailed info, do so.
-    if (defined &Carp::longmess) {
+    if ( defined &Carp::longmess ) {
+
         # Don't recursively enter the warn handler, since we're carping.
         local $SIG{__WARN__} = '';
 
-        # Skip two levels before reporting traceback: we're skipping 
-        # mydie and confess. 
+        # Skip two levels before reporting traceback: we're skipping
+        # mydie and confess.
         local $Carp::CarpLevel = 2;    # mydie + confess
 
         # Tell us all about it.
-        &warn(Carp::longmess("Signal @_"));
+        &warn( Carp::longmess("Signal @_") );
     }
 
     # No Carp. Tell us about the signal as best we can.
@@ -7198,7 +7619,8 @@ be able to get a stack trace, and output the warning message vi C<DB::dbwarn()>.
 =cut
 
 sub dbwarn {
-    # No entry/exit trace. 
+
+    # No entry/exit trace.
     local $frame = 0;
 
     # No return value printing.
@@ -7216,22 +7638,22 @@ sub dbwarn {
                          # require may be broken.
 
     # Use the core warn() unless Carp loaded OK.
-    CORE::warn(@_,
-        "\nCannot print stack trace, load with -MCarp option to see stack"),
+    CORE::warn( @_,
+        "\nCannot print stack trace, load with -MCarp option to see stack" ),
       return
       unless defined &Carp::longmess;
 
     # Save the current values of $single and $trace, and then turn them off.
-    my ($mysingle, $mytrace) = ($single, $trace);
+    my ( $mysingle, $mytrace ) = ( $single, $trace );
     $single = 0;
     $trace  = 0;
 
-    # We can call Carp::longmess without its being "debugged" (which we 
+    # We can call Carp::longmess without its being "debugged" (which we
     # don't want - we just want to use it!). Capture this for later.
     my $mess = Carp::longmess(@_);
 
     # Restore $single and $trace to their original values.
-    ($single, $trace) = ($mysingle, $mytrace);
+    ( $single, $trace ) = ( $mysingle, $mytrace );
 
     # Use the debugger's own special way of printing warnings to print
     # the stack trace message.
@@ -7253,35 +7675,35 @@ displaying the exception via its C<dbwarn()> routine.
 =cut
 
 sub dbdie {
-    local $frame = 0;
-    local $doret = -2;
+    local $frame         = 0;
+    local $doret         = -2;
     local $SIG{__DIE__}  = '';
     local $SIG{__WARN__} = '';
     my $i      = 0;
     my $ineval = 0;
     my $sub;
-    if ($dieLevel > 2) {
+    if ( $dieLevel > 2 ) {
         local $SIG{__WARN__} = \&dbwarn;
         &warn(@_);    # Yell no matter what
         return;
     }
-    if ($dieLevel < 2) {
+    if ( $dieLevel < 2 ) {
         die @_ if $^S;    # in eval propagate
     }
 
     # The code used to check $^S to see if compiliation of the current thing
     # hadn't finished. We don't do it anymore, figuring eval is pretty stable.
-    eval { require Carp }; 
+    eval { require Carp };
 
-    die (@_,
-        "\nCannot print stack trace, load with -MCarp option to see stack")
+    die@_,
+        "\nCannot print stack trace, load with -MCarp option to see stack" )
       unless defined &Carp::longmess;
 
     # We do not want to debug this chunk (automatic disabling works
     # inside DB::DB, but not in Carp). Save $single and $trace, turn them off,
     # get the stack trace from Carp::longmess (if possible), restore $signal
     # and $trace, and then die with the stack trace.
-    my ($mysingle, $mytrace) = ($single, $trace);
+    my ( $mysingle, $mytrace ) = ( $single, $trace );
     $single = 0;
     $trace  = 0;
     my $mess = "@_";
@@ -7290,7 +7712,7 @@ sub dbdie {
         package Carp;    # Do not include us in the list
         eval { $mess = Carp::longmess(@_); };
     }
-    ($single, $trace) = ($mysingle, $mytrace);
+    ( $single, $trace ) = ( $mysingle, $mytrace );
     die $mess;
 } ## end sub dbdie
 
@@ -7332,17 +7754,18 @@ sub dieLevel {
         $prevdie = $SIG{__DIE__} unless $dieLevel;
         $dieLevel = shift;
         if ($dieLevel) {
+
             # Always set it to dbdie() for non-zero values.
             $SIG{__DIE__} = \&DB::dbdie;    # if $dieLevel < 2;
 
-           # No longer exists, so don't try  to use it.
-           #$SIG{__DIE__} = \&DB::diehard if $dieLevel >= 2;
+            # No longer exists, so don't try  to use it.
+            #$SIG{__DIE__} = \&DB::diehard if $dieLevel >= 2;
 
             # If we've finished initialization, mention that stack dumps
             # are enabled, If dieLevel is 1, we won't stack dump if we die
             # in an eval().
             print $OUT "Stack dump during die enabled",
-              ($dieLevel == 1 ? " outside of evals" : ""), ".\n"
+              ( $dieLevel == 1 ? " outside of evals" : "" ), ".\n"
               if $I_m_init;
 
             # XXX This is probably obsolete, given that diehard() is gone.
@@ -7393,9 +7816,9 @@ to named subroutines (including those aliased via glob assignment).
 
 =head2 C<CvGV_name()>
 
-Wrapper for X<CvGV_name_or_bust>; tries to get the name of a reference
+Wrapper for C<CvGV_name_or_bust>; tries to get the name of a reference
 via that routine. If this fails, return the reference again (when the
-reference is stringified, it'll come out as "SOMETHING(0X...)").
+reference is stringified, it'll come out as C<SOMETHING(0x...)>).
 
 =cut
 
@@ -7411,7 +7834,7 @@ Calls L<Devel::Peek> to try to find the glob the ref lives in; returns
 C<undef> if L<Devel::Peek> can't be loaded, or if C<Devel::Peek::CvGV> can't
 find a glob for this ref.
 
-Returns "I<package>::I<glob name>" if the code ref is found in a glob.
+Returns C<< I<package>::I<glob name> >> if the code ref is found in a glob.
 
 =cut
 
@@ -7430,10 +7853,10 @@ sub CvGV_name_or_bust {
 A utility routine used in various places; finds the file where a subroutine 
 was defined, and returns that filename and a line-number range.
 
-Tries to use X<@sub> first; if it can't find it there, it tries building a
-reference to the subroutine and uses X<CvGV_name_or_bust> to locate it,
-loading it into X<@sub> as a side effect (XXX I think). If it can't find it
-this way, it brute-force searches X<%sub>, checking for identical references.
+Tries to use C<@sub> first; if it can't find it there, it tries building a
+reference to the subroutine and uses C<CvGV_name_or_bust> to locate it,
+loading it into C<@sub> as a side effect (XXX I think). If it can't find it
+this way, it brute-force searches C<%sub>, checking for identical references.
 
 =cut
 
@@ -7449,7 +7872,7 @@ sub find_sub {
         # Old stupid way...
         $subr = \&$subr;    # Hard reference
         my $s;
-        for (keys %sub) {
+        for ( keys %sub ) {
             $s = $_, last if $subr eq \&$_;
         }
         $sub{$s} if $s;
@@ -7458,7 +7881,7 @@ sub find_sub {
 
 =head2 C<methods>
 
-A subroutine that uses the utility function X<methods_via> to find all the
+A subroutine that uses the utility function C<methods_via> to find all the
 methods in the class corresponding to the current reference and in 
 C<UNIVERSAL>.
 
@@ -7472,13 +7895,12 @@ sub methods {
     $class = ref $class if ref $class;
 
     local %seen;
-    local %packs;
 
     # Show the methods that this class has.
-    methods_via($class, '', 1);
+    methods_via( $class, '', 1 );
 
     # Show the methods that UNIVERSAL has.
-    methods_via('UNIVERSAL', 'UNIVERSAL', 0);
+    methods_via( 'UNIVERSAL', 'UNIVERSAL', 0 );
 } ## end sub methods
 
 =head2 C<methods_via($class, $prefix, $crawl_upward)>
@@ -7492,40 +7914,47 @@ higher in the C<@ISA> tree, 0 if we should stop.
 =cut
 
 sub methods_via {
+
     # If we've processed this class already, just quit.
     my $class = shift;
+    return if $seen{$class}++;
 
-    # XXX This may be a bug - no other references to %packs.
-    return if $packs{$class}++;
-
-    # This is a package that is contributing the methods we're about to print. 
-    my $prefix = shift;
+    # This is a package that is contributing the methods we're about to print.
+    my $prefix  = shift;
     my $prepend = $prefix ? "via $prefix: " : '';
 
     my $name;
     for $name (
+
         # Keep if this is a defined subroutine in this class.
         grep { defined &{ ${"${class}::"}{$_} } }
-             # Extract from all the symbols in this class.
-             sort keys %{"${class}::"}
-      ) {
-        # XXX This should probably be %packs (or %packs should be %seen).
+
+        # Extract from all the symbols in this class.
+        sort keys %{"${class}::"}
+      )
+    {
+
+        # If we printed this already, skip it.
         next if $seen{$name}++;
+
+        # Print the new method name.
         local $\ = '';
         local $, = '';
         print $DB::OUT "$prepend$name\n";
     } ## end for $name (grep { defined...
 
     # If the $crawl_upward argument is false, just quit here.
-    return unless shift; 
+    return unless shift;
 
     # $crawl_upward true: keep going up the tree.
     # Find all the classes this one is a subclass of.
-    for $name (@{"${class}::ISA"}) {
+    for $name ( @{"${class}::ISA"} ) {
+
         # Set up the new prefix.
         $prepend = $prefix ? $prefix . " -> $name" : $name;
-        # Crawl up the tree and keep trying to crawl up. 
-        methods_via($name, $prepend, 1);
+
+        # Crawl up the tree and keep trying to crawl up.
+        methods_via( $name, $prepend, 1 );
     }
 } ## end sub methods_via
 
@@ -7536,10 +7965,9 @@ Just checks the contents of C<$^O> and sets the C<$doccmd> global accordingly.
 =cut
 
 sub setman {
-    $doccmd =
-      $^O !~ /^(?:MSWin32|VMS|os2|dos|amigaos|riscos|MacOS|NetWare)\z/s
-      ? "man"               # O Happy Day!
-      : "perldoc";          # Alas, poor unfortunates
+    $doccmd = $^O !~ /^(?:MSWin32|VMS|os2|dos|amigaos|riscos|MacOS|NetWare)\z/s
+      ? "man"         # O Happy Day!
+      : "perldoc";    # Alas, poor unfortunates
 } ## end sub setman
 
 =head2 C<runman> - run the appropriate command to show documentation
@@ -7559,7 +7987,7 @@ sub runman {
 
     # this way user can override, like with $doccmd="man -Mwhatever"
     # or even just "man " to disable the path check.
-    unless ($doccmd eq 'man') {
+    unless ( $doccmd eq 'man' ) {
         &system("$doccmd $page");
         return;
     }
@@ -7569,7 +7997,7 @@ sub runman {
     require Config;
     my $man1dir = $Config::Config{'man1dir'};
     my $man3dir = $Config::Config{'man3dir'};
-    for ($man1dir, $man3dir) { s#/[^/]*\z## if /\S/ }
+    for ( $man1dir, $man3dir ) { s#/[^/]*\z## if /\S/ }
     my $manpath = '';
     $manpath .= "$man1dir:" if $man1dir =~ /\S/;
     $manpath .= "$man3dir:" if $man3dir =~ /\S/ && $man1dir ne $man3dir;
@@ -7584,33 +8012,160 @@ sub runman {
             $doccmd,
 
             # I just *know* there are men without -M
-            (($manpath && !$nopathopt) ? ("-M", $manpath) : ()),
+            ( ( $manpath && !$nopathopt ) ? ( "-M", $manpath ) : () ),
             split ' ', $page
         )
       )
     {
-        unless ($page =~ /^perl\w/) {
-            if (
-                grep { $page eq $_ }
-                qw{
-                5004delta 5005delta amiga api apio book boot bot call compile
-                cygwin data dbmfilter debug debguts delta diag doc dos dsc embed
-                faq faq1 faq2 faq3 faq4 faq5 faq6 faq7 faq8 faq9 filter fork
-                form func guts hack hist hpux intern ipc lexwarn locale lol mod
-                modinstall modlib number obj op opentut os2 os390 pod port
-                ref reftut run sec style sub syn thrtut tie toc todo toot tootc
-                trap unicode var vms win32 xs xstut
-                }
-              )
-            {
+        unless ( $page =~ /^perl\w/ ) {
+# do it this way because its easier to slurp in to keep up to date - clunky though.
+my @pods = qw(
+    5004delta
+    5005delta
+    561delta
+    56delta
+    570delta
+    571delta
+    572delta
+    573delta
+    58delta
+    581delta
+    582delta
+    583delta
+    584delta
+    590delta
+    591delta
+    592delta
+    aix
+    amiga
+    apio
+    api
+    apollo
+    artistic
+    beos
+    book
+    boot
+    bot
+    bs2000
+    call
+    ce
+    cheat
+    clib
+    cn
+    compile
+    cygwin
+    data
+    dbmfilter
+    debguts
+    debtut
+    debug
+    delta
+    dgux
+    diag
+    doc
+    dos
+    dsc
+    ebcdic
+    embed
+    epoc
+    faq1
+    faq2
+    faq3
+    faq4
+    faq5
+    faq6
+    faq7
+    faq8
+    faq9
+    faq
+    filter
+    fork
+    form
+    freebsd
+    func
+    gpl
+    guts
+    hack
+    hist
+    hpux
+    hurd
+    intern
+    intro
+    iol
+    ipc
+    irix
+    jp
+    ko
+    lexwarn
+    locale
+    lol
+    machten
+    macos
+    macosx
+    mint
+    modinstall
+    modlib
+    mod
+    modstyle
+    mpeix
+    netware
+    newmod
+    number
+    obj
+    opentut
+    op
+    os2
+    os390
+    os400
+    othrtut
+    packtut
+    plan9
+    pod
+    podspec
+    port
+    qnx
+    ref
+    reftut
+    re
+    requick
+    reref
+    retut
+    run
+    sec
+    solaris
+    style
+    sub
+    syn
+    thrtut
+    tie
+    toc
+    todo
+    tooc
+    toot
+    trap
+    tru64
+    tw
+    unicode
+    uniintro
+    util
+    uts
+    var
+    vmesa
+    vms
+    vos
+    win32
+    xs
+    xstut
+);
+            if (grep { $page eq $_ } @pods) {
                 $page =~ s/^/perl/;
-                CORE::system($doccmd,
-                    (($manpath && !$nopathopt) ? ("-M", $manpath) : ()),
-                    $page);
+                CORE::system( $doccmd,
+                    ( ( $manpath && !$nopathopt ) ? ( "-M", $manpath ) : () ),
+                    $page );
             } ## end if (grep { $page eq $_...
         } ## end unless ($page =~ /^perl\w/)
     } ## end if (CORE::system($doccmd...
-    if (defined $oldpath) {
+    if ( defined $oldpath ) {
         $ENV{MANPATH} = $manpath;
     }
     else {
@@ -7632,27 +8187,49 @@ debugger has to have set up before the Perl core starts running:
 
 =over 4 
 
-=item * The debugger's own filehandles (copies of STD and STDOUT for now).
+=item *
+
+The debugger's own filehandles (copies of STD and STDOUT for now).
+
+=item *
+
+Characters for shell escapes, the recall command, and the history command.
 
-=item * Characters for shell escapes, the recall command, and the history command.
+=item *
 
-=item * The maximum recursion depth.
+The maximum recursion depth.
 
-=item * The size of a C<w> command's window.
+=item *
 
-=item * The before-this-line context to be printed in a C<v> (view a window around this line) command.
+The size of a C<w> command's window.
 
-=item * The fact that we're not in a sub at all right now.
+=item *
 
-=item * The default SIGINT handler for the debugger.
+The before-this-line context to be printed in a C<v> (view a window around this line) command.
 
-=item * The appropriate value of the flag in C<$^D> that says the debugger is running
+=item *
 
-=item * The current debugger recursion level
+The fact that we're not in a sub at all right now.
 
-=item * The list of postponed (XXX define) items and the C<$single> stack
+=item *
 
-=item * That we want no return values and no subroutine entry/exit trace.
+The default SIGINT handler for the debugger.
+
+=item *
+
+The appropriate value of the flag in C<$^D> that says the debugger is running
+
+=item *
+
+The current debugger recursion level
+
+=item *
+
+The list of postponed items and the C<$single> stack (XXX define this)
+
+=item *
+
+That we want no return values and no subroutine entry/exit trace.
 
 =back
 
@@ -7661,35 +8238,36 @@ debugger has to have set up before the Perl core starts running:
 # The following BEGIN is very handy if debugger goes havoc, debugging debugger?
 
 BEGIN {    # This does not compile, alas. (XXX eh?)
-    $IN      = \*STDIN;     # For bugs before DB::OUT has been opened
-    $OUT     = \*STDERR;    # For errors before DB::OUT has been opened
+    $IN  = \*STDIN;     # For bugs before DB::OUT has been opened
+    $OUT = \*STDERR;    # For errors before DB::OUT has been opened
 
-    # Define characters used by command parsing. 
-    $sh      = '!';         # Shell escape (does not work)
-    $rc      = ',';         # Recall command (does not work)
-    @hist    = ('?');       # Show history (does not work)
+    # Define characters used by command parsing.
+    $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' 
+    # This defines the point at which you get the 'deep recursion'
     # warning. It MUST be defined or the debugger will not load.
-    $deep    = 100;
+    $deep = 100;
 
-    # Number of lines around the current one that are shown in the 
+    # Number of lines around the current one that are shown in the
     # 'w' command.
-    $window  = 10;
+    $window = 10;
 
     # How much before-the-current-line context the 'v' command should
     # use in calculating the start of the window it will display.
     $preview = 3;
 
     # We're not in any sub yet, but we need this to be a defined value.
-    $sub     = '';
+    $sub = '';
 
-    # Set up the debugger's interrupt handler. It simply sets a flag 
+    # Set up the debugger's interrupt handler. It simply sets a flag
     # ($signal) that DB::DB() will check before each command is executed.
     $SIG{INT} = \&DB::catch;
 
     # The following lines supposedly, if uncommented, allow the debugger to
-    # debug itself. Perhaps we can try that someday. 
+    # debug itself. Perhaps we can try that someday.
     # This may be enabled to debug debugger:
     #$warnLevel = 1 unless defined $warnLevel;
     #$dieLevel = 1 unless defined $dieLevel;
@@ -7699,28 +8277,28 @@ BEGIN {    # This does not compile, alas. (XXX eh?)
     # DB::DB and DB::sub". We will turn it on forcibly before we try to
     # execute anything in the user's context, because we always want to
     # get control back.
-    $db_stop = 0;           # Compiler warning ...
-    $db_stop = 1 << 30;     # ... because this is only used in an eval() later.
+    $db_stop = 0;          # Compiler warning ...
+    $db_stop = 1 << 30;    # ... because this is only used in an eval() later.
 
     # This variable records how many levels we're nested in debugging. Used
-    # Used in the debugger prompt, and in determining whether it's all over or 
+    # Used in the debugger prompt, and in determining whether it's all over or
     # not.
-    $level   = 0;           # Level of recursive debugging
+    $level = 0;            # Level of recursive debugging
 
     # "Triggers bug (?) in perl if we postpone this until runtime."
     # XXX No details on this yet, or whether we should fix the bug instead
-    # of work around it. Stay tuned. 
+    # of work around it. Stay tuned.
     @postponed = @stack = (0);
 
     # Used to track the current stack depth using the auto-stacked-variable
     # trick.
-    $stack_depth = 0;    # Localized repeatedly; simple way to track $#stack
+    $stack_depth = 0;      # Localized repeatedly; simple way to track $#stack
 
     # Don't print return values on exiting a subroutine.
-    $doret       = -2;
+    $doret = -2;
 
     # No extry/exit tracing.
-    $frame       = 0;
+    $frame = 0;
 
 } ## end BEGIN
 
@@ -7748,46 +8326,56 @@ sub db_complete {
     # $text is the text to be completed.
     # $line is the incoming line typed by the user.
     # $start is the start of the text to be completed in the incoming line.
-    my ($text, $line, $start) = @_;
+    my ( $text, $line, $start ) = @_;
 
     # Save the initial text.
     # The search pattern is current package, ::, extract the next qualifier
     # Prefix and pack are set to undef.
-    my ($itext, $search, $prefix, $pack) =
-      ($text, "^\Q${'package'}::\E([^:]+)\$");
+    my ( $itext, $search, $prefix, $pack ) =
+      ( $text, "^\Q${'package'}::\E([^:]+)\$" );
 
 =head3 C<b postpone|compile> 
 
 =over 4
 
-=item * Find all the subroutines that might match in this package
+=item *
+
+Find all the subroutines that might match in this package
+
+=item *
+
+Add C<postpone>, C<load>, and C<compile> as possibles (we may be completing the keyword itself)
+
+=item *
 
-=item * Add "postpone", "load", and "compile" as possibles (we may be completing the keyword itself
+Include all the rest of the subs that are known
 
-=item * Include all the rest of the subs that are known
+=item *
 
-=item * C<grep> out the ones that match the text we have so far
+C<grep> out the ones that match the text we have so far
 
-=item * Return this as the list of possible completions
+=item *
+
+Return this as the list of possible completions
 
 =back
 
 =cut 
 
-    return sort grep /^\Q$text/, (keys %sub),
+    return sort grep /^\Q$text/, ( keys %sub ),
       qw(postpone load compile),    # subroutines
-      (map { /$search/ ? ($1) : () } keys %sub)
-      if (substr $line, 0, $start) =~ /^\|*[blc]\s+((postpone|compile)\s+)?$/;
+      ( map { /$search/ ? ($1) : () } keys %sub )
+      if ( substr $line, 0, $start ) =~ /^\|*[blc]\s+((postpone|compile)\s+)?$/;
 
 =head3 C<b load>
 
-Get all the possible files from @INC as it currently stands and
+Get all the possible files from C<@INC> as it currently stands and
 select the ones that match the text so far.
 
 =cut
 
     return sort grep /^\Q$text/, values %INC    # files
-      if (substr $line, 0, $start) =~ /^\|*b\s+load\s+$/;
+      if ( substr $line, 0, $start ) =~ /^\|*b\s+load\s+$/;
 
 =head3  C<V> (list variable) and C<m> (list modules)
 
@@ -7801,9 +8389,9 @@ get all possible matching packages. Return this sorted list.
 
 =cut
 
-    return sort map { ($_, db_complete($_ . "::", "V ", 2)) }
-      grep /^\Q$text/, map { /^(.*)::$/ ? ($1) : () } keys %::  # top-packages
-      if (substr $line, 0, $start) =~ /^\|*[Vm]\s+$/ and $text =~ /^\w*$/;
+    return sort map { ( $_, db_complete( $_ . "::", "V ", 2 ) ) }
+      grep /^\Q$text/, map { /^(.*)::$/ ? ($1) : () } keys %::    # top-packages
+      if ( substr $line, 0, $start ) =~ /^\|*[Vm]\s+$/ and $text =~ /^\w*$/;
 
 =head4 Qualified package names
 
@@ -7814,12 +8402,12 @@ start with 'main::'. Return this list.
 
 =cut
 
-    return sort map { ($_, db_complete($_ . "::", "V ", 2)) }
+    return sort map { ( $_, db_complete( $_ . "::", "V ", 2 ) ) }
       grep !/^main::/, grep /^\Q$text/,
-        map { /^(.*)::$/ ? ($prefix . "::$1") : () } keys %{ $prefix . '::' }
-          if (substr $line, 0, $start) =~ /^\|*[Vm]\s+$/
-              and $text =~ /^(.*[^:])::?(\w*)$/
-              and $prefix = $1;
+      map { /^(.*)::$/ ? ( $prefix . "::$1" ) : () } keys %{ $prefix . '::' }
+      if ( substr $line, 0, $start ) =~ /^\|*[Vm]\s+$/
+      and $text =~ /^(.*[^:])::?(\w*)$/
+      and $prefix = $1;
 
 =head3 C<f> - switch files
 
@@ -7838,10 +8426,10 @@ Possibilities are:
 
 =cut
 
-    if ($line =~ /^\|*f\s+(.*)/) {                              # Loaded files
-        # We might possibly want to switch to an eval (which has a "filename"
-        # like '(eval 9)'), so we may need to clean up the completion text 
-        # before proceeding. 
+    if ( $line =~ /^\|*f\s+(.*)/ ) {    # Loaded files
+           # We might possibly want to switch to an eval (which has a "filename"
+           # like '(eval 9)'), so we may need to clean up the completion text
+           # before proceeding.
         $prefix = length($1) - length($text);
         $text   = $1;
 
@@ -7855,7 +8443,7 @@ match the completion text so far.
 =cut
 
         return sort
-          map { substr $_, 2 + $prefix } grep /^_<\Q$text/, (keys %main::),
+          map { substr $_, 2 + $prefix } grep /^_<\Q$text/, ( keys %main:: ),
           $0;
     } ## end if ($line =~ /^\|*f\s+(.*)/)
 
@@ -7867,46 +8455,52 @@ all the matches qualified to the current package.
 
 =cut
 
-    if ((substr $text, 0, 1) eq '&') {    # subroutines
+    if ( ( substr $text, 0, 1 ) eq '&' ) {    # subroutines
         $text = substr $text, 1;
         $prefix = "&";
-        return sort map "$prefix$_", grep /^\Q$text/, (keys %sub),
+        return sort map "$prefix$_", grep /^\Q$text/, ( keys %sub ),
           (
             map { /$search/ ? ($1) : () }
               keys %sub
-              );
+          );
     } ## end if ((substr $text, 0, ...
 
 =head3  Scalar, array, and hash completion: partially qualified package
 
 Much like the above, except we have to do a little more cleanup:
 
-=over 4 
-
 =cut
 
-    if ($text =~ /^[\$@%](.*)::(.*)/) {    # symbols in a package
+    if ( $text =~ /^[\$@%](.*)::(.*)/ ) {    # symbols in a package
 
 =pod
 
-=item * Determine the package that the symbol is in. Put it in C<::> (effectively C<main::>) if no package is specified.
+=over 4 
+
+=item *
+
+Determine the package that the symbol is in. Put it in C<::> (effectively C<main::>) if no package is specified.
 
 =cut
 
-        $pack = ($1 eq 'main' ? '' : $1) . '::';
+        $pack = ( $1 eq 'main' ? '' : $1 ) . '::';
 
 =pod
 
-=item * Figure out the prefix vs. what needs completing.
+=item *
+
+Figure out the prefix vs. what needs completing.
 
 =cut
 
-        $prefix = (substr $text, 0, 1) . $1 . '::';
-        $text = $2;
+        $prefix = ( substr $text, 0, 1 ) . $1 . '::';
+        $text   = $2;
 
 =pod
 
-=item * Look through all the symbols in the package. C<grep> out all the possible hashes/arrays/scalars, and then C<grep> the possible matches out of those. C<map> the prefix onto all the possibilities.
+=item *
+
+Look through all the symbols in the package. C<grep> out all the possible hashes/arrays/scalars, and then C<grep> the possible matches out of those. C<map> the prefix onto all the possibilities.
 
 =cut
 
@@ -7915,12 +8509,14 @@ Much like the above, except we have to do a little more cleanup:
 
 =pod
 
-=item * If there's only one hit, and it's a package qualifier, and it's not equal to the initial text, re-complete it using the symbol we actually found.
+=item *
+
+If there's only one hit, and it's a package qualifier, and it's not equal to the initial text, re-complete it using the symbol we actually found.
 
 =cut
 
-        if (@out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext) {
-            return db_complete($out[0], $line, $start);
+        if ( @out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext ) {
+            return db_complete( $out[0], $line, $start );
         }
 
         # Return the list of possibles.
@@ -7934,48 +8530,55 @@ Much like the above, except we have to do a little more cleanup:
 
 =head3 Symbol completion: current package or package C<main>.
 
-=over 4
-
 =cut
 
-
-    if ($text =~ /^[\$@%]/) {    # symbols (in $package + packages in main)
+    if ( $text =~ /^[\$@%]/ ) {    # symbols (in $package + packages in main)
 
 =pod
 
-=item * If it's C<main>, delete main to just get C<::> leading.
+=over 4
+
+=item *
+
+If it's C<main>, delete main to just get C<::> leading.
 
 =cut
 
-        $pack = ($package eq 'main' ? '' : $package) . '::';
+        $pack = ( $package eq 'main' ? '' : $package ) . '::';
 
 =pod
 
-=item * We set the prefix to the item's sigil, and trim off the sigil to get the text to be completed.
+=item *
+
+We set the prefix to the item's sigil, and trim off the sigil to get the text to be completed.
 
 =cut
 
         $prefix = substr $text, 0, 1;
-        $text = substr $text, 1;
+        $text   = substr $text, 1;
 
 =pod
 
-=item * If the package is C<::> (C<main>), create an empty list; if it's something else, create a list of all the packages known.  Append whichever list to a list of all the possible symbols in the current package. C<grep> out the matches to the text entered so far, then C<map> the prefix back onto the symbols.
+=item *
+
+If the package is C<::> (C<main>), create an empty list; if it's something else, create a list of all the packages known.  Append whichever list to a list of all the possible symbols in the current package. C<grep> out the matches to the text entered so far, then C<map> the prefix back onto the symbols.
 
 =cut
 
         my @out = map "$prefix$_", grep /^\Q$text/,
-          (grep /^_?[a-zA-Z]/, keys %$pack),
-          ($pack eq '::' ? () : (grep /::$/, keys %::));
+          ( grep /^_?[a-zA-Z]/, keys %$pack ),
+          ( $pack eq '::' ? () : ( grep /::$/, keys %:: ) );
+
+=item *
 
-=item * If there's only one hit, it's a package qualifier, and it's not equal to the initial text, recomplete using this symbol.
+If there's only one hit, it's a package qualifier, and it's not equal to the initial text, recomplete using this symbol.
 
 =back
 
 =cut
 
-        if (@out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext) {
-            return db_complete($out[0], $line, $start);
+        if ( @out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext ) {
+            return db_complete( $out[0], $line, $start );
         }
 
         # Return the list of possibles.
@@ -7992,33 +8595,34 @@ question mark, which, if executed, will list the current value of the option.
 
 =cut
 
-    # Say, didn't the option command's character change?)
-    # XXX Yes it did. Fix the following pattern match to correct the problem.
-    # XXX This is a bug.
-    if ((substr $line, 0, $start) =~ /^\|*O\b.*\s$/) { # Options after a space
-        # We look for the text to be matched in the list of possible options, 
-        # and fetch the current value. 
+    if ( ( substr $line, 0, $start ) =~ /^\|*[oO]\b.*\s$/ )
+    {    # Options after space
+           # We look for the text to be matched in the list of possible options,
+           # and fetch the current value.
         my @out = grep /^\Q$text/, @options;
-        my $val = option_val($out[0], undef);
+        my $val = option_val( $out[0], undef );
 
         # Set up a 'query option's value' command.
         my $out = '? ';
-        if (not defined $val or $val =~ /[\n\r]/) {
-           # There's really nothing else we can do.
+        if ( not defined $val or $val =~ /[\n\r]/ ) {
+
+            # There's really nothing else we can do.
         }
 
         # We have a value. Create a proper option-setting command.
-        elsif ($val =~ /\s/) {
+        elsif ( $val =~ /\s/ ) {
+
             # XXX This may be an extraneous variable.
             my $found;
 
             # We'll want to quote the string (because of the embedded
             # whtespace), but we want to make sure we don't end up with
             # mismatched quote characters. We try several possibilities.
-            foreach $l (split //, qq/\"\'\#\|/) {
+            foreach $l ( split //, qq/\"\'\#\|/ ) {
+
                 # If we didn't find this quote character in the value,
                 # quote it using this quote character.
-                $out = "$l$val$l ", last if (index $val, $l) == -1;
+                $out = "$l$val$l ", last if ( index $val, $l ) == -1;
             }
         } ## end elsif ($val =~ /\s/)
 
@@ -8031,7 +8635,7 @@ question mark, which, if executed, will list the current value of the option.
         # makes the command into a query command. If there was just one,
         # have readline append that.
         $rl_attribs->{completer_terminator_character} =
-          (@out == 1 ? $out : '? ');
+          ( @out == 1 ? $out : '? ' );
 
         # Return list of possibilities.
         return sort @out;
@@ -8071,14 +8675,319 @@ environment. Used by the C<R> (restart) command.
 =cut
 
 sub clean_ENV {
-    if (defined($ini_pids)) {
+    if ( defined($ini_pids) ) {
         $ENV{PERLDB_PIDS} = $ini_pids;
     }
     else {
-        delete($ENV{PERLDB_PIDS});
+        delete( $ENV{PERLDB_PIDS} );
     }
 } ## end sub clean_ENV
 
+# PERLDBf_... flag names from perl.h
+our ( %DollarCaretP_flags, %DollarCaretP_flags_r );
+
+BEGIN {
+    %DollarCaretP_flags = (
+        PERLDBf_SUB       => 0x01,     # Debug sub enter/exit
+        PERLDBf_LINE      => 0x02,     # Keep line #
+        PERLDBf_NOOPT     => 0x04,     # Switch off optimizations
+        PERLDBf_INTER     => 0x08,     # Preserve more data
+        PERLDBf_SUBLINE   => 0x10,     # Keep subr source lines
+        PERLDBf_SINGLE    => 0x20,     # Start with single-step on
+        PERLDBf_NONAME    => 0x40,     # For _SUB: no name of the subr
+        PERLDBf_GOTO      => 0x80,     # Report goto: call DB::goto
+        PERLDBf_NAMEEVAL  => 0x100,    # Informative names for evals
+        PERLDBf_NAMEANON  => 0x200,    # Informative names for anon subs
+        PERLDB_ALL        => 0x33f,    # No _NONAME, _GOTO
+    );
+
+    %DollarCaretP_flags_r = reverse %DollarCaretP_flags;
+}
+
+sub parse_DollarCaretP_flags {
+    my $flags = shift;
+    $flags =~ s/^\s+//;
+    $flags =~ s/\s+$//;
+    my $acu = 0;
+    foreach my $f ( split /\s*\|\s*/, $flags ) {
+        my $value;
+        if ( $f =~ /^0x([[:xdigit:]]+)$/ ) {
+            $value = hex $1;
+        }
+        elsif ( $f =~ /^(\d+)$/ ) {
+            $value = int $1;
+        }
+        elsif ( $f =~ /^DEFAULT$/i ) {
+            $value = $DollarCaretP_flags{PERLDB_ALL};
+        }
+        else {
+            $f =~ /^(?:PERLDBf_)?(.*)$/i;
+            $value = $DollarCaretP_flags{ 'PERLDBf_' . uc($1) };
+            unless ( defined $value ) {
+                print $OUT (
+                    "Unrecognized \$^P flag '$f'!\n",
+                    "Acceptable flags are: "
+                      . join( ', ', sort keys %DollarCaretP_flags ),
+                    ", and hexadecimal and decimal numbers.\n"
+                );
+                return undef;
+            }
+        }
+        $acu |= $value;
+    }
+    $acu;
+}
+
+sub expand_DollarCaretP_flags {
+    my $DollarCaretP = shift;
+    my @bits         = (
+        map {
+            my $n = ( 1 << $_ );
+            ( $DollarCaretP & $n )
+              ? ( $DollarCaretP_flags_r{$n}
+                  || sprintf( '0x%x', $n ) )
+              : ()
+          } 0 .. 31
+    );
+    return @bits ? join( '|', @bits ) : 0;
+}
+
+=over 4
+
+=item rerun
+
+Rerun the current session to:
+
+    rerun        current position
+
+    rerun 4      command number 4
+
+    rerun -4     current command minus 4 (go back 4 steps)
+
+Whether this always makes sense, in the current context is unknowable, and is
+in part left as a useful exersize for the reader.  This sub returns the
+appropriate arguments to rerun the current session.
+
+=cut
+
+sub rerun {
+    my $i = shift; 
+    my @args;
+    pop(@truehist);                      # strim
+    unless (defined $truehist[$i]) {
+        print "Unable to return to non-existent command: $i\n";
+    } else {
+        $#truehist = ($i < 0 ? $#truehist + $i : $i > 0 ? $i : $#truehist);
+        my @temp = @truehist;            # store
+        push(@DB::typeahead, @truehist); # saved
+        @truehist = @hist = ();          # flush
+        @args = &restart();              # setup
+        &get_list("PERLDB_HIST");        # clean
+        &set_list("PERLDB_HIST", @temp); # reset
+    }
+    return @args;
+}
+
+=item restart
+
+Restarting the debugger is a complex operation that occurs in several phases.
+First, we try to reconstruct the command line that was used to invoke Perl
+and the debugger.
+
+=cut
+
+sub restart {
+    # I may not be able to resurrect you, but here goes ...
+    print $OUT
+"Warning: some settings and command-line options may be lost!\n";
+    my ( @script, @flags, $cl );
+
+    # If warn was on before, turn it on again.
+    push @flags, '-w' if $ini_warn;
+
+    # Rebuild the -I flags that were on the initial
+    # command line.
+    for (@ini_INC) {
+        push @flags, '-I', $_;
+    }
+
+    # Turn on taint if it was on before.
+    push @flags, '-T' if ${^TAINT};
+
+    # Arrange for setting the old INC:
+    # Save the current @init_INC in the environment.
+    set_list( "PERLDB_INC", @ini_INC );
+
+    # If this was a perl one-liner, go to the "file"
+    # corresponding to the one-liner read all the lines
+    # out of it (except for the first one, which is going
+    # to be added back on again when 'perl -d' runs: that's
+    # the 'require perl5db.pl;' line), and add them back on
+    # to the command line to be executed.
+    if ( $0 eq '-e' ) {
+        for ( 1 .. $#{'::_<-e'} ) {  # The first line is PERL5DB
+            chomp( $cl = ${'::_<-e'}[$_] );
+            push @script, '-e', $cl;
+        }
+    } ## end if ($0 eq '-e')
+
+    # Otherwise we just reuse the original name we had
+    # before.
+    else {
+        @script = $0;
+    }
+
+=pod
+
+After the command line  has been reconstructed, the next step is to save
+the debugger's status in environment variables. The C<DB::set_list> routine
+is used to save aggregate variables (both hashes and arrays); scalars are
+just popped into environment variables directly.
+
+=cut
+
+    # If the terminal supported history, grab it and
+    # save that in the environment.
+    set_list( "PERLDB_HIST",
+          $term->Features->{getHistory}
+        ? $term->GetHistory
+        : @hist );
+
+    # Find all the files that were visited during this
+    # session (i.e., the debugger had magic hashes
+    # corresponding to them) and stick them in the environment.
+    my @had_breakpoints = keys %had_breakpoints;
+    set_list( "PERLDB_VISITED", @had_breakpoints );
+
+    # Save the debugger options we chose.
+    set_list( "PERLDB_OPT", %option );
+    # set_list( "PERLDB_OPT", options2remember() );
+
+    # Save the break-on-loads.
+    set_list( "PERLDB_ON_LOAD", %break_on_load );
+
+=pod 
+
+The most complex part of this is the saving of all of the breakpoints. They
+can live in an awful lot of places, and we have to go through all of them,
+find the breakpoints, and then save them in the appropriate environment
+variable via C<DB::set_list>.
+
+=cut
+
+    # Go through all the breakpoints and make sure they're
+    # still valid.
+    my @hard;
+    for ( 0 .. $#had_breakpoints ) {
+
+        # We were in this file.
+        my $file = $had_breakpoints[$_];
+
+        # Grab that file's magic line hash.
+        *dbline = $main::{ '_<' . $file };
+
+        # Skip out if it doesn't exist, or if the breakpoint
+        # is in a postponed file (we'll do postponed ones
+        # later).
+        next unless %dbline or $postponed_file{$file};
+
+        # In an eval. This is a little harder, so we'll
+        # do more processing on that below.
+        ( push @hard, $file ), next
+          if $file =~ /^\(\w*eval/;
+
+        # XXX I have no idea what this is doing. Yet.
+        my @add;
+        @add = %{ $postponed_file{$file} }
+          if $postponed_file{$file};
+
+        # Save the list of all the breakpoints for this file.
+        set_list( "PERLDB_FILE_$_", %dbline, @add );
+    } ## end for (0 .. $#had_breakpoints)
+
+    # The breakpoint was inside an eval. This is a little
+    # more difficult. XXX and I don't understand it.
+    for (@hard) {
+        # Get over to the eval in question.
+        *dbline = $main::{ '_<' . $_ };
+        my ( $quoted, $sub, %subs, $line ) = quotemeta $_;
+        for $sub ( keys %sub ) {
+            next unless $sub{$sub} =~ /^$quoted:(\d+)-(\d+)$/;
+            $subs{$sub} = [ $1, $2 ];
+        }
+        unless (%subs) {
+            print $OUT
+              "No subroutines in $_, ignoring breakpoints.\n";
+            next;
+        }
+      LINES: for $line ( keys %dbline ) {
+
+            # One breakpoint per sub only:
+            my ( $offset, $sub, $found );
+          SUBS: for $sub ( keys %subs ) {
+                if (
+                    $subs{$sub}->[1] >=
+                    $line    # Not after the subroutine
+                    and (
+                        not defined $offset    # Not caught
+                        or $offset < 0
+                    )
+                  )
+                {                              # or badly caught
+                    $found  = $sub;
+                    $offset = $line - $subs{$sub}->[0];
+                    $offset = "+$offset", last SUBS
+                      if $offset >= 0;
+                } ## end if ($subs{$sub}->[1] >=...
+            } ## end for $sub (keys %subs)
+            if ( defined $offset ) {
+                $postponed{$found} =
+                  "break $offset if $dbline{$line}";
+            }
+            else {
+                print $OUT
+"Breakpoint in $_:$line ignored: after all the subroutines.\n";
+            }
+        } ## end for $line (keys %dbline)
+    } ## end for (@hard)
+
+    # Save the other things that don't need to be
+    # processed.
+    set_list( "PERLDB_POSTPONE",  %postponed );
+    set_list( "PERLDB_PRETYPE",   @$pretype );
+    set_list( "PERLDB_PRE",       @$pre );
+    set_list( "PERLDB_POST",      @$post );
+    set_list( "PERLDB_TYPEAHEAD", @typeahead );
+
+    # We are oficially restarting.
+    $ENV{PERLDB_RESTART} = 1;
+
+    # We are junking all child debuggers.
+    delete $ENV{PERLDB_PIDS};    # Restore ini state
+
+    # Set this back to the initial pid.
+    $ENV{PERLDB_PIDS} = $ini_pids if defined $ini_pids;
+
+=pod 
+
+After all the debugger status has been saved, we take the command we built up
+and then return it, so we can C<exec()> it. The debugger will spot the
+C<PERLDB_RESTART> environment variable and realize it needs to reload its state
+from the environment.
+
+=cut
+
+    # And run Perl again. Add the "-d" flag, all the
+    # flags we built up, the script (whether a one-liner
+    # or a file), add on the -emacs flag for a slave editor,
+    # and then the old arguments. 
+
+    return ($^X, '-d', @flags, @script, ($slave_editor ? '-emacs' : ()), @ARGS);
+
+};  # end restart
+
+=back
+
 =head1 END PROCESSING - THE C<END> BLOCK
 
 Come here at the very end of processing. We want to go into a 
@@ -8092,7 +9001,7 @@ We then figure out whether we're truly done (as in the user entered a C<q>
 command, or we finished execution while running nonstop). If we aren't,
 we set C<$single> to 1 (causing the debugger to get control again).
 
-We then call C<DB::fake::at_exit()>, which returns the C<Use 'q' to quit ...">
+We then call C<DB::fake::at_exit()>, which returns the C<Use 'q' to quit ...>
 message and returns control to the debugger. Repeat.
 
 When the user finally enters a C<q> command, C<$fall_off_end> is set to
@@ -8106,8 +9015,12 @@ END {
     $fall_off_end = 1 unless $inhibit_exit;
 
     # Do not stop in at_exit() and destructors on exit:
-    $DB::single = !$fall_off_end && !$runnonstop;
-    DB::fake::at_exit() unless $fall_off_end or $runnonstop;
+    if ($fall_off_end or $runnonstop) {
+        &save_hist();
+    } else {
+        $DB::single = 1;
+        DB::fake::at_exit();
+    }
 } ## end END
 
 =head1 PRE-5.8 COMMANDS
@@ -8122,7 +9035,7 @@ comments to keep things clear.
 
 =head2 Null command
 
-Does nothing. Used to 'turn off' commands.
+Does nothing. Used to I<turn off> commands.
 
 =cut
 
@@ -8143,20 +9056,21 @@ sub cmd_pre580_a {
     my $cmd  = shift;
 
     # Argument supplied. Add the action.
-    if ($cmd =~ /^(\d*)\s*(.*)/) {
+    if ( $cmd =~ /^(\d*)\s*(.*)/ ) {
 
         # If the line isn't there, use the current line.
         $i = $1 || $line;
         $j = $2;
 
         # If there is an action ...
-        if (length $j) {
+        if ( length $j ) {
 
             # ... but the line isn't breakable, skip it.
-            if ($dbline[$i] == 0) {
+            if ( $dbline[$i] == 0 ) {
                 print $OUT "Line $i may not have an action.\n";
             }
             else {
+
                 # ... and the line is breakable:
                 # Mark that there's an action in this file.
                 $had_breakpoints{$filename} |= 2;
@@ -8171,8 +9085,10 @@ sub cmd_pre580_a {
 
         # No action supplied.
         else {
+
             # Delete the action.
             $dbline{$i} =~ s/\0[^\0]*//;
+
             # Mark as having no break or action if nothing's left.
             delete $dbline{$i} if $dbline{$i} eq '';
         }
@@ -8186,27 +9102,28 @@ Add breakpoints.
 =cut
 
 sub cmd_pre580_b {
-    my $xcmd    = shift;
-    my $cmd     = shift;
+    my $xcmd   = shift;
+    my $cmd    = shift;
     my $dbline = shift;
 
     # Break on load.
-    if ($cmd =~ /^load\b\s*(.*)/) {
+    if ( $cmd =~ /^load\b\s*(.*)/ ) {
         my $file = $1;
         $file =~ s/\s+$//;
         &cmd_b_load($file);
     }
 
     # b compile|postpone <some sub> [<condition>]
-    # The interpreter actually traps this one for us; we just put the 
+    # The interpreter actually traps this one for us; we just put the
     # necessary condition in the %postponed hash.
-    elsif ($cmd =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/) {
+    elsif ( $cmd =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/ ) {
+
         # Capture the condition if there is one. Make it true if none.
         my $cond = length $3 ? $3 : '1';
 
         # Save the sub name and set $break to 1 if $1 was 'postpone', 0
         # if it was 'compile'.
-        my ($subname, $break) = ($2, $1 eq 'postpone');
+        my ( $subname, $break ) = ( $2, $1 eq 'postpone' );
 
         # De-Perl4-ify the name - ' separators to ::.
         $subname =~ s/\'/::/g;
@@ -8216,24 +9133,24 @@ sub cmd_pre580_b {
           unless $subname =~ /::/;
 
         # Add main if it starts with ::.
-        $subname = "main" . $subname if substr($subname, 0, 2) eq "::";
+        $subname = "main" . $subname if substr( $subname, 0, 2 ) eq "::";
 
         # Save the break type for this sub.
         $postponed{$subname} = $break ? "break +0 if $cond" : "compile";
     } ## end elsif ($cmd =~ ...
 
     # b <sub name> [<condition>]
-    elsif ($cmd =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/) {
+    elsif ( $cmd =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/ ) {
         my $subname = $1;
         my $cond = length $2 ? $2 : '1';
-        &cmd_b_sub($subname, $cond);
+        &cmd_b_sub( $subname, $cond );
     }
 
     # b <line> [<condition>].
-    elsif ($cmd =~ /^(\d*)\s*(.*)/) {
+    elsif ( $cmd =~ /^(\d*)\s*(.*)/ ) {
         my $i = $1 || $dbline;
         my $cond = length $2 ? $2 : '1';
-        &cmd_b_line($i, $cond);
+        &cmd_b_line( $i, $cond );
     }
 } ## end sub cmd_pre580_b
 
@@ -8246,13 +9163,14 @@ Delete all breakpoints unconditionally.
 sub cmd_pre580_D {
     my $xcmd = shift;
     my $cmd  = shift;
-    if ($cmd =~ /^\s*$/) {
+    if ( $cmd =~ /^\s*$/ ) {
         print $OUT "Deleting all breakpoints...\n";
 
         # %had_breakpoints lists every file that had at least one
         # breakpoint in it.
         my $file;
-        for $file (keys %had_breakpoints) {
+        for $file ( keys %had_breakpoints ) {
+
             # Switch to the desired file temporarily.
             local *dbline = $main::{ '_<' . $file };
 
@@ -8260,12 +9178,15 @@ sub cmd_pre580_D {
             my $was;
 
             # For all lines in this file ...
-            for ($i = 1 ; $i <= $max ; $i++) {
+            for ( $i = 1 ; $i <= $max ; $i++ ) {
+
                 # If there's a breakpoint or action on this line ...
-                if (defined $dbline{$i}) {
+                if ( defined $dbline{$i} ) {
+
                     # ... remove the breakpoint.
                     $dbline{$i} =~ s/^[^\0]+//;
-                    if ($dbline{$i} =~ s/^\0?$//) {
+                    if ( $dbline{$i} =~ s/^\0?$// ) {
+
                         # Remove the entry altogether if no action is there.
                         delete $dbline{$i};
                     }
@@ -8273,9 +9194,9 @@ sub cmd_pre580_D {
             } ## end for ($i = 1 ; $i <= $max...
 
             # If, after we turn off the "there were breakpoints in this file"
-            # bit, the entry in %had_breakpoints for this file is zero, 
+            # bit, the entry in %had_breakpoints for this file is zero,
             # we should remove this file from the hash.
-            if (not $had_breakpoints{$file} &= ~1) {
+            if ( not $had_breakpoints{$file} &= ~1 ) {
                 delete $had_breakpoints{$file};
             }
         } ## end for $file (keys %had_breakpoints)
@@ -8300,25 +9221,28 @@ sub cmd_pre580_h {
     my $cmd  = shift;
 
     # Print the *right* help, long format.
-    if ($cmd =~ /^\s*$/) {
+    if ( $cmd =~ /^\s*$/ ) {
         print_help($pre580_help);
     }
 
-    # 'h h' - explicitly-requested summary. 
-    elsif ($cmd =~ /^h\s*/) {
+    # 'h h' - explicitly-requested summary.
+    elsif ( $cmd =~ /^h\s*/ ) {
         print_help($pre580_summary);
     }
 
     # Find and print a command's help.
-    elsif ($cmd =~ /^h\s+(\S.*)$/) {
+    elsif ( $cmd =~ /^h\s+(\S.*)$/ ) {
         my $asked  = $1;                   # for proper errmsg
         my $qasked = quotemeta($asked);    # for searching
                                            # XXX: finds CR but not <CR>
-        if ($pre580_help =~ /^
+        if (
+            $pre580_help =~ /^
                               <?           # Optional '<'
                               (?:[IB]<)    # Optional markup
                               $qasked      # The command name
-                            /mx) {
+                            /mx
+          )
+        {
 
             while (
                 $pre580_help =~ /^
@@ -8329,8 +9253,9 @@ sub cmd_pre580_h {
                                    ([\s\S]*?)   # Lines starting with tabs
                                    \n           # Final newline
                                   )
-                                  (?!\s)/mgx)   # Line not starting with space
-                                                # (Next command's help)
+                                  (?!\s)/mgx
+              )    # Line not starting with space
+                   # (Next command's help)
             {
                 print_help($1);
             }
@@ -8354,23 +9279,26 @@ sub cmd_pre580_W {
     my $cmd  = shift;
 
     # Delete all watch expressions.
-    if ($cmd =~ /^$/) {
+    if ( $cmd =~ /^$/ ) {
+
         # No watching is going on.
         $trace &= ~2;
+
         # Kill all the watch expressions and values.
         @to_watch = @old_watch = ();
     }
 
     # Add a watch expression.
-    elsif ($cmd =~ /^(.*)/s) {
+    elsif ( $cmd =~ /^(.*)/s ) {
+
         # add it to the list to be watched.
         push @to_watch, $1;
 
-        # Get the current value of the expression. 
+        # Get the current value of the expression.
         # Doesn't handle expressions returning list values!
         $evalarg = $1;
         my ($val) = &eval;
-        $val = (defined $val) ? "'$val'" : 'undef';
+        $val = ( defined $val ) ? "'$val'" : 'undef';
 
         # Save it.
         push @old_watch, $val;
@@ -8406,14 +9334,15 @@ sub cmd_pre590_prepost {
 
 =head2 C<cmd_prepost>
 
-Actually does all the handling foe C<E<lt>>, C<E<gt>>, C<{{>, C<{>, etc.
+Actually does all the handling for C<E<lt>>, C<E<gt>>, C<{{>, C<{>, etc.
 Since the lists of actions are all held in arrays that are pointed to by
 references anyway, all we have to do is pick the right array reference and
 then use generic code to all, delete, or list actions.
 
 =cut
 
-sub cmd_prepost { my $cmd = shift;
+sub cmd_prepost {
+    my $cmd = shift;
 
     # No action supplied defaults to 'list'.
     my $line = shift || '?';
@@ -8424,9 +9353,9 @@ sub cmd_prepost { my $cmd = shift;
     # Make sure we have some array or another to address later.
     # This means that if ssome reason the tests fail, we won't be
     # trying to stash actions or delete them from the wrong place.
-    my $aref  = [];
+    my $aref = [];
 
-   # < - Perl code to run before prompt.
+    # < - Perl code to run before prompt.
     if ( $cmd =~ /^\</o ) {
         $which = 'pre-perl';
         $aref  = $pre;
@@ -8457,15 +9386,18 @@ sub cmd_prepost { my $cmd = shift;
         print $OUT "Confused by command: $cmd\n";
     }
 
-    # Yes. 
+    # Yes.
     else {
+
         # List actions.
         if ( $line =~ /^\s*\?\s*$/o ) {
             unless (@$aref) {
+
                 # Nothing there. Complain.
                 print $OUT "No $which actions.\n";
             }
             else {
+
                 # List the actions in the selected list.
                 print $OUT "$which commands:\n";
                 foreach my $action (@$aref) {
@@ -8478,21 +9410,25 @@ sub cmd_prepost { my $cmd = shift;
         else {
             if ( length($cmd) == 1 ) {
                 if ( $line =~ /^\s*\*\s*$/o ) {
-                    # It's a delete. Get rid of the old actions in the 
+
+                    # It's a delete. Get rid of the old actions in the
                     # selected list..
                     @$aref = ();
                     print $OUT "All $cmd actions cleared.\n";
                 }
                 else {
+
                     # Replace all the actions. (This is a <, >, or {).
                     @$aref = action($line);
                 }
             } ## end if ( length($cmd) == 1)
-            elsif ( length($cmd) == 2 ) { 
+            elsif ( length($cmd) == 2 ) {
+
                 # Add the action to the line. (This is a <<, >>, or {{).
                 push @$aref, action($line);
             }
             else {
+
                 # <<<, >>>>, {{{{{{ ... something not a command.
                 print $OUT
                   "Confused by strange length of $which command($cmd)...\n";
@@ -8501,7 +9437,6 @@ sub cmd_prepost { my $cmd = shift;
     } ## end else
 } ## end sub cmd_prepost
 
-
 =head1 C<DB::fake>
 
 Contains the C<at_exit> routine that the debugger uses to issue the
@@ -8520,3 +9455,4 @@ package DB;    # Do not trace this 1; below!
 
 1;
 
+