⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db.pm

📁 MSYS在windows下模拟了一个类unix的终端
💻 PM
📖 第 1 页 / 共 2 页
字号:
  my $name = shift;  $name =~ s/\'/::/;  $name = "${DB::package}\:\:" . $name if $name !~ /::/;  $name = "main" . $name if substr($name,0,2) eq "::";  my($fname, $from, $to) = ($DB::sub{$name} =~ /^(.*):(\d+)-(\d+)$/);  if ($from) {    # XXX this needs local()-ization of some sort    *DB::dbline = "::_<$fname";    ++$from while $DB::dbline[$from] == 0 && $from < $to;    return $from;  }  return undef;}sub clr_breaks {  my $s = shift;  my $i;  if (@_) {    while (@_) {      $i = shift;      $i = _find_subline($i) if ($i =~ /\D/);      $s->output("Subroutine not found.\n") unless $i;      if (defined $DB::dbline{$i}) {        $DB::dbline{$i} =~ s/^[^\0]+//;        if ($DB::dbline{$i} =~ s/^\0?$//) {          delete $DB::dbline{$i};        }      }    }  }  else {    for ($i = 1; $i <= $#DB::dbline ; $i++) {      if (defined $DB::dbline{$i}) {        $DB::dbline{$i} =~ s/^[^\0]+//;        if ($DB::dbline{$i} =~ s/^\0?$//) {          delete $DB::dbline{$i};        }      }    }  }}sub set_action {  my $s = shift;  my $i = shift;  my $act = shift;  $i = _find_subline($i) if ($i =~ /\D/);  $s->output("Subroutine not found.\n") unless $i;  if ($i) {    if ($DB::dbline[$i] == 0) {      $s->output("Line $i not actionable.\n");    }    else {      $DB::dbline{$i} =~ s/\0[^\0]*//;      $DB::dbline{$i} .= "\0" . $act;    }  }}sub clr_actions {  my $s = shift;  my $i;  if (@_) {    while (@_) {      my $i = shift;      $i = _find_subline($i) if ($i =~ /\D/);      $s->output("Subroutine not found.\n") unless $i;      if ($i && $DB::dbline[$i] != 0) {	$DB::dbline{$i} =~ s/\0[^\0]*//;	delete $DB::dbline{$i} if $DB::dbline{$i} =~ s/^\0?$//;      }    }  }  else {    for ($i = 1; $i <= $#DB::dbline ; $i++) {      if (defined $DB::dbline{$i}) {	$DB::dbline{$i} =~ s/\0[^\0]*//;	delete $DB::dbline{$i} if $DB::dbline{$i} =~ s/^\0?$//;      }    }  }}sub prestop {  my ($client, $val) = @_;  return defined($val) ? $preeval->{$client} = $val : $preeval->{$client};}sub poststop {  my ($client, $val) = @_;  return defined($val) ? $posteval->{$client} = $val : $posteval->{$client};}## "pure virtual" methods## client-specific pre/post-stop actions.sub cprestop {}sub cpoststop {}# client complete startupsub awaken {}sub skippkg {  my $s = shift;  push @skippkg, @_ if @_;}sub evalcode {  my ($client, $val) = @_;  if (defined $val) {    $running = 2;    # hand over to DB() to evaluate in its context    $ineval->{$client} = $val;  }  return $ineval->{$client};}sub ready {  my $s = shift;  return $ready = 1;}# stubs    sub init {}sub stop {}sub idle {}sub cleanup {}sub output {}## client init#for (@clients) { $_->init }$SIG{'INT'} = \&DB::catch;# disable this if stepping through END blocks is desired# (looks scary and deconstructivist with Swat)END { $ready = 0 }1;__END__=head1 NAMEDB - programmatic interface to the Perl debugging API (draft, subject tochange)=head1 SYNOPSIS    package CLIENT;    use DB;    @ISA = qw(DB);    # these (inherited) methods can be called by the client    CLIENT->register()      # register a client package name    CLIENT->done()          # de-register from the debugging API    CLIENT->skippkg('hide::hide')  # ask DB not to stop in this package    CLIENT->cont([WHERE])       # run some more (until BREAK or another breakpt)    CLIENT->step()              # single step    CLIENT->next()              # step over    CLIENT->ret()               # return from current subroutine    CLIENT->backtrace()         # return the call stack description    CLIENT->ready()             # call when client setup is done    CLIENT->trace_toggle()      # toggle subroutine call trace mode    CLIENT->subs([SUBS])        # return subroutine information    CLIENT->files()             # return list of all files known to DB    CLIENT->lines()             # return lines in currently loaded file    CLIENT->loadfile(FILE,LINE) # load a file and let other clients know    CLIENT->lineevents()        # return info on lines with actions    CLIENT->set_break([WHERE],[COND])    CLIENT->set_tbreak([WHERE])    CLIENT->clr_breaks([LIST])    CLIENT->set_action(WHERE,ACTION)    CLIENT->clr_actions([LIST])    CLIENT->evalcode(STRING)  # eval STRING in executing code's context    CLIENT->prestop([STRING]) # execute in code context before stopping    CLIENT->poststop([STRING])# execute in code context before resuming    # These methods will be called at the appropriate times.    # Stub versions provided do nothing.    # None of these can block.    CLIENT->init()          # called when debug API inits itself    CLIENT->stop(FILE,LINE) # when execution stops    CLIENT->idle()          # while stopped (can be a client event loop)    CLIENT->cleanup()       # just before exit    CLIENT->output(LIST)    # called to print any output that API must show=head1 DESCRIPTIONPerl debug information is frequently required not just by debuggers,but also by modules that need some "special" information to do theirjob properly, like profilers.This module abstracts and provides all of the hooks into Perl internaldebugging functionality, so that various implementations of Perl debuggers(or packages that want to simply get at the "privileged" debugging data)can all benefit from the development of this common code.  Currently usedby Swat, the perl/Tk GUI debugger.Note that multiple "front-ends" can latch into this debugging APIsimultaneously.  This is intended to facilitate things likedebugging with a command line and GUI at the same time, debugging debuggers etc.  [Sounds nice, but this needs some serious support -- GSAR]In particular, this API does B<not> provide the following functions:=over 4=item *data display=item *command processing=item *command alias management=item *user interface (tty or graphical)=backThese are intended to be services performed by the clients of this API.This module attempts to be squeaky clean w.r.t C<use strict;> and whenwarnings are enabled.=head2 Global VariablesThe following "public" global names can be read by clients of this API.Beware that these should be considered "readonly".=over 8=item  $DB::subName of current executing subroutine.=item  %DB::subThe keys of this hash are the names of all the known subroutines.  Each valueis an encoded string that has the sprintf(3) format C<("%s:%d-%d", filename, fromline, toline)>.=item  $DB::singleSingle-step flag.  Will be true if the API will stop at the next statement.=item  $DB::signalSignal flag. Will be set to a true value if a signal was caught.  Clients maycheck for this flag to abort time-consuming operations.=item  $DB::traceThis flag is set to true if the API is tracing through subroutine calls.=item  @DB::argsContains the arguments of current subroutine, or the C<@ARGV> array if in the toplevel context.=item  @DB::dblineList of lines in currently loaded file.=item  %DB::dblineActions in current file (keys are line numbers).  The values are strings thathave the sprintf(3) format C<("%s\000%s", breakcondition, actioncode)>. =item  $DB::packagePackage namespace of currently executing code.=item  $DB::filenameCurrently loaded filename.=item  $DB::subnameFully qualified name of currently executing subroutine.=item  $DB::linenoLine number that will be executed next.=back=head2 API MethodsThe following are methods in the DB base class.  A client mustaccess these methods by inheritance (*not* by calling them directly),since the API keeps track of clients through the inheritancemechanism.=over 8=item CLIENT->register()register a client object/package=item CLIENT->evalcode(STRING)eval STRING in executing code context=item CLIENT->skippkg('D::hide')ask DB not to stop in these packages=item CLIENT->run()run some more (until a breakpt is reached)=item CLIENT->step()single step=item CLIENT->next()step over=item CLIENT->done()de-register from the debugging API=back=head2 Client Callback MethodsThe following "virtual" methods can be defined by the client.  They willbe called by the API at appropriate points.  Note that unless specifiedotherwise, the debug API only defines empty, non-functional default versionsof these methods.=over 8=item CLIENT->init()Called after debug API inits itself.=item CLIENT->prestop([STRING])Usually inherited from DB package.  If no arguments are passed,returns the prestop action string.=item CLIENT->stop()Called when execution stops (w/ args file, line).=item CLIENT->idle()Called while stopped (can be a client event loop).=item CLIENT->poststop([STRING])Usually inherited from DB package.  If no arguments are passed,returns the poststop action string.=item CLIENT->evalcode(STRING)Usually inherited from DB package.  Ask for a STRING to be C<eval>-edin executing code context.=item CLIENT->cleanup()Called just before exit.=item CLIENT->output(LIST)Called when API must show a message (warnings, errors etc.).=back=head1 BUGSThe interface defined by this module is missing some of the later additionsto perl's debugging functionality.  As such, this interface should be consideredhighly experimental and subject to change.=head1 AUTHORGurusamy Sarathy	gsar@activestate.comThis code heavily adapted from an early version of perl5db.pl attributableto Larry Wall and the Perl Porters.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -