3 # Debugger for Perl 5.00x; perl5db.pl patch level:
5 $header = "perl5db.pl version $VERSION";
7 # It is crucial that there is no lexicals in scope of `eval ""' down below
9 # 'my' would make it visible from user code
10 # but so does local! --tchrist [... into @DB::res, not @res. IZ]
13 local $otrace = $trace;
14 local $osingle = $single;
16 { ($evalarg) = $evalarg =~ /(.*)/s; }
17 @res = eval "$usercontext $evalarg;\n"; # '\n' for nice recursive debug
23 local $saved[0]; # Preserve the old value of $@
28 } elsif ($onetimeDump) {
29 if ($onetimeDump eq 'dump') {
30 local $option{dumpDepth} = $onetimedumpDepth
31 if defined $onetimedumpDepth;
33 } elsif ($onetimeDump eq 'methods') {
40 # After this point it is safe to introduce lexicals
41 # However, one should not overdo it: leave as much control from outside as possible
43 # This file is automatically included if you do perl -d.
44 # It's probably not useful to include this yourself.
46 # Before venturing further into these twisty passages, it is
47 # wise to read the perldebguts man page or risk the ire of dragons.
49 # Perl supplies the values for %sub. It effectively inserts
50 # a &DB::DB(); in front of every place that can have a
51 # breakpoint. Instead of a subroutine call it calls &DB::sub with
52 # $DB::sub being the called subroutine. It also inserts a BEGIN
53 # {require 'perl5db.pl'} before the first line.
55 # After each `require'd file is compiled, but before it is executed, a
56 # call to DB::postponed($main::{'_<'.$filename}) is emulated. Here the
57 # $filename is the expanded name of the `require'd file (as found as
60 # Additional services from Perl interpreter:
62 # if caller() is called from the package DB, it provides some
65 # The array @{$main::{'_<'.$filename}} (herein called @dbline) is the
66 # line-by-line contents of $filename.
68 # The hash %{'_<'.$filename} (herein called %dbline) contains
69 # breakpoints and action (it is keyed by line number), and individual
70 # entries are settable (as opposed to the whole hash). Only true/false
71 # is important to the interpreter, though the values used by
72 # perl5db.pl have the form "$break_condition\0$action". Values are
73 # magical in numeric context.
75 # The scalar ${'_<'.$filename} contains $filename.
77 # Note that no subroutine call is possible until &DB::sub is defined
78 # (for subroutines defined outside of the package DB). In fact the same is
79 # true if $deep is not defined.
83 # At start reads $rcfile that may set important options. This file
84 # may define a subroutine &afterinit that will be executed after the
85 # debugger is initialized.
87 # After $rcfile is read reads environment variable PERLDB_OPTS and parses
88 # it as a rest of `O ...' line in debugger prompt.
90 # The options that can be specified only at startup:
91 # [To set in $rcfile, call &parse_options("optionName=new_value").]
93 # TTY - the TTY to use for debugging i/o.
95 # noTTY - if set, goes in NonStop mode. On interrupt if TTY is not set
96 # uses the value of noTTY or "/tmp/perldbtty$$" to find TTY using
97 # Term::Rendezvous. Current variant is to have the name of TTY in this
100 # ReadLine - If false, dummy ReadLine is used, so you can debug
101 # ReadLine applications.
103 # NonStop - if true, no i/o is performed until interrupt.
105 # LineInfo - file or pipe to print line number info to. If it is a
106 # pipe, a short "emacs like" message is used.
108 # RemotePort - host:port to connect to on remote host for remote debugging.
110 # Example $rcfile: (delete leading hashes!)
112 # &parse_options("NonStop=1 LineInfo=db.out");
113 # sub afterinit { $trace = 1; }
115 # The script will run without human intervention, putting trace
116 # information into db.out. (If you interrupt it, you would better
117 # reset LineInfo to something "interactive"!)
119 ##################################################################
121 # Enhanced by ilya@math.ohio-state.edu (Ilya Zakharevich)
123 # modified Perl debugger, to be run from Emacs in perldb-mode
124 # Ray Lischner (uunet!mntgfx!lisch) as of 5 Nov 1990
125 # Johan Vromans -- upgrade to 4.0 pl 10
126 # Ilya Zakharevich -- patches after 5.001 (and some before ;-)
130 # A lot of things changed after 0.94. First of all, core now informs
131 # debugger about entry into XSUBs, overloaded operators, tied operations,
132 # BEGIN and END. Handy with `O f=2'.
134 # This can make debugger a little bit too verbose, please be patient
135 # and report your problems promptly.
137 # Now the option frame has 3 values: 0,1,2.
139 # Note that if DESTROY returns a reference to the object (or object),
140 # the deletion of data may be postponed until the next function call,
141 # due to the need to examine the return value.
143 # Changes: 0.95: `v' command shows versions.
144 # Changes: 0.96: `v' command shows version of readline.
145 # primitive completion works (dynamic variables, subs for `b' and `l',
146 # options). Can `p %var'
147 # Better help (`h <' now works). New commands <<, >>, {, {{.
148 # {dump|print}_trace() coded (to be able to do it from <<cmd).
149 # `c sub' documented.
150 # At last enough magic combined to stop after the end of debuggee.
151 # !! should work now (thanks to Emacs bracket matching an extra
152 # `]' in a regexp is caught).
153 # `L', `D' and `A' span files now (as documented).
154 # Breakpoints in `require'd code are possible (used in `R').
155 # Some additional words on internal work of debugger.
156 # `b load filename' implemented.
157 # `b postpone subr' implemented.
158 # now only `q' exits debugger (overwritable on $inhibit_exit).
159 # When restarting debugger breakpoints/actions persist.
160 # Buglet: When restarting debugger only one breakpoint/action per
161 # autoloaded function persists.
162 # Changes: 0.97: NonStop will not stop in at_exit().
163 # Option AutoTrace implemented.
164 # Trace printed differently if frames are printed too.
165 # new `inhibitExit' option.
166 # printing of a very long statement interruptible.
167 # Changes: 0.98: New command `m' for printing possible methods
168 # 'l -' is a synonym for `-'.
169 # Cosmetic bugs in printing stack trace.
170 # `frame' & 8 to print "expanded args" in stack trace.
171 # Can list/break in imported subs.
172 # new `maxTraceLen' option.
173 # frame & 4 and frame & 8 granted.
175 # nonstoppable lines do not have `:' near the line number.
176 # `b compile subname' implemented.
177 # Will not use $` any more.
178 # `-' behaves sane now.
179 # Changes: 0.99: Completion for `f', `m'.
180 # `m' will remove duplicate names instead of duplicate functions.
181 # `b load' strips trailing whitespace.
182 # completion ignores leading `|'; takes into account current package
183 # when completing a subroutine name (same for `l').
184 # Changes: 1.07: Many fixed by tchrist 13-March-2000
186 # + Added bare minimal security checks on perldb rc files, plus
187 # comments on what else is needed.
188 # + Fixed the ornaments that made "|h" completely unusable.
189 # They are not used in print_help if they will hurt. Strip pod
190 # if we're paging to less.
191 # + Fixed mis-formatting of help messages caused by ornaments
192 # to restore Larry's original formatting.
193 # + Fixed many other formatting errors. The code is still suboptimal,
194 # and needs a lot of work at restructuring. It's also misindented
196 # + Fixed bug where trying to look at an option like your pager
198 # + Fixed some $? processing. Note: if you use csh or tcsh, you will
199 # lose. You should consider shell escapes not using their shell,
200 # or else not caring about detailed status. This should really be
201 # unified into one place, too.
202 # + Fixed bug where invisible trailing whitespace on commands hoses you,
203 # tricking Perl into thinking you weren't calling a debugger command!
204 # + Fixed bug where leading whitespace on commands hoses you. (One
205 # suggests a leading semicolon or any other irrelevant non-whitespace
206 # to indicate literal Perl code.)
207 # + Fixed bugs that ate warnings due to wrong selected handle.
208 # + Fixed a precedence bug on signal stuff.
209 # + Fixed some unseemly wording.
210 # + Fixed bug in help command trying to call perl method code.
211 # + Fixed to call dumpvar from exception handler. SIGPIPE killed us.
213 # + Added some comments. This code is still nasty spaghetti.
214 # + Added message if you clear your pre/post command stacks which was
215 # very easy to do if you just typed a bare >, <, or {. (A command
216 # without an argument should *never* be a destructive action; this
217 # API is fundamentally screwed up; likewise option setting, which
218 # is equally buggered.)
219 # + Added command stack dump on argument of "?" for >, <, or {.
220 # + Added a semi-built-in doc viewer command that calls man with the
221 # proper %Config::Config path (and thus gets caching, man -k, etc),
222 # or else perldoc on obstreperous platforms.
223 # + Added to and rearranged the help information.
224 # + Detected apparent misuse of { ... } to declare a block; this used
225 # to work but now is a command, and mysteriously gave no complaint.
227 # Changes: 1.08: Apr 25, 2001 Jon Eveland <jweveland@yahoo.com>
229 # + This patch to perl5db.pl cleans up formatting issues on the help
230 # summary (h h) screen in the debugger. Mostly columnar alignment
231 # issues, plus converted the printed text to use all spaces, since
232 # tabs don't seem to help much here.
234 # Changes: 1.09: May 19, 2001 Ilya Zakharevich <ilya@math.ohio-state.edu>
235 # 0) Minor bugs corrected;
236 # a) Support for auto-creation of new TTY window on startup, either
237 # unconditionally, or if started as a kid of another debugger session;
238 # b) New `O'ption CreateTTY
239 # I<CreateTTY> bits control attempts to create a new TTY on events:
240 # 1: on fork() 2: debugger is started inside debugger
242 # c) Code to auto-create a new TTY window on OS/2 (currently one
243 # extra window per session - need named pipes to have more...);
244 # d) Simplified interface for custom createTTY functions (with a backward
245 # compatibility hack); now returns the TTY name to use; return of ''
246 # means that the function reset the I/O handles itself;
247 # d') Better message on the semantic of custom createTTY function;
248 # e) Convert the existing code to create a TTY into a custom createTTY
250 # f) Consistent support for TTY names of the form "TTYin,TTYout";
251 # g) Switch line-tracing output too to the created TTY window;
252 # h) make `b fork' DWIM with CORE::GLOBAL::fork;
253 # i) High-level debugger API cmd_*():
254 # cmd_b_load($filenamepart) # b load filenamepart
255 # cmd_b_line($lineno [, $cond]) # b lineno [cond]
256 # cmd_b_sub($sub [, $cond]) # b sub [cond]
257 # cmd_stop() # Control-C
258 # cmd_d($lineno) # d lineno (B)
259 # The cmd_*() API returns FALSE on failure; in this case it outputs
260 # the error message to the debugging output.
261 # j) Low-level debugger API
262 # break_on_load($filename) # b load filename
263 # @files = report_break_on_load() # List files with load-breakpoints
264 # breakable_line_in_filename($name, $from [, $to])
265 # # First breakable line in the
266 # # range $from .. $to. $to defaults
267 # # to $from, and may be less than $to
268 # breakable_line($from [, $to]) # Same for the current file
269 # break_on_filename_line($name, $lineno [, $cond])
270 # # Set breakpoint,$cond defaults to 1
271 # break_on_filename_line_range($name, $from, $to [, $cond])
272 # # As above, on the first
273 # # breakable line in range
274 # break_on_line($lineno [, $cond]) # As above, in the current file
275 # break_subroutine($sub [, $cond]) # break on the first breakable line
276 # ($name, $from, $to) = subroutine_filename_lines($sub)
277 # # The range of lines of the text
278 # The low-level API returns TRUE on success, and die()s on failure.
280 # Changes: 1.10: May 23, 2001 Daniel Lewart <d-lewart@uiuc.edu>
282 # + Fixed warnings generated by "perl -dWe 42"
283 # + Corrected spelling errors
284 # + Squeezed Help (h) output into 80 columns
286 # Changes: 1.11: May 24, 2001 David Dyck <dcd@tc.fluke.com>
287 # + Made "x @INC" work like it used to
289 # Changes: 1.12: May 24, 2001 Daniel Lewart <d-lewart@uiuc.edu>
290 # + Fixed warnings generated by "O" (Show debugger options)
291 # + Fixed warnings generated by "p 42" (Print expression)
292 # Changes: 1.13: Jun 19, 2001 Scott.L.Miller@compaq.com
293 # + Added windowSize option
294 # Changes: 1.14: Oct 9, 2001 multiple
295 # + Clean up after itself on VMS (Charles Lane in 12385)
296 # + Adding "@ file" syntax (Peter Scott in 12014)
297 # + Debug reloading selfloaded stuff (Ilya Zakharevich in 11457)
298 # + $^S and other debugger fixes (Ilya Zakharevich in 11120)
299 # + Forgot a my() declaration (Ilya Zakharevich in 11085)
300 # Changes: 1.15: Nov 6, 2001 Michael G Schwern <schwern@pobox.com>
301 # + Updated 1.14 change log
302 # + Added *dbline explainatory comments
303 # + Mentioning perldebguts man page
304 # Changes: 1.16: Feb 15, 2002 Mark-Jason Dominus <mjd@plover.com>
305 # + $onetimeDump improvements
306 # Changes: 1.17: Feb 20, 2002 Richard Foley <richard.foley@rfi.net>
307 # Moved some code to cmd_[.]()'s for clarity and ease of handling,
308 # rationalised the following commands and added cmd_wrapper() to
309 # enable switching between old and frighteningly consistent new
310 # behaviours for diehards: 'o CommandSet=pre580' (sigh...)
311 # a(add), A(del) # action expr (added del by line)
312 # + b(add), B(del) # break [line] (was b,D)
313 # + w(add), W(del) # watch expr (was W,W) added del by expr
314 # + h(summary), h h(long) # help (hh) (was h h,h)
315 # + m(methods), M(modules) # ... (was m,v)
316 # + o(option) # lc (was O)
317 # + v(view code), V(view Variables) # ... (was w,V)
318 # Changes: 1.18: Mar 17, 2002 Richard Foley <richard.foley@rfi.net>
319 # + fixed missing cmd_O bug
320 # Changes: 1.19: Mar 29, 2002 Spider Boardman
321 # + Added missing local()s -- DB::DB is called recursively.
322 # Changes: 1.20: Feb 17, 2003 Richard Foley <richard.foley@rfi.net>
323 # + pre'n'post commands no longer trashed with no args
324 # + watch val joined out of eval()
326 ####################################################################
328 # Needed for the statement after exec():
330 BEGIN { $ini_warn = $^W; $^W = 0 } # Switch compilation warnings off until another BEGIN.
332 # test if assertions are supported and actived:
335 eval "sub asserting_test : assertion {1}; 1";
336 # $ini_assertion = undef => assertions unsupported,
337 # " = 1 => assertions suported
338 # print "\$ini_assertion=$ini_assertion\n";
341 local($^W) = 0; # Switch run-time warnings off during init.
344 $dumpvar::arrayDepth,
345 $dumpvar::dumpDBFiles,
346 $dumpvar::dumpPackages,
347 $dumpvar::quoteHighBit,
348 $dumpvar::printUndef,
357 # Command-line + PERLLIB:
360 # $prevwarn = $prevdie = $prevbus = $prevsegv = ''; # Does not help?!
362 $trace = $signal = $single = 0; # Uninitialized warning suppression
363 # (local $^W cannot help - other packages!).
364 $inhibit_exit = $option{PrintRet} = 1;
366 @options = qw(hashDepth arrayDepth CommandSet dumpDepth
367 DumpDBFiles DumpPackages DumpReused
368 compactDump veryCompact quote HighBit undefPrint
369 globPrint PrintRet UsageOnly frame AutoTrace
370 TTY noTTY ReadLine NonStop LineInfo maxTraceLen
371 recallCommand ShellBang pager tkRunning ornaments
372 signalLevel warnLevel dieLevel inhibit_exit
373 ImmediateStop bareStringify CreateTTY
374 RemotePort windowSize DollarCaretP OnlyAssertions
377 @RememberOnROptions = qw(DollarCaretP OnlyAssertions);
380 hashDepth => \$dumpvar::hashDepth,
381 arrayDepth => \$dumpvar::arrayDepth,
382 CommandSet => \$CommandSet,
383 DumpDBFiles => \$dumpvar::dumpDBFiles,
384 DumpPackages => \$dumpvar::dumpPackages,
385 DumpReused => \$dumpvar::dumpReused,
386 HighBit => \$dumpvar::quoteHighBit,
387 undefPrint => \$dumpvar::printUndef,
388 globPrint => \$dumpvar::globPrint,
389 UsageOnly => \$dumpvar::usageOnly,
390 CreateTTY => \$CreateTTY,
391 bareStringify => \$dumpvar::bareStringify,
393 AutoTrace => \$trace,
394 inhibit_exit => \$inhibit_exit,
395 maxTraceLen => \$maxtrace,
396 ImmediateStop => \$ImmediateStop,
397 RemotePort => \$remoteport,
398 windowSize => \$window,
399 WarnAssertions => \$warnassertions,
403 compactDump => \&dumpvar::compactDump,
404 veryCompact => \&dumpvar::veryCompact,
405 quote => \&dumpvar::quote,
408 ReadLine => \&ReadLine,
409 NonStop => \&NonStop,
410 LineInfo => \&LineInfo,
411 recallCommand => \&recallCommand,
412 ShellBang => \&shellBang,
414 signalLevel => \&signalLevel,
415 warnLevel => \&warnLevel,
416 dieLevel => \&dieLevel,
417 tkRunning => \&tkRunning,
418 ornaments => \&ornaments,
419 RemotePort => \&RemotePort,
420 DollarCaretP => \&DollarCaretP,
421 OnlyAssertions=> \&OnlyAssertions,
425 compactDump => 'dumpvar.pl',
426 veryCompact => 'dumpvar.pl',
427 quote => 'dumpvar.pl',
430 # These guys may be defined in $ENV{PERL5DB} :
431 $rl = 1 unless defined $rl;
432 $warnLevel = 1 unless defined $warnLevel;
433 $dieLevel = 1 unless defined $dieLevel;
434 $signalLevel = 1 unless defined $signalLevel;
435 $pre = [] unless defined $pre;
436 $post = [] unless defined $post;
437 $pretype = [] unless defined $pretype;
438 $CreateTTY = 3 unless defined $CreateTTY;
439 $CommandSet = '580' unless defined $CommandSet;
441 warnLevel($warnLevel);
443 signalLevel($signalLevel);
446 defined $ENV{PAGER} ? $ENV{PAGER} :
447 eval { require Config } &&
448 defined $Config::Config{pager} ? $Config::Config{pager}
450 ) unless defined $pager;
452 &recallCommand("!") unless defined $prc;
453 &shellBang("!") unless defined $psh;
455 $maxtrace = 400 unless defined $maxtrace;
456 $ini_pids = $ENV{PERLDB_PIDS};
457 if (defined $ENV{PERLDB_PIDS}) {
458 $pids = "[$ENV{PERLDB_PIDS}]";
459 $ENV{PERLDB_PIDS} .= "->$$";
462 $ENV{PERLDB_PIDS} = "$$";
467 *emacs = $slave_editor if $slave_editor; # May be used in afterinit()...
469 if (-e "/dev/tty") { # this is the wrong metric!
472 $rcfile="perldb.ini";
475 # This isn't really safe, because there's a race
476 # between checking and opening. The solution is to
477 # open and fstat the handle, but then you have to read and
478 # eval the contents. But then the silly thing gets
479 # your lexical scope, which is unfortunately at best.
483 # Just exactly what part of the word "CORE::" don't you understand?
484 local $SIG{__WARN__};
487 unless (is_safe_file($file)) {
488 CORE::warn <<EO_GRIPE;
489 perldb: Must not source insecure rcfile $file.
490 You or the superuser must be the owner, and it must not
491 be writable by anyone but its owner.
497 CORE::warn("perldb: couldn't parse $file: $@") if $@;
501 # Verifies that owner is either real user or superuser and that no
502 # one but owner may write to it. This function is of limited use
503 # when called on a path instead of upon a handle, because there are
504 # no guarantees that filename (by dirent) whose file (by ino) is
505 # eventually accessed is the same as the one tested.
506 # Assumes that the file's existence is not in doubt.
509 stat($path) || return; # mysteriously vaporized
510 my($dev,$ino,$mode,$nlink,$uid,$gid) = stat(_);
512 return 0 if $uid != 0 && $uid != $<;
513 return 0 if $mode & 022;
518 safe_do("./$rcfile");
520 elsif (defined $ENV{HOME} && -f "$ENV{HOME}/$rcfile") {
521 safe_do("$ENV{HOME}/$rcfile");
523 elsif (defined $ENV{LOGDIR} && -f "$ENV{LOGDIR}/$rcfile") {
524 safe_do("$ENV{LOGDIR}/$rcfile");
527 if (defined $ENV{PERLDB_OPTS}) {
528 parse_options($ENV{PERLDB_OPTS});
531 if ( not defined &get_fork_TTY and defined $ENV{TERM} and $ENV{TERM} eq 'xterm'
532 and defined $ENV{WINDOWID} and defined $ENV{DISPLAY} ) { # _inside_ XTERM?
533 *get_fork_TTY = \&xterm_get_fork_TTY;
534 } elsif ($^O eq 'os2') {
535 *get_fork_TTY = \&os2_get_fork_TTY;
538 # Here begin the unreadable code. It needs fixing.
540 if (exists $ENV{PERLDB_RESTART}) {
541 delete $ENV{PERLDB_RESTART};
543 @hist = get_list('PERLDB_HIST');
544 %break_on_load = get_list("PERLDB_ON_LOAD");
545 %postponed = get_list("PERLDB_POSTPONE");
546 my @had_breakpoints= get_list("PERLDB_VISITED");
547 for (0 .. $#had_breakpoints) {
548 my %pf = get_list("PERLDB_FILE_$_");
549 $postponed_file{$had_breakpoints[$_]} = \%pf if %pf;
551 my %opt = get_list("PERLDB_OPT");
553 while (($opt,$val) = each %opt) {
554 $val =~ s/[\\\']/\\$1/g;
555 parse_options("$opt'$val'");
557 @INC = get_list("PERLDB_INC");
559 $pretype = [get_list("PERLDB_PRETYPE")];
560 $pre = [get_list("PERLDB_PRE")];
561 $post = [get_list("PERLDB_POST")];
562 @typeahead = get_list("PERLDB_TYPEAHEAD", @typeahead);
568 # Is Perl being run from a slave editor or graphical debugger?
569 $slave_editor = ((defined $main::ARGV[0]) and ($main::ARGV[0] eq '-emacs'));
570 $rl = 0, shift(@main::ARGV) if $slave_editor;
572 #require Term::ReadLine;
574 if ($^O eq 'cygwin') {
575 # /dev/tty is binary. use stdin for textmode
577 } elsif (-e "/dev/tty") {
578 $console = "/dev/tty";
579 } elsif ($^O eq 'dos' or -e "con" or $^O eq 'MSWin32') {
581 } elsif ($^O eq 'MacOS') {
582 if ($MacPerl::Version !~ /MPW/) {
583 $console = "Dev:Console:Perl Debug"; # Separate window for application
585 $console = "Dev:Console";
588 $console = "sys\$command";
591 if (($^O eq 'MSWin32') and ($slave_editor or defined $ENV{EMACS})) {
595 if ($^O eq 'NetWare') {
600 if (defined $ENV{OS2_SHELL} and ($slave_editor or $ENV{WINDOWID})) { # In OS/2
608 $console = $tty if defined $tty;
610 if (defined $remoteport) {
612 $OUT = new IO::Socket::INET( Timeout => '10',
613 PeerAddr => $remoteport,
616 if (!$OUT) { die "Unable to connect to remote host: $remoteport\n"; }
619 create_IN_OUT(4) if $CreateTTY & 4;
621 my ($i, $o) = split /,/, $console;
622 $o = $i unless defined $o;
623 open(IN,"+<$i") || open(IN,"<$i") || open(IN,"<&STDIN");
624 open(OUT,"+>$o") || open(OUT,">$o") || open(OUT,">&STDERR")
625 || open(OUT,">&STDOUT"); # so we don't dongle stdout
626 } elsif (not defined $console) {
628 open(OUT,">&STDERR") || open(OUT,">&STDOUT"); # so we don't dongle stdout
629 $console = 'STDIN/OUT';
631 # so open("|more") can read from STDOUT and so we don't dingle stdin
632 $IN = \*IN, $OUT = \*OUT if $console or not defined $console;
634 my $previous = select($OUT);
635 $| = 1; # for DB::OUT
638 $LINEINFO = $OUT unless defined $LINEINFO;
639 $lineinfo = $console unless defined $lineinfo;
641 $header =~ s/.Header: ([^,]+),v(\s+\S+\s+\S+).*$/$1$2/;
642 unless ($runnonstop) {
645 if ($term_pid eq '-1') {
646 print $OUT "\nDaughter DB session started...\n";
648 print $OUT "\nLoading DB routines from $header\n";
649 print $OUT ("Editor support ",
650 $slave_editor ? "enabled" : "available",
652 print $OUT "\nEnter h or `h h' for help, or `$doccmd perldebug' for more help.\n\n";
660 s/(.*)/'$1'/ unless /^-?[\d.]+$/;
663 if (defined &afterinit) { # May be defined in $rcfile
669 ############################################################ Subroutines
672 # _After_ the perl program is compiled, $single is set to 1:
673 if ($single and not $second_time++) {
674 if ($runnonstop) { # Disable until signal
675 for ($i=0; $i <= $stack_depth; ) {
679 # return; # Would not print trace!
680 } elsif ($ImmediateStop) {
685 $runnonstop = 0 if $single or $signal; # Disable it if interactive.
687 local($package, $filename, $line) = caller;
688 local $filename_ini = $filename;
689 local $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
690 "package $package;"; # this won't let them modify, alas
691 local(*dbline) = $main::{'_<' . $filename};
693 # we need to check for pseudofiles on Mac OS (these are files
694 # not attached to a filename, but instead stored in Dev:Pseudo)
695 if ($^O eq 'MacOS' && $#dbline < 0) {
696 $filename_ini = $filename = 'Dev:Pseudo';
697 *dbline = $main::{'_<' . $filename};
700 local $max = $#dbline;
701 if ($dbline{$line} && (($stop,$action) = split(/\0/,$dbline{$line}))) {
705 $evalarg = "\$DB::signal |= 1 if do {$stop}"; &eval;
706 $dbline{$line} =~ s/;9($|\0)/$1/;
709 my $was_signal = $signal;
711 for (my $n = 0; $n <= $#to_watch; $n++) {
712 $evalarg = $to_watch[$n];
713 local $onetimeDump; # Do not output results
714 my ($val) = join("', '", &eval); # Fix context (&eval is doing array)? - rjsf
715 $val = ( (defined $val) ? "'$val'" : 'undef' );
716 if ($val ne $old_watch[$n]) {
719 Watchpoint $n:\t$to_watch[$n] changed:
720 old value:\t$old_watch[$n]
723 $old_watch[$n] = $val;
727 if ($trace & 4) { # User-installed watch
728 return if watchfunction($package, $filename, $line)
729 and not $single and not $was_signal and not ($trace & ~4);
731 $was_signal = $signal;
733 if ($single || ($trace & 1) || $was_signal) {
735 $position = "\032\032$filename:$line:0\n";
736 print_lineinfo($position);
737 } elsif ($package eq 'DB::fake') {
740 Debugged program terminated. Use B<q> to quit or B<R> to restart,
741 use B<O> I<inhibit_exit> to avoid stopping after program termination,
742 B<h q>, B<h R> or B<h O> to get additional info.
745 $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
746 "package $package;"; # this won't let them modify, alas
749 $prefix = $sub =~ /::/ ? "" : "${'package'}::";
750 $prefix .= "$sub($filename:";
751 $after = ($dbline[$line] =~ /\n$/ ? '' : "\n");
752 if (length($prefix) > 30) {
753 $position = "$prefix$line):\n$line:\t$dbline[$line]$after";
758 $position = "$prefix$line$infix$dbline[$line]$after";
761 print_lineinfo(' ' x $stack_depth, "$line:\t$dbline[$line]$after");
763 print_lineinfo($position);
765 for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) { #{ vi
766 last if $dbline[$i] =~ /^\s*[\;\}\#\n]/;
768 $after = ($dbline[$i] =~ /\n$/ ? '' : "\n");
769 $incr_pos = "$prefix$i$infix$dbline[$i]$after";
770 $position .= $incr_pos;
772 print_lineinfo(' ' x $stack_depth, "$i:\t$dbline[$i]$after");
774 print_lineinfo($incr_pos);
779 $evalarg = $action, &eval if $action;
780 if ($single || $was_signal) {
781 local $level = $level + 1;
782 foreach $evalarg (@$pre) {
785 print $OUT $stack_depth . " levels deep in subroutine calls!\n"
788 $incr = -1; # for backward motion.
789 @typeahead = (@$pretype, @typeahead);
791 while (($term || &setterm),
792 ($term_pid == $$ or resetterm(1)),
793 defined ($cmd=&readline("$pidprompt DB" . ('<' x $level) .
794 ($#hist+1) . ('>' x $level) . " ")))
798 $cmd =~ s/\\$/\n/ && do {
799 $cmd .= &readline(" cont: ");
802 $cmd =~ /^$/ && ($cmd = $laststep);
803 push(@hist,$cmd) if length($cmd) > 1;
805 $cmd =~ s/^\s+//s; # trim annoying leading whitespace
806 $cmd =~ s/\s+$//s; # trim annoying trailing whitespace
807 ($i) = split(/\s+/,$cmd);
809 # squelch the sigmangler
811 local $SIG{__WARN__};
812 eval "\$cmd =~ $alias{$i}";
815 print $OUT "Couldn't evaluate `$i' alias: $@";
819 $cmd =~ /^q$/ && do {
824 $cmd =~ /^t$/ && do {
827 print $OUT "Trace = " .
828 (($trace & 1) ? "on" : "off" ) . "\n";
830 $cmd =~ /^S(\s+(!)?(.+))?$/ && do {
831 $Srev = defined $2; $Spatt = $3; $Snocheck = ! defined $1;
834 foreach $subname (sort(keys %sub)) {
835 if ($Snocheck or $Srev^($subname =~ /$Spatt/)) {
836 print $OUT $subname,"\n";
840 $cmd =~ s/^X\b/V $package/;
841 $cmd =~ /^V$/ && do {
842 $cmd = "V $package"; };
843 $cmd =~ /^V\b\s*(\S+)\s*(.*)/ && do {
844 local ($savout) = select($OUT);
846 @vars = split(' ',$2);
847 do 'dumpvar.pl' unless defined &main::dumpvar;
848 if (defined &main::dumpvar) {
851 # must detect sigpipe failures
852 eval { &main::dumpvar($packname,
853 defined $option{dumpDepth}
854 ? $option{dumpDepth} : -1,
857 die unless $@ =~ /dumpvar print failed/;
860 print $OUT "dumpvar.pl not available.\n";
864 $cmd =~ s/^x\b/ / && do { # So that will be evaled
865 $onetimeDump = 'dump';
866 # handle special "x 3 blah" syntax
867 if ($cmd =~ s/^\s*(\d+)(?=\s)/ /) {
868 $onetimedumpDepth = $1;
871 $cmd =~ s/^m\s+([\w:]+)\s*$/ / && do {
872 methods($1); next CMD};
873 $cmd =~ s/^m\b/ / && do { # So this will be evaled
874 $onetimeDump = 'methods'; };
875 $cmd =~ /^f\b\s*(.*)/ && do {
879 print $OUT "The old f command is now the r command.\n"; # hint
880 print $OUT "The new f command switches filenames.\n";
883 if (!defined $main::{'_<' . $file}) {
884 if (($try) = grep(m#^_<.*$file#, keys %main::)) {{
885 $try = substr($try,2);
886 print $OUT "Choosing $try matching `$file':\n";
890 if (!defined $main::{'_<' . $file}) {
891 print $OUT "No file matching `$file' is loaded.\n";
893 } elsif ($file ne $filename) {
894 *dbline = $main::{'_<' . $file};
900 print $OUT "Already in $file.\n";
904 $cmd =~ /^\.$/ && do {
905 $incr = -1; # for backward motion.
907 $filename = $filename_ini;
908 *dbline = $main::{'_<' . $filename};
910 print_lineinfo($position);
912 $cmd =~ /^-$/ && do {
913 $start -= $incr + $window + 1;
914 $start = 1 if $start <= 0;
916 $cmd = 'l ' . ($start) . '+'; };
918 $cmd =~ /^([aAbBhlLMoOPvwW]\b|[<>\{]{1,2})\s*(.*)/so && do {
919 &cmd_wrapper($1, $2, $line);
922 # rjsf <- pre|post commands stripped out
923 $cmd =~ /^y(?:\s+(\d*)\s*(.*))?$/ && do {
924 eval { require PadWalker; PadWalker->VERSION(0.08) }
925 or &warn($@ =~ /locate/
926 ? "PadWalker module not found - please install\n"
929 do 'dumpvar.pl' unless defined &main::dumpvar;
930 defined &main::dumpvar
931 or print $OUT "dumpvar.pl not available.\n"
933 my @vars = split(' ', $2 || '');
934 my $h = eval { PadWalker::peek_my(($1 || 0) + 1) };
935 $@ and $@ =~ s/ at .*//, &warn($@), next CMD;
936 my $savout = select($OUT);
937 dumpvar::dumplex($_, $h->{$_},
938 defined $option{dumpDepth}
939 ? $option{dumpDepth} : -1,
944 $cmd =~ /^n$/ && do {
945 end_report(), next CMD if $finished and $level <= 1;
949 $cmd =~ /^s$/ && do {
950 end_report(), next CMD if $finished and $level <= 1;
954 $cmd =~ /^c\b\s*([\w:]*)\s*$/ && do {
955 end_report(), next CMD if $finished and $level <= 1;
957 # Probably not needed, since we finish an interactive
958 # sub-session anyway...
959 # local $filename = $filename;
960 # local *dbline = *dbline; # XXX Would this work?!
961 if ($subname =~ /\D/) { # subroutine name
962 $subname = $package."::".$subname
963 unless $subname =~ /::/;
964 ($file,$i) = (find_sub($subname) =~ /^(.*):(.*)$/);
968 *dbline = $main::{'_<' . $filename};
969 $had_breakpoints{$filename} |= 1;
971 ++$i while $dbline[$i] == 0 && $i < $max;
973 print $OUT "Subroutine $subname not found.\n";
978 if ($dbline[$i] == 0) {
979 print $OUT "Line $i not breakable.\n";
982 $dbline{$i} =~ s/($|\0)/;9$1/; # add one-time-only b.p.
984 for ($i=0; $i <= $stack_depth; ) {
988 $cmd =~ /^r$/ && do {
989 end_report(), next CMD if $finished and $level <= 1;
990 $stack[$stack_depth] |= 1;
991 $doret = $option{PrintRet} ? $stack_depth - 1 : -2;
993 $cmd =~ /^R$/ && do {
994 print $OUT "Warning: some settings and command-line options may be lost!\n";
995 my (@script, @flags, $cl);
996 push @flags, '-w' if $ini_warn;
997 if ($ini_assertion and @{^ASSERTING}) {
998 push @flags, (map { /\:\^\(\?\:(.*)\)\$\)/ ?
999 "-A$1" : "-A$_" } @{^ASSERTING});
1001 # Put all the old includes at the start to get
1002 # the same debugger.
1004 push @flags, '-I', $_;
1006 push @flags, '-T' if ${^TAINT};
1007 # Arrange for setting the old INC:
1008 set_list("PERLDB_INC", @ini_INC);
1010 for (1..$#{'::_<-e'}) { # The first line is PERL5DB
1011 chomp ($cl = ${'::_<-e'}[$_]);
1012 push @script, '-e', $cl;
1017 set_list("PERLDB_HIST",
1018 $term->Features->{getHistory}
1019 ? $term->GetHistory : @hist);
1020 my @had_breakpoints = keys %had_breakpoints;
1021 set_list("PERLDB_VISITED", @had_breakpoints);
1022 set_list("PERLDB_OPT", options2remember());
1023 set_list("PERLDB_ON_LOAD", %break_on_load);
1025 for (0 .. $#had_breakpoints) {
1026 my $file = $had_breakpoints[$_];
1027 *dbline = $main::{'_<' . $file};
1028 next unless %dbline or $postponed_file{$file};
1029 (push @hard, $file), next
1030 if $file =~ /^\(\w*eval/;
1032 @add = %{$postponed_file{$file}}
1033 if $postponed_file{$file};
1034 set_list("PERLDB_FILE_$_", %dbline, @add);
1036 for (@hard) { # Yes, really-really...
1037 # Find the subroutines in this eval
1038 *dbline = $main::{'_<' . $_};
1039 my ($quoted, $sub, %subs, $line) = quotemeta $_;
1040 for $sub (keys %sub) {
1041 next unless $sub{$sub} =~ /^$quoted:(\d+)-(\d+)$/;
1042 $subs{$sub} = [$1, $2];
1046 "No subroutines in $_, ignoring breakpoints.\n";
1049 LINES: for $line (keys %dbline) {
1050 # One breakpoint per sub only:
1051 my ($offset, $sub, $found);
1052 SUBS: for $sub (keys %subs) {
1053 if ($subs{$sub}->[1] >= $line # Not after the subroutine
1054 and (not defined $offset # Not caught
1055 or $offset < 0 )) { # or badly caught
1057 $offset = $line - $subs{$sub}->[0];
1058 $offset = "+$offset", last SUBS if $offset >= 0;
1061 if (defined $offset) {
1062 $postponed{$found} =
1063 "break $offset if $dbline{$line}";
1065 print $OUT "Breakpoint in $_:$line ignored: after all the subroutines.\n";
1069 set_list("PERLDB_POSTPONE", %postponed);
1070 set_list("PERLDB_PRETYPE", @$pretype);
1071 set_list("PERLDB_PRE", @$pre);
1072 set_list("PERLDB_POST", @$post);
1073 set_list("PERLDB_TYPEAHEAD", @typeahead);
1074 $ENV{PERLDB_RESTART} = 1;
1075 delete $ENV{PERLDB_PIDS}; # Restore ini state
1076 $ENV{PERLDB_PIDS} = $ini_pids if defined $ini_pids;
1077 #print "$^X, '-d', @flags, @script, ($slave_editor ? '-emacs' : ()), @ARGS";
1078 exec($^X, '-d', @flags, @script, ($slave_editor ? '-emacs' : ()), @ARGS) ||
1079 print $OUT "exec failed: $!\n";
1081 $cmd =~ /^T$/ && do {
1082 print_trace($OUT, 1); # skip DB
1084 $cmd =~ /^w\b\s*(.*)/s && do { &cmd_w('w', $1); next CMD; };
1085 $cmd =~ /^W\b\s*(.*)/s && do { &cmd_W('W', $1); next CMD; };
1086 $cmd =~ /^\/(.*)$/ && do {
1088 $inpat =~ s:([^\\])/$:$1:;
1090 # squelch the sigmangler
1091 local $SIG{__DIE__};
1092 local $SIG{__WARN__};
1093 eval '$inpat =~ m'."\a$inpat\a";
1105 $start = 1 if ($start > $max);
1106 last if ($start == $end);
1107 if ($dbline[$start] =~ m' . "\a$pat\a" . 'i) {
1108 if ($slave_editor) {
1109 print $OUT "\032\032$filename:$start:0\n";
1111 print $OUT "$start:\t", $dbline[$start], "\n";
1116 print $OUT "/$pat/: not found\n" if ($start == $end);
1118 $cmd =~ /^\?(.*)$/ && do {
1120 $inpat =~ s:([^\\])\?$:$1:;
1122 # squelch the sigmangler
1123 local $SIG{__DIE__};
1124 local $SIG{__WARN__};
1125 eval '$inpat =~ m'."\a$inpat\a";
1137 $start = $max if ($start <= 0);
1138 last if ($start == $end);
1139 if ($dbline[$start] =~ m' . "\a$pat\a" . 'i) {
1140 if ($slave_editor) {
1141 print $OUT "\032\032$filename:$start:0\n";
1143 print $OUT "$start:\t", $dbline[$start], "\n";
1148 print $OUT "?$pat?: not found\n" if ($start == $end);
1150 $cmd =~ /^$rc+\s*(-)?(\d+)?$/ && do {
1151 pop(@hist) if length($cmd) > 1;
1152 $i = $1 ? ($#hist-($2||1)) : ($2||$#hist);
1154 print $OUT $cmd, "\n";
1156 $cmd =~ /^$sh$sh\s*([\x00-\xff]*)/ && do {
1159 $cmd =~ /^$rc([^$rc].*)$/ && do {
1161 pop(@hist) if length($cmd) > 1;
1162 for ($i = $#hist; $i; --$i) {
1163 last if $hist[$i] =~ /$pat/;
1166 print $OUT "No such command!\n\n";
1170 print $OUT $cmd, "\n";
1172 $cmd =~ /^$sh$/ && do {
1173 &system($ENV{SHELL}||"/bin/sh");
1175 $cmd =~ /^$sh\s*([\x00-\xff]*)/ && do {
1176 # XXX: using csh or tcsh destroys sigint retvals!
1177 #&system($1); # use this instead
1178 &system($ENV{SHELL}||"/bin/sh","-c",$1);
1180 $cmd =~ /^H\b\s*(-(\d+))?/ && do {
1181 $end = $2 ? ($#hist-$2) : 0;
1182 $hist = 0 if $hist < 0;
1183 for ($i=$#hist; $i>$end; $i--) {
1184 print $OUT "$i: ",$hist[$i],"\n"
1185 unless $hist[$i] =~ /^.?$/;
1188 $cmd =~ /^(?:man|(?:perl)?doc)\b(?:\s+([^(]*))?$/ && do {
1191 $cmd =~ s/^p$/print {\$DB::OUT} \$_/;
1192 $cmd =~ s/^p\b/print {\$DB::OUT} /;
1193 $cmd =~ s/^=\s*// && do {
1195 if (length $cmd == 0) {
1196 @keys = sort keys %alias;
1197 } elsif (my($k,$v) = ($cmd =~ /^(\S+)\s+(\S.*)/)) {
1198 # can't use $_ or kill //g state
1199 for my $x ($k, $v) { $x =~ s/\a/\\a/g }
1200 $alias{$k} = "s\a$k\a$v\a";
1201 # squelch the sigmangler
1202 local $SIG{__DIE__};
1203 local $SIG{__WARN__};
1204 unless (eval "sub { s\a$k\a$v\a }; 1") {
1205 print $OUT "Can't alias $k to $v: $@\n";
1214 if ((my $v = $alias{$k}) =~ s
\as\a$k\a(.*)\a$
\a1
\a) {
1215 print $OUT "$k\t= $1\n";
1217 elsif (defined $alias{$k}) {
1218 print $OUT "$k\t$alias{$k}\n";
1221 print "No alias for $k\n";
1225 $cmd =~ /^source\s+(.*\S)/ && do {
1226 if (open my $fh, $1) {
1229 &warn("Can't execute `$1': $!\n");
1232 $cmd =~ /^\|\|?\s*[^|]/ && do {
1233 if ($pager =~ /^\|/) {
1234 open(SAVEOUT,">&STDOUT") || &warn("Can't save STDOUT");
1235 open(STDOUT,">&OUT") || &warn("Can't redirect STDOUT");
1237 open(SAVEOUT,">&OUT") || &warn("Can't save DB::OUT");
1240 unless ($piped=open(OUT,$pager)) {
1241 &warn("Can't pipe output to `$pager'");
1242 if ($pager =~ /^\|/) {
1243 open(OUT,">&STDOUT") # XXX: lost message
1244 || &warn("Can't restore DB::OUT");
1245 open(STDOUT,">&SAVEOUT")
1246 || &warn("Can't restore STDOUT");
1249 open(OUT,">&STDOUT") # XXX: lost message
1250 || &warn("Can't restore DB::OUT");
1254 $SIG{PIPE}= \&DB::catch if $pager =~ /^\|/
1255 && ("" eq $SIG{PIPE} || "DEFAULT" eq $SIG{PIPE});
1256 $selected= select(OUT);
1258 select( $selected ), $selected= "" unless $cmd =~ /^\|\|/;
1259 $cmd =~ s/^\|+\s*//;
1262 # XXX Local variants do not work!
1263 $cmd =~ s/^t\s/\$DB::trace |= 1;\n/;
1264 $cmd =~ s/^s\s/\$DB::single = 1;\n/ && do {$laststep = 's'};
1265 $cmd =~ s/^n\s/\$DB::single = 2;\n/ && do {$laststep = 'n'};
1267 $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd"; &eval;
1269 $onetimeDump = undef;
1270 $onetimedumpDepth = undef;
1271 } elsif ($term_pid == $$) {
1276 if ($pager =~ /^\|/) {
1278 # we cannot warn here: the handle is missing --tchrist
1279 close(OUT) || print SAVEOUT "\nCan't close DB::OUT\n";
1281 # most of the $? crud was coping with broken cshisms
1283 print SAVEOUT "Pager `$pager' failed: ";
1285 print SAVEOUT "shell returned -1\n";
1288 ( $? & 127 ) ? " (SIG#".($?&127).")" : "",
1289 ( $? & 128 ) ? " -- core dumped" : "", "\n";
1291 print SAVEOUT "status ", ($? >> 8), "\n";
1295 open(OUT,">&STDOUT") || &warn("Can't restore DB::OUT");
1296 open(STDOUT,">&SAVEOUT") || &warn("Can't restore STDOUT");
1297 $SIG{PIPE} = "DEFAULT" if $SIG{PIPE} eq \&DB::catch;
1298 # Will stop ignoring SIGPIPE if done like nohup(1)
1299 # does SIGINT but Perl doesn't give us a choice.
1301 open(OUT,">&SAVEOUT") || &warn("Can't restore DB::OUT");
1304 select($selected), $selected= "" unless $selected eq "";
1308 $fall_off_end = 1 unless defined $cmd; # Emulate `q' on EOF
1309 foreach $evalarg (@$post) {
1312 } # if ($single || $signal)
1313 ($@, $!, $^E, $,, $/, $\, $^W) = @saved;
1317 # The following code may be executed now:
1321 my ($al, $ret, @ret) = "";
1322 if (length($sub) > 10 && substr($sub, -10, 10) eq '::AUTOLOAD') {
1325 local $stack_depth = $stack_depth + 1; # Protect from non-local exits
1326 $#stack = $stack_depth;
1327 $stack[-1] = $single;
1329 $single |= 4 if $stack_depth == $deep;
1331 ? ( print_lineinfo(' ' x ($stack_depth - 1), "in "),
1332 # Why -1? But it works! :-(
1333 print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
1334 : print_lineinfo(' ' x ($stack_depth - 1), "entering $sub$al\n")) if $frame;
1343 $signal=1 unless $warnassertions;
1349 $single |= $stack[$stack_depth--];
1351 ? ( print_lineinfo(' ' x $stack_depth, "out "),
1352 print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
1353 : print_lineinfo(' ' x $stack_depth, "exited $sub$al\n")) if $frame & 2;
1354 if ($doret eq $stack_depth or $frame & 16) {
1356 my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
1357 print $fh ' ' x $stack_depth if $frame & 16;
1358 print $fh "list context return from $sub:\n";
1359 dumpit($fh, \@ret );
1371 $signal=1 unless $warnassertions;
1373 $ret=undef unless defined wantarray;
1376 if (defined wantarray) {
1382 $single |= $stack[$stack_depth--];
1384 ? ( print_lineinfo(' ' x $stack_depth, "out "),
1385 print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
1386 : print_lineinfo(' ' x $stack_depth, "exited $sub$al\n")) if $frame & 2;
1387 if ($doret eq $stack_depth or $frame & 16 and defined wantarray) {
1389 my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
1390 print $fh (' ' x $stack_depth) if $frame & 16;
1391 print $fh (defined wantarray
1392 ? "scalar context return from $sub: "
1393 : "void context return from $sub\n");
1394 dumpit( $fh, $ret ) if defined wantarray;
1403 ### Functions with multiple modes of failure die on error, the rest
1404 ### returns FALSE on error.
1405 ### User-interface functions cmd_* output error message.
1407 ### Note all cmd_[a-zA-Z]'s require $cmd, $line, $dblineno as first arguments
1412 'A' => 'pre580_null',
1414 'B' => 'pre580_null',
1415 'd' => 'pre580_null',
1418 'M' => 'pre580_null',
1420 'o' => 'pre580_null',
1426 '<' => 'pre590_prepost',
1427 '<<' => 'pre590_prepost',
1428 '>' => 'pre590_prepost',
1429 '>>' => 'pre590_prepost',
1430 '{' => 'pre590_prepost',
1431 '{{' => 'pre590_prepost',
1438 my $dblineno = shift;
1440 # with this level of indirection we can wrap
1441 # to old (pre580) or other command sets easily
1444 $set{$CommandSet}{$cmd} || ($cmd =~ /^[<>{]+/o ? 'prepost' : $cmd)
1446 # print "cmd_wrapper($cmd): $CommandSet($set{$CommandSet}{$cmd}) => call($call)\n";
1448 return &$call($cmd, $line, $dblineno);
1452 my $cmd = shift; # a
1453 my $line = shift || ''; # [.|line] expr
1454 my $dbline = shift; $line =~ s/^(\.|(?:[^\d]))/$dbline/;
1455 if ($line =~ /^\s*(\d*)\s*(\S.+)/) {
1456 my ($lineno, $expr) = ($1, $2);
1458 if ($dbline[$lineno] == 0) {
1459 print $OUT "Line $lineno($dbline[$lineno]) does not have an action?\n";
1461 $had_breakpoints{$filename} |= 2;
1462 $dbline{$lineno} =~ s/\0[^\0]*//;
1463 $dbline{$lineno} .= "\0" . action($expr);
1467 print $OUT "Adding an action requires an optional lineno and an expression\n"; # hint
1472 my $cmd = shift; # A
1473 my $line = shift || '';
1474 my $dbline = shift; $line =~ s/^\./$dbline/;
1476 eval { &delete_action(); 1 } or print $OUT $@ and return;
1477 } elsif ($line =~ /^(\S.*)/) {
1478 eval { &delete_action($1); 1 } or print $OUT $@ and return;
1480 print $OUT "Deleting an action requires a line number, or '*' for all\n"; # hint
1487 die "Line $i has no action .\n" if $dbline[$i] == 0;
1488 $dbline{$i} =~ s/\0[^\0]*//; # \^a
1489 delete $dbline{$i} if $dbline{$i} eq '';
1491 print $OUT "Deleting all actions...\n";
1492 for my $file (keys %had_breakpoints) {
1493 local *dbline = $main::{'_<' . $file};
1496 for ($i = 1; $i <= $max ; $i++) {
1497 if (defined $dbline{$i}) {
1498 $dbline{$i} =~ s/\0[^\0]*//;
1499 delete $dbline{$i} if $dbline{$i} eq '';
1501 unless ($had_breakpoints{$file} &= ~2) {
1502 delete $had_breakpoints{$file};
1510 my $cmd = shift; # b
1511 my $line = shift; # [.|line] [cond]
1512 my $dbline = shift; $line =~ s/^\./$dbline/;
1513 if ($line =~ /^\s*$/) {
1514 &cmd_b_line($dbline, 1);
1515 } elsif ($line =~ /^load\b\s*(.*)/) {
1516 my $file = $1; $file =~ s/\s+$//;
1518 } elsif ($line =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/) {
1519 my $cond = length $3 ? $3 : '1';
1520 my ($subname, $break) = ($2, $1 eq 'postpone');
1521 $subname =~ s/\'/::/g;
1522 $subname = "${'package'}::" . $subname unless $subname =~ /::/;
1523 $subname = "main".$subname if substr($subname,0,2) eq "::";
1524 $postponed{$subname} = $break ? "break +0 if $cond" : "compile";
1525 } elsif ($line =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/) {
1527 $cond = length $2 ? $2 : '1';
1528 &cmd_b_sub($subname, $cond);
1529 } elsif ($line =~ /^(\d*)\s*(.*)/) {
1530 $line = $1 || $dbline;
1531 $cond = length $2 ? $2 : '1';
1532 &cmd_b_line($line, $cond);
1534 print "confused by line($line)?\n";
1540 $break_on_load{$file} = 1;
1541 $had_breakpoints{$file} |= 1;
1544 sub report_break_on_load {
1545 sort keys %break_on_load;
1553 push @files, $::INC{$file} if $::INC{$file};
1554 $file .= '.pm', redo unless $file =~ /\./;
1556 break_on_load($_) for @files;
1557 @files = report_break_on_load;
1560 print $OUT "Will stop on load of `@files'.\n";
1563 $filename_error = '';
1565 sub breakable_line {
1566 my ($from, $to) = @_;
1569 my $delta = $from < $to ? +1 : -1;
1570 my $limit = $delta > 0 ? $#dbline : 1;
1571 $limit = $to if ($limit - $to) * $delta > 0;
1572 $i += $delta while $dbline[$i] == 0 and ($limit - $i) * $delta > 0;
1574 return $i unless $dbline[$i] == 0;
1575 my ($pl, $upto) = ('', '');
1576 ($pl, $upto) = ('s', "..$to") if @_ >=2 and $from != $to;
1577 die "Line$pl $from$upto$filename_error not breakable\n";
1580 sub breakable_line_in_filename {
1582 local *dbline = $main::{'_<' . $f};
1583 local $filename_error = " of `$f'";
1588 my ($i, $cond) = @_;
1589 $cond = 1 unless @_ >= 2;
1593 die "Line $i$filename_error not breakable.\n" if $dbline[$i] == 0;
1594 $had_breakpoints{$filename} |= 1;
1595 if ($dbline{$i}) { $dbline{$i} =~ s/^[^\0]*/$cond/; }
1596 else { $dbline{$i} = $cond; }
1600 eval { break_on_line(@_); 1 } or do {
1602 print $OUT $@ and return;
1606 sub break_on_filename_line {
1607 my ($f, $i, $cond) = @_;
1608 $cond = 1 unless @_ >= 3;
1609 local *dbline = $main::{'_<' . $f};
1610 local $filename_error = " of `$f'";
1611 local $filename = $f;
1612 break_on_line($i, $cond);
1615 sub break_on_filename_line_range {
1616 my ($f, $from, $to, $cond) = @_;
1617 my $i = breakable_line_in_filename($f, $from, $to);
1618 $cond = 1 unless @_ >= 3;
1619 break_on_filename_line($f,$i,$cond);
1622 sub subroutine_filename_lines {
1623 my ($subname,$cond) = @_;
1624 # Filename below can contain ':'
1625 find_sub($subname) =~ /^(.*):(\d+)-(\d+)$/;
1628 sub break_subroutine {
1629 my $subname = shift;
1630 my ($file,$s,$e) = subroutine_filename_lines($subname) or
1631 die "Subroutine $subname not found.\n";
1632 $cond = 1 unless @_ >= 2;
1633 break_on_filename_line_range($file,$s,$e,@_);
1637 my ($subname,$cond) = @_;
1638 $cond = 1 unless @_ >= 2;
1639 unless (ref $subname eq 'CODE') {
1640 $subname =~ s/\'/::/g;
1642 $subname = "${'package'}::" . $subname
1643 unless $subname =~ /::/;
1644 $subname = "CORE::GLOBAL::$s"
1645 if not defined &$subname and $s !~ /::/ and defined &{"CORE::GLOBAL::$s"};
1646 $subname = "main".$subname if substr($subname,0,2) eq "::";
1648 eval { break_subroutine($subname,$cond); 1 } or do {
1650 print $OUT $@ and return;
1655 my $cmd = shift; # B
1656 my $line = ($_[0] =~ /^\./) ? $dbline : shift || '';
1657 my $dbline = shift; $line =~ s/^\./$dbline/;
1659 eval { &delete_breakpoint(); 1 } or print $OUT $@ and return;
1660 } elsif ($line =~ /^(\S.*)/) {
1661 eval { &delete_breakpoint($line || $dbline); 1 } or do {
1663 print $OUT $@ and return;
1666 print $OUT "Deleting a breakpoint requires a line number, or '*' for all\n"; # hint
1670 sub delete_breakpoint {
1673 die "Line $i not breakable.\n" if $dbline[$i] == 0;
1674 $dbline{$i} =~ s/^[^\0]*//;
1675 delete $dbline{$i} if $dbline{$i} eq '';
1677 print $OUT "Deleting all breakpoints...\n";
1678 for my $file (keys %had_breakpoints) {
1679 local *dbline = $main::{'_<' . $file};
1682 for ($i = 1; $i <= $max ; $i++) {
1683 if (defined $dbline{$i}) {
1684 $dbline{$i} =~ s/^[^\0]+//;
1685 if ($dbline{$i} =~ s/^\0?$//) {
1690 if (not $had_breakpoints{$file} &= ~1) {
1691 delete $had_breakpoints{$file};
1695 undef %postponed_file;
1696 undef %break_on_load;
1700 sub cmd_stop { # As on ^C, but not signal-safy.
1705 my $cmd = shift; # h
1706 my $line = shift || '';
1707 if ($line =~ /^h\s*/) {
1709 } elsif ($line =~ /^(\S.*)$/) {
1710 # support long commands; otherwise bogus errors
1711 # happen when you ask for h on <CR> for example
1712 my $asked = $1; # for proper errmsg
1713 my $qasked = quotemeta($asked); # for searching
1714 # XXX: finds CR but not <CR>
1715 if ($help =~ /^<?(?:[IB]<)$qasked/m) {
1716 while ($help =~ /^(<?(?:[IB]<)$qasked([\s\S]*?)\n)(?!\s)/mg) {
1720 print_help("B<$asked> is not a debugger command.\n");
1723 print_help($summary);
1728 my $current_line = $line;
1729 my $cmd = shift; # l
1731 $line =~ s/^-\s*$/-/;
1732 if ($line =~ /^(\$.*)/s) {
1735 print($OUT "Error: $@\n"), next CMD if $@;
1737 print($OUT "Interpreted as: $1 $s\n");
1740 } elsif ($line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s) {
1741 my $s = $subname = $1;
1742 $subname =~ s/\'/::/;
1743 $subname = $package."::".$subname
1744 unless $subname =~ /::/;
1745 $subname = "CORE::GLOBAL::$s"
1746 if not defined &$subname and $s !~ /::/
1747 and defined &{"CORE::GLOBAL::$s"};
1748 $subname = "main".$subname if substr($subname,0,2) eq "::";
1749 @pieces = split(/:/,find_sub($subname) || $sub{$subname});
1750 $subrange = pop @pieces;
1751 $file = join(':', @pieces);
1752 if ($file ne $filename) {
1753 print $OUT "Switching to file '$file'.\n"
1754 unless $slave_editor;
1755 *dbline = $main::{'_<' . $file};
1760 if (eval($subrange) < -$window) {
1761 $subrange =~ s/-.*/+/;
1764 &cmd_l('l', $subrange);
1766 print $OUT "Subroutine $subname not found.\n";
1768 } elsif ($line =~ /^\s*$/) {
1769 $incr = $window - 1;
1770 $line = $start . '-' . ($start + $incr);
1772 } elsif ($line =~ /^(\d*)\+(\d*)$/) {
1775 $incr = $window - 1 unless $incr;
1776 $line = $start . '-' . ($start + $incr);
1778 } elsif ($line =~ /^((-?[\d\$\.]+)([-,]([\d\$\.]+))?)?/) {
1779 $end = (!defined $2) ? $max : ($4 ? $4 : $2);
1780 $end = $max if $end > $max;
1782 $i = $line if $i eq '.';
1785 if ($slave_editor) {
1786 print $OUT "\032\032$filename:$i:0\n";
1789 for (; $i <= $end; $i++) {
1791 ($stop,$action) = split(/\0/, $dbline{$i}) if
1793 $arrow = ($i==$current_line
1794 and $filename eq $filename_ini)
1796 : ($dbline[$i]+0 ? ':' : ' ') ;
1797 $arrow .= 'b' if $stop;
1798 $arrow .= 'a' if $action;
1799 print $OUT "$i$arrow\t", $dbline[$i];
1800 $i++, last if $signal;
1802 print $OUT "\n" unless $dbline[$i-1] =~ /\n$/;
1804 $start = $i; # remember in case they want more
1805 $start = $max if $start > $max;
1810 my $cmd = shift; # L
1811 my $arg = shift || 'abw'; $arg = 'abw' unless $CommandSet eq '580'; # sigh...
1812 my $action_wanted = ($arg =~ /a/) ? 1 : 0;
1813 my $break_wanted = ($arg =~ /b/) ? 1 : 0;
1814 my $watch_wanted = ($arg =~ /w/) ? 1 : 0;
1816 if ($break_wanted or $action_wanted) {
1817 for my $file (keys %had_breakpoints) {
1818 local *dbline = $main::{'_<' . $file};
1821 for ($i = 1; $i <= $max; $i++) {
1822 if (defined $dbline{$i}) {
1823 print $OUT "$file:\n" unless $was++;
1824 print $OUT " $i:\t", $dbline[$i];
1825 ($stop,$action) = split(/\0/, $dbline{$i});
1826 print $OUT " break if (", $stop, ")\n"
1827 if $stop and $break_wanted;
1828 print $OUT " action: ", $action, "\n"
1829 if $action and $action_wanted;
1835 if (%postponed and $break_wanted) {
1836 print $OUT "Postponed breakpoints in subroutines:\n";
1838 for $subname (keys %postponed) {
1839 print $OUT " $subname\t$postponed{$subname}\n";
1843 my @have = map { # Combined keys
1844 keys %{$postponed_file{$_}}
1845 } keys %postponed_file;
1846 if (@have and ($break_wanted or $action_wanted)) {
1847 print $OUT "Postponed breakpoints in files:\n";
1849 for $file (keys %postponed_file) {
1850 my $db = $postponed_file{$file};
1851 print $OUT " $file:\n";
1852 for $line (sort {$a <=> $b} keys %$db) {
1853 print $OUT " $line:\n";
1854 my ($stop,$action) = split(/\0/, $$db{$line});
1855 print $OUT " break if (", $stop, ")\n"
1856 if $stop and $break_wanted;
1857 print $OUT " action: ", $action, "\n"
1858 if $action and $action_wanted;
1864 if (%break_on_load and $break_wanted) {
1865 print $OUT "Breakpoints on load:\n";
1867 for $file (keys %break_on_load) {
1868 print $OUT " $file\n";
1872 if ($watch_wanted) {
1874 print $OUT "Watch-expressions:\n" if @to_watch;
1875 for my $expr (@to_watch) {
1876 print $OUT " $expr\n";
1888 my $cmd = shift; # o
1889 my $opt = shift || ''; # opt[=val]
1890 if ($opt =~ /^(\S.*)/) {
1900 print $OUT "The old O command is now the o command.\n"; # hint
1901 print $OUT "Use 'h' to get current command help synopsis or\n"; #
1902 print $OUT "use 'o CommandSet=pre580' to revert to old usage\n"; #
1906 my $cmd = shift; # v
1909 if ($line =~ /^(\d*)$/) {
1910 $incr = $window - 1;
1913 $line = $start . '-' . ($start + $incr);
1919 my $cmd = shift; # w
1920 my $expr = shift || '';
1921 if ($expr =~ /^(\S.*)/) {
1922 push @to_watch, $expr;
1924 my ($val) = join(' ', &eval);
1925 $val = (defined $val) ? "'$val'" : 'undef' ;
1926 push @old_watch, $val;
1929 print $OUT "Adding a watch-expression requires an expression\n"; # hint
1934 my $cmd = shift; # W
1935 my $expr = shift || '';
1938 print $OUT "Deleting all watch expressions ...\n";
1939 @to_watch = @old_watch = ();
1940 } elsif ($expr =~ /^(\S.*)/) {
1942 foreach (@to_watch) {
1943 my $val = $to_watch[$i_cnt];
1944 if ($val eq $expr) { # =~ m/^\Q$i$/) {
1945 splice(@to_watch, $i_cnt, 1);
1950 print $OUT "Deleting a watch-expression requires an expression, or '*' for all\n"; # hint
1957 if ($cmd =~ /^.\b\s*([+-]?)\s*(~?)\s*(\w+(\s*\|\s*\w+)*)\s*$/) {
1958 my ($how, $neg, $flags)=($1, $2, $3);
1959 my $acu=parse_DollarCaretP_flags($flags);
1961 $acu= ~$acu if $neg;
1962 if ($how eq '+') { $^P|=$acu }
1963 elsif ($how eq '-') { $^P&=~$acu }
1966 # else { print $OUT "undefined acu\n" }
1968 my $expanded=expand_DollarCaretP_flags($^P);
1969 print $OUT "Internal Perl debugger flags:\n\$^P=$expanded\n";
1973 ### END of the API section
1976 @saved = ($@, $!, $^E, $,, $/, $\, $^W);
1977 $, = ""; $/ = "\n"; $\ = ""; $^W = 0;
1980 sub print_lineinfo {
1981 resetterm(1) if $LINEINFO eq $OUT and $term_pid != $$;
1987 # The following takes its argument via $evalarg to preserve current @_
1990 my $subname = shift;
1991 if ($postponed{$subname} =~ s/^break\s([+-]?\d+)\s+if\s//) {
1992 my $offset = $1 || 0;
1993 # Filename below can contain ':'
1994 my ($file,$i) = (find_sub($subname) =~ /^(.*):(\d+)-.*$/);
1997 local *dbline = $main::{'_<' . $file};
1998 local $^W = 0; # != 0 is magical below
1999 $had_breakpoints{$file} |= 1;
2001 ++$i until $dbline[$i] != 0 or $i >= $max;
2002 $dbline{$i} = delete $postponed{$subname};
2005 print $OUT "Subroutine $subname not found.\n";
2009 elsif ($postponed{$subname} eq 'compile') { $signal = 1 }
2010 #print $OUT "In postponed_sub for `$subname'.\n";
2014 if ($ImmediateStop) {
2018 return &postponed_sub
2019 unless ref \$_[0] eq 'GLOB'; # A subroutine is compiled.
2020 # Cannot be done before the file is compiled
2021 local *dbline = shift;
2022 my $filename = $dbline;
2023 $filename =~ s/^_<//;
2025 $signal = 1, print $OUT "'$filename' loaded...\n"
2026 if $break_on_load{$filename};
2027 print_lineinfo(' ' x $stack_depth, "Package $filename.\n") if $frame;
2028 return unless $postponed_file{$filename};
2029 $had_breakpoints{$filename} |= 1;
2030 #%dbline = %{$postponed_file{$filename}}; # Cannot be done: unsufficient magic
2032 for $key (keys %{$postponed_file{$filename}}) {
2033 $dbline{$key} = ${$postponed_file{$filename}}{$key};
2035 delete $postponed_file{$filename};
2039 local ($savout) = select(shift);
2040 my $osingle = $single;
2041 my $otrace = $trace;
2042 $single = $trace = 0;
2045 unless (defined &main::dumpValue) {
2048 if (defined &main::dumpValue) {
2053 my $maxdepth = shift || $option{dumpDepth};
2054 $maxdepth = -1 unless defined $maxdepth; # -1 means infinite depth
2055 &main::dumpValue($v, $maxdepth);
2058 print $OUT "dumpvar.pl not available.\n";
2065 # Tied method do not create a context, so may get wrong message:
2070 resetterm(1) if $fh eq $LINEINFO and $LINEINFO eq $OUT and $term_pid != $$;
2071 my @sub = dump_trace($_[0] + 1, $_[1]);
2072 my $short = $_[2]; # Print short report, next one for sub name
2074 for ($i=0; $i <= $#sub; $i++) {
2077 my $args = defined $sub[$i]{args}
2078 ? "(@{ $sub[$i]{args} })"
2080 $args = (substr $args, 0, $maxtrace - 3) . '...'
2081 if length $args > $maxtrace;
2082 my $file = $sub[$i]{file};
2083 $file = $file eq '-e' ? $file : "file `$file'" unless $short;
2085 $s = (substr $s, 0, $maxtrace - 3) . '...' if length $s > $maxtrace;
2087 my $sub = @_ >= 4 ? $_[3] : $s;
2088 print $fh "$sub[$i]{context}=$sub$args from $file:$sub[$i]{line}\n";
2090 print $fh "$sub[$i]{context} = $s$args" .
2091 " called from $file" .
2092 " line $sub[$i]{line}\n";
2099 my $count = shift || 1e9;
2102 my ($p,$file,$line,$sub,$h,$args,$e,$r,@a,@sub,$context);
2103 my $nothard = not $frame & 8;
2104 local $frame = 0; # Do not want to trace this.
2105 my $otrace = $trace;
2108 $i < $count and ($p,$file,$line,$sub,$h,$context,$e,$r) = caller($i);
2113 if (not defined $arg) {
2115 } elsif ($nothard and tied $arg) {
2117 } elsif ($nothard and $type = ref $arg) {
2118 push @a, "ref($type)";
2120 local $_ = "$arg"; # Safe to stringify now - should not call f().
2123 unless /^(?: -?[\d.]+ | \*[\w:]* )$/x;
2124 s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
2125 s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
2129 $context = $context ? '@' : (defined $context ? "\$" : '.');
2130 $args = $h ? [@a] : undef;
2131 $e =~ s/\n\s*\;\s*\Z// if $e;
2132 $e =~ s/([\\\'])/\\$1/g if $e;
2134 $sub = "require '$e'";
2135 } elsif (defined $r) {
2137 } elsif ($sub eq '(eval)') {
2138 $sub = "eval {...}";
2140 push(@sub, {context => $context, sub => $sub, args => $args,
2141 file => $file, line => $line});
2150 while ($action =~ s/\\$//) {
2159 # i hate using globals!
2160 $balanced_brace_re ||= qr{
2163 (?> [^{}] + ) # Non-parens without backtracking
2165 (??{ $balanced_brace_re }) # Group with matching parens
2169 return $_[0] !~ m/$balanced_brace_re/;
2173 &readline("cont: ");
2177 # We save, change, then restore STDIN and STDOUT to avoid fork() since
2178 # some non-Unix systems can do system() but have problems with fork().
2179 open(SAVEIN,"<&STDIN") || &warn("Can't save STDIN");
2180 open(SAVEOUT,">&STDOUT") || &warn("Can't save STDOUT");
2181 open(STDIN,"<&IN") || &warn("Can't redirect STDIN");
2182 open(STDOUT,">&OUT") || &warn("Can't redirect STDOUT");
2184 # XXX: using csh or tcsh destroys sigint retvals!
2186 open(STDIN,"<&SAVEIN") || &warn("Can't restore STDIN");
2187 open(STDOUT,">&SAVEOUT") || &warn("Can't restore STDOUT");
2192 # most of the $? crud was coping with broken cshisms
2194 &warn("(Command exited ", ($? >> 8), ")\n");
2196 &warn( "(Command died of SIG#", ($? & 127),
2197 (($? & 128) ? " -- core dumped" : "") , ")", "\n");
2207 eval { require Term::ReadLine } or die $@;
2210 my ($i, $o) = split $tty, /,/;
2211 $o = $i unless defined $o;
2212 open(IN,"<$i") or die "Cannot open TTY `$i' for read: $!";
2213 open(OUT,">$o") or die "Cannot open TTY `$o' for write: $!";
2216 my $sel = select($OUT);
2220 eval "require Term::Rendezvous;" or die;
2221 my $rv = $ENV{PERLDB_NOTTY} || "/tmp/perldbtty$$";
2222 my $term_rv = new Term::Rendezvous $rv;
2224 $OUT = $term_rv->OUT;
2227 if ($term_pid eq '-1') { # In a TTY with another debugger
2231 $term = new Term::ReadLine::Stub 'perldb', $IN, $OUT;
2233 $term = new Term::ReadLine 'perldb', $IN, $OUT;
2235 $rl_attribs = $term->Attribs;
2236 $rl_attribs->{basic_word_break_characters} .= '-:+/*,[])}'
2237 if defined $rl_attribs->{basic_word_break_characters}
2238 and index($rl_attribs->{basic_word_break_characters}, ":") == -1;
2239 $rl_attribs->{special_prefixes} = '$@&%';
2240 $rl_attribs->{completer_word_break_characters} .= '$@&%';
2241 $rl_attribs->{completion_function} = \&db_complete;
2243 $LINEINFO = $OUT unless defined $LINEINFO;
2244 $lineinfo = $console unless defined $lineinfo;
2246 if ($term->Features->{setHistory} and "@hist" ne "?") {
2247 $term->SetHistory(@hist);
2249 ornaments($ornaments) if defined $ornaments;
2253 # Example get_fork_TTY functions
2254 sub xterm_get_fork_TTY {
2255 (my $name = $0) =~ s,^.*[/\\],,s;
2256 open XT, qq[3>&1 xterm -title "Daughter Perl debugger $pids $name" -e sh -c 'tty 1>&3;\
2260 $pidprompt = ''; # Shown anyway in titlebar
2264 # This example function resets $IN, $OUT itself
2265 sub os2_get_fork_TTY {
2266 local $^F = 40; # XXXX Fixme!
2268 my ($in1, $out1, $in2, $out2);
2269 # Having -d in PERL5OPT would lead to a disaster...
2270 local $ENV{PERL5OPT} = $ENV{PERL5OPT} if $ENV{PERL5OPT};
2271 $ENV{PERL5OPT} =~ s/(?:^|(?<=\s))-d\b// if $ENV{PERL5OPT};
2272 $ENV{PERL5OPT} =~ s/(?:^|(?<=\s))-d\B/-/ if $ENV{PERL5OPT};
2273 print $OUT "Making kid PERL5OPT->`$ENV{PERL5OPT}'.\n" if $ENV{PERL5OPT};
2274 local $ENV{PERL5LIB} = $ENV{PERL5LIB} ? $ENV{PERL5LIB} : $ENV{PERLLIB};
2275 $ENV{PERL5LIB} = '' unless defined $ENV{PERL5LIB};
2276 $ENV{PERL5LIB} = join ';', @ini_INC, split /;/, $ENV{PERL5LIB};
2277 (my $name = $0) =~ s,^.*[/\\],,s;
2279 if ( pipe $in1, $out1 and pipe $in2, $out2
2280 # system P_SESSION will fail if there is another process
2281 # in the same session with a "dependent" asynchronous child session.
2282 and @args = ($rl, fileno $in1, fileno $out2,
2283 "Daughter Perl debugger $pids $name") and
2284 (($kpid = CORE::system 4, $^X, '-we', <<'ES', @args) >= 0 # P_SESSION
2285 END {sleep 5 unless $loaded}
2286 BEGIN {open STDIN, '</dev/con' or warn "reopen stdin: $!"}
2289 my ($rl, $in) = (shift, shift); # Read from $in and pass through
2291 system P_NOWAIT, $^X, '-we', <<EOS or die "Cannot start a grandkid";
2292 open IN, '<&=$in' or die "open <&=$in: \$!";
2293 \$| = 1; print while sysread IN, \$_, 1<<16;
2297 open OUT, ">&=$out" or die "Cannot open &=$out for writing: $!";
2299 require Term::ReadKey if $rl;
2300 Term::ReadKey::ReadMode(4) if $rl; # Nodelay on kbd. Pipe is automatically nodelay...
2301 print while sysread STDIN, $_, 1<<($rl ? 16 : 0);
2303 or warn "system P_SESSION: $!, $^E" and 0)
2304 and close $in1 and close $out2 ) {
2305 $pidprompt = ''; # Shown anyway in titlebar
2306 reset_IN_OUT($in2, $out1);
2308 return ''; # Indicate that reset_IN_OUT is called
2313 sub create_IN_OUT { # Create a window with IN/OUT handles redirected there
2314 my $in = &get_fork_TTY if defined &get_fork_TTY;
2315 $in = $fork_TTY if defined $fork_TTY; # Backward compatibility
2316 if (not defined $in) {
2318 print_help(<<EOP) if $why == 1;
2319 I<#########> Forked, but do not know how to create a new B<TTY>. I<#########>
2321 print_help(<<EOP) if $why == 2;
2322 I<#########> Daughter session, do not know how to change a B<TTY>. I<#########>
2323 This may be an asynchronous session, so the parent debugger may be active.
2325 print_help(<<EOP) if $why != 4;
2326 Since two debuggers fight for the same TTY, input is severely entangled.
2330 I know how to switch the output to a different window in xterms
2331 and OS/2 consoles only. For a manual switch, put the name of the created I<TTY>
2332 in B<\$DB::fork_TTY>, or define a function B<DB::get_fork_TTY()> returning this.
2334 On I<UNIX>-like systems one can get the name of a I<TTY> for the given window
2335 by typing B<tty>, and disconnect the I<shell> from I<TTY> by B<sleep 1000000>.
2338 } elsif ($in ne '') {
2341 $console = ''; # Indicate no need to open-from-the-console
2346 sub resetterm { # We forked, so we need a different TTY
2348 my $systemed = $in > 1 ? '-' : '';
2350 $pids =~ s/\]/$systemed->$$]/;
2352 $pids = "[$term_pid->$$]";
2356 return unless $CreateTTY & $in;
2363 my $left = @typeahead;
2364 my $got = shift @typeahead;
2366 print $OUT "auto(-$left)", shift, $got, "\n";
2367 $term->AddHistory($got)
2368 if length($got) > 1 and defined $term->Features->{addHistory};
2374 my $line = CORE::readline($cmdfhs[-1]);
2375 defined $line ? (print $OUT ">> $line" and return $line)
2376 : close pop @cmdfhs;
2378 if (ref $OUT and UNIVERSAL::isa($OUT, 'IO::Socket::INET')) {
2379 $OUT->write(join('', @_));
2381 $IN->recv( $stuff, 2048 ); # XXX: what's wrong with sysread?
2385 $term->readline(@_);
2390 my ($opt, $val)= @_;
2391 $val = option_val($opt,'N/A');
2392 $val =~ s/([\\\'])/\\$1/g;
2393 printf $OUT "%20s = '%s'\n", $opt, $val;
2396 sub options2remember {
2397 foreach my $k (@RememberOnROptions) {
2398 $option{$k}=option_val($k, 'N/A');
2404 my ($opt, $default)= @_;
2406 if (defined $optionVars{$opt}
2407 and defined ${$optionVars{$opt}}) {
2408 $val = ${$optionVars{$opt}};
2409 } elsif (defined $optionAction{$opt}
2410 and defined &{$optionAction{$opt}}) {
2411 $val = &{$optionAction{$opt}}();
2412 } elsif (defined $optionAction{$opt}
2413 and not defined $option{$opt}
2414 or defined $optionVars{$opt}
2415 and not defined ${$optionVars{$opt}}) {
2418 $val = $option{$opt};
2420 $val = $default unless defined $val;
2427 # too dangerous to let intuitive usage overwrite important things
2428 # defaultion should never be the default
2429 my %opt_needs_val = map { ( $_ => 1 ) } qw{
2430 dumpDepth arrayDepth hashDepth LineInfo maxTraceLen ornaments windowSize
2431 pager quote ReadLine recallCommand RemotePort ShellBang TTY
2436 s/^(\w+)(\W?)// or print($OUT "Invalid option `$_'\n"), last;
2437 my ($opt,$sep) = ($1,$2);
2440 print($OUT "Option query `$opt?' followed by non-space `$_'\n"), last
2442 #&dump_option($opt);
2443 } elsif ($sep !~ /\S/) {
2445 $val = "1"; # this is an evil default; make 'em set it!
2446 } elsif ($sep eq "=") {
2447 if (s/ (["']) ( (?: \\. | (?! \1 ) [^\\] )* ) \1 //x) {
2449 ($val = $2) =~ s/\\([$quote\\])/$1/g;
2453 print OUT qq(Option better cleared using $opt=""\n)
2457 } else { #{ to "let some poor schmuck bounce on the % key in B<vi>."
2458 my ($end) = "\\" . substr( ")]>}$sep", index("([<{",$sep), 1 ); #}
2459 s/^(([^\\$end]|\\[\\$end])*)$end($|\s+)// or
2460 print($OUT "Unclosed option value `$opt$sep$_'\n"), last;
2461 ($val = $1) =~ s/\\([\\$end])/$1/g;
2465 my $matches = grep( /^\Q$opt/ && ($option = $_), @options )
2466 || grep( /^\Q$opt/i && ($option = $_), @options );
2468 print($OUT "Unknown option `$opt'\n"), next unless $matches;
2469 print($OUT "Ambiguous option `$opt'\n"), next if $matches > 1;
2471 if ($opt_needs_val{$option} && $val_defaulted) {
2472 my $cmd = ($CommandSet eq '580') ? 'o' : 'O';
2473 print $OUT "Option `$opt' is non-boolean. Use `$cmd $option=VAL' to set, `$cmd $option?' to query\n";
2477 $option{$option} = $val if defined $val;
2482 require '$optionRequire{$option}';
2484 } || die # XXX: shouldn't happen
2485 if defined $optionRequire{$option} &&
2488 ${$optionVars{$option}} = $val
2489 if defined $optionVars{$option} &&
2492 &{$optionAction{$option}} ($val)
2493 if defined $optionAction{$option} &&
2494 defined &{$optionAction{$option}} &&
2498 dump_option($option) unless $OUT eq \*STDERR;
2503 my ($stem,@list) = @_;
2505 $ENV{"${stem}_n"} = @list;
2506 for $i (0 .. $#list) {
2508 $val =~ s/\\/\\\\/g;
2509 $val =~ s/([\0-\37\177\200-\377])/"\\0x" . unpack('H2',$1)/eg;
2510 $ENV{"${stem}_$i"} = $val;
2517 my $n = delete $ENV{"${stem}_n"};
2519 for $i (0 .. $n - 1) {
2520 $val = delete $ENV{"${stem}_$i"};
2521 $val =~ s/\\((\\)|0x(..))/ $2 ? $2 : pack('H2', $3) /ge;
2529 return; # Put nothing on the stack - malloc/free land!
2533 my($msg)= join("",@_);
2534 $msg .= ": $!\n" unless $msg =~ /\n$/;
2540 my $switch_li = $LINEINFO eq $OUT;
2541 if ($term and $term->Features->{newTTY}) {
2542 ($IN, $OUT) = (shift, shift);
2543 $term->newTTY($IN, $OUT);
2545 &warn("Too late to set IN/OUT filehandles, enabled on next `R'!\n");
2547 ($IN, $OUT) = (shift, shift);
2549 my $o = select $OUT;
2552 $LINEINFO = $OUT if $switch_li;
2556 if (@_ and $term and $term->Features->{newTTY}) {
2557 my ($in, $out) = shift;
2559 ($in, $out) = split /,/, $in, 2;
2563 open IN, $in or die "cannot open `$in' for read: $!";
2564 open OUT, ">$out" or die "cannot open `$out' for write: $!";
2565 reset_IN_OUT(\*IN,\*OUT);
2568 &warn("Too late to set TTY, enabled on next `R'!\n") if $term and @_;
2569 # Useful if done through PERLDB_OPTS:
2570 $console = $tty = shift if @_;
2576 &warn("Too late to set noTTY, enabled on next `R'!\n") if @_;
2578 $notty = shift if @_;
2584 &warn("Too late to set ReadLine, enabled on next `R'!\n") if @_;
2592 &warn("Too late to set RemotePort, enabled on next 'R'!\n") if @_;
2594 $remoteport = shift if @_;
2599 if (${$term->Features}{tkRunning}) {
2600 return $term->tkRunning(@_);
2603 print $OUT "tkRunning not supported by current ReadLine package.\n";
2610 &warn("Too late to set up NonStop mode, enabled on next `R'!\n") if @_;
2612 $runnonstop = shift if @_;
2618 &warn("Some flag changes could not take effect until next 'R'!\n") if @_;
2620 $^P = parse_DollarCaretP_flags(shift) if @_;
2621 expand_DollarCaretP_flags($^P)
2624 sub OnlyAssertions {
2626 &warn("Too late to set up OnlyAssertions mode, enabled on next 'R'!\n") if @_;
2629 unless (defined $ini_assertion) {
2631 &warn("Current Perl interpreter doesn't support assertions");
2636 unless ($ini_assertion) {
2637 print "Assertions will be active on next 'R'!\n";
2640 $^P&= ~$DollarCaretP_flags{PERLDBf_SUB};
2641 $^P|=$DollarCaretP_flags{PERLDBf_ASSERTION};
2644 $^P|=$DollarCaretP_flags{PERLDBf_SUB};
2647 !($^P & $DollarCaretP_flags{PERLDBf_SUB}) || 0;
2653 $pager="|".$pager unless $pager =~ /^(\+?\>|\|)/;
2660 $sh = quotemeta shift;
2661 $sh .= "\\b" if $sh =~ /\w$/;
2665 $psh =~ s/\\(.)/$1/g;
2670 if (defined $term) {
2671 local ($warnLevel,$dieLevel) = (0, 1);
2672 return '' unless $term->Features->{ornaments};
2673 eval { $term->ornaments(@_) } || '';
2681 $rc = quotemeta shift;
2682 $rc .= "\\b" if $rc =~ /\w$/;
2686 $prc =~ s/\\(.)/$1/g;
2691 return $lineinfo unless @_;
2693 my $stream = ($lineinfo =~ /^(\+?\>|\|)/) ? $lineinfo : ">$lineinfo";
2694 $slave_editor = ($stream =~ /^\|/);
2695 open(LINEINFO, "$stream") || &warn("Cannot open `$stream' for write");
2696 $LINEINFO = \*LINEINFO;
2697 my $save = select($LINEINFO);
2703 sub list_modules { # versions
2711 s/^Term::ReadLine::readline$/readline/;
2712 if (defined ${ $_ . '::VERSION' }) {
2713 $version{$file} = "${ $_ . '::VERSION' } from ";
2715 $version{$file} .= $INC{$file};
2717 dumpit($OUT,\%version);
2721 # XXX: make sure there are tabs between the command and explanation,
2722 # or print_help will screw up your formatting if you have
2723 # eeevil ornaments enabled. This is an insane mess.
2726 Help is currently only available for the new 580 CommandSet,
2727 if you really want old behaviour, presumably you know what
2731 B<s> [I<expr>] Single step [in I<expr>].
2732 B<n> [I<expr>] Next, steps over subroutine calls [in I<expr>].
2733 <B<CR>> Repeat last B<n> or B<s> command.
2734 B<r> Return from current subroutine.
2735 B<c> [I<line>|I<sub>] Continue; optionally inserts a one-time-only breakpoint
2736 at the specified position.
2737 B<l> I<min>B<+>I<incr> List I<incr>+1 lines starting at I<min>.
2738 B<l> I<min>B<->I<max> List lines I<min> through I<max>.
2739 B<l> I<line> List single I<line>.
2740 B<l> I<subname> List first window of lines from subroutine.
2741 B<l> I<\$var> List first window of lines from subroutine referenced by I<\$var>.
2742 B<l> List next window of lines.
2743 B<-> List previous window of lines.
2744 B<v> [I<line>] View window around I<line>.
2745 B<.> Return to the executed line.
2746 B<f> I<filename> Switch to viewing I<filename>. File must be already loaded.
2747 I<filename> may be either the full name of the file, or a regular
2748 expression matching the full file name:
2749 B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
2750 Evals (with saved bodies) are considered to be filenames:
2751 B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
2752 (in the order of execution).
2753 B</>I<pattern>B</> Search forwards for I<pattern>; final B</> is optional.
2754 B<?>I<pattern>B<?> Search backwards for I<pattern>; final B<?> is optional.
2755 B<L> [I<a|b|w>] List actions and or breakpoints and or watch-expressions.
2756 B<S> [[B<!>]I<pattern>] List subroutine names [not] matching I<pattern>.
2757 B<t> Toggle trace mode.
2758 B<t> I<expr> Trace through execution of I<expr>.
2759 B<b> Sets breakpoint on current line)
2760 B<b> [I<line>] [I<condition>]
2761 Set breakpoint; I<line> defaults to the current execution line;
2762 I<condition> breaks if it evaluates to true, defaults to '1'.
2763 B<b> I<subname> [I<condition>]
2764 Set breakpoint at first line of subroutine.
2765 B<b> I<\$var> Set breakpoint at first line of subroutine referenced by I<\$var>.
2766 B<b> B<load> I<filename> Set breakpoint on 'require'ing the given file.
2767 B<b> B<postpone> I<subname> [I<condition>]
2768 Set breakpoint at first line of subroutine after
2770 B<b> B<compile> I<subname>
2771 Stop after the subroutine is compiled.
2772 B<B> [I<line>] Delete the breakpoint for I<line>.
2773 B<B> I<*> Delete all breakpoints.
2774 B<a> [I<line>] I<command>
2775 Set an action to be done before the I<line> is executed;
2776 I<line> defaults to the current execution line.
2777 Sequence is: check for breakpoint/watchpoint, print line
2778 if necessary, do action, prompt user if necessary,
2781 B<A> [I<line>] Delete the action for I<line>.
2782 B<A> I<*> Delete all actions.
2783 B<w> I<expr> Add a global watch-expression.
2785 B<W> I<expr> Delete a global watch-expression.
2786 B<W> I<*> Delete all watch-expressions.
2787 B<V> [I<pkg> [I<vars>]] List some (default all) variables in package (default current).
2788 Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
2789 B<X> [I<vars>] Same as \"B<V> I<currentpackage> [I<vars>]\".
2790 B<y> [I<n> [I<Vars>]] List lexicals in higher scope <n>. Vars same as B<V>.
2791 B<x> I<expr> Evals expression in list context, dumps the result.
2792 B<m> I<expr> Evals expression in list context, prints methods callable
2793 on the first element of the result.
2794 B<m> I<class> Prints methods callable via the given class.
2795 B<M> Show versions of loaded modules.
2796 B<y> [I<n> [I<vars>]] List lexical variables I<n> levels up from current sub
2798 B<<> ? List Perl commands to run before each prompt.
2799 B<<> I<expr> Define Perl command to run before each prompt.
2800 B<<<> I<expr> Add to the list of Perl commands to run before each prompt.
2801 B<< *> Delete the list of perl commands to run before each prompt.
2802 B<>> ? List Perl commands to run after each prompt.
2803 B<>> I<expr> Define Perl command to run after each prompt.
2804 B<>>B<>> I<expr> Add to the list of Perl commands to run after each prompt.
2805 B<>>B< *> Delete the list of Perl commands to run after each prompt.
2806 B<{> I<db_command> Define debugger command to run before each prompt.
2807 B<{> ? List debugger commands to run before each prompt.
2808 B<{{> I<db_command> Add to the list of debugger commands to run before each prompt.
2809 B<{ *> Delete the list of debugger commands to run before each prompt.
2810 B<$prc> I<number> Redo a previous command (default previous command).
2811 B<$prc> I<-number> Redo number'th-to-last command.
2812 B<$prc> I<pattern> Redo last command that started with I<pattern>.
2813 See 'B<O> I<recallCommand>' too.
2814 B<$psh$psh> I<cmd> Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
2815 . ( $rc eq $sh ? "" : "
2816 B<$psh> [I<cmd>] Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")." ) . "
2817 See 'B<O> I<shellBang>' too.
2818 B<source> I<file> Execute I<file> containing debugger commands (may nest).
2819 B<H> I<-number> Display last number commands (default all).
2820 B<p> I<expr> Same as \"I<print {DB::OUT} expr>\" in current package.
2821 B<|>I<dbcmd> Run debugger command, piping DB::OUT to current pager.
2822 B<||>I<dbcmd> Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
2823 B<\=> [I<alias> I<value>] Define a command alias, or list current aliases.
2824 I<command> Execute as a perl statement in current package.
2825 B<R> Pure-man-restart of debugger, some of debugger state
2826 and command-line options may be lost.
2827 Currently the following settings are preserved:
2828 history, breakpoints and actions, debugger B<O>ptions
2829 and the following command-line options: I<-w>, I<-I>, I<-e>.
2831 B<o> [I<opt>] ... Set boolean option to true
2832 B<o> [I<opt>B<?>] Query options
2833 B<o> [I<opt>B<=>I<val>] [I<opt>=B<\">I<val>B<\">] ...
2834 Set options. Use quotes in spaces in value.
2835 I<recallCommand>, I<ShellBang> chars used to recall command or spawn shell;
2836 I<pager> program for output of \"|cmd\";
2837 I<tkRunning> run Tk while prompting (with ReadLine);
2838 I<signalLevel> I<warnLevel> I<dieLevel> level of verbosity;
2839 I<inhibit_exit> Allows stepping off the end of the script.
2840 I<ImmediateStop> Debugger should stop as early as possible.
2841 I<RemotePort> Remote hostname:port for remote debugging
2842 The following options affect what happens with B<V>, B<X>, and B<x> commands:
2843 I<arrayDepth>, I<hashDepth> print only first N elements ('' for all);
2844 I<compactDump>, I<veryCompact> change style of array and hash dump;
2845 I<globPrint> whether to print contents of globs;
2846 I<DumpDBFiles> dump arrays holding debugged files;
2847 I<DumpPackages> dump symbol tables of packages;
2848 I<DumpReused> dump contents of \"reused\" addresses;
2849 I<quote>, I<HighBit>, I<undefPrint> change style of string dump;
2850 I<bareStringify> Do not print the overload-stringified value;
2851 Other options include:
2852 I<PrintRet> affects printing of return value after B<r> command,
2853 I<frame> affects printing messages on subroutine entry/exit.
2854 I<AutoTrace> affects printing messages on possible breaking points.
2855 I<maxTraceLen> gives max length of evals/args listed in stack trace.
2856 I<ornaments> affects screen appearance of the command line.
2857 I<CreateTTY> bits control attempts to create a new TTY on events:
2858 1: on fork() 2: debugger is started inside debugger
2860 During startup options are initialized from \$ENV{PERLDB_OPTS}.
2861 You can put additional initialization options I<TTY>, I<noTTY>,
2862 I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
2863 `B<R>' after you set them).
2865 B<q> or B<^D> Quit. Set B<\$DB::finished = 0> to debug global destruction.
2866 B<h> Summary of debugger commands.
2867 B<h> [I<db_command>] Get help [on a specific debugger command], enter B<|h> to page.
2868 B<h h> Long help for debugger commands
2869 B<$doccmd> I<manpage> Runs the external doc viewer B<$doccmd> command on the
2870 named Perl I<manpage>, or on B<$doccmd> itself if omitted.
2871 Set B<\$DB::doccmd> to change viewer.
2873 Type `|h h' for a paged display if this was too hard to read.
2875 "; # Fix balance of vi % matching: }}}}
2877 # note: tabs in the following section are not-so-helpful
2878 $summary = <<"END_SUM";
2879 I<List/search source lines:> I<Control script execution:>
2880 B<l> [I<ln>|I<sub>] List source code B<T> Stack trace
2881 B<-> or B<.> List previous/current line B<s> [I<expr>] Single step [in expr]
2882 B<v> [I<line>] View around line B<n> [I<expr>] Next, steps over subs
2883 B<f> I<filename> View source in file <B<CR>/B<Enter>> Repeat last B<n> or B<s>
2884 B</>I<pattern>B</> B<?>I<patt>B<?> Search forw/backw B<r> Return from subroutine
2885 B<M> Show module versions B<c> [I<ln>|I<sub>] Continue until position
2886 I<Debugger controls:> B<L> List break/watch/actions
2887 B<o> [...] Set debugger options B<t> [I<expr>] Toggle trace [trace expr]
2888 B<<>[B<<>]|B<{>[B<{>]|B<>>[B<>>] [I<cmd>] Do pre/post-prompt B<b> [I<ln>|I<event>|I<sub>] [I<cnd>] Set breakpoint
2889 B<$prc> [I<N>|I<pat>] Redo a previous command B<B> I<ln|*> Delete a/all breakpoints
2890 B<H> [I<-num>] Display last num commands B<a> [I<ln>] I<cmd> Do cmd before line
2891 B<=> [I<a> I<val>] Define/list an alias B<A> I<ln|*> Delete a/all actions
2892 B<h> [I<db_cmd>] Get help on command B<w> I<expr> Add a watch expression
2893 B<h h> Complete help page B<W> I<expr|*> Delete a/all watch exprs
2894 B<|>[B<|>]I<db_cmd> Send output to pager B<$psh>\[B<$psh>\] I<syscmd> Run cmd in a subprocess
2895 B<q> or B<^D> Quit B<R> Attempt a restart
2896 I<Data Examination:> B<expr> Execute perl code, also see: B<s>,B<n>,B<t> I<expr>
2897 B<x>|B<m> I<expr> Evals expr in list context, dumps the result or lists methods.
2898 B<p> I<expr> Print expression (uses script's current package).
2899 B<S> [[B<!>]I<pat>] List subroutine names [not] matching pattern
2900 B<V> [I<Pk> [I<Vars>]] List Variables in Package. Vars can be ~pattern or !pattern.
2901 B<X> [I<Vars>] Same as \"B<V> I<current_package> [I<Vars>]\".
2902 B<y> [I<n> [I<Vars>]] List lexicals in higher scope <n>. Vars same as B<V>.
2903 For more help, type B<h> I<cmd_letter>, or run B<$doccmd perldebug> for all docs.
2905 # ')}}; # Fix balance of vi % matching
2907 # and this is really numb...
2910 B<s> [I<expr>] Single step [in I<expr>].
2911 B<n> [I<expr>] Next, steps over subroutine calls [in I<expr>].
2912 <B<CR>> Repeat last B<n> or B<s> command.
2913 B<r> Return from current subroutine.
2914 B<c> [I<line>|I<sub>] Continue; optionally inserts a one-time-only breakpoint
2915 at the specified position.
2916 B<l> I<min>B<+>I<incr> List I<incr>+1 lines starting at I<min>.
2917 B<l> I<min>B<->I<max> List lines I<min> through I<max>.
2918 B<l> I<line> List single I<line>.
2919 B<l> I<subname> List first window of lines from subroutine.
2920 B<l> I<\$var> List first window of lines from subroutine referenced by I<\$var>.
2921 B<l> List next window of lines.
2922 B<-> List previous window of lines.
2923 B<w> [I<line>] List window around I<line>.
2924 B<.> Return to the executed line.
2925 B<f> I<filename> Switch to viewing I<filename>. File must be already loaded.
2926 I<filename> may be either the full name of the file, or a regular
2927 expression matching the full file name:
2928 B<f> I</home/me/foo.pl> and B<f> I<oo\\.> may access the same file.
2929 Evals (with saved bodies) are considered to be filenames:
2930 B<f> I<(eval 7)> and B<f> I<eval 7\\b> access the body of the 7th eval
2931 (in the order of execution).
2932 B</>I<pattern>B</> Search forwards for I<pattern>; final B</> is optional.
2933 B<?>I<pattern>B<?> Search backwards for I<pattern>; final B<?> is optional.
2934 B<L> List all breakpoints and actions.
2935 B<S> [[B<!>]I<pattern>] List subroutine names [not] matching I<pattern>.
2936 B<t> Toggle trace mode.
2937 B<t> I<expr> Trace through execution of I<expr>.
2938 B<b> [I<line>] [I<condition>]
2939 Set breakpoint; I<line> defaults to the current execution line;
2940 I<condition> breaks if it evaluates to true, defaults to '1'.
2941 B<b> I<subname> [I<condition>]
2942 Set breakpoint at first line of subroutine.
2943 B<b> I<\$var> Set breakpoint at first line of subroutine referenced by I<\$var>.
2944 B<b> B<load> I<filename> Set breakpoint on `require'ing the given file.
2945 B<b> B<postpone> I<subname> [I<condition>]
2946 Set breakpoint at first line of subroutine after
2948 B<b> B<compile> I<subname>
2949 Stop after the subroutine is compiled.
2950 B<d> [I<line>] Delete the breakpoint for I<line>.
2951 B<D> Delete all breakpoints.
2952 B<a> [I<line>] I<command>
2953 Set an action to be done before the I<line> is executed;
2954 I<line> defaults to the current execution line.
2955 Sequence is: check for breakpoint/watchpoint, print line
2956 if necessary, do action, prompt user if necessary,
2958 B<a> [I<line>] Delete the action for I<line>.
2959 B<A> Delete all actions.
2960 B<W> I<expr> Add a global watch-expression.
2961 B<W> Delete all watch-expressions.
2962 B<V> [I<pkg> [I<vars>]] List some (default all) variables in package (default current).
2963 Use B<~>I<pattern> and B<!>I<pattern> for positive and negative regexps.
2964 B<X> [I<vars>] Same as \"B<V> I<currentpackage> [I<vars>]\".
2965 B<x> I<expr> Evals expression in list context, dumps the result.
2966 B<m> I<expr> Evals expression in list context, prints methods callable
2967 on the first element of the result.
2968 B<m> I<class> Prints methods callable via the given class.
2970 B<<> ? List Perl commands to run before each prompt.
2971 B<<> I<expr> Define Perl command to run before each prompt.
2972 B<<<> I<expr> Add to the list of Perl commands to run before each prompt.
2973 B<>> ? List Perl commands to run after each prompt.
2974 B<>> I<expr> Define Perl command to run after each prompt.
2975 B<>>B<>> I<expr> Add to the list of Perl commands to run after each prompt.
2976 B<{> I<db_command> Define debugger command to run before each prompt.
2977 B<{> ? List debugger commands to run before each prompt.
2978 B<{{> I<db_command> Add to the list of debugger commands to run before each prompt.
2979 B<$prc> I<number> Redo a previous command (default previous command).
2980 B<$prc> I<-number> Redo number'th-to-last command.
2981 B<$prc> I<pattern> Redo last command that started with I<pattern>.
2982 See 'B<O> I<recallCommand>' too.
2983 B<$psh$psh> I<cmd> Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT)"
2984 . ( $rc eq $sh ? "" : "
2985 B<$psh> [I<cmd>] Run I<cmd> in subshell (forces \"\$SHELL -c 'cmd'\")." ) . "
2986 See 'B<O> I<shellBang>' too.
2987 B<source> I<file> Execute I<file> containing debugger commands (may nest).
2988 B<H> I<-number> Display last number commands (default all).
2989 B<p> I<expr> Same as \"I<print {DB::OUT} expr>\" in current package.
2990 B<|>I<dbcmd> Run debugger command, piping DB::OUT to current pager.
2991 B<||>I<dbcmd> Same as B<|>I<dbcmd> but DB::OUT is temporarilly select()ed as well.
2992 B<\=> [I<alias> I<value>] Define a command alias, or list current aliases.
2993 I<command> Execute as a perl statement in current package.
2994 B<v> Show versions of loaded modules.
2995 B<R> Pure-man-restart of debugger, some of debugger state
2996 and command-line options may be lost.
2997 Currently the following settings are preserved:
2998 history, breakpoints and actions, debugger B<O>ptions
2999 and the following command-line options: I<-w>, I<-I>, I<-e>.
3001 B<O> [I<opt>] ... Set boolean option to true
3002 B<O> [I<opt>B<?>] Query options
3003 B<O> [I<opt>B<=>I<val>] [I<opt>=B<\">I<val>B<\">] ...
3004 Set options. Use quotes in spaces in value.
3005 I<recallCommand>, I<ShellBang> chars used to recall command or spawn shell;
3006 I<pager> program for output of \"|cmd\";
3007 I<tkRunning> run Tk while prompting (with ReadLine);
3008 I<signalLevel> I<warnLevel> I<dieLevel> level of verbosity;
3009 I<inhibit_exit> Allows stepping off the end of the script.
3010 I<ImmediateStop> Debugger should stop as early as possible.
3011 I<RemotePort> Remote hostname:port for remote debugging
3012 The following options affect what happens with B<V>, B<X>, and B<x> commands:
3013 I<arrayDepth>, I<hashDepth> print only first N elements ('' for all);
3014 I<compactDump>, I<veryCompact> change style of array and hash dump;
3015 I<globPrint> whether to print contents of globs;
3016 I<DumpDBFiles> dump arrays holding debugged files;
3017 I<DumpPackages> dump symbol tables of packages;
3018 I<DumpReused> dump contents of \"reused\" addresses;
3019 I<quote>, I<HighBit>, I<undefPrint> change style of string dump;
3020 I<bareStringify> Do not print the overload-stringified value;
3021 Other options include:
3022 I<PrintRet> affects printing of return value after B<r> command,
3023 I<frame> affects printing messages on subroutine entry/exit.
3024 I<AutoTrace> affects printing messages on possible breaking points.
3025 I<maxTraceLen> gives max length of evals/args listed in stack trace.
3026 I<ornaments> affects screen appearance of the command line.
3027 I<CreateTTY> bits control attempts to create a new TTY on events:
3028 1: on fork() 2: debugger is started inside debugger
3030 During startup options are initialized from \$ENV{PERLDB_OPTS}.
3031 You can put additional initialization options I<TTY>, I<noTTY>,
3032 I<ReadLine>, I<NonStop>, and I<RemotePort> there (or use
3033 `B<R>' after you set them).
3035 B<q> or B<^D> Quit. Set B<\$DB::finished = 0> to debug global destruction.
3036 B<h> [I<db_command>] Get help [on a specific debugger command], enter B<|h> to page.
3037 B<h h> Summary of debugger commands.
3038 B<$doccmd> I<manpage> Runs the external doc viewer B<$doccmd> command on the
3039 named Perl I<manpage>, or on B<$doccmd> itself if omitted.
3040 Set B<\$DB::doccmd> to change viewer.
3042 Type `|h' for a paged display if this was too hard to read.
3044 "; # Fix balance of vi % matching: }}}}
3046 # note: tabs in the following section are not-so-helpful
3047 $pre580_summary = <<"END_SUM";
3048 I<List/search source lines:> I<Control script execution:>
3049 B<l> [I<ln>|I<sub>] List source code B<T> Stack trace
3050 B<-> or B<.> List previous/current line B<s> [I<expr>] Single step [in expr]
3051 B<w> [I<line>] List around line B<n> [I<expr>] Next, steps over subs
3052 B<f> I<filename> View source in file <B<CR>/B<Enter>> Repeat last B<n> or B<s>
3053 B</>I<pattern>B</> B<?>I<patt>B<?> Search forw/backw B<r> Return from subroutine
3054 B<v> Show versions of modules B<c> [I<ln>|I<sub>] Continue until position
3055 I<Debugger controls:> B<L> List break/watch/actions
3056 B<O> [...] Set debugger options B<t> [I<expr>] Toggle trace [trace expr]
3057 B<<>[B<<>]|B<{>[B<{>]|B<>>[B<>>] [I<cmd>] Do pre/post-prompt B<b> [I<ln>|I<event>|I<sub>] [I<cnd>] Set breakpoint
3058 B<$prc> [I<N>|I<pat>] Redo a previous command B<d> [I<ln>] or B<D> Delete a/all breakpoints
3059 B<H> [I<-num>] Display last num commands B<a> [I<ln>] I<cmd> Do cmd before line
3060 B<=> [I<a> I<val>] Define/list an alias B<W> I<expr> Add a watch expression
3061 B<h> [I<db_cmd>] Get help on command B<A> or B<W> Delete all actions/watch
3062 B<|>[B<|>]I<db_cmd> Send output to pager B<$psh>\[B<$psh>\] I<syscmd> Run cmd in a subprocess
3063 B<q> or B<^D> Quit B<R> Attempt a restart
3064 I<Data Examination:> B<expr> Execute perl code, also see: B<s>,B<n>,B<t> I<expr>
3065 B<x>|B<m> I<expr> Evals expr in list context, dumps the result or lists methods.
3066 B<p> I<expr> Print expression (uses script's current package).
3067 B<S> [[B<!>]I<pat>] List subroutine names [not] matching pattern
3068 B<V> [I<Pk> [I<Vars>]] List Variables in Package. Vars can be ~pattern or !pattern.
3069 B<X> [I<Vars>] Same as \"B<V> I<current_package> [I<Vars>]\".
3070 B<y> [I<n> [I<Vars>]] List lexicals in higher scope <n>. Vars same as B<V>.
3071 For more help, type B<h> I<cmd_letter>, or run B<$doccmd perldebug> for all docs.
3073 # ')}}; # Fix balance of vi % matching
3080 # Restore proper alignment destroyed by eeevil I<> and B<>
3081 # ornaments: A pox on both their houses!
3083 # A help command will have everything up to and including
3084 # the first tab sequence padded into a field 16 (or if indented 20)
3085 # wide. If it's wider than that, an extra space will be added.
3087 ^ # only matters at start of line
3088 ( \040{4} | \t )* # some subcommands are indented
3089 ( < ? # so <CR> works
3090 [BI] < [^\t\n] + ) # find an eeevil ornament
3091 ( \t+ ) # original separation, discarded
3092 ( .* ) # this will now start (no earlier) than
3095 my($leadwhite, $command, $midwhite, $text) = ($1, $2, $3, $4);
3096 my $clean = $command;
3097 $clean =~ s/[BI]<([^>]*)>/$1/g;
3098 # replace with this whole string:
3099 ($leadwhite ? " " x 4 : "")
3101 . ((" " x (16 + ($leadwhite ? 4 : 0) - length($clean))) || " ")
3106 s{ # handle bold ornaments
3107 B < ( [^>] + | > ) >
3109 $Term::ReadLine::TermCap::rl_term_set[2]
3111 . $Term::ReadLine::TermCap::rl_term_set[3]
3114 s{ # handle italic ornaments
3115 I < ( [^>] + | > ) >
3117 $Term::ReadLine::TermCap::rl_term_set[0]
3119 . $Term::ReadLine::TermCap::rl_term_set[1]
3127 return if defined $ENV{LESS} && $ENV{LESS} =~ /r/;
3128 my $is_less = $pager =~ /\bless\b/;
3129 if ($pager =~ /\bmore\b/) {
3130 my @st_more = stat('/usr/bin/more');
3131 my @st_less = stat('/usr/bin/less');
3132 $is_less = @st_more && @st_less
3133 && $st_more[0] == $st_less[0]
3134 && $st_more[1] == $st_less[1];
3136 # changes environment!
3137 $ENV{LESS} .= 'r' if $is_less;
3143 $SIG{'ABRT'} = 'DEFAULT';
3144 kill 'ABRT', $$ if $panic++;
3145 if (defined &Carp::longmess) {
3146 local $SIG{__WARN__} = '';
3147 local $Carp::CarpLevel = 2; # mydie + confess
3148 &warn(Carp::longmess("Signal @_"));
3152 print $DB::OUT "Got signal @_\n";
3160 local $SIG{__WARN__} = '';
3161 local $SIG{__DIE__} = '';
3162 eval { require Carp } if defined $^S; # If error/warning during compilation,
3163 # require may be broken.
3164 CORE::warn(@_, "\nCannot print stack trace, load with -MCarp option to see stack"),
3165 return unless defined &Carp::longmess;
3166 my ($mysingle,$mytrace) = ($single,$trace);
3167 $single = 0; $trace = 0;
3168 my $mess = Carp::longmess(@_);
3169 ($single,$trace) = ($mysingle,$mytrace);
3176 local $SIG{__DIE__} = '';
3177 local $SIG{__WARN__} = '';
3178 my $i = 0; my $ineval = 0; my $sub;
3179 if ($dieLevel > 2) {
3180 local $SIG{__WARN__} = \&dbwarn;
3181 &warn(@_); # Yell no matter what
3184 if ($dieLevel < 2) {
3185 die @_ if $^S; # in eval propagate
3187 # No need to check $^S, eval is much more robust nowadays
3188 eval { require Carp }; #if defined $^S;# If error/warning during compilation,
3189 # require may be broken.
3191 die(@_, "\nCannot print stack trace, load with -MCarp option to see stack")
3192 unless defined &Carp::longmess;
3194 # We do not want to debug this chunk (automatic disabling works
3195 # inside DB::DB, but not in Carp).
3196 my ($mysingle,$mytrace) = ($single,$trace);
3197 $single = 0; $trace = 0;
3200 package Carp; # Do not include us in the list
3202 $mess = Carp::longmess(@_);
3205 ($single,$trace) = ($mysingle,$mytrace);
3211 $prevwarn = $SIG{__WARN__} unless $warnLevel;
3214 $SIG{__WARN__} = \&DB::dbwarn;
3215 } elsif ($prevwarn) {
3216 $SIG{__WARN__} = $prevwarn;
3225 $prevdie = $SIG{__DIE__} unless $dieLevel;
3228 $SIG{__DIE__} = \&DB::dbdie; # if $dieLevel < 2;
3229 #$SIG{__DIE__} = \&DB::diehard if $dieLevel >= 2;
3230 print $OUT "Stack dump during die enabled",
3231 ( $dieLevel == 1 ? " outside of evals" : ""), ".\n"
3233 print $OUT "Dump printed too.\n" if $dieLevel > 2;
3234 } elsif ($prevdie) {
3235 $SIG{__DIE__} = $prevdie;
3236 print $OUT "Default die handler restored.\n";
3244 $prevsegv = $SIG{SEGV} unless $signalLevel;
3245 $prevbus = $SIG{BUS} unless $signalLevel;
3246 $signalLevel = shift;
3248 $SIG{SEGV} = \&DB::diesignal;
3249 $SIG{BUS} = \&DB::diesignal;
3251 $SIG{SEGV} = $prevsegv;
3252 $SIG{BUS} = $prevbus;
3260 my $name = CvGV_name_or_bust($in);
3261 defined $name ? $name : $in;
3264 sub CvGV_name_or_bust {
3266 return if $skipCvGV; # Backdoor to avoid problems if XS broken...
3267 return unless ref $in;
3268 $in = \&$in; # Hard reference...
3269 eval {require Devel::Peek; 1} or return;
3270 my $gv = Devel::Peek::CvGV($in) or return;
3271 *$gv{PACKAGE} . '::' . *$gv{NAME};
3277 return unless defined &$subr;
3278 my $name = CvGV_name_or_bust($subr);
3280 $data = $sub{$name} if defined $name;
3281 return $data if defined $data;
3284 $subr = \&$subr; # Hard reference
3287 $s = $_, last if $subr eq \&$_;
3295 $class = ref $class if ref $class;
3298 methods_via($class, '', 1);
3299 methods_via('UNIVERSAL', 'UNIVERSAL', 0);
3304 return if $packs{$class}++;
3306 my $prepend = $prefix ? "via $prefix: " : '';
3308 for $name (grep {defined &{${"${class}::"}{$_}}}
3309 sort keys %{"${class}::"}) {
3310 next if $seen{ $name }++;
3313 print $DB::OUT "$prepend$name\n";
3315 return unless shift; # Recurse?
3316 for $name (@{"${class}::ISA"}) {
3317 $prepend = $prefix ? $prefix . " -> $name" : $name;
3318 methods_via($name, $prepend, 1);
3323 $doccmd = $^O !~ /^(?:MSWin32|VMS|os2|dos|amigaos|riscos|MacOS|NetWare)\z/s
3324 ? "man" # O Happy Day!
3325 : "perldoc"; # Alas, poor unfortunates
3331 &system("$doccmd $doccmd");
3334 # this way user can override, like with $doccmd="man -Mwhatever"
3335 # or even just "man " to disable the path check.
3336 unless ($doccmd eq 'man') {
3337 &system("$doccmd $page");
3341 $page = 'perl' if lc($page) eq 'help';
3344 my $man1dir = $Config::Config{'man1dir'};
3345 my $man3dir = $Config::Config{'man3dir'};
3346 for ($man1dir, $man3dir) { s#/[^/]*\z## if /\S/ }
3348 $manpath .= "$man1dir:" if $man1dir =~ /\S/;
3349 $manpath .= "$man3dir:" if $man3dir =~ /\S/ && $man1dir ne $man3dir;
3350 chop $manpath if $manpath;
3351 # harmless if missing, I figure
3352 my $oldpath = $ENV{MANPATH};
3353 $ENV{MANPATH} = $manpath if $manpath;
3354 my $nopathopt = $^O =~ /dunno what goes here/;
3355 if (CORE::system($doccmd,
3356 # I just *know* there are men without -M
3357 (($manpath && !$nopathopt) ? ("-M", $manpath) : ()),
3360 unless ($page =~ /^perl\w/) {
3361 if (grep { $page eq $_ } qw{
3362 5004delta 5005delta amiga api apio book boot bot call compile
3363 cygwin data dbmfilter debug debguts delta diag doc dos dsc embed
3364 faq faq1 faq2 faq3 faq4 faq5 faq6 faq7 faq8 faq9 filter fork
3365 form func guts hack hist hpux intern ipc lexwarn locale lol mod
3366 modinstall modlib number obj op opentut os2 os390 pod port
3367 ref reftut run sec style sub syn thrtut tie toc todo toot tootc
3368 trap unicode var vms win32 xs xstut
3372 CORE::system($doccmd,
3373 (($manpath && !$nopathopt) ? ("-M", $manpath) : ()),
3378 if (defined $oldpath) {
3379 $ENV{MANPATH} = $manpath;
3381 delete $ENV{MANPATH};
3385 # The following BEGIN is very handy if debugger goes havoc, debugging debugger?
3387 BEGIN { # This does not compile, alas.
3388 $IN = \*STDIN; # For bugs before DB::OUT has been opened
3389 $OUT = \*STDERR; # For errors before DB::OUT has been opened
3393 $deep = 100; # warning if stack gets this deep
3397 $SIG{INT} = \&DB::catch;
3398 # This may be enabled to debug debugger:
3399 #$warnLevel = 1 unless defined $warnLevel;
3400 #$dieLevel = 1 unless defined $dieLevel;
3401 #$signalLevel = 1 unless defined $signalLevel;
3403 $db_stop = 0; # Compiler warning
3405 $level = 0; # Level of recursive debugging
3406 # @stack and $doret are needed in sub sub, which is called for DB::postponed.
3407 # Triggers bug (?) in perl is we postpone this until runtime:
3408 @postponed = @stack = (0);
3409 $stack_depth = 0; # Localized $#stack
3414 BEGIN {$^W = $ini_warn;} # Switch warnings back
3416 #use Carp; # This did break, left for debugging
3419 # Specific code for b c l V m f O, &blah, $blah, @blah, %blah
3420 my($text, $line, $start) = @_;
3421 my ($itext, $search, $prefix, $pack) =
3422 ($text, "^\Q${'package'}::\E([^:]+)\$");
3424 return sort grep /^\Q$text/, (keys %sub), qw(postpone load compile), # subroutines
3425 (map { /$search/ ? ($1) : () } keys %sub)
3426 if (substr $line, 0, $start) =~ /^\|*[blc]\s+((postpone|compile)\s+)?$/;
3427 return sort grep /^\Q$text/, values %INC # files
3428 if (substr $line, 0, $start) =~ /^\|*b\s+load\s+$/;
3429 return sort map {($_, db_complete($_ . "::", "V ", 2))}
3430 grep /^\Q$text/, map { /^(.*)::$/ ? ($1) : ()} keys %:: # top-packages
3431 if (substr $line, 0, $start) =~ /^\|*[Vm]\s+$/ and $text =~ /^\w*$/;
3432 return sort map {($_, db_complete($_ . "::", "V ", 2))}
3434 grep /^\Q$text/, map { /^(.*)::$/ ? ($prefix . "::$1") : ()} keys %{$prefix . '::'}
3436 if (substr $line, 0, $start) =~ /^\|*[Vm]\s+$/
3437 and $text =~ /^(.*[^:])::?(\w*)$/ and $prefix = $1;
3438 if ( $line =~ /^\|*f\s+(.*)/ ) { # Loaded files
3439 # We may want to complete to (eval 9), so $text may be wrong
3440 $prefix = length($1) - length($text);
3443 map {substr $_, 2 + $prefix} grep /^_<\Q$text/, (keys %main::), $0
3445 if ((substr $text, 0, 1) eq '&') { # subroutines
3446 $text = substr $text, 1;
3448 return sort map "$prefix$_",
3451 (map { /$search/ ? ($1) : () }
3454 if ($text =~ /^[\$@%](.*)::(.*)/) { # symbols in a package
3455 $pack = ($1 eq 'main' ? '' : $1) . '::';
3456 $prefix = (substr $text, 0, 1) . $1 . '::';
3459 = map "$prefix$_", grep /^\Q$text/, grep /^_?[a-zA-Z]/, keys %$pack ;
3460 if (@out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext) {
3461 return db_complete($out[0], $line, $start);
3465 if ($text =~ /^[\$@%]/) { # symbols (in $package + packages in main)
3466 $pack = ($package eq 'main' ? '' : $package) . '::';
3467 $prefix = substr $text, 0, 1;
3468 $text = substr $text, 1;
3469 my @out = map "$prefix$_", grep /^\Q$text/,
3470 (grep /^_?[a-zA-Z]/, keys %$pack),
3471 ( $pack eq '::' ? () : (grep /::$/, keys %::) ) ;
3472 if (@out == 1 and $out[0] =~ /::$/ and $out[0] ne $itext) {
3473 return db_complete($out[0], $line, $start);
3477 if ((substr $line, 0, $start) =~ /^\|*O\b.*\s$/) { # Options after a space
3478 my @out = grep /^\Q$text/, @options;
3479 my $val = option_val($out[0], undef);
3481 if (not defined $val or $val =~ /[\n\r]/) {
3482 # Can do nothing better
3483 } elsif ($val =~ /\s/) {
3485 foreach $l (split //, qq/\"\'\#\|/) {
3486 $out = "$l$val$l ", last if (index $val, $l) == -1;
3491 # Default to value if one completion, to question if many
3492 $rl_attribs->{completer_terminator_character} = (@out == 1 ? $out : '? ');
3495 return $term->filename_list($text); # filenames
3500 print $OUT "Use `q' to quit or `R' to restart. `h q' for details.\n"
3504 if (defined($ini_pids)) {
3505 $ENV{PERLDB_PIDS} = $ini_pids;
3507 delete($ENV{PERLDB_PIDS});
3512 # PERLDBf_... flag names from perl.h
3513 our (%DollarCaretP_flags, %DollarCaretP_flags_r);
3515 %DollarCaretP_flags =
3516 ( PERLDBf_SUB => 0x01, # Debug sub enter/exit
3517 PERLDBf_LINE => 0x02, # Keep line #
3518 PERLDBf_NOOPT => 0x04, # Switch off optimizations
3519 PERLDBf_INTER => 0x08, # Preserve more data
3520 PERLDBf_SUBLINE => 0x10, # Keep subr source lines
3521 PERLDBf_SINGLE => 0x20, # Start with single-step on
3522 PERLDBf_NONAME => 0x40, # For _SUB: no name of the subr
3523 PERLDBf_GOTO => 0x80, # Report goto: call DB::goto
3524 PERLDBf_NAMEEVAL => 0x100, # Informative names for evals
3525 PERLDBf_NAMEANON => 0x200, # Informative names for anon subs
3526 PERLDBf_ASSERTION => 0x400, # Debug assertion subs enter/exit
3527 PERLDB_ALL => 0x33f, # No _NONAME, _GOTO, _ASSERTION
3530 %DollarCaretP_flags_r=reverse %DollarCaretP_flags;
3533 sub parse_DollarCaretP_flags {
3538 foreach my $f (split /\s*\|\s*/, $flags) {
3540 if ($f=~/^0x([[:xdigit:]]+)$/) {
3543 elsif ($f=~/^(\d+)$/) {
3546 elsif ($f=~/^DEFAULT$/i) {
3547 $value=$DollarCaretP_flags{PERLDB_ALL};
3550 $f=~/^(?:PERLDBf_)?(.*)$/i;
3551 $value=$DollarCaretP_flags{'PERLDBf_'.uc($1)};
3552 unless (defined $value) {
3553 print $OUT ("Unrecognized \$^P flag '$f'!\n",
3554 "Acceptable flags are: ".
3555 join(', ', sort keys %DollarCaretP_flags),
3556 ", and hexadecimal and decimal numbers.\n");
3565 sub expand_DollarCaretP_flags {
3566 my $DollarCaretP=shift;
3567 my @bits= ( map { my $n=(1<<$_);
3568 ($DollarCaretP & $n)
3569 ? ($DollarCaretP_flags_r{$n}
3570 || sprintf('0x%x', $n))
3572 return @bits ? join('|', @bits) : 0;
3576 $finished = 1 if $inhibit_exit; # So that some keys may be disabled.
3577 $fall_off_end = 1 unless $inhibit_exit;
3578 # Do not stop in at_exit() and destructors on exit:
3579 $DB::single = !$fall_off_end && !$runnonstop;
3580 DB::fake::at_exit() unless $fall_off_end or $runnonstop;
3584 # ===================================== pre580 ================================
3585 # this is very sad below here...
3588 sub cmd_pre580_null {
3595 if ($cmd =~ /^(\d*)\s*(.*)/) {
3596 $i = $1 || $line; $j = $2;
3598 if ($dbline[$i] == 0) {
3599 print $OUT "Line $i may not have an action.\n";
3601 $had_breakpoints{$filename} |= 2;
3602 $dbline{$i} =~ s/\0[^\0]*//;
3603 $dbline{$i} .= "\0" . action($j);
3606 $dbline{$i} =~ s/\0[^\0]*//;
3607 delete $dbline{$i} if $dbline{$i} eq '';
3616 if ($cmd =~ /^load\b\s*(.*)/) {
3617 my $file = $1; $file =~ s/\s+$//;
3619 } elsif ($cmd =~ /^(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/) {
3620 my $cond = length $3 ? $3 : '1';
3621 my ($subname, $break) = ($2, $1 eq 'postpone');
3622 $subname =~ s/\'/::/g;
3623 $subname = "${'package'}::" . $subname
3624 unless $subname =~ /::/;
3625 $subname = "main".$subname if substr($subname,0,2) eq "::";
3626 $postponed{$subname} = $break ? "break +0 if $cond" : "compile";
3627 } elsif ($cmd =~ /^([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/) {
3629 my $cond = length $2 ? $2 : '1';
3630 &cmd_b_sub($subname, $cond);
3631 } elsif ($cmd =~ /^(\d*)\s*(.*)/) {
3632 my $i = $1 || $dbline;
3633 my $cond = length $2 ? $2 : '1';
3634 &cmd_b_line($i, $cond);
3641 if ($cmd =~ /^\s*$/) {
3642 print $OUT "Deleting all breakpoints...\n";
3644 for $file (keys %had_breakpoints) {
3645 local *dbline = $main::{'_<' . $file};
3649 for ($i = 1; $i <= $max ; $i++) {
3650 if (defined $dbline{$i}) {
3651 $dbline{$i} =~ s/^[^\0]+//;
3652 if ($dbline{$i} =~ s/^\0?$//) {
3658 if (not $had_breakpoints{$file} &= ~1) {
3659 delete $had_breakpoints{$file};
3663 undef %postponed_file;
3664 undef %break_on_load;
3671 if ($cmd =~ /^\s*$/) {
3672 print_help($pre580_help);
3673 } elsif ($cmd =~ /^h\s*/) {
3674 print_help($pre580_summary);
3675 } elsif ($cmd =~ /^h\s+(\S.*)$/) {
3676 my $asked = $1; # for proper errmsg
3677 my $qasked = quotemeta($asked); # for searching
3678 # XXX: finds CR but not <CR>
3679 if ($pre580_help =~ /^<?(?:[IB]<)$qasked/m) {
3680 while ($pre580_help =~ /^(<?(?:[IB]<)$qasked([\s\S]*?)\n)(?!\s)/mg) {
3684 print_help("B<$asked> is not a debugger command.\n");
3694 @to_watch = @old_watch = ();
3695 } elsif ($cmd =~ /^(.*)/s) {
3699 $val = (defined $val) ? "'$val'" : 'undef' ;
3700 push @old_watch, $val;
3705 sub cmd_pre590_prepost {
3707 my $line = shift || '*'; # delete
3710 return &cmd_prepost($cmd, $line, $dbline);
3713 sub cmd_prepost { # cannot do &cmd_<(), <, <<, >>, {, {{, etc.
3715 my $line = shift || '?';
3719 if ($cmd =~ /^\</o) {
3720 $which = 'pre-perl';
3722 } elsif ($cmd =~ /^\>/o) {
3723 $which = 'post-perl';
3725 } elsif ($cmd =~ /^\{/o) {
3726 if ($cmd =~ /^\{.*\}$/o && unbalanced(substr($cmd,1))) {
3727 print $OUT "$cmd is now a debugger command\nuse `;$cmd' if you mean Perl code\n";
3728 # $DB::cmd = "h $cmd";
3731 $which = 'pre-debugger';
3737 print $OUT "Confused by command: $cmd\n";
3739 if ($line =~ /^\s*\?\s*$/o) {
3741 print $OUT "No $which actions.\n";
3742 # print $OUT "If you meant to delete them all - use '$cmd *' or 'o commandSet=pre590'\n"; # hint
3744 print $OUT "$which commands:\n";
3745 foreach my $action (@$aref) {
3746 print $OUT "\t$cmd -- $action\n";
3750 if (length($cmd) == 1) {
3751 if ($line =~ /^\s*\*\s*$/o) {
3752 @$aref = (); # delete
3753 print $OUT "All $cmd actions cleared.\n";
3755 @$aref = action($line); # set
3757 } elsif (length($cmd) == 2) { # append
3758 push @$aref, action($line);
3760 print $OUT "Confused by strange length of $which command($cmd)...\n";
3769 "Debugged program terminated. Use `q' to quit or `R' to restart.";
3772 package DB; # Do not trace this 1; below!