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

📄 perldebug.pod

📁 MSYS在windows下模拟了一个类unix的终端
💻 POD
📖 第 1 页 / 共 3 页
字号:
possible.=item C<ReadLine>If false, readline support in the debugger is disabled in orderto debug applications that themselves use ReadLine.=item C<NonStop>If set, the debugger goes into non-interactive mode until interrupted, orprogrammatically by setting $DB::signal or $DB::single.=backHere's an example of using the C<$ENV{PERLDB_OPTS}> variable:    $ PERLDB_OPTS="NonStop frame=2" perl -d myprogramThat will run the script B<myprogram> without human intervention,printing out the call tree with entry and exit points.  Note thatC<NonStop=1 frame=2> is equivalent to C<N f=2>, and that originally,options could be uniquely abbreviated by the first letter (modulothe C<Dump*> options).  It is nevertheless recommended that youalways spell them out in full for legibility and future compatibility.Other examples include    $ PERLDB_OPTS="NonStop frame=2" perl -d myprogramwhich runs script non-interactively, printing info on each entryinto a subroutine and each executed line into the file named F<listing>.(If you interrupt it, you would better reset C<LineInfo> to something"interactive"!)Other examples include (using standard shell syntax to show environmentvariable settings):  $ ( PERLDB_OPTS="NonStop frame=1 AutoTrace LineInfo=tperl.out"      perl -d myprogram )which may be useful for debugging a program that uses C<Term::ReadLine>itself.  Do not forget to detach your shell from the TTY in the window thatcorresponds to F</dev/ttyXX>, say, by issuing a command like  $ sleep 1000000See L<perldebguts/"Debugger Internals"> for details.=head2 Debugger input/output=over 8=item PromptThe debugger prompt is something like    DB<8>or even    DB<<17>>where that number is the command number, and which you'd use toaccess with the built-in B<csh>-like history mechanism.  For example,C<!17> would repeat command number 17.  The depth of the anglebrackets indicates the nesting depth of the debugger.  You couldget more than one set of brackets, for example, if you'd alreadyat a breakpoint and then printed the result of a function call thatitself has a breakpoint, or you step into an expression via C<s/n/texpression> command.=item Multiline commandsIf you want to enter a multi-line command, such as a subroutinedefinition with several statements or a format, escape the newlinethat would normally end the debugger command with a backslash.Here's an example:      DB<1> for (1..4) {         \      cont:     print "ok\n";   \      cont: }      ok      ok      ok      okNote that this business of escaping a newline is specific to interactivecommands typed into the debugger.=item Stack backtraceHere's an example of what a stack backtrace via C<T> command mightlook like:    $ = main::infested called from file `Ambulation.pm' line 10    @ = Ambulation::legs(1, 2, 3, 4) called from file `camel_flea' line 7    $ = main::pests('bactrian', 4) called from file `camel_flea' line 4The left-hand character up there indicates the context in which thefunction was called, with C<$> and C<@> meaning scalar or listcontexts respectively, and C<.> meaning void context (which isactually a sort of scalar context).  The display above saysthat you were in the function C<main::infested> when you ran thestack dump, and that it was called in scalar context from line10 of the file I<Ambulation.pm>, but without any arguments at all,meaning it was called as C<&infested>.  The next stack frame showsthat the function C<Ambulation::legs> was called in list contextfrom the I<camel_flea> file with four arguments.  The last stackframe shows that C<main::pests> was called in scalar context,also from I<camel_flea>, but from line 4.If you execute the C<T> command from inside an active C<use>statement, the backtrace will contain both a C<require> frame andan C<eval>) frame.=item Line Listing FormatThis shows the sorts of output the C<l> command can produce:    DB<<13>> l  101:                @i{@i} = ();  102:b               @isa{@i,$pack} = ()  103                     if(exists $i{$prevpack} || exists $isa{$pack});  104             }  105  106             next  107==>              if(exists $isa{$pack});  108  109:a           if ($extra-- > 0) {  110:                %isa = ($pack,1);Breakable lines are marked with C<:>.  Lines with breakpoints aremarked by C<b> and those with actions by C<a>.  The line that'sabout to be executed is marked by C<< ==> >>.Please be aware that code in debugger listings may not look the sameas your original source code.  Line directives and external sourcefilters can alter the code before Perl sees it, causing code to movefrom its original positions or take on entirely different forms.=item Frame listingWhen the C<frame> option is set, the debugger would print entered (andoptionally exited) subroutines in different styles.  See L<perldebguts>for incredibly long examples of these.=back=head2 Debugging compile-time statementsIf you have compile-time executable statements (such as code withinBEGIN and CHECK blocks or C<use> statements), these will I<not> bestopped by debugger, although C<require>s and INIT blocks will, andcompile-time statements can be traced with C<AutoTrace> option setin C<PERLDB_OPTS>).  From your own Perl code, however, you cantransfer control back to the debugger using the following statement,which is harmless if the debugger is not running:    $DB::single = 1;If you set C<$DB::single> to 2, it's equivalent to havingjust typed the C<n> command, whereas a value of 1 means the C<s>command.  The C<$DB::trace>  variable should be set to 1 to simulatehaving typed the C<t> command.Another way to debug compile-time code is to start the debugger, set abreakpoint on the I<load> of some module:    DB<7> b load f:/perllib/lib/Carp.pm  Will stop on load of `f:/perllib/lib/Carp.pm'.and then restart the debugger using the C<R> command (if possible).  One can use C<bcompile subname> for the same purpose.=head2 Debugger CustomizationThe debugger probably contains enough configuration hooks that youwon't ever have to modify it yourself.  You may change the behaviourof debugger from within the debugger using its C<O> command, fromthe command line via the C<PERLDB_OPTS> environment variable, andfrom customization files.You can do some customization by setting up a F<.perldb> file, whichcontains initialization code.  For instance, you could make aliaseslike these (the last one is one people expect to be there):    $DB::alias{'len'}  = 's/^len(.*)/p length($1)/';    $DB::alias{'stop'} = 's/^stop (at|in)/b/';    $DB::alias{'ps'}   = 's/^ps\b/p scalar /';    $DB::alias{'quit'} = 's/^quit(\s*)/exit/';You can change options from F<.perldb> by using calls like this one;    parse_options("NonStop=1 LineInfo=db.out AutoTrace=1 frame=2");The code is executed in the package C<DB>.  Note that F<.perldb> isprocessed before processing C<PERLDB_OPTS>.  If F<.perldb> defines thesubroutine C<afterinit>, that function is called after debuggerinitialization ends.  F<.perldb> may be contained in the currentdirectory, or in the home directory.  Because this file is sourcedin by Perl and may contain arbitrary commands, for security reasons,it must be owned by the superuser or the current user, and writableby no one but its owner.If you want to modify the debugger, copy F<perl5db.pl> from thePerl library to another name and hack it to your heart's content.You'll then want to set your C<PERL5DB> environment variable to saysomething like this:    BEGIN { require "myperl5db.pl" }As a last resort, you could also use C<PERL5DB> to customize the debuggerby directly setting internal variables or calling debugger functions.Note that any variables and functions that are not documented inthis document (or in L<perldebguts>) are considered for internaluse only, and as such are subject to change without notice.=head2 Readline SupportAs shipped, the only command-line history supplied is a simplistic onethat checks for leading exclamation points.  However, if you installthe Term::ReadKey and Term::ReadLine modules from CPAN, you willhave full editing capabilities much like GNU I<readline>(3) provides.Look for these in the F<modules/by-module/Term> directory on CPAN.These do not support normal B<vi> command-line editing, however.A rudimentary command-line completion is also available.Unfortunately, the names of lexical variables are not available forcompletion.=head2 Editor Support for DebuggingIf you have the FSF's version of B<emacs> installed on your system,it can interact with the Perl debugger to provide an integratedsoftware development environment reminiscent of its interactionswith C debuggers.Perl comes with a start file for making B<emacs> act like asyntax-directed editor that understands (some of) Perl's syntax.Look in the I<emacs> directory of the Perl source distribution.A similar setup by Tom Christiansen for interacting with anyvendor-shipped B<vi> and the X11 window system is also available.This works similarly to the integrated multiwindow support thatB<emacs> provides, where the debugger drives the editor.  At thetime of this writing, however, that tool's eventual location in thePerl distribution was uncertain.Users of B<vi> should also look into B<vim> and B<gvim>, the mouseyand windy version, for coloring of Perl keywords.  Note that only perl can truly parse Perl, so all such CASE toolsfall somewhat short of the mark, especially if you don't programyour Perl as a C programmer might.=head2 The Perl ProfilerIf you wish to supply an alternative debugger for Perl to run, justinvoke your script with a colon and a package argument given to theB<-d> flag.  The most popular alternative debuggers for Perl is thePerl profiler.  Devel::DProf is now included with the standard Perldistribution.  To profile your Perl program in the file F<mycode.pl>,just type:    $ perl -d:DProf mycode.plWhen the script terminates the profiler will dump the profileinformation to a file called F<tmon.out>.  A tool like B<dprofpp>,also supplied with the standard Perl distribution, can be used tointerpret the information in that profile.=head1 Debugging regular expressionsC<use re 'debug'> enables you to see the gory details of how thePerl regular expression engine works.  In order to understand thistypically voluminous output, one must not only have some idea aboutabout how regular expression matching works in general, but alsoknow how Perl's regular expressions are internally compiled intoan automaton.  These matters are explored in some detail inL<perldebguts/"Debugging regular expressions">.=head1 Debugging memory usagePerl contains internal support for reporting its own memory usage,but this is a fairly advanced concept that requires some understandingof how memory allocation works.See L<perldebguts/"Debugging Perl memory usage"> for the details.=head1 SEE ALSOYou did try the B<-w> switch, didn't you?L<perldebguts>,L<re>,L<DB>,L<Devel::Dprof>,L<dprofpp>,L<Dumpvalue>,andL<perlrun>.=head1 BUGSYou cannot get stack frame information or in any fashion debug functionsthat were not compiled by Perl, such as those from C or C++ extensions.If you alter your @_ arguments in a subroutine (such as with C<shift>or C<pop>, the stack backtrace will not show the original values.The debugger does not currently work in conjunction with the B<-W>command-line switch, because it itself is not free of warnings.If you're in a slow syscall (like C<wait>ing, C<accept>ing, or C<read>ingfrom your keyboard or a socket) and haven't set up your own C<$SIG{INT}>handler, then you won't be able to CTRL-C your way back to the debugger,because the debugger's own C<$SIG{INT}> handler doesn't understand thatit needs to raise an exception to longjmp(3) out of slow syscalls.

⌨️ 快捷键说明

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