perldebguts.pod

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 878 行 · 第 1/3 页

POD
878
字号
=head1 NAMEperldebguts - Guts of Perl debugging =head1 DESCRIPTIONThis is not the perldebug(1) manpage, which tells you how to usethe debugger.  This manpage describes low-level details concerningthe debugger's internals, which range from difficult to impossibleto understand for anyone who isn't incredibly intimate with Perl's guts.Caveat lector.=head1 Debugger InternalsPerl has special debugging hooks at compile-time and run-time usedto create debugging environments.  These hooks are not to be confusedwith the I<perl -Dxxx> command described in L<perlrun>, which isusable only if a special Perl is built per the instructions in theF<INSTALL> podpage in the Perl source tree.For example, whenever you call Perl's built-in C<caller> functionfrom the package C<DB>, the arguments that the corresponding stackframe was called with are copied to the C<@DB::args> array.  Thesemechanisms are enabled by calling Perl with the B<-d> switch.Specifically, the following additional features are enabled(cf. L<perlvar/$^P>):=over 4=item *Perl inserts the contents of C<$ENV{PERL5DB}> (or C<BEGIN {require'perl5db.pl'}> if not present) before the first line of your program.=item *Each array C<@{"_<$filename"}> holds the lines of $filename for afile compiled by Perl.  The same is also true for C<eval>ed stringsthat contain subroutines, or which are currently being executed.The $filename for C<eval>ed strings looks like C<(eval 34)>.Code assertions in regexes look like C<(re_eval 19)>.Values in this array are magical in numeric context: they compareequal to zero only if the line is not breakable.=item *Each hash C<%{"_<$filename"}> contains breakpoints and actions keyedby line number.  Individual entries (as opposed to the whole hash)are settable.  Perl only cares about Boolean true here, althoughthe values used by F<perl5db.pl> have the formC<"$break_condition\0$action">.  The same holds for evaluated strings that contain subroutines, orwhich are currently being executed.  The $filename for C<eval>ed stringslooks like C<(eval 34)> or  C<(re_eval 19)>.=item *Each scalar C<${"_<$filename"}> contains C<"_<$filename">.  This isalso the case for evaluated strings that contain subroutines, orwhich are currently being executed.  The $filename for C<eval>edstrings looks like C<(eval 34)> or C<(re_eval 19)>.=item *After each C<require>d file is compiled, but before it is executed,C<DB::postponed(*{"_<$filename"})> is called if the subroutineC<DB::postponed> exists.  Here, the $filename is the expanded name ofthe C<require>d file, as found in the values of %INC.=item *After each subroutine C<subname> is compiled, the existence ofC<$DB::postponed{subname}> is checked.  If this key exists,C<DB::postponed(subname)> is called if the C<DB::postponed> subroutinealso exists.=item *A hash C<%DB::sub> is maintained, whose keys are subroutine namesand whose values have the form C<filename:startline-endline>.C<filename> has the form C<(eval 34)> for subroutines defined insideC<eval>s, or C<(re_eval 19)> for those within regex code assertions.=item *When the execution of your program reaches a point that can hold abreakpoint, the C<DB::DB()> subroutine is called if any of the variablesC<$DB::trace>, C<$DB::single>, or C<$DB::signal> is true.  These variablesare not C<local>izable.  This feature is disabled when executinginside C<DB::DB()>, including functions called from it unless C<< $^D & (1<<30) >> is true.=item *When execution of the program reaches a subroutine call, a call toC<&DB::sub>(I<args>) is made instead, with C<$DB::sub> holding thename of the called subroutine. (This doesn't happen if the subroutinewas compiled in the C<DB> package.)=backNote that if C<&DB::sub> needs external data for it to work, nosubroutine call is possible without it. As an example, the standarddebugger's C<&DB::sub> depends on the C<$DB::deep> variable(it defines how many levels of recursion deep into the debugger you can gobefore a mandatory break).  If C<$DB::deep> is not defined, subroutinecalls are not possible, even though C<&DB::sub> exists.=head2 Writing Your Own Debugger=head3 Environment VariablesThe C<PERL5DB> environment variable can be used to define a debugger.For example, the minimal "working" debugger (it actually doesn't do anything)consists of one line:  sub DB::DB {}It can easily be defined like this:  $ PERL5DB="sub DB::DB {}" perl -d your-scriptAnother brief debugger, slightly more useful, can be createdwith only the line:  sub DB::DB {print ++$i; scalar <STDIN>}This debugger prints a number which increments for each statementencountered and waits for you to hit a newline before continuingto the next statement.The following debugger is actually useful:  {    package DB;    sub DB  {}    sub sub {print ++$i, " $sub\n"; &$sub}  }It prints the sequence number of each subroutine call and the name of thecalled subroutine.  Note that C<&DB::sub> is being compiled into thepackage C<DB> through the use of the C<package> directive.When it starts, the debugger reads your rc file (F<./.perldb> orF<~/.perldb> under Unix), which can set important options.(A subroutine (C<&afterinit>) can be defined here as well; it is executedafter the debugger completes its own initialization.)After the rc file is read, the debugger reads the PERLDB_OPTSenvironment variable and uses it to set debugger options. Thecontents of this variable are treated as if they were the argumentof an C<o ...> debugger command (q.v. in L<perldebug/Options>).=head3 Debugger internal variablesIn addition to the file and subroutine-related variables mentioned above,the debugger also maintains various magical internal variables.=over 4=item *C<@DB::dbline> is an alias for C<@{"::_<current_file"}>, whichholds the lines of the currently-selected file (compiled by Perl), eitherexplicitly chosen with the debugger's C<f> command, or implicitly by flowof execution.Values in this array are magical in numeric context: they compareequal to zero only if the line is not breakable.=item *C<%DB::dbline>, is an alias for C<%{"::_<current_file"}>, whichcontains breakpoints and actions keyed by line number inthe currently-selected file, either explicitly chosen with thedebugger's C<f> command, or implicitly by flow of execution.As previously noted, individual entries (as opposed to the whole hash)are settable.  Perl only cares about Boolean true here, althoughthe values used by F<perl5db.pl> have the formC<"$break_condition\0$action">.=back=head3 Debugger customization functionsSome functions are provided to simplify customization.=over 4=item *See L<perldebug/"Configurable Options"> for a description of options parsed byC<DB::parse_options(string)>.=item *C<DB::dump_trace(skip[,count])> skips the specified number of framesand returns a list containing information about the calling frames (allof them, if C<count> is missing).  Each entry is reference to a hashwith keys C<context> (either C<.>, C<$>, or C<@>), C<sub> (subroutinename, or info about C<eval>), C<args> (C<undef> or a reference toan array), C<file>, and C<line>.=item *C<DB::print_trace(FH, skip[, count[, short]])> printsformatted info about caller frames.  The last two functions may beconvenient as arguments to C<< < >>, C<< << >> commands.=backNote that any variables and functions that are not documented inthis manpages (or in L<perldebug>) are considered for internal   use only, and as such are subject to change without notice.=head1 Frame Listing Output ExamplesThe C<frame> option can be used to control the output of frame information.  For example, contrast this expression trace: $ perl -de 42 Stack dump during die enabled outside of evals. Loading DB routines from perl5db.pl patch level 0.94 Emacs support available. Enter h or `h h' for help. main::(-e:1):   0   DB<1> sub foo { 14 }   DB<2> sub bar { 3 }   DB<3> t print foo() * bar() main::((eval 172):3):   print foo() + bar(); main::foo((eval 168):2): main::bar((eval 170):2): 42with this one, once the C<o>ption C<frame=2> has been set:   DB<4> o f=2                frame = '2'   DB<5> t print foo() * bar() 3:      foo() * bar() entering main::foo  2:     sub foo { 14 }; exited main::foo entering main::bar  2:     sub bar { 3 }; exited main::bar 42By way of demonstration, we present below a laborious listingresulting from setting your C<PERLDB_OPTS> environment variable tothe value C<f=n N>, and running I<perl -d -V> from the command line.Examples use various values of C<n> are shown to give you a feelfor the difference between settings.  Long those it may be, thisis not a complete listing, but only excerpts.=over 4=item 1  entering main::BEGIN   entering Config::BEGIN    Package lib/Exporter.pm.    Package lib/Carp.pm.   Package lib/Config.pm.   entering Config::TIEHASH   entering Exporter::import    entering Exporter::export  entering Config::myconfig   entering Config::FETCH   entering Config::FETCH   entering Config::FETCH   entering Config::FETCH=item 2  entering main::BEGIN   entering Config::BEGIN    Package lib/Exporter.pm.    Package lib/Carp.pm.   exited Config::BEGIN   Package lib/Config.pm.   entering Config::TIEHASH   exited Config::TIEHASH   entering Exporter::import    entering Exporter::export    exited Exporter::export

⌨️ 快捷键说明

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