📄 ch20_02.htm
字号:
<html><head><title>Debugger Commands (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly & Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Debugger Commands"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch20_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch20_01.htm">Chapter 20: The Perl Debugger</a></td><td align="right" valign="top" width="172"><a href="ch20_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">20.2. Debugger Commands</h2><p><a name="INDEX-3525"></a><a name="INDEX-3526"></a><a name="INDEX-3527"></a><a name="INDEX-3528"></a>When you type commands into the debugger, you don't need to terminatethem with a semicolon. Use a backslash to continue lines (but only inthe debugger).</p><p>Since the debugger uses <tt class="literal">eval</tt> to execute commands,<tt class="literal">my</tt>, <tt class="literal">our</tt>, and<tt class="literal">local</tt> settings will disappear once the commandreturns. If a debugger command coincides with some function in yourown program, simply precede the function call with anything thatdoesn't look like a debugger command, such as a leading<tt class="literal">;</tt> or a <tt class="literal">+</tt>.</p><p>If the output of a debugger built-in command scrolls past yourscreen, just precede the command with a leading pipe symbol so it'srun through your pager:<blockquote><pre class="programlisting">DB<1> <b class="emphasis-bold">|h</b></pre></blockquote></p><p>The debugger has plenty of commands, and we divide them (somewhatarbitrarily) into stepping and running, breakpoints, tracing, display,locating code, automatic command execution, and, of course, miscellaneous.</p><p>Perhaps the most important command is <tt class="literal">h</tt>, whichprovides help. If you type <tt class="literal">h h</tt> at the debuggerprompt, you'll get a compact help listing designed to fit on onescreen. If you type <tt class="literal">h</tt><em class="replaceable">COMMAND</em>, you'll get help on that debuggercommand.</p><h3 class="sect2">20.2.1. Stepping and Running</h3><p><a name="INDEX-3529"></a><a name="INDEX-3530"></a>The debugger operates by <em class="emphasis">stepping</em> through yourprogram line by line. The following commands let you control what youskip over and where you stop.</p><dl><dt><b><tt class="literal">s</tt></b></dt><dt><b><tt class="literal">s</tt><em class="replaceable">EXPR</em></b></dt><dd><p><a name="INDEX-"></a>The <tt class="literal">s</tt> debugger command single-steps through theprogram. That is, the debugger will execute the next line of yourprogram until another statement is reached, descending into subroutinecalls as necessary. If the next line to execute involves a functioncall, then the debugger stops at the first line inside thatfunction. If an <em class="replaceable">EXPR</em> is supplied thatincludes function calls, these will be single-stepped, too.</p></dd><dt><b><tt class="literal">n</tt></b></dt><dt><b><tt class="literal">n</tt> <em class="replaceable">EXPR</em></b></dt><dd><p><a name="INDEX-"></a>The <tt class="literal">n</tt> command executes subroutine calls, withoutstepping through them, until the beginning of the next statement atthis same level (or higher). If an <em class="replaceable">EXPR</em> issupplied that includes function calls, those functions will beexecuted with stops before each statement.</p></dd><dt><b><tt class="literal"><ENTER></tt></b></dt><dd><p>If you just hit enter at the debugger prompt, the previous<tt class="literal">n</tt> or <tt class="literal">s</tt> command is repeated.</p></dd><dt><b><tt class="literal">.</tt></b></dt><dd><p>The <tt class="literal">.</tt> command returns the internal debugger pointer to the linelast executed and prints out that line.<a name="INDEX-"></a></p></dd><dt><b><tt class="literal">r</tt></b></dt><dd><p><a name="INDEX-"></a>This command continues until the currently executingsubroutine returns. It displays the return value if the <tt class="literal">PrintRet</tt> option isset, which it is by default.</p></dd></dl><p></p><h3 class="sect2">20.2.2. Breakpoints</h3><a name="INDEX-3531"></a><a name="INDEX-3532"></a><dl><dt><b><tt class="literal">b</tt></b></dt><dt><b><tt class="literal">b</tt> <em class="replaceable">LINE</em></b></dt><dt><b><tt class="literal">b</tt> <em class="replaceable">CONDITION</em></b></dt><dt><b><tt class="literal">b</tt> <em class="replaceable">LINE</em> <em class="replaceable">CONDITION</em></b></dt><dt><b><tt class="literal">b</tt> <em class="replaceable">SUBNAME</em></b></dt><dt><b><tt class="literal">b</tt> <em class="replaceable">SUBNAME</em> <em class="replaceable">CONDITION</em></b></dt><dt><b><tt class="literal">b postpone</tt> <em class="replaceable">SUBNAME</em></b></dt><dt><b><tt class="literal">b postpone</tt> <em class="replaceable">SUBNAME</em> <em class="replaceable">CONDITION</em></b></dt><dt><b><tt class="literal">b compile</tt> <em class="replaceable">SUBNAME</em></b></dt><dt><b><tt class="literal">b load</tt> <em class="replaceable">FILENAME</em></b></dt><dd><p>The <tt class="literal">b</tt> debugger command sets a <em class="emphasis">breakpoint</em> before <em class="replaceable">LINE</em>, tellingthe debugger to stop the program at that point so that youcan poke around. If <em class="replaceable">LINE</em> is omitted, sets a breakpoint on the linethat's about to execute. If <em class="replaceable">CONDITION</em> is specified, it's evaluatedeach time the statement is reached: a breakpoint is triggered only if<em class="replaceable">CONDITION</em> is true. Breakpoints may only be set on lines that beginan executable statement. Note that conditions don't use <tt class="literal">if</tt>:<blockquote><pre class="programlisting">b 237 $x > 30b 237 ++$count237 < 11b 33 /pattern/i</pre></blockquote>The <tt class="literal">b</tt><em class="replaceable">SUBNAME</em> form sets a (possibly conditional) breakpointbefore the first line of the named subroutine. <em class="replaceable">SUBNAME</em> may be avariable containing a code reference; if so, <em class="replaceable">CONDITION</em> is notsupported.</p><p>There are several ways to set a breakpoint on code that hasn't evenbeen compiled yet. The <tt class="literal">b postpone</tt> form sets a (possiblyconditional) breakpoint at the first line of <em class="replaceable">SUBNAME</em> after it iscompiled.</p><p>The <tt class="literal">b compile</tt> form sets a breakpoint on the first statement to beexecuted after <em class="replaceable">SUBNAME</em> is compiled. Note that unlike the<tt class="literal">postpone</tt> form, this statement is outside the subroutine in questionbecause the subroutine hasn't been called yet, only compiled.</p><p>The <tt class="literal">b load</tt> form sets a breakpoint on the first executed line ofthe file. The <em class="replaceable">FILENAME</em> should be a full pathname as found in the <tt class="literal">%INC</tt>values.</p></dd><dt><b><tt class="literal">d</tt></b></dt><dt><b><tt class="literal">d</tt> <em class="replaceable">LINE</em></b></dt><dd><p><a name="INDEX-3533"></a><a name="INDEX-3534"></a>This command deletes the breakpoint at <em class="replaceable">LINE</em>; if omitted, it deletesthe breakpoint on the line about to execute.</p></dd><dt><b><tt class="literal">D</tt></b></dt><dd><p>This command deletes all breakpoints.</p></dd><dt><b><tt class="literal">L</tt></b></dt><dd><p><a name="INDEX-3535"></a><a name="INDEX-3536"></a>This command lists all the breakpoints and actions.</p></dd><dt><b><tt class="literal">c</tt></b></dt><dt><b><tt class="literal">c</tt> <em class="replaceable">LINE</em></b></dt><dd><p>This command continues execution, optionally inserting a one-time-onlybreakpoint at the specified <em class="replaceable">LINE</em>.</p></dd></dl><h3 class="sect2">20.2.3. Tracing</h3><a name="INDEX-3537"></a><a name="INDEX-3538"></a><dl><dt><b><tt class="literal">T</tt></b></dt><dd><p>This command produces a stack backtrace.</p></dd><dt><b><tt class="literal">t</tt></b></dt><dt><b><tt class="literal">t</tt> <em class="replaceable">EXPR</em></b></dt><dd><p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -