package DB;
-# Debugger for Perl 5.001m; perl5db.pl patch level:
+# Debugger for Perl 5.00x; perl5db.pl patch level:
-$header = 'perl5db.pl patch level 0.93';
+$header = 'perl5db.pl patch level 0.94';
# Enhanced by ilya@math.ohio-state.edu (Ilya Zakharevich)
# Latest version available: ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
# reset LineInfo to something "interactive"!)
#
+# Needed for the statement after exec():
-local($^W) = 0;
+BEGIN { $ini_warn = $^W; $^W = 0 } # Switch compilation warnings off until another BEGIN.
+local($^W) = 0; # Switch run-time warnings off during init.
warn ( # Do not ;-)
$dumpvar::hashDepth,
$dumpvar::arrayDepth,
$dumpvar::usageOnly,
@ARGS,
$Carp::CarpLevel,
+ $panic,
+ $first_time,
) if 0;
+# Command-line + PERLLIB:
+@ini_INC = @INC;
+
# $prevwarn = $prevdie = $prevbus = $prevsegv = ''; # Does not help?!
$trace = $signal = $single = 0; # Uninitialized warning suppression
parse_options($ENV{PERLDB_OPTS});
}
+if (exists $ENV{PERLDB_RESTART}) {
+ delete $ENV{PERLDB_RESTART};
+ # $restart = 1;
+ @hist = get_list('PERLDB_HIST');
+ my @visited = get_list("PERLDB_VISITED");
+ for (0 .. $#visited) {
+ %{$postponed{$visited[$_]}} = get_list("PERLDB_FILE_$_");
+ }
+ my %opt = get_list("PERLDB_OPT");
+ my ($opt,$val);
+ while (($opt,$val) = each %opt) {
+ $val =~ s/[\\\']/\\$1/g;
+ parse_options("$opt'$val'");
+ }
+ @INC = get_list("PERLDB_INC");
+ @ini_INC = @INC;
+}
+
if ($notty) {
$runnonstop = 1;
} else {
############################################################ Subroutines
-# The following code may be executed now, but gives FPE later:
-# BEGIN {warn 5}
-
sub DB {
- if ($runnonstop) { # Disable until signal
+ unless ($first_time++) { # Do when-running init
+ if ($runnonstop) { # Disable until signal
for ($i=0; $i <= $#stack; ) {
$stack[$i++] &= ~1;
}
- $single = $runnonstop = 0; # Once only
+ $single = 0;
return;
+ }
+ # Define a subroutine in which we will stop
+# eval <<'EOE';
+# sub at_end::db {"Debuggee terminating";}
+# END {
+# $DB::step = 1;
+# print $OUT "Debuggee terminating.\n";
+# &at_end::db;}
+# EOE
}
&save;
if ($doret) {
}
}
($package, $filename, $line) = caller;
+ $filename_ini = $filename;
$usercontext = '($@, $!, $,, $/, $\, $^W) = @saved;' .
"package $package;"; # this won't let them modify, alas
local(*dbline) = "::_<$filename";
+ install_breakpoints($filename) unless $visited{$filename}++;
$max = $#dbline;
if (($stop,$action) = split(/\0/,$dbline{$line})) {
if ($stop eq '1') {
$signal |= 1;
- } else {
+ } elsif ($stop) {
$evalarg = "\$DB::signal |= do {$stop;}"; &eval;
$dbline{$line} =~ s/;9($|\0)/$1/;
}
if ($single || $trace || $signal) {
$term || &setterm;
if ($emacs) {
- print $LINEINFO "\032\032$filename:$line:0\n";
+ $position = "\032\032$filename:$line:0\n";
+ print $LINEINFO $position;
} else {
$sub =~ s/\'/::/;
$prefix = $sub =~ /::/ ? "" : "${'package'}::";
$prefix .= "$sub($filename:";
$after = ($dbline[$line] =~ /\n$/ ? '' : "\n");
if (length($prefix) > 30) {
- print $LINEINFO "$prefix$line):\n$line:\t", $dbline[$line], $after;
+ $position = "$prefix$line):\n$line:\t$dbline[$line]$after";
+ print $LINEINFO $position;
$prefix = "";
$infix = ":\t";
} else {
$infix = "):\t";
- print $LINEINFO "$prefix$line$infix",$dbline[$line], $after;
+ $position = "$prefix$line$infix$dbline[$line]$after";
+ print $LINEINFO $position;
}
for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) { #{ vi
last if $dbline[$i] =~ /^\s*[\;\}\#\n]/;
$after = ($dbline[$i] =~ /\n$/ ? '' : "\n");
- print $LINEINFO "$prefix$i$infix", $dbline[$i], $after;
+ $incr_pos = "$prefix$i$infix$dbline[$i]$after";
+ print $LINEINFO $incr_pos;
+ $position .= $incr_pos;
}
}
}
$start = $line;
CMD:
while (($term || &setterm),
- defined ($cmd=$term->readline(" DB" . ('<' x $level) .
- ($#hist+1) . ('>' x $level) .
- " "))) {
- { # <-- Do we know what this brace is for?
+ defined ($cmd=&readline(" DB" . ('<' x $level) .
+ ($#hist+1) . ('>' x $level) .
+ " "))) {
+ #{ # <-- Do we know what this brace is for?
$single = 0;
$signal = 0;
$cmd =~ s/\\$/\n/ && do {
- $cmd .= $term->readline(" cont: ");
+ $cmd .= &readline(" cont: ");
redo CMD;
};
$cmd =~ /^q$/ && exit 0;
@vars = split(' ',$2);
do 'dumpvar.pl' unless defined &main::dumpvar;
if (defined &main::dumpvar) {
+ local $frame = 0;
&main::dumpvar($packname,@vars);
} else {
print $OUT "dumpvar.pl not available.\n";
next CMD;
} elsif ($file ne $filename) {
*dbline = "::_<$file";
+ $visited{$file}++;
$max = $#dbline;
$filename = $file;
$start = 1;
$file = join(':', @pieces);
if ($file ne $filename) {
*dbline = "::_<$file";
+ $visited{$file}++;
$max = $#dbline;
$filename = $file;
}
print $OUT "Subroutine $subname not found.\n";
next CMD;
} };
+ $cmd =~ /^\.$/ && do {
+ $start = $line;
+ $filename = $filename_ini;
+ *dbline = "::_<$filename";
+ $max = $#dbline;
+ print $LINEINFO $position;
+ next CMD };
$cmd =~ /^w\b\s*(\d*)$/ && do {
$incr = $window - 1;
$start = $1 if $1;
$start -= $preview;
+ #print $OUT 'l ' . $start . '-' . ($start + $incr);
$cmd = 'l ' . $start . '-' . ($start + $incr); };
$cmd =~ /^-$/ && do {
$incr = $window - 1;
$incr = $2;
$incr = $window - 1 unless $incr;
$cmd = 'l ' . $start . '-' . ($start + $incr); };
- $cmd =~ /^l\b\s*(([\d\$\.]+)([-,]([\d\$\.]+))?)?/ && do {
- $end = (!$2) ? $max : ($4 ? $4 : $2);
+ $cmd =~ /^l\b\s*((-?[\d\$\.]+)([-,]([\d\$\.]+))?)?/ && do {
+ $end = (!defined $2) ? $max : ($4 ? $4 : $2);
$end = $max if $end > $max;
$i = $2;
$i = $line if $i eq '.';
$i = $end;
} else {
for (; $i <= $end; $i++) {
- print $OUT "$i:\t", $dbline[$i];
+ ($stop,$action) = split(/\0/, $dbline{$i});
+ $arrow = ($i==$line
+ and $filename eq $filename_ini)
+ ? '==>'
+ : ':' ;
+ $arrow .= 'b' if $stop;
+ $arrow .= 'a' if $action;
+ print $OUT "$i$arrow\t", $dbline[$i];
last if $signal;
}
}
if ($i) {
$filename = $file;
*dbline = "::_<$filename";
+ $visited{$filename}++;
$max = $#dbline;
++$i while $dbline[$i] == 0 && $i < $max;
$dbline{$i} =~ s/^[^\0]*/$cond/;
$single = 1;
$laststep = $cmd;
last CMD; };
- $cmd =~ /^c\b\s*(\d*)\s*$/ && do {
+ $cmd =~ /^c\b\s*([\w:]*)\s*$/ && do {
$i = $1;
+ if ($i =~ /\D/) { # subroutine name
+ ($file,$i) = ($sub{$i} =~ /^(.*):(.*)$/);
+ $i += 0;
+ if ($i) {
+ $filename = $file;
+ *dbline = "::_<$filename";
+ $visited{$filename}++;
+ $max = $#dbline;
+ ++$i while $dbline[$i] == 0 && $i < $max;
+ } else {
+ print $OUT "Subroutine $subname not found.\n";
+ next CMD;
+ }
+ }
if ($i) {
if ($dbline[$i] == 0) {
print $OUT "Line $i not breakable.\n";
$stack[$#stack] |= 1;
$doret = 1;
last CMD; };
+ $cmd =~ /^R$/ && do {
+ print $OUT "Warning: a lot of settings and command-line options may be lost!\n";
+ my (@script, @flags, $cl);
+ push @flags, '-w' if $ini_warn;
+ # Put all the old includes at the start to get
+ # the same debugger.
+ for (@ini_INC) {
+ push @flags, '-I', $_;
+ }
+ # Arrange for setting the old INC:
+ set_list("PERLDB_INC", @ini_INC);
+ if ($0 eq '-e') {
+ for (1..$#{'::_<-e'}) { # The first line is PERL5DB
+ chomp ($cl = $ {'::_<-e'}[$_]);
+ push @script, '-e', $cl;
+ }
+ } else {
+ @script = $0;
+ }
+ set_list("PERLDB_HIST",
+ $term->Features->{getHistory}
+ ? $term->GetHistory : @hist);
+ my @visited = keys %visited;
+ set_list("PERLDB_VISITED", @visited);
+ set_list("PERLDB_OPT", %option);
+ for (0 .. $#visited) {
+ *dbline = "::_<$visited[$_]";
+ set_list("PERLDB_FILE_$_", %dbline);
+ }
+ $ENV{PERLDB_RESTART} = 1;
+ #print "$^X, '-d', @flags, @script, ($emacs ? '-emacs' : ()), @ARGS";
+ exec $^X, '-d', @flags, @script, ($emacs ? '-emacs' : ()), @ARGS;
+ print $OUT "exec failed: $!\n";
+ last CMD; };
$cmd =~ /^T$/ && do {
local($p,$f,$l,$s,$h,$a,$e,$r,@a,@sub);
for ($i = 1;
$cmd =~ s/^s\s/\$DB::single = 1;\n/ && do {$laststep = 's'};
$cmd =~ s/^n\s/\$DB::single = 2;\n/ && do {$laststep = 'n'};
} # PIPE:
- } # <-- Do we know what this brace is for?
+ #} # <-- Do we know what this brace is for?
$evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd"; &eval;
if ($onetimeDump) {
$onetimeDump = undef;
}
}
+sub install_breakpoints {
+ my $filename = shift;
+ return unless exists $postponed{$filename};
+ my %break = %{$postponed{$filename}};
+ for (keys %break) {
+ my $i = $_;
+ #if (/\D/) { # Subroutine name
+ #}
+ $dbline{$i} = $break{$_}; # Cannot be done before the file is around
+ }
+}
+
sub dumpit {
local ($savout) = select($OUT);
do 'dumpvar.pl' unless defined &main::dumpValue;
if (defined &main::dumpValue) {
+ local $frame = 0;
&main::dumpValue(shift);
} else {
print $OUT "dumpvar.pl not available.\n";
}
sub setterm {
+ local $frame = 0;
eval "require Term::ReadLine;" or die $@;
if ($notty) {
if ($tty) {
$LINEINFO = $OUT unless defined $LINEINFO;
$lineinfo = $console unless defined $lineinfo;
$term->MinLine(2);
+ if ($term->Features->{setHistory} and "@hist" ne "?") {
+ $term->SetHistory(@hist);
+ }
}
sub readline {
+ if (@typeahead) {
+ my $left = @typeahead;
+ my $got = shift @typeahead;
+ print $OUT "auto(-$left)", shift, $got, "\n";
+ $term->AddHistory($got)
+ if length($got) > 1 and defined $term->Features->{addHistory};
+ return $got;
+ }
local $frame = 0;
$term->readline(@_);
}
print $OUT "Unknown option `$opt'\n" unless $matches;
print $OUT "Ambiguous option `$opt'\n" if $matches > 1;
$option{$option} = $val if $matches == 1 and defined $val;
- eval "require '$optionRequire{$option}'"
+ eval "local \$frame = 0; require '$optionRequire{$option}'"
if $matches == 1 and defined $optionRequire{$option} and defined $val;
$ {$optionVars{$option}} = $val
if $matches == 1
}
}
+sub set_list {
+ my ($stem,@list) = @_;
+ my $val;
+ $ENV{"$ {stem}_n"} = @list;
+ for $i (0 .. $#list) {
+ $val = $list[$i];
+ $val =~ s/\\/\\\\/g;
+ $val =~ s/[\0-\37\177\200-\377]/"\\0x" . unpack('H2',$&)/eg;
+ $ENV{"$ {stem}_$i"} = $val;
+ }
+}
+
+sub get_list {
+ my $stem = shift;
+ my @list;
+ my $n = delete $ENV{"$ {stem}_n"};
+ my $val;
+ for $i (0 .. $n - 1) {
+ $val = delete $ENV{"$ {stem}_$i"};
+ $val =~ s/\\((\\)|0x(..))/ $2 ? $2 : pack('H2', $3) /ge;
+ push @list, $val;
+ }
+ @list;
+}
+
sub catch {
$signal = 1;
}
l List next window of lines.
- List previous window of lines.
w [line] List window around line.
+. Return to the executed line.
f filename Switch to viewing filename.
/pattern/ Search forwards for pattern; final / is optional.
?pattern? Search backwards for pattern; final ? is optional.
-L List all breakpoints and actions.
+L List all breakpoints and actions for the current file.
S [[!]pattern] List subroutine names [not] matching pattern.
t Toggle trace mode.
t expr Trace through execution of expr.
||dbcmd Same as |dbcmd but DB::OUT is temporarilly select()ed as well.
\= [alias value] Define a command alias, or list current aliases.
command Execute as a perl statement in current package.
+R Pure-man-restart of debugger, debugger state and command-line
+ options are lost.
h [db_command] Get help [on a specific debugger command], enter |h to page.
h h Summary of debugger commands.
q or ^D Quit.
$summary = <<"END_SUM";
List/search source lines: Control script execution:
l [ln|sub] List source code T Stack trace
- - List previous lines s [expr] Single step [in expr]
+ - or . List previous/current line s [expr] Single step [in expr]
w [line] List around line n [expr] Next, steps over subs
f filename View source in file <CR> Repeat last n or s
/pattern/ Search forward r Return from subroutine
= [a val] Define/list an alias a [ln] cmd Do cmd before line
h [db_cmd] Get help on command A Delete all actions
|[|]dbcmd Send output to pager $psh\[$psh\] syscmd Run cmd in a subprocess
- q or ^D Quit
+ q or ^D Quit R Attempt a restart
Data Examination: expr Execute perl code, also see: s,n,t expr
S [[!]pat] List subroutine names [not] matching pattern
V [Pk [Vars]] List Variables in Package. Vars can be ~pattern or !pattern.
# '); # Fix balance of Emacs parsing
}
-
sub diesignal {
+ local $frame = 0;
$SIG{'ABRT'} = DEFAULT;
kill 'ABRT', $$ if $panic++;
print $DB::OUT "Got $_[0]!\n"; # in the case cannot continue
}
sub dbwarn {
+ local $frame = 0;
local $SIG{__WARN__} = '';
require Carp;
#&warn("Entering dbwarn\n");
}
sub dbdie {
+ local $frame = 0;
local $SIG{__DIE__} = '';
local $SIG{__WARN__} = '';
my $i = 0; my $ineval = 0; my $sub;
die $mess;
}
-# sub diehard { # Always dump, useful if fatal is
-# # deeply in evals.
-# local $SIG{__DIE__} = '';
-# require Carp;
-# # We do not want to debug this (automatic disabling works inside DB::DB)
-# my ($mysingle,$mytrace) = ($single,$trace);
-# $single = 0; $trace = 0;
-# my $mess = Carp::longmess(@_);
-# ($single,$trace) = ($mysingle,$mytrace);
-# die $mess;
-# }
-
sub warnLevel {
if (@_) {
$prevwarn = $SIG{__WARN__} unless $warnLevel;
$level = 0; # Level of recursive debugging
}
-#use Carp; # This did break, left for debuggin
-
-1;
-package DB;
-
-# modified Perl debugger, to be run from Emacs in perldb-mode
-# Ray Lischner (uunet!mntgfx!lisch) as of 5 Nov 1990
-# Johan Vromans -- upgrade to 4.0 pl 10
-
-$header = '$RCSfile: perl5db.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:07 $';
-#
-# This file is automatically included if you do perl -d.
-# It's probably not useful to include this yourself.
-#
-# Perl supplies the values for @line and %sub. It effectively inserts
-# a &DB'DB(<linenum>); in front of every place that can
-# have a breakpoint. It also inserts a do 'perldb.pl' before the first line.
-#
-# $Log: perldb.pl,v $
-
-# Is Perl being run from Emacs?
-$emacs = ((defined $main::ARGV[0]) and ($main::ARGV[0] eq '-emacs'));
-shift(@main::ARGV) if $emacs;
-
-#require Term::ReadLine;
-
-local($^W) = 0;
-
-if (-e "/dev/tty") {
- $console = "/dev/tty";
- $rcfile=".perldb";
-}
-elsif (-e "con") {
- $console = "con";
- $rcfile="perldb.ini";
-}
-else {
- $console = "sys\$command";
- $rcfile="perldb.ini";
-}
-
-# Around a bug:
-if (defined $ENV{'OS2_SHELL'}) { # In OS/2
- if ($DB::emacs) {
- $console = undef;
- } else {
- $console = "/dev/con";
- }
-}
-
-open(IN, "<$console") || open(IN, "<&STDIN"); # so we don't dingle stdin
-open(OUT,">$console") || open(OUT, ">&STDERR")
- || open(OUT, ">&STDOUT"); # so we don't dongle stdout
-select(OUT);
-$| = 1; # for DB::OUT
-select(STDOUT);
-$| = 1; # for real STDOUT
-$sub = '';
+BEGIN {$^W = $ini_warn;} # Switch warnings back
-$header =~ s/.Header: ([^,]+),v(\s+\S+\s+\S+).*$/$1$2/;
-print OUT "\nLoading DB routines from $header\n";
-print OUT ("Emacs support ",
- $emacs ? "enabled" : "available",
- ".\n");
-print OUT "\nEnter h for help.\n\n";
-
-@ARGS;
-
-sub DB {
- &save;
- ($pkg, $filename, $line) = caller;
- $usercontext = '($@, $!, $,, $/, $\, $^W) = @saved;' .
- "package $pkg;"; # this won't let them modify, alas
- local(*dbline) = "::_<$filename";
- $max = $#dbline;
- if (($stop,$action) = split(/\0/,$dbline{$line})) {
- if ($stop eq '1') {
- $signal |= 1;
- }
- else {
- $evalarg = "\$DB::signal |= do {$stop;}"; &eval;
- $dbline{$line} =~ s/;9($|\0)/$1/;
- }
- }
- if ($single || $trace || $signal) {
- if ($emacs) {
- print OUT "\032\032$filename:$line:0\n";
- } else {
- $prefix = $sub =~ /'|::/ ? "" : "${pkg}::";
- $prefix .= "$sub($filename:";
- if (length($prefix) > 30) {
- print OUT "$prefix$line):\n$line:\t",$dbline[$line];
- $prefix = "";
- $infix = ":\t";
- }
- else {
- $infix = "):\t";
- print OUT "$prefix$line$infix",$dbline[$line];
- }
- for ($i = $line + 1; $i <= $max && $dbline[$i] == 0; ++$i) {
- last if $dbline[$i] =~ /^\s*(}|#|\n)/;
- print OUT "$prefix$i$infix",$dbline[$i];
- }
- }
- }
- $evalarg = $action, &eval if $action;
- if ($single || $signal) {
- $evalarg = $pre, &eval if $pre;
- print OUT $#stack . " levels deep in subroutine calls!\n"
- if $single & 4;
- $start = $line;
- CMD:
- while ((print OUT " DB<", $#hist+1, "> "), $cmd=&gets) {
- {
- $single = 0;
- $signal = 0;
- $cmd eq '' && exit 0;
- chop($cmd);
- $cmd =~ s/\\$// && do {
- print OUT " cont: ";
- $cmd .= &gets;
- redo CMD;
- };
- $cmd =~ /^q$/ && exit 0;
- $cmd =~ /^$/ && ($cmd = $laststep);
- push(@hist,$cmd) if length($cmd) > 1;
- ($i) = split(/\s+/,$cmd);
- eval "\$cmd =~ $alias{$i}", print OUT $@ if $alias{$i};
- $cmd =~ /^h$/ && do {
- print OUT "
-T Stack trace.
-s Single step.
-n Next, steps over subroutine calls.
-r Return from current subroutine.
-c [line] Continue; optionally inserts a one-time-only breakpoint
- at the specified line.
-<CR> Repeat last n or s.
-l min+incr List incr+1 lines starting at min.
-l min-max List lines.
-l line List line;
-l List next window.
-- List previous window.
-w line List window around line.
-l subname List subroutine.
-f filename Switch to filename.
-/pattern/ Search forwards for pattern; final / is optional.
-?pattern? Search backwards for pattern.
-L List breakpoints and actions.
-S List subroutine names.
-t Toggle trace mode.
-b [line] [condition]
- Set breakpoint; line defaults to the current execution line;
- condition breaks if it evaluates to true, defaults to \'1\'.
-b subname [condition]
- Set breakpoint at first line of subroutine.
-d [line] Delete breakpoint.
-D Delete all breakpoints.
-a [line] command
- Set an action to be done before the line is executed.
- Sequence is: check for breakpoint, print line if necessary,
- do action, prompt user if breakpoint or step, evaluate line.
-A Delete all actions.
-V [pkg [vars]] List some (default all) variables in package (default current).
-X [vars] Same as \"V currentpackage [vars]\".
-< command Define command before prompt.
-> command Define command after prompt.
-! number Redo command (default previous command).
-! -number Redo number\'th to last command.
-H -number Display last number commands (default all).
-q or ^D Quit.
-p expr Same as \"print DB::OUT expr\" in current package.
-= [alias value] Define a command alias, or list current aliases.
-command Execute as a perl statement in current package.
-
-";
- next CMD; };
- $cmd =~ /^t$/ && do {
- $trace = !$trace;
- print OUT "Trace = ".($trace?"on":"off")."\n";
- next CMD; };
- $cmd =~ /^S$/ && do {
- foreach $subname (sort(keys %sub)) {
- print OUT $subname,"\n";
- }
- next CMD; };
- $cmd =~ s/^X\b/V $pkg/;
- $cmd =~ /^V$/ && do {
- $cmd = "V $pkg"; };
- $cmd =~ /^V\b\s*(\S+)\s*(.*)/ && do {
- local ($savout) = select(OUT);
- $packname = $1;
- @vars = split(' ',$2);
- do 'dumpvar.pl' unless defined &main::dumpvar;
- if (defined &main::dumpvar) {
- &main::dumpvar($packname,@vars);
- }
- else {
- print DB::OUT "dumpvar.pl not available.\n";
- }
- select ($savout);
- next CMD; };
- $cmd =~ /^f\b\s*(.*)/ && do {
- $file = $1;
- if (!$file) {
- print OUT "The old f command is now the r command.\n";
- print OUT "The new f command switches filenames.\n";
- next CMD;
- }
- if (!defined $main::{'_<' . $file}) {
- if (($try) = grep(m#^_<.*$file#, keys %main::)) {
- $file = substr($try,2);
- print "\n$file:\n";
- }
- }
- if (!defined $main::{'_<' . $file}) {
- print OUT "There's no code here anything matching $file.\n";
- next CMD;
- }
- elsif ($file ne $filename) {
- *dbline = "::_<$file";
- $max = $#dbline;
- $filename = $file;
- $start = 1;
- $cmd = "l";
- } };
- $cmd =~ /^l\b\s*([':A-Za-z_][':\w]*)/ && do {
- $subname = $1;
- $subname = "main::" . $subname unless $subname =~ /'|::/;
- $subname = "main" . $subname if substr($subname,0,1)eq "'";
- $subname = "main" . $subname if substr($subname,0,2)eq "::";
- # VMS filespecs may (usually do) contain ':', so don't use split
- ($file,$subrange) = $sub{$subname} =~ /(.*):(.*)/;
- if ($file ne $filename) {
- *dbline = "::_<$file";
- $max = $#dbline;
- $filename = $file;
- }
- if ($subrange) {
- if (eval($subrange) < -$window) {
- $subrange =~ s/-.*/+/;
- }
- $cmd = "l $subrange";
- } else {
- print OUT "Subroutine $1 not found.\n";
- next CMD;
- } };
- $cmd =~ /^w\b\s*(\d*)$/ && do {
- $incr = $window - 1;
- $start = $1 if $1;
- $start -= $preview;
- $cmd = 'l ' . $start . '-' . ($start + $incr); };
- $cmd =~ /^-$/ && do {
- $incr = $window - 1;
- $cmd = 'l ' . ($start-$window*2) . '+'; };
- $cmd =~ /^l$/ && do {
- $incr = $window - 1;
- $cmd = 'l ' . $start . '-' . ($start + $incr); };
- $cmd =~ /^l\b\s*(\d*)\+(\d*)$/ && do {
- $start = $1 if $1;
- $incr = $2;
- $incr = $window - 1 unless $incr;
- $cmd = 'l ' . $start . '-' . ($start + $incr); };
- $cmd =~ /^l\b\s*(([\d\$\.]+)([-,]([\d\$\.]+))?)?/ && do {
- $end = (!$2) ? $max : ($4 ? $4 : $2);
- $end = $max if $end > $max;
- $i = $2;
- $i = $line if $i eq '.';
- $i = 1 if $i < 1;
- if ($emacs) {
- print OUT "\032\032$filename:$i:0\n";
- $i = $end;
- } else {
- for (; $i <= $end; $i++) {
- print OUT "$i:\t", $dbline[$i];
- last if $signal;
- }
- }
- $start = $i; # remember in case they want more
- $start = $max if $start > $max;
- next CMD; };
- $cmd =~ /^D$/ && do {
- print OUT "Deleting all breakpoints...\n";
- for ($i = 1; $i <= $max ; $i++) {
- if (defined $dbline{$i}) {
- $dbline{$i} =~ s/^[^\0]+//;
- if ($dbline{$i} =~ s/^\0?$//) {
- delete $dbline{$i};
- }
- }
- }
- next CMD; };
- $cmd =~ /^L$/ && do {
- for ($i = 1; $i <= $max; $i++) {
- if (defined $dbline{$i}) {
- print OUT "$i:\t", $dbline[$i];
- ($stop,$action) = split(/\0/, $dbline{$i});
- print OUT " break if (", $stop, ")\n"
- if $stop;
- print OUT " action: ", $action, "\n"
- if $action;
- last if $signal;
- }
- }
- next CMD; };
- $cmd =~ /^b\b\s*([':A-Za-z_][':\w]*)\s*(.*)/ && do {
- $subname = $1;
- $cond = $2 || '1';
- $subname = "${pkg}::" . $subname
- unless $subname =~ /'|::/;
- $subname = "main" . $subname if substr($subname,0,1) eq "'";
- $subname = "main" . $subname if substr($subname,0,2) eq "::";
- # VMS filespecs may (usually do) contain ':', so don't use split
- ($filename,$i) = $sub{$subname} =~ /(.*):(.*)/;
- $i += 0;
- if ($i) {
- *dbline = "::_<$filename";
- ++$i while $dbline[$i] == 0 && $i < $#dbline;
- $dbline{$i} =~ s/^[^\0]*/$cond/;
- } else {
- print OUT "Subroutine $subname not found.\n";
- }
- next CMD; };
- $cmd =~ /^b\b\s*(\d*)\s*(.*)/ && do {
- $i = ($1?$1:$line);
- $cond = $2 || '1';
- if ($dbline[$i] == 0) {
- print OUT "Line $i not breakable.\n";
- } else {
- $dbline{$i} =~ s/^[^\0]*/$cond/;
- }
- next CMD; };
- $cmd =~ /^d\b\s*(\d+)?/ && do {
- $i = ($1?$1:$line);
- $dbline{$i} =~ s/^[^\0]*//;
- delete $dbline{$i} if $dbline{$i} eq '';
- next CMD; };
- $cmd =~ /^A$/ && do {
- for ($i = 1; $i <= $max ; $i++) {
- if (defined $dbline{$i}) {
- $dbline{$i} =~ s/\0[^\0]*//;
- delete $dbline{$i} if $dbline{$i} eq '';
- }
- }
- next CMD; };
- $cmd =~ /^<\s*(.*)/ && do {
- $pre = action($1);
- next CMD; };
- $cmd =~ /^>\s*(.*)/ && do {
- $post = action($1);
- next CMD; };
- $cmd =~ /^a\b\s*(\d+)(\s+(.*))?/ && do {
- $i = $1;
- if ($dbline[$i] == 0) {
- print OUT "Line $i may not have an action.\n";
- } else {
- $dbline{$i} =~ s/\0[^\0]*//;
- $dbline{$i} .= "\0" . action($3);
- }
- next CMD; };
- $cmd =~ /^n$/ && do {
- $single = 2;
- $laststep = $cmd;
- last CMD; };
- $cmd =~ /^s$/ && do {
- $single = 1;
- $laststep = $cmd;
- last CMD; };
- $cmd =~ /^c\b\s*(\d*)\s*$/ && do {
- $i = $1;
- if ($i) {
- if ($dbline[$i] == 0) {
- print OUT "Line $i not breakable.\n";
- next CMD;
- }
- $dbline{$i} =~ s/(\0|$)/;9$1/; # add one-time-only b.p.
- }
- for ($i=0; $i <= $#stack; ) {
- $stack[$i++] &= ~1;
- }
- last CMD; };
- $cmd =~ /^r$/ && do {
- $stack[$#stack] |= 2;
- last CMD; };
- $cmd =~ /^T$/ && do {
- local($p,$f,$l,$s,$h,$a,@a,@sub);
- for ($i = 1; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) {
- @a = ();
- for $arg (@args) {
- $_ = "$arg";
- s/'/\\'/g;
- s/([^\0]*)/'$1'/
- unless /^(?: -?[\d.]+ | \*[\w:]* )$/x;
- s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
- s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
- push(@a, $_);
- }
- $w = $w ? '@ = ' : '$ = ';
- $a = $h ? '(' . join(', ', @a) . ')' : '';
- push(@sub, "$w$s$a from file $f line $l\n");
- last if $signal;
- }
- for ($i=0; $i <= $#sub; $i++) {
- last if $signal;
- print OUT $sub[$i];
- }
- next CMD; };
- $cmd =~ /^\/(.*)$/ && do {
- $inpat = $1;
- $inpat =~ s:([^\\])/$:$1:;
- if ($inpat ne "") {
- eval '$inpat =~ m'."\a$inpat\a";
- if ($@ ne "") {
- print OUT "$@";
- next CMD;
- }
- $pat = $inpat;
- }
- $end = $start;
- eval '
- for (;;) {
- ++$start;
- $start = 1 if ($start > $max);
- last if ($start == $end);
- if ($dbline[$start] =~ m'."\a$pat\a".'i) {
- if ($emacs) {
- print OUT "\032\032$filename:$start:0\n";
- } else {
- print OUT "$start:\t", $dbline[$start], "\n";
- }
- last;
- }
- } ';
- print OUT "/$pat/: not found\n" if ($start == $end);
- next CMD; };
- $cmd =~ /^\?(.*)$/ && do {
- $inpat = $1;
- $inpat =~ s:([^\\])\?$:$1:;
- if ($inpat ne "") {
- eval '$inpat =~ m'."\a$inpat\a";
- if ($@ ne "") {
- print OUT "$@";
- next CMD;
- }
- $pat = $inpat;
- }
- $end = $start;
- eval '
- for (;;) {
- --$start;
- $start = $max if ($start <= 0);
- last if ($start == $end);
- if ($dbline[$start] =~ m'."\a$pat\a".'i) {
- if ($emacs) {
- print OUT "\032\032$filename:$start:0\n";
- } else {
- print OUT "$start:\t", $dbline[$start], "\n";
- }
- last;
- }
- } ';
- print OUT "?$pat?: not found\n" if ($start == $end);
- next CMD; };
- $cmd =~ /^!+\s*(-)?(\d+)?$/ && do {
- pop(@hist) if length($cmd) > 1;
- $i = ($1?($#hist-($2?$2:1)):($2?$2:$#hist));
- $cmd = $hist[$i] . "\n";
- print OUT $cmd;
- redo CMD; };
- $cmd =~ /^!(.+)$/ && do {
- $pat = "^$1";
- pop(@hist) if length($cmd) > 1;
- for ($i = $#hist; $i; --$i) {
- last if $hist[$i] =~ $pat;
- }
- if (!$i) {
- print OUT "No such command!\n\n";
- next CMD;
- }
- $cmd = $hist[$i] . "\n";
- print OUT $cmd;
- redo CMD; };
- $cmd =~ /^H\b\s*(-(\d+))?/ && do {
- $end = $2?($#hist-$2):0;
- $hist = 0 if $hist < 0;
- for ($i=$#hist; $i>$end; $i--) {
- print OUT "$i: ",$hist[$i],"\n"
- unless $hist[$i] =~ /^.?$/;
- };
- next CMD; };
- $cmd =~ s/^p( .*)?$/print DB::OUT$1/;
- $cmd =~ /^=/ && do {
- if (local($k,$v) = ($cmd =~ /^=\s*(\S+)\s+(.*)/)) {
- $alias{$k}="s~$k~$v~";
- print OUT "$k = $v\n";
- } elsif ($cmd =~ /^=\s*$/) {
- foreach $k (sort keys(%alias)) {
- if (($v = $alias{$k}) =~ s~^s\~$k\~(.*)\~$~$1~) {
- print OUT "$k = $v\n";
- } else {
- print OUT "$k\t$alias{$k}\n";
- };
- };
- };
- next CMD; };
- }
- $evalarg = $cmd; &eval;
- print OUT "\n";
- }
- if ($post) {
- $evalarg = $post; &eval;
- }
- }
- ($@, $!, $,, $/, $\, $^W) = @saved;
- ();
-}
-
-sub save {
- @saved = ($@, $!, $,, $/, $\, $^W);
- $, = ""; $/ = "\n"; $\ = ""; $^W = 0;
-}
-
-# The following takes its argument via $evalarg to preserve current @_
-
-sub eval {
- eval "$usercontext $evalarg; &DB::save";
- print OUT $@;
-}
-
-sub action {
- local($action) = @_;
- while ($action =~ s/\\$//) {
- print OUT "+ ";
- $action .= &gets;
- }
- $action;
-}
-
-sub gets {
- local($.);
- <IN>;
-}
-
-sub catch {
- $signal = 1;
-}
-
-sub sub {
- push(@stack, $single);
- $single &= 1;
- $single |= 4 if $#stack == $deep;
- if (wantarray) {
- @i = &$sub;
- $single |= pop(@stack);
- @i;
- }
- else {
- $i = &$sub;
- $single |= pop(@stack);
- $i;
- }
-}
-
-$trace = $signal = $single = 0; # uninitialized warning suppression
-
-@hist = ('?');
-$SIG{'INT'} = "DB::catch";
-$deep = 100; # warning if stack gets this deep
-$window = 10;
-$preview = 3;
-
-@stack = (0);
-@ARGS = @ARGV;
-for (@args) {
- s/'/\\'/g;
- s/(.*)/'$1'/ unless /^-?[\d.]+$/;
-}
-
-if (-f $rcfile) {
- do "./$rcfile";
-}
-elsif (-f "$ENV{'LOGDIR'}/$rcfile") {
- do "$ENV{'LOGDIR'}/$rcfile";
-}
-elsif (-f "$ENV{'HOME'}/$rcfile") {
- do "$ENV{'HOME'}/$rcfile";
-}
+#use Carp; # This did break, left for debuggin
1;