perldebug.html
来自「perl教程」· HTML 代码 · 共 1,321 行 · 第 1/4 页
HTML
1,321 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>perldebug - Perl debugging</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>perldebug - Perl debugging</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#the_perl_debugger">The Perl Debugger</a></li>
<ul>
<li><a href="#debugger_commands">Debugger Commands</a></li>
<li><a href="#configurable_options">Configurable Options</a></li>
<li><a href="#debugger_input_output">Debugger input/output</a></li>
<li><a href="#debugging_compiletime_statements">Debugging compile-time statements</a></li>
<li><a href="#debugger_customization">Debugger Customization</a></li>
<li><a href="#readline_support">Readline Support</a></li>
<li><a href="#editor_support_for_debugging">Editor Support for Debugging</a></li>
<li><a href="#the_perl_profiler">The Perl Profiler</a></li>
</ul>
<li><a href="#debugging_regular_expressions">Debugging regular expressions</a></li>
<li><a href="#debugging_memory_usage">Debugging memory usage</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#bugs">BUGS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>perldebug - Perl debugging</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>First of all, have you tried using the <strong>-w</strong> switch?</p>
<p>If you're new to the Perl debugger, you may prefer to read
<a href="../../lib/Pod/perldebtut.html">the perldebtut manpage</a>, which is a tutorial introduction to the debugger .</p>
<p>
</p>
<hr />
<h1><a name="the_perl_debugger">The Perl Debugger</a></h1>
<p>If you invoke Perl with the <strong>-d</strong> switch, your script runs under the
Perl source debugger. This works like an interactive Perl
environment, prompting for debugger commands that let you examine
source code, set breakpoints, get stack backtraces, change the values of
variables, etc. This is so convenient that you often fire up
the debugger all by itself just to test out Perl constructs
interactively to see what they do. For example:</p>
<pre>
$ perl -d -e 42</pre>
<p>In Perl, the debugger is not a separate program the way it usually is in the
typical compiled environment. Instead, the <strong>-d</strong> flag tells the compiler
to insert source information into the parse trees it's about to hand off
to the interpreter. That means your code must first compile correctly
for the debugger to work on it. Then when the interpreter starts up, it
preloads a special Perl library file containing the debugger.</p>
<p>The program will halt <em>right before</em> the first run-time executable
statement (but see below regarding compile-time statements) and ask you
to enter a debugger command. Contrary to popular expectations, whenever
the debugger halts and shows you a line of code, it always displays the
line it's <em>about</em> to execute, rather than the one it has just executed.</p>
<p>Any command not recognized by the debugger is directly executed
(<a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>'d) as Perl code in the current package. (The debugger
uses the DB package for keeping its own state information.)</p>
<p>Note that the said <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a> is bound by an implicit scope. As a
result any newly introduced lexical variable or any modified
capture buffer content is lost after the eval. The debugger is a
nice environment to learn Perl, but if you interactively experiment using
material which should be in the same scope, stuff it in one line.</p>
<p>For any text entered at the debugger prompt, leading and trailing whitespace
is first stripped before further processing. If a debugger command
coincides with some function in your own program, merely precede the
function with something that doesn't look like a debugger command, such
as a leading <code>;</code> or perhaps a <code>+</code>, or by wrapping it with parentheses
or braces.</p>
<p>
</p>
<h2><a name="debugger_commands">Debugger Commands</a></h2>
<p>The debugger understands the following commands:</p>
<dl>
<dt><strong><a name="item_h">h</a></strong>
<dd>
<p>Prints out a summary help message</p>
</dd>
</li>
<dt><strong><a name="item_h__5bcommand_5d">h [command]</a></strong>
<dd>
<p>Prints out a help message for the given debugger command.</p>
</dd>
</li>
<dt><strong><a name="item_h_h">h h</a></strong>
<dd>
<p>The special argument of <a href="#item_h_h"><code>h h</code></a> produces the entire help page, which is quite long.</p>
</dd>
<dd>
<p>If the output of the <a href="#item_h_h"><code>h h</code></a> command (or any command, for that matter) scrolls
past your screen, precede the command with a leading pipe symbol so
that it's run through your pager, as in</p>
</dd>
<dd>
<pre>
DB> |h h</pre>
</dd>
<dd>
<p>You may change the pager which is used via <code>o pager=...</code> command.</p>
</dd>
</li>
<dt><strong><a name="item_p_expr">p expr</a></strong>
<dd>
<p>Same as <code>print {$DB::OUT} expr</code> in the current package. In particular,
because this is just Perl's own <a href="../../lib/Pod/perlfunc.html#item_print"><code>print</code></a> function, this means that nested
data structures and objects are not dumped, unlike with the <a href="../../lib/Pod/perlguts.html#item_x"><code>x</code></a> command.</p>
</dd>
<dd>
<p>The <code>DB::OUT</code> filehandle is opened to <em>/dev/tty</em>, regardless of
where STDOUT may be redirected to.</p>
</dd>
</li>
<dt><strong><a name="item_x__5bmaxdepth_5d_expr">x [maxdepth] expr</a></strong>
<dd>
<p>Evaluates its expression in list context and dumps out the result in a
pretty-printed fashion. Nested data structures are printed out
recursively, unlike the real <a href="../../lib/Pod/perlfunc.html#item_print"><code>print</code></a> function in Perl. When dumping
hashes, you'll probably prefer 'x \%h' rather than 'x %h'.
See <a href="../../lib/Dumpvalue.html">the Dumpvalue manpage</a> if you'd like to do this yourself.</p>
</dd>
<dd>
<p>The output format is governed by multiple options described under
<a href="#configurable_options">Configurable Options</a>.</p>
</dd>
<dd>
<p>If the <code>maxdepth</code> is included, it must be a numeral <em>N</em>; the value is
dumped only <em>N</em> levels deep, as if the <a href="#item_dumpdepth"><code>dumpDepth</code></a> option had been
temporarily set to <em>N</em>.</p>
</dd>
</li>
<dt><strong><a name="item_v__5bpkg__5bvars_5d_5d">V [pkg [vars]]</a></strong>
<dd>
<p>Display all (or some) variables in package (defaulting to <code>main</code>)
using a data pretty-printer (hashes show their keys and values so
you see what's what, control characters are made printable, etc.).
Make sure you don't put the type specifier (like <code>$</code>) there, just
the symbol names, like this:</p>
</dd>
<dd>
<pre>
V DB filename line</pre>
</dd>
<dd>
<p>Use <code>~pattern</code> and <code>!pattern</code> for positive and negative regexes.</p>
</dd>
<dd>
<p>This is similar to calling the <a href="../../lib/Pod/perlguts.html#item_x"><code>x</code></a> command on each applicable var.</p>
</dd>
</li>
<dt><strong><a name="item_x__5bvars_5d">X [vars]</a></strong>
<dd>
<p>Same as <code>V currentpackage [vars]</code>.</p>
</dd>
</li>
<dt><strong><a name="item_y__5blevel__5bvars_5d_5d">y [level [vars]]</a></strong>
<dd>
<p>Display all (or some) lexical variables (mnemonic: <code>mY</code> variables)
in the current scope or <em>level</em> scopes higher. You can limit the
variables that you see with <em>vars</em> which works exactly as it does
for the <code>V</code> and <a href="../../lib/Pod/perlguts.html#item_x"><code>X</code></a> commands. Requires the <code>PadWalker</code> module
version 0.08 or higher; will warn if this isn't installed. Output
is pretty-printed in the same style as for <code>V</code> and the format is
controlled by the same options.</p>
</dd>
</li>
<dt><strong><a name="item_t">T</a></strong>
<dd>
<p>Produce a stack backtrace. See below for details on its output.</p>
</dd>
</li>
<dt><strong><a name="item_s__5bexpr_5d">s [expr]</a></strong>
<dd>
<p>Single step. Executes until the beginning of another
statement, descending into subroutine calls. If an expression is
supplied that includes function calls, it too will be single-stepped.</p>
</dd>
</li>
<dt><strong><a name="item_n__5bexpr_5d">n [expr]</a></strong>
<dd>
<p>Next. Executes over subroutine calls, until the beginning
of the next statement. If an expression is supplied that includes
function calls, those functions will be executed with stops before
each statement.</p>
</dd>
</li>
<dt><strong><a name="item_r">r</a></strong>
<dd>
<p>Continue until the return from the current subroutine.
Dump the return value if the <a href="#item_printret"><code>PrintRet</code></a> option is set (default).</p>
</dd>
</li>
<dt><strong><a name="item__3ccr_3e"><CR></a></strong>
<dd>
<p>Repeat last <a href="../../lib/Pod/perlguts.html#item_n"><code>n</code></a> or <a href="../../lib/Pod/perlguts.html#item_s"><code>s</code></a> command.</p>
</dd>
</li>
<dt><strong><a name="item_c__5bline_7csub_5d">c [line|sub]</a></strong>
<dd>
<p>Continue, optionally inserting a one-time-only breakpoint
at the specified line or subroutine.</p>
</dd>
</li>
<dt><strong><a name="item_l">l</a></strong>
<dd>
<p>List next window of lines.</p>
</dd>
</li>
<dt><strong><a name="item_l_min_2bincr">l min+incr</a></strong>
<dd>
<p>List <code>incr+1</code> lines starting at <code>min</code>.</p>
</dd>
</li>
<dt><strong><a name="item_l_min_2dmax">l min-max</a></strong>
<dd>
<p>List lines <code>min</code> through <code>max</code>. <code>l -</code> is synonymous to <a href="#item__2d"><code>-</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_l_line">l line</a></strong>
<dd>
<p>List a single line.</p>
</dd>
</li>
<dt><strong><a name="item_l_subname">l subname</a></strong>
<dd>
<p>List first window of lines from subroutine. <em>subname</em> may
be a variable that contains a code reference.</p>
</dd>
</li>
<dt><strong><a name="item__2d">-</a></strong>
<dd>
<p>List previous window of lines.</p>
</dd>
</li>
<dt><strong><a name="item_v__5bline_5d">v [line]</a></strong>
<dd>
<p>View a few lines of code around the current line.</p>
</dd>
</li>
<dt><strong><a name="item__2e">.</a></strong>
<dd>
<p>Return the internal debugger pointer to the line last
executed, and print out that line.</p>
</dd>
</li>
<dt><strong><a name="item_f_filename">f filename</a></strong>
<dd>
<p>Switch to viewing a different file or <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a> statement. If <em>filename</em>
is not a full pathname found in the values of %INC, it is considered
a regex.</p>
</dd>
<dd>
<p><a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>ed strings (when accessible) are considered to be filenames:
<a href="../../lib/Pod/perlguts.html#item_f"><code>f (eval 7)</code></a> and <code>f eval 7\b</code> access the body of the 7th <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>ed string
(in the order of execution). The bodies of the currently executed <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>
and of <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>ed strings that define subroutines are saved and thus
accessible.</p>
</dd>
</li>
<dt><strong><a name="item__2fpattern_2f">/pattern/</a></strong>
<dd>
<p>Search forwards for pattern (a Perl regex); final / is optional.
The search is case-insensitive by default.</p>
</dd>
</li>
<dt><strong><a name="item__3fpattern_3f">?pattern?</a></strong>
<dd>
<p>Search backwards for pattern; final ? is optional.
The search is case-insensitive by default.</p>
</dd>
</li>
<dt><strong><a name="item_l__5babw_5d">L [abw]</a></strong>
<dd>
<p>List (default all) actions, breakpoints and watch expressions</p>
</dd>
</li>
<dt><strong><a name="item_s__5b_5b_21_5dregex_5d">S [[!]regex]</a></strong>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?