📄 ch06_01.htm
字号:
<html><head><title>Debugging (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch05_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch06_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h1 class="chapter">Chapter 6. Debugging</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4> <p> <a href="#perlnut2-CHP-6-SECT-1">The Perl Debugger</a><br /><a href="ch06_02.htm">Debugger Commands</a><br /><a href="ch06_03.htm">Using the Debugger</a><br /><a href="ch06_04.htm">Customizing the Debugger</a><br /><a href="ch06_05.htm">The Perl Profiler</a><br /><a href="ch06_06.htm">The perlbug Program</a><br /></p></div><p>Of course everyone writes perfect code on the first try, but on thoserare occasions when something goes wrong, and you'rehaving trouble with your Perl script, there are several things youcan do<a name="INDEX-1109" /></a>: </p><ul><li><p>Run the script with the <em class="emphasis">-w</em> switch, which printswarnings about possible problems in your code.</p></li><li><p>Use the Perl debugger.</p></li><li><p>Use another debugger, or a profiler such as the Devel::DProf module.</p></li></ul><p>The major focus of this chapter is the Perl debugger, which providesan interactive Perl environment. The chapter also describes the DProfmodule and the <em class="emphasis">dprofpp</em> program that comes withit; together they can provide you with a profile of your Perl script.If you've ever used any debugger, and you understandconcepts such as breakpoints and backtraces, you'llhave no trouble learning to use the Perl debugger. Even if youhaven't used another debugger, the commanddescriptions and some experimenting should get you going.</p><div class="sect1"><a name="perlnut2-CHP-6-SECT-1" /></a><h2 class="sect1">6.1. The Perl Debugger</h2><p><a name="INDEX-1110" /></a><a name="INDEX-1111" /></a><a name="INDEX-1112" /></a>Torun your script under the Perl source debugger, invoke Perl with the<em class="emphasis">-d</em> switch:</p><blockquote><pre class="code">perl -d myprogram</pre></blockquote><p>This works like an interactive Perl environment, prompting fordebugger commands that let you examine source code, set breakpoints,get stack backtraces, change the values of variables, etc. If yourprogram takes any switches or arguments, you must include them in thecommand:</p><blockquote><pre class="code">perl -d myprogram myinput</pre></blockquote><p>In Perl, the debugger is not a separate program as it is in thetypical compiled environment. Instead, the <em class="emphasis">-d</em>flag tells the compiler to insert source information into the parsetrees it's about to hand off to the interpreter.This means your code must compile correctly for the debugger to workon it—the debugger won't run until you havefixed all compiler errors.</p><p>After your code has compiled, and the debugger has started up, theprogram halts right before the first runtime executable statement(see <a href="ch06_03.htm#perlnut2-CHP-6-SECT-3">Section 6.3, "Using the Debugger"</a>regarding compile time statements) and waits for you to enter adebugger command. Whenever the debugger halts and shows you a line ofcode, it always displays the line it's about toexecute, rather than the one it has just executed.</p><p>Any command not recognized by the debugger is directly executed asPerl code in the current package. To be recognized by the debugger,the command must start at the beginning of the line; otherwise, thedebugger assumes it's for Perl.</p></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch05_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch06_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">5. Function Reference</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">6.2. Debugger Commands</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"> </map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -