PageRenderTime 73ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/IronPython_Main/Runtime/Tests/LinqDlrTests/testenv/perl/lib/perl5db.pl

#
Perl | 2708 lines | 2336 code | 122 blank | 250 comment | 346 complexity | cd6c6e1e1013ccf2cd73d23aa4915f3c MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. package DB;
  2. # Debugger for Perl 5.00x; perl5db.pl patch level:
  3. $VERSION = 1.07;
  4. $header = "perl5db.pl version $VERSION";
  5. #
  6. # This file is automatically included if you do perl -d.
  7. # It's probably not useful to include this yourself.
  8. #
  9. # Perl supplies the values for %sub. It effectively inserts
  10. # a &DB'DB(); in front of every place that can have a
  11. # breakpoint. Instead of a subroutine call it calls &DB::sub with
  12. # $DB::sub being the called subroutine. It also inserts a BEGIN
  13. # {require 'perl5db.pl'} before the first line.
  14. #
  15. # After each `require'd file is compiled, but before it is executed, a
  16. # call to DB::postponed($main::{'_<'.$filename}) is emulated. Here the
  17. # $filename is the expanded name of the `require'd file (as found as
  18. # value of %INC).
  19. #
  20. # Additional services from Perl interpreter:
  21. #
  22. # if caller() is called from the package DB, it provides some
  23. # additional data.
  24. #
  25. # The array @{$main::{'_<'.$filename}} is the line-by-line contents of
  26. # $filename.
  27. #
  28. # The hash %{'_<'.$filename} contains breakpoints and action (it is
  29. # keyed by line number), and individual entries are settable (as
  30. # opposed to the whole hash). Only true/false is important to the
  31. # interpreter, though the values used by perl5db.pl have the form
  32. # "$break_condition\0$action". Values are magical in numeric context.
  33. #
  34. # The scalar ${'_<'.$filename} contains $filename.
  35. #
  36. # Note that no subroutine call is possible until &DB::sub is defined
  37. # (for subroutines defined outside of the package DB). In fact the same is
  38. # true if $deep is not defined.
  39. #
  40. # $Log: perldb.pl,v $
  41. #
  42. # At start reads $rcfile that may set important options. This file
  43. # may define a subroutine &afterinit that will be executed after the
  44. # debugger is initialized.
  45. #
  46. # After $rcfile is read reads environment variable PERLDB_OPTS and parses
  47. # it as a rest of `O ...' line in debugger prompt.
  48. #
  49. # The options that can be specified only at startup:
  50. # [To set in $rcfile, call &parse_options("optionName=new_value").]
  51. #
  52. # TTY - the TTY to use for debugging i/o.
  53. #
  54. # noTTY - if set, goes in NonStop mode. On interrupt if TTY is not set
  55. # uses the value of noTTY or "/tmp/perldbtty$$" to find TTY using
  56. # Term::Rendezvous. Current variant is to have the name of TTY in this
  57. # file.
  58. #
  59. # ReadLine - If false, dummy ReadLine is used, so you can debug
  60. # ReadLine applications.
  61. #
  62. # NonStop - if true, no i/o is performed until interrupt.
  63. #
  64. # LineInfo - file or pipe to print line number info to. If it is a
  65. # pipe, a short "emacs like" message is used.
  66. #
  67. # RemotePort - host:port to connect to on remote host for remote debugging.
  68. #
  69. # Example $rcfile: (delete leading hashes!)
  70. #
  71. # &parse_options("NonStop=1 LineInfo=db.out");
  72. # sub afterinit { $trace = 1; }
  73. #
  74. # The script will run without human intervention, putting trace
  75. # information into db.out. (If you interrupt it, you would better
  76. # reset LineInfo to something "interactive"!)
  77. #
  78. ##################################################################
  79. # Enhanced by ilya@math.ohio-state.edu (Ilya Zakharevich)
  80. # Latest version available: ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
  81. # modified Perl debugger, to be run from Emacs in perldb-mode
  82. # Ray Lischner (uunet!mntgfx!lisch) as of 5 Nov 1990
  83. # Johan Vromans -- upgrade to 4.0 pl 10
  84. # Ilya Zakharevich -- patches after 5.001 (and some before ;-)
  85. # Changelog:
  86. # A lot of things changed after 0.94. First of all, core now informs
  87. # debugger about entry into XSUBs, overloaded operators, tied operations,
  88. # BEGIN and END. Handy with `O f=2'.
  89. # This can make debugger a little bit too verbose, please be patient
  90. # and report your problems promptly.
  91. # Now the option frame has 3 values: 0,1,2.
  92. # Note that if DESTROY returns a reference to the object (or object),
  93. # the deletion of data may be postponed until the next function call,
  94. # due to the need to examine the return value.
  95. # Changes: 0.95: `v' command shows versions.
  96. # Changes: 0.96: `v' command shows version of readline.
  97. # primitive completion works (dynamic variables, subs for `b' and `l',
  98. # options). Can `p %var'
  99. # Better help (`h <' now works). New commands <<, >>, {, {{.
  100. # {dump|print}_trace() coded (to be able to do it from <<cmd).
  101. # `c sub' documented.
  102. # At last enough magic combined to stop after the end of debuggee.
  103. # !! should work now (thanks to Emacs bracket matching an extra
  104. # `]' in a regexp is caught).
  105. # `L', `D' and `A' span files now (as documented).
  106. # Breakpoints in `require'd code are possible (used in `R').
  107. # Some additional words on internal work of debugger.
  108. # `b load filename' implemented.
  109. # `b postpone subr' implemented.
  110. # now only `q' exits debugger (overwriteable on $inhibit_exit).
  111. # When restarting debugger breakpoints/actions persist.
  112. # Buglet: When restarting debugger only one breakpoint/action per
  113. # autoloaded function persists.
  114. # Changes: 0.97: NonStop will not stop in at_exit().
  115. # Option AutoTrace implemented.
  116. # Trace printed differently if frames are printed too.
  117. # new `inhibitExit' option.
  118. # printing of a very long statement interruptible.
  119. # Changes: 0.98: New command `m' for printing possible methods
  120. # 'l -' is a synonim for `-'.
  121. # Cosmetic bugs in printing stack trace.
  122. # `frame' & 8 to print "expanded args" in stack trace.
  123. # Can list/break in imported subs.
  124. # new `maxTraceLen' option.
  125. # frame & 4 and frame & 8 granted.
  126. # new command `m'
  127. # nonstoppable lines do not have `:' near the line number.
  128. # `b compile subname' implemented.
  129. # Will not use $` any more.
  130. # `-' behaves sane now.
  131. # Changes: 0.99: Completion for `f', `m'.
  132. # `m' will remove duplicate names instead of duplicate functions.
  133. # `b load' strips trailing whitespace.
  134. # completion ignores leading `|'; takes into account current package
  135. # when completing a subroutine name (same for `l').
  136. # Changes: 1.07: Many fixed by tchrist 13-March-2000
  137. # BUG FIXES:
  138. # + Added bare mimimal security checks on perldb rc files, plus
  139. # comments on what else is needed.
  140. # + Fixed the ornaments that made "|h" completely unusable.
  141. # They are not used in print_help if they will hurt. Strip pod
  142. # if we're paging to less.
  143. # + Fixed mis-formatting of help messages caused by ornaments
  144. # to restore Larry's original formatting.
  145. # + Fixed many other formatting errors. The code is still suboptimal,
  146. # and needs a lot of work at restructuing. It's also misindented
  147. # in many places.
  148. # + Fixed bug where trying to look at an option like your pager
  149. # shows "1".
  150. # + Fixed some $? processing. Note: if you use csh or tcsh, you will
  151. # lose. You should consider shell escapes not using their shell,
  152. # or else not caring about detailed status. This should really be
  153. # unified into one place, too.
  154. # + Fixed bug where invisible trailing whitespace on commands hoses you,
  155. # tricking Perl into thinking you wern't calling a debugger command!
  156. # + Fixed bug where leading whitespace on commands hoses you. (One
  157. # suggests a leading semicolon or any other irrelevant non-whitespace
  158. # to indicate literal Perl code.)
  159. # + Fixed bugs that ate warnings due to wrong selected handle.
  160. # + Fixed a precedence bug on signal stuff.
  161. # + Fixed some unseemly wording.
  162. # + Fixed bug in help command trying to call perl method code.
  163. # + Fixed to call dumpvar from exception handler. SIGPIPE killed us.
  164. # ENHANCEMENTS:
  165. # + Added some comments. This code is still nasty spaghetti.
  166. # + Added message if you clear your pre/post command stacks which was
  167. # very easy to do if you just typed a bare >, <, or {. (A command
  168. # without an argument should *never* be a destructive action; this
  169. # API is fundamentally screwed up; likewise option setting, which
  170. # is equally buggered.)
  171. # + Added command stack dump on argument of "?" for >, <, or {.
  172. # + Added a semi-built-in doc viewer command that calls man with the
  173. # proper %Config::Config path (and thus gets caching, man -k, etc),
  174. # or else perldoc on obstreperous platforms.
  175. # + Added to and rearranged the help information.
  176. # + Detected apparent misuse of { ... } to declare a block; this used
  177. # to work but now is a command, and mysteriously gave no complaint.
  178. ####################################################################
  179. # Needed for the statement after exec():
  180. BEGIN { $ini_warn = $^W; $^W = 0 } # Switch compilation warnings off until another BEGIN.
  181. local($^W) = 0; # Switch run-time warnings off during init.
  182. warn ( # Do not ;-)
  183. $dumpvar::hashDepth,
  184. $dumpvar::arrayDepth,
  185. $dumpvar::dumpDBFiles,
  186. $dumpvar::dumpPackages,
  187. $dumpvar::quoteHighBit,
  188. $dumpvar::printUndef,
  189. $dumpvar::globPrint,
  190. $dumpvar::usageOnly,
  191. @ARGS,
  192. $Carp::CarpLevel,
  193. $panic,
  194. $second_time,
  195. ) if 0;
  196. # Command-line + PERLLIB:
  197. @ini_INC = @INC;
  198. # $prevwarn = $prevdie = $prevbus = $prevsegv = ''; # Does not help?!
  199. $trace = $signal = $single = 0; # Uninitialized warning suppression
  200. # (local $^W cannot help - other packages!).
  201. $inhibit_exit = $option{PrintRet} = 1;
  202. @options = qw(hashDepth arrayDepth DumpDBFiles DumpPackages DumpReused
  203. compactDump veryCompact quote HighBit undefPrint
  204. globPrint PrintRet UsageOnly frame AutoTrace
  205. TTY noTTY ReadLine NonStop LineInfo maxTraceLen
  206. recallCommand ShellBang pager tkRunning ornaments
  207. signalLevel warnLevel dieLevel inhibit_exit
  208. ImmediateStop bareStringify
  209. RemotePort);
  210. %optionVars = (
  211. hashDepth => \$dumpvar::hashDepth,
  212. arrayDepth => \$dumpvar::arrayDepth,
  213. DumpDBFiles => \$dumpvar::dumpDBFiles,
  214. DumpPackages => \$dumpvar::dumpPackages,
  215. DumpReused => \$dumpvar::dumpReused,
  216. HighBit => \$dumpvar::quoteHighBit,
  217. undefPrint => \$dumpvar::printUndef,
  218. globPrint => \$dumpvar::globPrint,
  219. UsageOnly => \$dumpvar::usageOnly,
  220. bareStringify => \$dumpvar::bareStringify,
  221. frame => \$frame,
  222. AutoTrace => \$trace,
  223. inhibit_exit => \$inhibit_exit,
  224. maxTraceLen => \$maxtrace,
  225. ImmediateStop => \$ImmediateStop,
  226. RemotePort => \$remoteport,
  227. );
  228. %optionAction = (
  229. compactDump => \&dumpvar::compactDump,
  230. veryCompact => \&dumpvar::veryCompact,
  231. quote => \&dumpvar::quote,
  232. TTY => \&TTY,
  233. noTTY => \&noTTY,
  234. ReadLine => \&ReadLine,
  235. NonStop => \&NonStop,
  236. LineInfo => \&LineInfo,
  237. recallCommand => \&recallCommand,
  238. ShellBang => \&shellBang,
  239. pager => \&pager,
  240. signalLevel => \&signalLevel,
  241. warnLevel => \&warnLevel,
  242. dieLevel => \&dieLevel,
  243. tkRunning => \&tkRunning,
  244. ornaments => \&ornaments,
  245. RemotePort => \&RemotePort,
  246. );
  247. %optionRequire = (
  248. compactDump => 'dumpvar.pl',
  249. veryCompact => 'dumpvar.pl',
  250. quote => 'dumpvar.pl',
  251. );
  252. # These guys may be defined in $ENV{PERL5DB} :
  253. $rl = 1 unless defined $rl;
  254. $warnLevel = 0 unless defined $warnLevel;
  255. $dieLevel = 0 unless defined $dieLevel;
  256. $signalLevel = 1 unless defined $signalLevel;
  257. $pre = [] unless defined $pre;
  258. $post = [] unless defined $post;
  259. $pretype = [] unless defined $pretype;
  260. warnLevel($warnLevel);
  261. dieLevel($dieLevel);
  262. signalLevel($signalLevel);
  263. &pager(
  264. (defined($ENV{PAGER})
  265. ? $ENV{PAGER}
  266. : ($^O eq 'os2'
  267. ? 'cmd /c more'
  268. : 'more'))) unless defined $pager;
  269. setman();
  270. &recallCommand("!") unless defined $prc;
  271. &shellBang("!") unless defined $psh;
  272. $maxtrace = 400 unless defined $maxtrace;
  273. if (-e "/dev/tty") { # this is the wrong metric!
  274. $rcfile=".perldb";
  275. } else {
  276. $rcfile="perldb.ini";
  277. }
  278. # This isn't really safe, because there's a race
  279. # between checking and opening. The solution is to
  280. # open and fstat the handle, but then you have to read and
  281. # eval the contents. But then the silly thing gets
  282. # your lexical scope, which is unfortunately at best.
  283. sub safe_do {
  284. my $file = shift;
  285. # Just exactly what part of the word "CORE::" don't you understand?
  286. local $SIG{__WARN__};
  287. local $SIG{__DIE__};
  288. unless (is_safe_file($file)) {
  289. CORE::warn <<EO_GRIPE;
  290. perldb: Must not source insecure rcfile $file.
  291. You or the superuser must be the owner, and it must not
  292. be writable by anyone but its owner.
  293. EO_GRIPE
  294. return;
  295. }
  296. do $file;
  297. CORE::warn("perldb: couldn't parse $file: $@") if $@;
  298. }
  299. # Verifies that owner is either real user or superuser and that no
  300. # one but owner may write to it. This function is of limited use
  301. # when called on a path instead of upon a handle, because there are
  302. # no guarantees that filename (by dirent) whose file (by ino) is
  303. # eventually accessed is the same as the one tested.
  304. # Assumes that the file's existence is not in doubt.
  305. sub is_safe_file {
  306. my $path = shift;
  307. stat($path) || return; # mysteriously vaporized
  308. my($dev,$ino,$mode,$nlink,$uid,$gid) = stat(_);
  309. return 0 if $uid != 0 && $uid != $<;
  310. return 0 if $mode & 022;
  311. return 1;
  312. }
  313. if (-f $rcfile) {
  314. safe_do("./$rcfile");
  315. }
  316. elsif (defined $ENV{HOME} && -f "$ENV{HOME}/$rcfile") {
  317. safe_do("$ENV{HOME}/$rcfile");
  318. }
  319. elsif (defined $ENV{LOGDIR} && -f "$ENV{LOGDIR}/$rcfile") {
  320. safe_do("$ENV{LOGDIR}/$rcfile");
  321. }
  322. if (defined $ENV{PERLDB_OPTS}) {
  323. parse_options($ENV{PERLDB_OPTS});
  324. }
  325. # Here begin the unreadable code. It needs fixing.
  326. if (exists $ENV{PERLDB_RESTART}) {
  327. delete $ENV{PERLDB_RESTART};
  328. # $restart = 1;
  329. @hist = get_list('PERLDB_HIST');
  330. %break_on_load = get_list("PERLDB_ON_LOAD");
  331. %postponed = get_list("PERLDB_POSTPONE");
  332. my @had_breakpoints= get_list("PERLDB_VISITED");
  333. for (0 .. $#had_breakpoints) {
  334. my %pf = get_list("PERLDB_FILE_$_");
  335. $postponed_file{$had_breakpoints[$_]} = \%pf if %pf;
  336. }
  337. my %opt = get_list("PERLDB_OPT");
  338. my ($opt,$val);
  339. while (($opt,$val) = each %opt) {
  340. $val =~ s/[\\\']/\\$1/g;
  341. parse_options("$opt'$val'");
  342. }
  343. @INC = get_list("PERLDB_INC");
  344. @ini_INC = @INC;
  345. $pretype = [get_list("PERLDB_PRETYPE")];
  346. $pre = [get_list("PERLDB_PRE")];
  347. $post = [get_list("PERLDB_POST")];
  348. @typeahead = get_list("PERLDB_TYPEAHEAD", @typeahead);
  349. }
  350. if ($notty) {
  351. $runnonstop = 1;
  352. } else {
  353. # Is Perl being run from a slave editor or graphical debugger?
  354. $slave_editor = ((defined $main::ARGV[0]) and ($main::ARGV[0] eq '-emacs'));
  355. $rl = 0, shift(@main::ARGV) if $slave_editor;
  356. #require Term::ReadLine;
  357. if ($^O eq 'cygwin') {
  358. # /dev/tty is binary. use stdin for textmode
  359. undef $console;
  360. } elsif (-e "/dev/tty") {
  361. $console = "/dev/tty";
  362. } elsif ($^O eq 'dos' or -e "con" or $^O eq 'MSWin32') {
  363. $console = "con";
  364. } elsif ($^O eq 'MacOS') {
  365. if ($MacPerl::Version !~ /MPW/) {
  366. $console = "Dev:Console:Perl Debug"; # Separate window for application
  367. } else {
  368. $console = "Dev:Console";
  369. }
  370. } else {
  371. $console = "sys\$command";
  372. }
  373. if (($^O eq 'MSWin32') and ($slave_editor or defined $ENV{EMACS})) {
  374. $console = undef;
  375. }
  376. # Around a bug:
  377. if (defined $ENV{OS2_SHELL} and ($slave_editor or $ENV{WINDOWID})) { # In OS/2
  378. $console = undef;
  379. }
  380. if ($^O eq 'epoc') {
  381. $console = undef;
  382. }
  383. $console = $tty if defined $tty;
  384. if (defined $remoteport) {
  385. require IO::Socket;
  386. $OUT = new IO::Socket::INET( Timeout => '10',
  387. PeerAddr => $remoteport,
  388. Proto => 'tcp',
  389. );
  390. if (!$OUT) { die "Unable to connect to remote host: $remoteport\n"; }
  391. $IN = $OUT;
  392. }
  393. else {
  394. if (defined $console) {
  395. open(IN,"+<$console") || open(IN,"<$console") || open(IN,"<&STDIN");
  396. open(OUT,"+>$console") || open(OUT,">$console") || open(OUT,">&STDERR")
  397. || open(OUT,">&STDOUT"); # so we don't dongle stdout
  398. } else {
  399. open(IN,"<&STDIN");
  400. open(OUT,">&STDERR") || open(OUT,">&STDOUT"); # so we don't dongle stdout
  401. $console = 'STDIN/OUT';
  402. }
  403. # so open("|more") can read from STDOUT and so we don't dingle stdin
  404. $IN = \*IN;
  405. $OUT = \*OUT;
  406. }
  407. select($OUT);
  408. $| = 1; # for DB::OUT
  409. select(STDOUT);
  410. $LINEINFO = $OUT unless defined $LINEINFO;
  411. $lineinfo = $console unless defined $lineinfo;
  412. $| = 1; # for real STDOUT
  413. $header =~ s/.Header: ([^,]+),v(\s+\S+\s+\S+).*$/$1$2/;
  414. unless ($runnonstop) {
  415. print $OUT "\nLoading DB routines from $header\n";
  416. print $OUT ("Editor support ",
  417. $slave_editor ? "enabled" : "available",
  418. ".\n");
  419. print $OUT "\nEnter h or `h h' for help, or `$doccmd perldebug' for more help.\n\n";
  420. }
  421. }
  422. @ARGS = @ARGV;
  423. for (@args) {
  424. s/\'/\\\'/g;
  425. s/(.*)/'$1'/ unless /^-?[\d.]+$/;
  426. }
  427. if (defined &afterinit) { # May be defined in $rcfile
  428. &afterinit();
  429. }
  430. $I_m_init = 1;
  431. ############################################################ Subroutines
  432. sub DB {
  433. # _After_ the perl program is compiled, $single is set to 1:
  434. if ($single and not $second_time++) {
  435. if ($runnonstop) { # Disable until signal
  436. for ($i=0; $i <= $stack_depth; ) {
  437. $stack[$i++] &= ~1;
  438. }
  439. $single = 0;
  440. # return; # Would not print trace!
  441. } elsif ($ImmediateStop) {
  442. $ImmediateStop = 0;
  443. $signal = 1;
  444. }
  445. }
  446. $runnonstop = 0 if $single or $signal; # Disable it if interactive.
  447. &save;
  448. ($package, $filename, $line) = caller;
  449. $filename_ini = $filename;
  450. $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
  451. "package $package;"; # this won't let them modify, alas
  452. local(*dbline) = $main::{'_<' . $filename};
  453. $max = $#dbline;
  454. if (($stop,$action) = split(/\0/,$dbline{$line})) {
  455. if ($stop eq '1') {
  456. $signal |= 1;
  457. } elsif ($stop) {
  458. $evalarg = "\$DB::signal |= 1 if do {$stop}"; &eval;
  459. $dbline{$line} =~ s/;9($|\0)/$1/;
  460. }
  461. }
  462. my $was_signal = $signal;
  463. if ($trace & 2) {
  464. for (my $n = 0; $n <= $#to_watch; $n++) {
  465. $evalarg = $to_watch[$n];
  466. local $onetimeDump; # Do not output results
  467. my ($val) = &eval; # Fix context (&eval is doing array)?
  468. $val = ( (defined $val) ? "'$val'" : 'undef' );
  469. if ($val ne $old_watch[$n]) {
  470. $signal = 1;
  471. print $OUT <<EOP;
  472. Watchpoint $n:\t$to_watch[$n] changed:
  473. old value:\t$old_watch[$n]
  474. new value:\t$val
  475. EOP
  476. $old_watch[$n] = $val;
  477. }
  478. }
  479. }
  480. if ($trace & 4) { # User-installed watch
  481. return if watchfunction($package, $filename, $line)
  482. and not $single and not $was_signal and not ($trace & ~4);
  483. }
  484. $was_signal = $signal;
  485. $signal = 0;
  486. if ($single || ($trace & 1) || $was_signal) {
  487. if ($slave_editor) {
  488. $position = "\032\032$filename:$line:0\n";
  489. print $LINEINFO $position;
  490. } elsif ($package eq 'DB::fake') {
  491. $term || &setterm;
  492. print_help(<<EOP);
  493. Debugged program terminated. Use B<q> to quit or B<R> to restart,
  494. use B<O> I<inhibit_exit> to avoid stopping after program termination,
  495. B<h q>, B<h R> or B<h O> to get additional info.
  496. EOP
  497. $package = 'main';
  498. $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' .
  499. "package $package;"; # this won't let them modify, alas
  500. } else {
  501. $sub =~ s/\'/::/;
  502. $prefix = $sub =~ /::/ ? "" : "${'package'}::";
  503. $prefix .= "$sub($filename:";
  504. $after = ($dbline[$line] =~ /\n$/ ? '' : "\n");
  505. if (length($prefix) > 30) {
  506. $position = "$prefix$line):\n$line:\t$dbline[$line]$after";
  507. $prefix = "";
  508. $infix = ":\t";
  509. } else {
  510. $infix = "):\t";
  511. $position = "$prefix$line$infix$dbline[$line]$after";
  512. }
  513. if ($frame) {
  514. print $LINEINFO ' ' x $stack_depth, "$line:\t$dbline[$line]$after";
  515. } else {
  516. print $LINEINFO $position;
  517. }
  518. for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) { #{ vi
  519. last if $dbline[$i] =~ /^\s*[\;\}\#\n]/;
  520. last if $signal;
  521. $after = ($dbline[$i] =~ /\n$/ ? '' : "\n");
  522. $incr_pos = "$prefix$i$infix$dbline[$i]$after";
  523. $position .= $incr_pos;
  524. if ($frame) {
  525. print $LINEINFO ' ' x $stack_depth, "$i:\t$dbline[$i]$after";
  526. } else {
  527. print $LINEINFO $incr_pos;
  528. }
  529. }
  530. }
  531. }
  532. $evalarg = $action, &eval if $action;
  533. if ($single || $was_signal) {
  534. local $level = $level + 1;
  535. foreach $evalarg (@$pre) {
  536. &eval;
  537. }
  538. print $OUT $stack_depth . " levels deep in subroutine calls!\n"
  539. if $single & 4;
  540. $start = $line;
  541. $incr = -1; # for backward motion.
  542. @typeahead = (@$pretype, @typeahead);
  543. CMD:
  544. while (($term || &setterm),
  545. ($term_pid == $$ or &resetterm),
  546. defined ($cmd=&readline(" DB" . ('<' x $level) .
  547. ($#hist+1) . ('>' x $level) .
  548. " ")))
  549. {
  550. $single = 0;
  551. $signal = 0;
  552. $cmd =~ s/\\$/\n/ && do {
  553. $cmd .= &readline(" cont: ");
  554. redo CMD;
  555. };
  556. $cmd =~ /^$/ && ($cmd = $laststep);
  557. push(@hist,$cmd) if length($cmd) > 1;
  558. PIPE: {
  559. $cmd =~ s/^\s+//s; # trim annoying leading whitespace
  560. $cmd =~ s/\s+$//s; # trim annoying trailing whitespace
  561. ($i) = split(/\s+/,$cmd);
  562. if ($alias{$i}) {
  563. # squelch the sigmangler
  564. local $SIG{__DIE__};
  565. local $SIG{__WARN__};
  566. eval "\$cmd =~ $alias{$i}";
  567. if ($@) {
  568. print $OUT "Couldn't evaluate `$i' alias: $@";
  569. next CMD;
  570. }
  571. }
  572. $cmd =~ /^q$/ && ($fall_off_end = 1) && exit $?;
  573. $cmd =~ /^h$/ && do {
  574. print_help($help);
  575. next CMD; };
  576. $cmd =~ /^h\s+h$/ && do {
  577. print_help($summary);
  578. next CMD; };
  579. # support long commands; otherwise bogus errors
  580. # happen when you ask for h on <CR> for example
  581. $cmd =~ /^h\s+(\S.*)$/ && do {
  582. my $asked = $1; # for proper errmsg
  583. my $qasked = quotemeta($asked); # for searching
  584. # XXX: finds CR but not <CR>
  585. if ($help =~ /^<?(?:[IB]<)$qasked/m) {
  586. while ($help =~ /^(<?(?:[IB]<)$qasked([\s\S]*?)\n)(?!\s)/mg) {
  587. print_help($1);
  588. }
  589. } else {
  590. print_help("B<$asked> is not a debugger command.\n");
  591. }
  592. next CMD; };
  593. $cmd =~ /^t$/ && do {
  594. $trace ^= 1;
  595. print $OUT "Trace = " .
  596. (($trace & 1) ? "on" : "off" ) . "\n";
  597. next CMD; };
  598. $cmd =~ /^S(\s+(!)?(.+))?$/ && do {
  599. $Srev = defined $2; $Spatt = $3; $Snocheck = ! defined $1;
  600. foreach $subname (sort(keys %sub)) {
  601. if ($Snocheck or $Srev^($subname =~ /$Spatt/)) {
  602. print $OUT $subname,"\n";
  603. }
  604. }
  605. next CMD; };
  606. $cmd =~ /^v$/ && do {
  607. list_versions(); next CMD};
  608. $cmd =~ s/^X\b/V $package/;
  609. $cmd =~ /^V$/ && do {
  610. $cmd = "V $package"; };
  611. $cmd =~ /^V\b\s*(\S+)\s*(.*)/ && do {
  612. local ($savout) = select($OUT);
  613. $packname = $1;
  614. @vars = split(' ',$2);
  615. do 'dumpvar.pl' unless defined &main::dumpvar;
  616. if (defined &main::dumpvar) {
  617. local $frame = 0;
  618. local $doret = -2;
  619. # must detect sigpipe failures
  620. eval { &main::dumpvar($packname,@vars) };
  621. if ($@) {
  622. die unless $@ =~ /dumpvar print failed/;
  623. }
  624. } else {
  625. print $OUT "dumpvar.pl not available.\n";
  626. }
  627. select ($savout);
  628. next CMD; };
  629. $cmd =~ s/^x\b/ / && do { # So that will be evaled
  630. $onetimeDump = 'dump'; };
  631. $cmd =~ s/^m\s+([\w:]+)\s*$/ / && do {
  632. methods($1); next CMD};
  633. $cmd =~ s/^m\b/ / && do { # So this will be evaled
  634. $onetimeDump = 'methods'; };
  635. $cmd =~ /^f\b\s*(.*)/ && do {
  636. $file = $1;
  637. $file =~ s/\s+$//;
  638. if (!$file) {
  639. print $OUT "The old f command is now the r command.\n";
  640. print $OUT "The new f command switches filenames.\n";
  641. next CMD;
  642. }
  643. if (!defined $main::{'_<' . $file}) {
  644. if (($try) = grep(m#^_<.*$file#, keys %main::)) {{
  645. $try = substr($try,2);
  646. print $OUT "Choosing $try matching `$file':\n";
  647. $file = $try;
  648. }}
  649. }
  650. if (!defined $main::{'_<' . $file}) {
  651. print $OUT "No file matching `$file' is loaded.\n";
  652. next CMD;
  653. } elsif ($file ne $filename) {
  654. *dbline = $main::{'_<' . $file};
  655. $max = $#dbline;
  656. $filename = $file;
  657. $start = 1;
  658. $cmd = "l";
  659. } else {
  660. print $OUT "Already in $file.\n";
  661. next CMD;
  662. }
  663. };
  664. $cmd =~ s/^l\s+-\s*$/-/;
  665. $cmd =~ /^([lb])\b\s*(\$.*)/s && do {
  666. $evalarg = $2;
  667. my ($s) = &eval;
  668. print($OUT "Error: $@\n"), next CMD if $@;
  669. $s = CvGV_name($s);
  670. print($OUT "Interpreted as: $1 $s\n");
  671. $cmd = "$1 $s";
  672. };
  673. $cmd =~ /^l\b\s*([\':A-Za-z_][\':\w]*(\[.*\])?)/s && do {
  674. $subname = $1;
  675. $subname =~ s/\'/::/;
  676. $subname = $package."::".$subname
  677. unless $subname =~ /::/;
  678. $subname = "main".$subname if substr($subname,0,2) eq "::";
  679. @pieces = split(/:/,find_sub($subname) || $sub{$subname});
  680. $subrange = pop @pieces;
  681. $file = join(':', @pieces);
  682. if ($file ne $filename) {
  683. print $OUT "Switching to file '$file'.\n"
  684. unless $slave_editor;
  685. *dbline = $main::{'_<' . $file};
  686. $max = $#dbline;
  687. $filename = $file;
  688. }
  689. if ($subrange) {
  690. if (eval($subrange) < -$window) {
  691. $subrange =~ s/-.*/+/;
  692. }
  693. $cmd = "l $subrange";
  694. } else {
  695. print $OUT "Subroutine $subname not found.\n";
  696. next CMD;
  697. } };
  698. $cmd =~ /^\.$/ && do {
  699. $incr = -1; # for backward motion.
  700. $start = $line;
  701. $filename = $filename_ini;
  702. *dbline = $main::{'_<' . $filename};
  703. $max = $#dbline;
  704. print $LINEINFO $position;
  705. next CMD };
  706. $cmd =~ /^w\b\s*(\d*)$/ && do {
  707. $incr = $window - 1;
  708. $start = $1 if $1;
  709. $start -= $preview;
  710. #print $OUT 'l ' . $start . '-' . ($start + $incr);
  711. $cmd = 'l ' . $start . '-' . ($start + $incr); };
  712. $cmd =~ /^-$/ && do {
  713. $start -= $incr + $window + 1;
  714. $start = 1 if $start <= 0;
  715. $incr = $window - 1;
  716. $cmd = 'l ' . ($start) . '+'; };
  717. $cmd =~ /^l$/ && do {
  718. $incr = $window - 1;
  719. $cmd = 'l ' . $start . '-' . ($start + $incr); };
  720. $cmd =~ /^l\b\s*(\d*)\+(\d*)$/ && do {
  721. $start = $1 if $1;
  722. $incr = $2;
  723. $incr = $window - 1 unless $incr;
  724. $cmd = 'l ' . $start . '-' . ($start + $incr); };
  725. $cmd =~ /^l\b\s*((-?[\d\$\.]+)([-,]([\d\$\.]+))?)?/ && do {
  726. $end = (!defined $2) ? $max : ($4 ? $4 : $2);
  727. $end = $max if $end > $max;
  728. $i = $2;
  729. $i = $line if $i eq '.';
  730. $i = 1 if $i < 1;
  731. $incr = $end - $i;
  732. if ($slave_editor) {
  733. print $OUT "\032\032$filename:$i:0\n";
  734. $i = $end;
  735. } else {
  736. for (; $i <= $end; $i++) {
  737. ($stop,$action) = split(/\0/, $dbline{$i});
  738. $arrow = ($i==$line
  739. and $filename eq $filename_ini)
  740. ? '==>'
  741. : ($dbline[$i]+0 ? ':' : ' ') ;
  742. $arrow .= 'b' if $stop;
  743. $arrow .= 'a' if $action;
  744. print $OUT "$i$arrow\t", $dbline[$i];
  745. $i++, last if $signal;
  746. }
  747. print $OUT "\n" unless $dbline[$i-1] =~ /\n$/;
  748. }
  749. $start = $i; # remember in case they want more
  750. $start = $max if $start > $max;
  751. next CMD; };
  752. $cmd =~ /^D$/ && do {
  753. print $OUT "Deleting all breakpoints...\n";
  754. my $file;
  755. for $file (keys %had_breakpoints) {
  756. local *dbline = $main::{'_<' . $file};
  757. my $max = $#dbline;
  758. my $was;
  759. for ($i = 1; $i <= $max ; $i++) {
  760. if (defined $dbline{$i}) {
  761. $dbline{$i} =~ s/^[^\0]+//;
  762. if ($dbline{$i} =~ s/^\0?$//) {
  763. delete $dbline{$i};
  764. }
  765. }
  766. }
  767. if (not $had_breakpoints{$file} &= ~1) {
  768. delete $had_breakpoints{$file};
  769. }
  770. }
  771. undef %postponed;
  772. undef %postponed_file;
  773. undef %break_on_load;
  774. next CMD; };
  775. $cmd =~ /^L$/ && do {
  776. my $file;
  777. for $file (keys %had_breakpoints) {
  778. local *dbline = $main::{'_<' . $file};
  779. my $max = $#dbline;
  780. my $was;
  781. for ($i = 1; $i <= $max; $i++) {
  782. if (defined $dbline{$i}) {
  783. print $OUT "$file:\n" unless $was++;
  784. print $OUT " $i:\t", $dbline[$i];
  785. ($stop,$action) = split(/\0/, $dbline{$i});
  786. print $OUT " break if (", $stop, ")\n"
  787. if $stop;
  788. print $OUT " action: ", $action, "\n"
  789. if $action;
  790. last if $signal;
  791. }
  792. }
  793. }
  794. if (%postponed) {
  795. print $OUT "Postponed breakpoints in subroutines:\n";
  796. my $subname;
  797. for $subname (keys %postponed) {
  798. print $OUT " $subname\t$postponed{$subname}\n";
  799. last if $signal;
  800. }
  801. }
  802. my @have = map { # Combined keys
  803. keys %{$postponed_file{$_}}
  804. } keys %postponed_file;
  805. if (@have) {
  806. print $OUT "Postponed breakpoints in files:\n";
  807. my ($file, $line);
  808. for $file (keys %postponed_file) {
  809. my $db = $postponed_file{$file};
  810. print $OUT " $file:\n";
  811. for $line (sort {$a <=> $b} keys %$db) {
  812. print $OUT " $line:\n";
  813. my ($stop,$action) = split(/\0/, $$db{$line});
  814. print $OUT " break if (", $stop, ")\n"
  815. if $stop;
  816. print $OUT " action: ", $action, "\n"
  817. if $action;
  818. last if $signal;
  819. }
  820. last if $signal;
  821. }
  822. }
  823. if (%break_on_load) {
  824. print $OUT "Breakpoints on load:\n";
  825. my $file;
  826. for $file (keys %break_on_load) {
  827. print $OUT " $file\n";
  828. last if $signal;
  829. }
  830. }
  831. if ($trace & 2) {
  832. print $OUT "Watch-expressions:\n";
  833. my $expr;
  834. for $expr (@to_watch) {
  835. print $OUT " $expr\n";
  836. last if $signal;
  837. }
  838. }
  839. next CMD; };
  840. $cmd =~ /^b\b\s*load\b\s*(.*)/ && do {
  841. my $file = $1; $file =~ s/\s+$//;
  842. {
  843. $break_on_load{$file} = 1;
  844. $break_on_load{$::INC{$file}} = 1 if $::INC{$file};
  845. $file .= '.pm', redo unless $file =~ /\./;
  846. }
  847. $had_breakpoints{$file} |= 1;
  848. print $OUT "Will stop on load of `@{[join '\', `', sort keys %break_on_load]}'.\n";
  849. next CMD; };
  850. $cmd =~ /^b\b\s*(postpone|compile)\b\s*([':A-Za-z_][':\w]*)\s*(.*)/ && do {
  851. my $cond = length $3 ? $3 : '1';
  852. my ($subname, $break) = ($2, $1 eq 'postpone');
  853. $subname =~ s/\'/::/g;
  854. $subname = "${'package'}::" . $subname
  855. unless $subname =~ /::/;
  856. $subname = "main".$subname if substr($subname,0,2) eq "::";
  857. $postponed{$subname} = $break
  858. ? "break +0 if $cond" : "compile";
  859. next CMD; };
  860. $cmd =~ /^b\b\s*([':A-Za-z_][':\w]*(?:\[.*\])?)\s*(.*)/ && do {
  861. $subname = $1;
  862. $cond = length $2 ? $2 : '1';
  863. $subname =~ s/\'/::/g;
  864. $subname = "${'package'}::" . $subname
  865. unless $subname =~ /::/;
  866. $subname = "main".$subname if substr($subname,0,2) eq "::";
  867. # Filename below can contain ':'
  868. ($file,$i) = (find_sub($subname) =~ /^(.*):(.*)$/);
  869. $i += 0;
  870. if ($i) {
  871. local $filename = $file;
  872. local *dbline = $main::{'_<' . $filename};
  873. $had_breakpoints{$filename} |= 1;
  874. $max = $#dbline;
  875. ++$i while $dbline[$i] == 0 && $i < $max;
  876. $dbline{$i} =~ s/^[^\0]*/$cond/;
  877. } else {
  878. print $OUT "Subroutine $subname not found.\n";
  879. }
  880. next CMD; };
  881. $cmd =~ /^b\b\s*(\d*)\s*(.*)/ && do {
  882. $i = $1 || $line;
  883. $cond = length $2 ? $2 : '1';
  884. if ($dbline[$i] == 0) {
  885. print $OUT "Line $i not breakable.\n";
  886. } else {
  887. $had_breakpoints{$filename} |= 1;
  888. $dbline{$i} =~ s/^[^\0]*/$cond/;
  889. }
  890. next CMD; };
  891. $cmd =~ /^d\b\s*(\d*)/ && do {
  892. $i = $1 || $line;
  893. if ($dbline[$i] == 0) {
  894. print $OUT "Line $i not breakable.\n";
  895. } else {
  896. $dbline{$i} =~ s/^[^\0]*//;
  897. delete $dbline{$i} if $dbline{$i} eq '';
  898. }
  899. next CMD; };
  900. $cmd =~ /^A$/ && do {
  901. print $OUT "Deleting all actions...\n";
  902. my $file;
  903. for $file (keys %had_breakpoints) {
  904. local *dbline = $main::{'_<' . $file};
  905. my $max = $#dbline;
  906. my $was;
  907. for ($i = 1; $i <= $max ; $i++) {
  908. if (defined $dbline{$i}) {
  909. $dbline{$i} =~ s/\0[^\0]*//;
  910. delete $dbline{$i} if $dbline{$i} eq '';
  911. }
  912. }
  913. unless ($had_breakpoints{$file} &= ~2) {
  914. delete $had_breakpoints{$file};
  915. }
  916. }
  917. next CMD; };
  918. $cmd =~ /^O\s*$/ && do {
  919. for (@options) {
  920. &dump_option($_);
  921. }
  922. next CMD; };
  923. $cmd =~ /^O\s*(\S.*)/ && do {
  924. parse_options($1);
  925. next CMD; };
  926. $cmd =~ /^\<\<\s*(.*)/ && do { # \<\< for CPerl sake: not HERE
  927. push @$pre, action($1);
  928. next CMD; };
  929. $cmd =~ /^>>\s*(.*)/ && do {
  930. push @$post, action($1);
  931. next CMD; };
  932. $cmd =~ /^<\s*(.*)/ && do {
  933. unless ($1) {
  934. print $OUT "All < actions cleared.\n";
  935. $pre = [];
  936. next CMD;
  937. }
  938. if ($1 eq '?') {
  939. unless (@$pre) {
  940. print $OUT "No pre-prompt Perl actions.\n";
  941. next CMD;
  942. }
  943. print $OUT "Perl commands run before each prompt:\n";
  944. for my $action ( @$pre ) {
  945. print $OUT "\t< -- $action\n";
  946. }
  947. next CMD;
  948. }
  949. $pre = [action($1)];
  950. next CMD; };
  951. $cmd =~ /^>\s*(.*)/ && do {
  952. unless ($1) {
  953. print $OUT "All > actions cleared.\n";
  954. $post = [];
  955. next CMD;
  956. }
  957. if ($1 eq '?') {
  958. unless (@$post) {
  959. print $OUT "No post-prompt Perl actions.\n";
  960. next CMD;
  961. }
  962. print $OUT "Perl commands run after each prompt:\n";
  963. for my $action ( @$post ) {
  964. print $OUT "\t> -- $action\n";
  965. }
  966. next CMD;
  967. }
  968. $post = [action($1)];
  969. next CMD; };
  970. $cmd =~ /^\{\{\s*(.*)/ && do {
  971. if ($cmd =~ /^\{.*\}$/ && unbalanced(substr($cmd,2))) {
  972. print $OUT "{{ is now a debugger command\n",
  973. "use `;{{' if you mean Perl code\n";
  974. $cmd = "h {{";
  975. redo CMD;
  976. }
  977. push @$pretype, $1;
  978. next CMD; };
  979. $cmd =~ /^\{\s*(.*)/ && do {
  980. unless ($1) {
  981. print $OUT "All { actions cleared.\n";
  982. $pretype = [];
  983. next CMD;
  984. }
  985. if ($1 eq '?') {
  986. unless (@$pretype) {
  987. print $OUT "No pre-prompt debugger actions.\n";
  988. next CMD;
  989. }
  990. print $OUT "Debugger commands run before each prompt:\n";
  991. for my $action ( @$pretype ) {
  992. print $OUT "\t{ -- $action\n";
  993. }
  994. next CMD;
  995. }
  996. if ($cmd =~ /^\{.*\}$/ && unbalanced(substr($cmd,1))) {
  997. print $OUT "{ is now a debugger command\n",
  998. "use `;{' if you mean Perl code\n";
  999. $cmd = "h {";
  1000. redo CMD;
  1001. }
  1002. $pretype = [$1];
  1003. next CMD; };
  1004. $cmd =~ /^a\b\s*(\d*)\s*(.*)/ && do {
  1005. $i = $1 || $line; $j = $2;
  1006. if (length $j) {
  1007. if ($dbline[$i] == 0) {
  1008. print $OUT "Line $i may not have an action.\n";
  1009. } else {
  1010. $had_breakpoints{$filename} |= 2;
  1011. $dbline{$i} =~ s/\0[^\0]*//;
  1012. $dbline{$i} .= "\0" . action($j);
  1013. }
  1014. } else {
  1015. $dbline{$i} =~ s/\0[^\0]*//;
  1016. delete $dbline{$i} if $dbline{$i} eq '';
  1017. }
  1018. next CMD; };
  1019. $cmd =~ /^n$/ && do {
  1020. end_report(), next CMD if $finished and $level <= 1;
  1021. $single = 2;
  1022. $laststep = $cmd;
  1023. last CMD; };
  1024. $cmd =~ /^s$/ && do {
  1025. end_report(), next CMD if $finished and $level <= 1;
  1026. $single = 1;
  1027. $laststep = $cmd;
  1028. last CMD; };
  1029. $cmd =~ /^c\b\s*([\w:]*)\s*$/ && do {
  1030. end_report(), next CMD if $finished and $level <= 1;
  1031. $subname = $i = $1;
  1032. # Probably not needed, since we finish an interactive
  1033. # sub-session anyway...
  1034. # local $filename = $filename;
  1035. # local *dbline = *dbline; # XXX Would this work?!
  1036. if ($i =~ /\D/) { # subroutine name
  1037. $subname = $package."::".$subname
  1038. unless $subname =~ /::/;
  1039. ($file,$i) = (find_sub($subname) =~ /^(.*):(.*)$/);
  1040. $i += 0;
  1041. if ($i) {
  1042. $filename = $file;
  1043. *dbline = $main::{'_<' . $filename};
  1044. $had_breakpoints{$filename} |= 1;
  1045. $max = $#dbline;
  1046. ++$i while $dbline[$i] == 0 && $i < $max;
  1047. } else {
  1048. print $OUT "Subroutine $subname not found.\n";
  1049. next CMD;
  1050. }
  1051. }
  1052. if ($i) {
  1053. if ($dbline[$i] == 0) {
  1054. print $OUT "Line $i not breakable.\n";
  1055. next CMD;
  1056. }
  1057. $dbline{$i} =~ s/($|\0)/;9$1/; # add one-time-only b.p.
  1058. }
  1059. for ($i=0; $i <= $stack_depth; ) {
  1060. $stack[$i++] &= ~1;
  1061. }
  1062. last CMD; };
  1063. $cmd =~ /^r$/ && do {
  1064. end_report(), next CMD if $finished and $level <= 1;
  1065. $stack[$stack_depth] |= 1;
  1066. $doret = $option{PrintRet} ? $stack_depth - 1 : -2;
  1067. last CMD; };
  1068. $cmd =~ /^R$/ && do {
  1069. print $OUT "Warning: some settings and command-line options may be lost!\n";
  1070. my (@script, @flags, $cl);
  1071. push @flags, '-w' if $ini_warn;
  1072. # Put all the old includes at the start to get
  1073. # the same debugger.
  1074. for (@ini_INC) {
  1075. push @flags, '-I', $_;
  1076. }
  1077. # Arrange for setting the old INC:
  1078. set_list("PERLDB_INC", @ini_INC);
  1079. if ($0 eq '-e') {
  1080. for (1..$#{'::_<-e'}) { # The first line is PERL5DB
  1081. chomp ($cl = ${'::_<-e'}[$_]);
  1082. push @script, '-e', $cl;
  1083. }
  1084. } else {
  1085. @script = $0;
  1086. }
  1087. set_list("PERLDB_HIST",
  1088. $term->Features->{getHistory}
  1089. ? $term->GetHistory : @hist);
  1090. my @had_breakpoints = keys %had_breakpoints;
  1091. set_list("PERLDB_VISITED", @had_breakpoints);
  1092. set_list("PERLDB_OPT", %option);
  1093. set_list("PERLDB_ON_LOAD", %break_on_load);
  1094. my @hard;
  1095. for (0 .. $#had_breakpoints) {
  1096. my $file = $had_breakpoints[$_];
  1097. *dbline = $main::{'_<' . $file};
  1098. next unless %dbline or $postponed_file{$file};
  1099. (push @hard, $file), next
  1100. if $file =~ /^\(eval \d+\)$/;
  1101. my @add;
  1102. @add = %{$postponed_file{$file}}
  1103. if $postponed_file{$file};
  1104. set_list("PERLDB_FILE_$_", %dbline, @add);
  1105. }
  1106. for (@hard) { # Yes, really-really...
  1107. # Find the subroutines in this eval
  1108. *dbline = $main::{'_<' . $_};
  1109. my ($quoted, $sub, %subs, $line) = quotemeta $_;
  1110. for $sub (keys %sub) {
  1111. next unless $sub{$sub} =~ /^$quoted:(\d+)-(\d+)$/;
  1112. $subs{$sub} = [$1, $2];
  1113. }
  1114. unless (%subs) {
  1115. print $OUT
  1116. "No subroutines in $_, ignoring breakpoints.\n";
  1117. next;
  1118. }
  1119. LINES: for $line (keys %dbline) {
  1120. # One breakpoint per sub only:
  1121. my ($offset, $sub, $found);
  1122. SUBS: for $sub (keys %subs) {
  1123. if ($subs{$sub}->[1] >= $line # Not after the subroutine
  1124. and (not defined $offset # Not caught
  1125. or $offset < 0 )) { # or badly caught
  1126. $found = $sub;
  1127. $offset = $line - $subs{$sub}->[0];
  1128. $offset = "+$offset", last SUBS if $offset >= 0;
  1129. }
  1130. }
  1131. if (defined $offset) {
  1132. $postponed{$found} =
  1133. "break $offset if $dbline{$line}";
  1134. } else {
  1135. print $OUT "Breakpoint in $_:$line ignored: after all the subroutines.\n";
  1136. }
  1137. }
  1138. }
  1139. set_list("PERLDB_POSTPONE", %postponed);
  1140. set_list("PERLDB_PRETYPE", @$pretype);
  1141. set_list("PERLDB_PRE", @$pre);
  1142. set_list("PERLDB_POST", @$post);
  1143. set_list("PERLDB_TYPEAHEAD", @typeahead);
  1144. $ENV{PERLDB_RESTART} = 1;
  1145. #print "$^X, '-d', @flags, @script, ($slave_editor ? '-emacs' : ()), @ARGS";
  1146. exec $^X, '-d', @flags, @script, ($slave_editor ? '-emacs' : ()), @ARGS;
  1147. print $OUT "exec failed: $!\n";
  1148. last CMD; };
  1149. $cmd =~ /^T$/ && do {
  1150. print_trace($OUT, 1); # skip DB
  1151. next CMD; };
  1152. $cmd =~ /^W\s*$/ && do {
  1153. $trace &= ~2;
  1154. @to_watch = @old_watch = ();
  1155. next CMD; };
  1156. $cmd =~ /^W\b\s*(.*)/s && do {
  1157. push @to_watch, $1;
  1158. $evalarg = $1;
  1159. my ($val) = &eval;
  1160. $val = (defined $val) ? "'$val'" : 'undef' ;
  1161. push @old_watch, $val;
  1162. $trace |= 2;
  1163. next CMD; };
  1164. $cmd =~ /^\/(.*)$/ && do {
  1165. $inpat = $1;
  1166. $inpat =~ s:([^\\])/$:$1:;
  1167. if ($inpat ne "") {
  1168. # squelch the sigmangler
  1169. local $SIG{__DIE__};
  1170. local $SIG{__WARN__};
  1171. eval '$inpat =~ m'."\a$inpat\a";
  1172. if ($@ ne "") {
  1173. print $OUT "$@";
  1174. next CMD;
  1175. }
  1176. $pat = $inpat;
  1177. }
  1178. $end = $start;
  1179. $incr = -1;
  1180. eval '
  1181. for (;;) {
  1182. ++$start;
  1183. $start = 1 if ($start > $max);
  1184. last if ($start == $end);
  1185. if ($dbline[$start] =~ m' . "\a$pat\a" . 'i) {
  1186. if ($slave_editor) {
  1187. print $OUT "\032\032$filename:$start:0\n";
  1188. } else {
  1189. print $OUT "$start:\t", $dbline[$start], "\n";
  1190. }
  1191. last;
  1192. }
  1193. } ';
  1194. print $OUT "/$pat/: not found\n" if ($start == $end);
  1195. next CMD; };
  1196. $cmd =~ /^\?(.*)$/ && do {
  1197. $inpat = $1;
  1198. $inpat =~ s:([^\\])\?$:$1:;
  1199. if ($inpat ne "") {
  1200. # squelch the sigmangler
  1201. local $SIG{__DIE__};
  1202. local $SIG{__WARN__};
  1203. eval '$inpat =~ m'."\a$inpat\a";
  1204. if ($@ ne "") {
  1205. print $OUT $@;
  1206. next CMD;
  1207. }
  1208. $pat = $inpat;
  1209. }
  1210. $end = $start;
  1211. $incr = -1;
  1212. eval '
  1213. for (;;) {
  1214. --$start;
  1215. $start = $max if ($start <= 0);
  1216. last if ($start == $end);
  1217. if ($dbline[$start] =~ m' . "\a$pat\a" . 'i) {
  1218. if ($slave_editor) {
  1219. print $OUT "\032\032$filename:$start:0\n";
  1220. } else {
  1221. print $OUT "$start:\t", $dbline[$start], "\n";
  1222. }
  1223. last;
  1224. }
  1225. } ';
  1226. print $OUT "?$pat?: not found\n" if ($start == $end);
  1227. next CMD; };
  1228. $cmd =~ /^$rc+\s*(-)?(\d+)?$/ && do {
  1229. pop(@hist) if length($cmd) > 1;
  1230. $i = $1 ? ($#hist-($2||1)) : ($2||$#hist);
  1231. $cmd = $hist[$i];
  1232. print $OUT $cmd, "\n";
  1233. redo CMD; };
  1234. $cmd =~ /^$sh$sh\s*([\x00-\xff]*)/ && do {
  1235. &system($1);
  1236. next CMD; };
  1237. $cmd =~ /^$rc([^$rc].*)$/ && do {
  1238. $pat = "^$1";
  1239. pop(@hist) if length($cmd) > 1;
  1240. for ($i = $#hist; $i; --$i) {
  1241. last if $hist[$i] =~ /$pat/;
  1242. }
  1243. if (!$i) {
  1244. print $OUT "No such command!\n\n";
  1245. next CMD;
  1246. }
  1247. $cmd = $hist[$i];
  1248. print $OUT $cmd, "\n";
  1249. redo CMD; };
  1250. $cmd =~ /^$sh$/ && do {
  1251. &system($ENV{SHELL}||"/bin/sh");
  1252. next CMD; };
  1253. $cmd =~ /^$sh\s*([\x00-\xff]*)/ && do {
  1254. # XXX: using csh or tcsh destroys sigint retvals!
  1255. #&system($1); # use this instead
  1256. &system($ENV{SHELL}||"/bin/sh","-c",$1);
  1257. next CMD; };
  1258. $cmd =~ /^H\b\s*(-(\d+))?/ && do {
  1259. $end = $2 ? ($#hist-$2) : 0;
  1260. $hist = 0 if $hist < 0;
  1261. for ($i=$#hist; $i>$end; $i--) {
  1262. print $OUT "$i: ",$hist[$i],"\n"
  1263. unless $hist[$i] =~ /^.?$/;
  1264. };
  1265. next CMD; };
  1266. $cmd =~ /^(?:man|(?:perl)?doc)\b(?:\s+([^(]*))?$/ && do {
  1267. runman($1);
  1268. next CMD; };
  1269. $cmd =~ s/^p$/print {\$DB::OUT} \$_/;
  1270. $cmd =~ s/^p\b/print {\$DB::OUT} /;
  1271. $cmd =~ s/^=\s*// && do {
  1272. my @keys;
  1273. if (length $cmd == 0) {
  1274. @keys = sort keys %alias;
  1275. }
  1276. elsif (my($k,$v) = ($cmd =~ /^(\S+)\s+(\S.*)/)) {
  1277. # can't use $_ or kill //g state
  1278. for my $x ($k, $v) { $x =~ s/\a/\\a/g }
  1279. $alias{$k} = "s\a$k\a$v\a";
  1280. # squelch the sigmangler
  1281. local $SIG{__DIE__};
  1282. local $SIG{__WARN__};
  1283. unless (eval "sub { s\a$k\a$v\a }; 1") {
  1284. print $OUT "Can't alias $k to $v: $@\n";
  1285. delete $alias{$k};
  1286. next CMD;
  1287. }
  1288. @keys = ($k);
  1289. }
  1290. else {
  1291. @keys = ($cmd);
  1292. }
  1293. for my $k (@keys) {
  1294. if ((my $v = $alias{$k}) =~ ss\a$k\a(.*)\a$1) {
  1295. print $OUT "$k\t= $1\n";
  1296. }
  1297. elsif (defined $alias{$k}) {
  1298. print $OUT "$k\t$alias{$k}\n";
  1299. }
  1300. else {
  1301. print "No alias for $k\n";
  1302. }
  1303. }
  1304. next CMD; };
  1305. $cmd =~ /^\|\|?\s*[^|]/ && do {
  1306. if ($pager =~ /^\|/) {
  1307. open(SAVEOUT,">&STDOUT") || &warn("Can't save STDOUT");
  1308. open(STDOUT,">&OUT") || &warn("Can't redirect STDOUT");
  1309. } else {
  1310. open(SAVEOUT,">&OUT") || &warn("Can't save DB::OUT");
  1311. }
  1312. fix_less();
  1313. unless ($piped=open(OUT,$pager)) {
  1314. &warn("Can't pipe output to `$pager'");
  1315. if ($pager =~ /^\|/) {
  1316. open(OUT,">&STDOUT") # XXX: lost message
  1317. || &warn("Can't restore DB::OUT");
  1318. open(STDOUT,">&SAVEOUT")
  1319. || &warn("Can't restore STDOUT");
  1320. close(SAVEOUT);
  1321. } else {
  1322. open(OUT,">&STDOUT") # XXX: lost message
  1323. || &warn("Can't restore DB::OUT");
  1324. }
  1325. next CMD;
  1326. }
  1327. $SIG{PIPE}= \&DB::catch if $pager =~ /^\|/
  1328. && ("" eq $SIG{PIPE} || "DEFAULT" eq $SIG{PIPE});
  1329. $selected= select(OUT);
  1330. $|= 1;
  1331. select( $selected ), $selected= "" unless $cmd =~ /^\|\|/;
  1332. $cmd =~ s/^\|+\s*//;
  1333. redo PIPE;
  1334. };
  1335. # XXX Local variants do not work!
  1336. $cmd =~ s/^t\s/\$DB::trace |= 1;\n/;
  1337. $cmd =~ s/^s\s/\$DB::single = 1;\n/ && do {$laststep = 's'};
  1338. $cmd =~ s/^n\s/\$DB::single = 2;\n/ && do {$laststep = 'n'};
  1339. } # PIPE:
  1340. $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd"; &eval;
  1341. if ($onetimeDump) {
  1342. $onetimeDump = undef;
  1343. } elsif ($term_pid == $$) {
  1344. print $OUT "\n";
  1345. }
  1346. } continue { # CMD:
  1347. if ($piped) {
  1348. if ($pager =~ /^\|/) {
  1349. $? = 0;
  1350. # we cannot warn here: the handle is missing --tchrist
  1351. close(OUT) || print SAVEOUT "\nCan't close DB::OUT\n";
  1352. # most of the $? crud was coping with broken cshisms
  1353. if ($?) {
  1354. print SAVEOUT "Pager `$pager' failed: ";
  1355. if ($? == -1) {
  1356. print SAVEOUT "shell returned -1\n";
  1357. } elsif ($? >> 8) {
  1358. print SAVEOUT
  1359. ( $? & 127 ) ? " (SIG#".($?&127).")" : "",
  1360. ( $? & 128 ) ? " -- core dumped" : "", "\n";
  1361. } else {
  1362. print SAVEOUT "status ", ($? >> 8), "\n";
  1363. }
  1364. }
  1365. open(OUT,">&STDOUT") || &warn("Can't restore DB::OUT");
  1366. open(STDOUT,">&SAVEOUT") || &warn("Can't restore STDOUT");
  1367. $SIG{PIPE} = "DEFAULT" if $SIG{PIPE} eq \&DB::catch;
  1368. # Will stop ignoring SIGPIPE if done like nohup(1)
  1369. # does SIGINT but Perl doesn't give us a choice.
  1370. } else {
  1371. open(OUT,">&SAVEOUT") || &warn("Can't restore DB::OUT");
  1372. }
  1373. close(SAVEOUT);
  1374. select($selected), $selected= "" unless $selected eq "";
  1375. $piped= "";
  1376. }
  1377. } # CMD:
  1378. $fall_off_end = 1 unless defined $cmd; # Emulate `q' on EOF
  1379. foreach $evalarg (@$post) {
  1380. &eval;
  1381. }
  1382. } # if ($single || $signal)
  1383. ($@, $!, $^E, $,, $/, $\, $^W) = @saved;
  1384. ();
  1385. }
  1386. # The following code may be executed now:
  1387. # BEGIN {warn 4}
  1388. sub sub {
  1389. my ($al, $ret, @ret) = "";
  1390. if (length($sub) > 10 && substr($sub, -10, 10) eq '::AUTOLOAD') {
  1391. $al = " for $$sub";
  1392. }
  1393. local $stack_depth = $stack_depth + 1; # Protect from non-local exits
  1394. $#stack = $stack_depth;
  1395. $stack[-1] = $single;
  1396. $single &= 1;
  1397. $single |= 4 if $stack_depth == $deep;
  1398. ($frame & 4
  1399. ? ( (print $LINEINFO ' ' x ($stack_depth - 1), "in "),
  1400. # Why -1? But it works! :-(
  1401. print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
  1402. : print $LINEINFO ' ' x ($stack_depth - 1), "entering $sub$al\n") if $frame;
  1403. if (wantarray) {
  1404. @ret = &$sub;
  1405. $single |= $stack[$stack_depth--];
  1406. ($frame & 4
  1407. ? ( (print $LINEINFO ' ' x $stack_depth, "out "),
  1408. print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
  1409. : print $LINEINFO ' ' x $stack_depth, "exited $sub$al\n") if $frame & 2;
  1410. if ($doret eq $stack_depth or $frame & 16) {
  1411. my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
  1412. print $fh ' ' x $stack_depth if $frame & 16;
  1413. print $fh "list context return from $sub:\n";
  1414. dumpit($fh, \@ret );
  1415. $doret = -2;
  1416. }
  1417. @ret;
  1418. } else {
  1419. if (defined wantarray) {
  1420. $ret = &$sub;
  1421. } else {
  1422. &$sub; undef $ret;
  1423. };
  1424. $single |= $stack[$stack_depth--];
  1425. ($frame & 4
  1426. ? ( (print $LINEINFO ' ' x $stack_depth, "out "),
  1427. print_trace($LINEINFO, -1, 1, 1, "$sub$al") )
  1428. : print $LINEINFO ' ' x $stack_depth, "exited $sub$al\n") if $frame & 2;
  1429. if ($doret eq $stack_depth or $frame & 16 and defined wantarray) {
  1430. my $fh = ($doret eq $stack_depth ? $OUT : $LINEINFO);
  1431. print $fh (' ' x $stack_depth) if $frame & 16;
  1432. print $fh (defined wantarray
  1433. ? "scalar context return from $sub: "
  1434. : "void context return from $sub\n");
  1435. dumpit( $fh, $ret ) if defined wantarray;
  1436. $doret = -2;
  1437. }
  1438. $ret;
  1439. }
  1440. }
  1441. sub save {
  1442. @saved = ($@, $!, $^E, $,, $/, $\, $^W);
  1443. $, = ""; $/ = "\n"; $\ = ""; $^W = 0;
  1444. }
  1445. # The following takes its argument via $evalarg to preserve current @_
  1446. sub eval {
  1447. # 'my' would make it visible from user code
  1448. # but so does local! --tchrist
  1449. local @res;
  1450. {
  1451. local $otrace = $trace;
  1452. local $osingle = $single;
  1453. local $od = $^D;
  1454. { ($evalarg) = $evalarg =~ /(.*)/s; }
  1455. @res = eval "$usercontext $evalarg;\n"; # '\n' for nice recursive debug
  1456. $trace = $otrace;
  1457. $single = $osingle;
  1458. $^D = $od;
  1459. }
  1460. my $at = $@;
  1461. local $saved[0]; # Preserve the old value of $@
  1462. eval { &DB::save };
  1463. if ($at) {
  1464. print $OUT $at;
  1465. } elsif ($onetimeDump eq 'dump') {
  1466. dumpit($OUT, \@res);
  1467. } elsif ($onetimeDump eq 'methods') {
  1468. methods($res[0]);
  1469. }
  1470. @res;
  1471. }
  1472. sub postponed_sub {
  1473. my $subname = shift;
  1474. if ($postponed{$subname} =~ s/^break\s([+-]?\d+)\s+if\s//) {
  1475. my $offset = $1 || 0;
  1476. # Filename below can contain ':'
  1477. my ($file,$i) = (find_sub($subname) =~ /^(.*):(\d+)-.*$/);
  1478. if ($i) {
  1479. $i += $offset;
  1480. local *dbline = $main::{'_<' . $file};
  1481. local $^W = 0; # != 0 is magical below
  1482. $had_breakpoints{$file} |= 1;
  1483. my $max = $#dbline;
  1484. ++$i until $dbline[$i] != 0 or $i >= $max;
  1485. $dbline{$i} = delete $p…

Large files files are truncated, but you can click here to view the full file