Install Perl 5.8.8
[msysgit.git] / mingw / html / pod / perldebug.html
blob9492671428abc0ff472e392bf7e71de1016d0057
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>perldebug - Perl debugging</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;perldebug - Perl debugging</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#description">DESCRIPTION</a></li>
24 <li><a href="#the_perl_debugger">The Perl Debugger</a></li>
25 <ul>
27 <li><a href="#debugger_commands">Debugger Commands</a></li>
28 <li><a href="#configurable_options">Configurable Options</a></li>
29 <li><a href="#debugger_input_output">Debugger input/output</a></li>
30 <li><a href="#debugging_compiletime_statements">Debugging compile-time statements</a></li>
31 <li><a href="#debugger_customization">Debugger Customization</a></li>
32 <li><a href="#readline_support">Readline Support</a></li>
33 <li><a href="#editor_support_for_debugging">Editor Support for Debugging</a></li>
34 <li><a href="#the_perl_profiler">The Perl Profiler</a></li>
35 </ul>
37 <li><a href="#debugging_regular_expressions">Debugging regular expressions</a></li>
38 <li><a href="#debugging_memory_usage">Debugging memory usage</a></li>
39 <li><a href="#see_also">SEE ALSO</a></li>
40 <li><a href="#bugs">BUGS</a></li>
41 </ul>
42 <!-- INDEX END -->
44 <hr />
45 <p>
46 </p>
47 <h1><a name="name_x_debug__x_debugger_">NAME
48 </a></h1>
49 <p>perldebug - Perl debugging</p>
50 <p>
51 </p>
52 <hr />
53 <h1><a name="description">DESCRIPTION</a></h1>
54 <p>First of all, have you tried using the <strong>-w</strong> switch?</p>
55 <p>If you're new to the Perl debugger, you may prefer to read
56 <a href="file://C|\msysgit\mingw\html/pod/perldebtut.html">the perldebtut manpage</a>, which is a tutorial introduction to the debugger .</p>
57 <p>
58 </p>
59 <hr />
60 <h1><a name="the_perl_debugger">The Perl Debugger</a></h1>
61 <p>If you invoke Perl with the <strong>-d</strong> switch, your script runs under the
62 Perl source debugger. This works like an interactive Perl
63 environment, prompting for debugger commands that let you examine
64 source code, set breakpoints, get stack backtraces, change the values of
65 variables, etc. This is so convenient that you often fire up
66 the debugger all by itself just to test out Perl constructs
67 interactively to see what they do. For example:
68 </p>
69 <pre>
70 $ perl -d -e 42</pre>
71 <p>In Perl, the debugger is not a separate program the way it usually is in the
72 typical compiled environment. Instead, the <strong>-d</strong> flag tells the compiler
73 to insert source information into the parse trees it's about to hand off
74 to the interpreter. That means your code must first compile correctly
75 for the debugger to work on it. Then when the interpreter starts up, it
76 preloads a special Perl library file containing the debugger.</p>
77 <p>The program will halt <em>right before</em> the first run-time executable
78 statement (but see below regarding compile-time statements) and ask you
79 to enter a debugger command. Contrary to popular expectations, whenever
80 the debugger halts and shows you a line of code, it always displays the
81 line it's <em>about</em> to execute, rather than the one it has just executed.</p>
82 <p>Any command not recognized by the debugger is directly executed
83 (<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>'d) as Perl code in the current package. (The debugger
84 uses the DB package for keeping its own state information.)</p>
85 <p>Note that the said <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a> is bound by an implicit scope. As a
86 result any newly introduced lexical variable or any modified
87 capture buffer content is lost after the eval. The debugger is a
88 nice environment to learn Perl, but if you interactively experiment using
89 material which should be in the same scope, stuff it in one line.</p>
90 <p>For any text entered at the debugger prompt, leading and trailing whitespace
91 is first stripped before further processing. If a debugger command
92 coincides with some function in your own program, merely precede the
93 function with something that doesn't look like a debugger command, such
94 as a leading <code>;</code> or perhaps a <code>+</code>, or by wrapping it with parentheses
95 or braces.</p>
96 <p>
97 </p>
98 <h2><a name="debugger_commands">Debugger Commands</a></h2>
99 <p>The debugger understands the following commands:</p>
100 <dl>
101 <dt><strong><a name="item_h_x_3cdebugger_command_2c_h_3e">h
102 </a></strong>
104 <dd>
105 <p>Prints out a summary help message</p>
106 </dd>
107 </li>
108 <dt><strong><a name="item_h__5bcommand_5d">h [command]</a></strong>
110 <dd>
111 <p>Prints out a help message for the given debugger command.</p>
112 </dd>
113 </li>
114 <dt><strong><a name="item_h_h">h h</a></strong>
116 <dd>
117 <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>
118 </dd>
119 <dd>
120 <p>If the output of the <a href="#item_h_h"><code>h h</code></a> command (or any command, for that matter) scrolls
121 past your screen, precede the command with a leading pipe symbol so
122 that it's run through your pager, as in</p>
123 </dd>
124 <dd>
125 <pre>
126 DB&gt; |h h</pre>
127 </dd>
128 <dd>
129 <p>You may change the pager which is used via <code>o pager=...</code> command.</p>
130 </dd>
131 </li>
132 <dt><strong><a name="item_p_expr_x_3cdebugger_command_2c_p_3e">p expr
133 </a></strong>
135 <dd>
136 <p>Same as <code>print {$DB::OUT} expr</code> in the current package. In particular,
137 because this is just Perl's own <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_print"><code>print</code></a> function, this means that nested
138 data structures and objects are not dumped, unlike with the <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_x"><code>x</code></a> command.</p>
139 </dd>
140 <dd>
141 <p>The <code>DB::OUT</code> filehandle is opened to <em>/dev/tty</em>, regardless of
142 where STDOUT may be redirected to.</p>
143 </dd>
144 </li>
145 <dt><strong><a name="item_x__5bmaxdepth_5d_expr_x_3cdebugger_command_2c_x_3e">x [maxdepth] expr
146 </a></strong>
148 <dd>
149 <p>Evaluates its expression in list context and dumps out the result in a
150 pretty-printed fashion. Nested data structures are printed out
151 recursively, unlike the real <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_print"><code>print</code></a> function in Perl. When dumping
152 hashes, you'll probably prefer 'x \%h' rather than 'x %h'.
153 See <a href="file://C|\msysgit\mingw\html/lib/Dumpvalue.html">the Dumpvalue manpage</a> if you'd like to do this yourself.</p>
154 </dd>
155 <dd>
156 <p>The output format is governed by multiple options described under
157 <a href="#configurable_options">Configurable Options</a>.</p>
158 </dd>
159 <dd>
160 <p>If the <code>maxdepth</code> is included, it must be a numeral <em>N</em>; the value is
161 dumped only <em>N</em> levels deep, as if the <code>dumpDepth</code> option had been
162 temporarily set to <em>N</em>.</p>
163 </dd>
164 </li>
165 <dt><strong><a name="item_v__5bpkg__5bvars_5d_5d_x_3cdebugger_command_2c_v_3">V [pkg [vars]]
166 </a></strong>
168 <dd>
169 <p>Display all (or some) variables in package (defaulting to <code>main</code>)
170 using a data pretty-printer (hashes show their keys and values so
171 you see what's what, control characters are made printable, etc.).
172 Make sure you don't put the type specifier (like <code>$</code>) there, just
173 the symbol names, like this:</p>
174 </dd>
175 <dd>
176 <pre>
177 V DB filename line</pre>
178 </dd>
179 <dd>
180 <p>Use <code>~pattern</code> and <code>!pattern</code> for positive and negative regexes.</p>
181 </dd>
182 <dd>
183 <p>This is similar to calling the <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_x"><code>x</code></a> command on each applicable var.</p>
184 </dd>
185 </li>
186 <dt><strong><a name="item_x__5bvars_5d_x_3cdebugger_command_2c_x_3e">X [vars]
187 </a></strong>
189 <dd>
190 <p>Same as <code>V currentpackage [vars]</code>.</p>
191 </dd>
192 </li>
193 <dt><strong><a name="item_y__5blevel__5bvars_5d_5d_x_3cdebugger_command_2c_y">y [level [vars]]
194 </a></strong>
196 <dd>
197 <p>Display all (or some) lexical variables (mnemonic: <code>mY</code> variables)
198 in the current scope or <em>level</em> scopes higher. You can limit the
199 variables that you see with <em>vars</em> which works exactly as it does
200 for the <code>V</code> and <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_x"><code>X</code></a> commands. Requires the <code>PadWalker</code> module
201 version 0.08 or higher; will warn if this isn't installed. Output
202 is pretty-printed in the same style as for <code>V</code> and the format is
203 controlled by the same options.</p>
204 </dd>
205 </li>
206 <dt><strong><a name="item_t_x_3cdebugger_command_2c_t_3e_x_3cbacktrace_3e_x_">T
207 </a></strong>
209 <dd>
210 <p>Produce a stack backtrace. See below for details on its output.</p>
211 </dd>
212 </li>
213 <dt><strong><a name="item_s__5bexpr_5d_x_3cdebugger_command_2c_s_3e_x_3cstep">s [expr]
214 </a></strong>
216 <dd>
217 <p>Single step. Executes until the beginning of another
218 statement, descending into subroutine calls. If an expression is
219 supplied that includes function calls, it too will be single-stepped.</p>
220 </dd>
221 </li>
222 <dt><strong><a name="item_n__5bexpr_5d_x_3cdebugger_command_2c_n_3e">n [expr]
223 </a></strong>
225 <dd>
226 <p>Next. Executes over subroutine calls, until the beginning
227 of the next statement. If an expression is supplied that includes
228 function calls, those functions will be executed with stops before
229 each statement.</p>
230 </dd>
231 </li>
232 <dt><strong><a name="item_r_x_3cdebugger_command_2c_r_3e">r
233 </a></strong>
235 <dd>
236 <p>Continue until the return from the current subroutine.
237 Dump the return value if the <code>PrintRet</code> option is set (default).</p>
238 </dd>
239 </li>
240 <dt><strong><a name="item__3ccr_3e">&lt;CR&gt;</a></strong>
242 <dd>
243 <p>Repeat last <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_n"><code>n</code></a> or <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_s"><code>s</code></a> command.</p>
244 </dd>
245 </li>
246 <dt><strong><a name="item_c__5bline_7csub_5d_x_3cdebugger_command_2c_c_3e">c [line|sub]
247 </a></strong>
249 <dd>
250 <p>Continue, optionally inserting a one-time-only breakpoint
251 at the specified line or subroutine.</p>
252 </dd>
253 </li>
254 <dt><strong><a name="item_l_x_3cdebugger_command_2c_l_3e">l
255 </a></strong>
257 <dd>
258 <p>List next window of lines.</p>
259 </dd>
260 </li>
261 <dt><strong><a name="item_l_min_2bincr">l min+incr</a></strong>
263 <dd>
264 <p>List <code>incr+1</code> lines starting at <code>min</code>.</p>
265 </dd>
266 </li>
267 <dt><strong><a name="item_l_min_2dmax">l min-max</a></strong>
269 <dd>
270 <p>List lines <code>min</code> through <code>max</code>. <code>l -</code> is synonymous to <code>-</code>.</p>
271 </dd>
272 </li>
273 <dt><strong><a name="item_l_line">l line</a></strong>
275 <dd>
276 <p>List a single line.</p>
277 </dd>
278 </li>
279 <dt><strong><a name="item_l_subname">l subname</a></strong>
281 <dd>
282 <p>List first window of lines from subroutine. <em>subname</em> may
283 be a variable that contains a code reference.</p>
284 </dd>
285 </li>
286 <dt><strong><a name="item__2d_x_3cdebugger_command_2c__2d_3e">-
287 </a></strong>
289 <dd>
290 <p>List previous window of lines.</p>
291 </dd>
292 </li>
293 <dt><strong><a name="item_v__5bline_5d_x_3cdebugger_command_2c_v_3e">v [line]
294 </a></strong>
296 <dd>
297 <p>View a few lines of code around the current line.</p>
298 </dd>
299 </li>
300 <dt><strong><a name="item__2e_x_3cdebugger_command_2c__2e_3e">.
301 </a></strong>
303 <dd>
304 <p>Return the internal debugger pointer to the line last
305 executed, and print out that line.</p>
306 </dd>
307 </li>
308 <dt><strong><a name="item_f_filename_x_3cdebugger_command_2c_f_3e">f filename
309 </a></strong>
311 <dd>
312 <p>Switch to viewing a different file or <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a> statement. If <em>filename</em>
313 is not a full pathname found in the values of %INC, it is considered
314 a regex.</p>
315 </dd>
316 <dd>
317 <p><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed strings (when accessible) are considered to be filenames:
318 <a href="file://C|\msysgit\mingw\html/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="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed string
319 (in the order of execution). The bodies of the currently executed <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>
320 and of <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed strings that define subroutines are saved and thus
321 accessible.</p>
322 </dd>
323 </li>
324 <dt><strong><a name="item__2fpattern_2f">/pattern/</a></strong>
326 <dd>
327 <p>Search forwards for pattern (a Perl regex); final / is optional.
328 The search is case-insensitive by default.</p>
329 </dd>
330 </li>
331 <dt><strong><a name="item__3fpattern_3f">?pattern?</a></strong>
333 <dd>
334 <p>Search backwards for pattern; final ? is optional.
335 The search is case-insensitive by default.</p>
336 </dd>
337 </li>
338 <dt><strong><a name="item_l__5babw_5d_x_3cdebugger_command_2c_l_3e">L [abw]
339 </a></strong>
341 <dd>
342 <p>List (default all) actions, breakpoints and watch expressions</p>
343 </dd>
344 </li>
345 <dt><strong><a name="item_s__5b_5b_21_5dregex_5d_x_3cdebugger_command_2c_s_3">S [[!]regex]
346 </a></strong>
348 <dd>
349 <p>List subroutine names [not] matching the regex.</p>
350 </dd>
351 </li>
352 <dt><strong><a name="item_t_x_3cdebugger_command_2c_t_3e">t
353 </a></strong>
355 <dd>
356 <p>Toggle trace mode (see also the <code>AutoTrace</code> option).</p>
357 </dd>
358 </li>
359 <dt><strong><a name="item_t_expr_x_3cdebugger_command_2c_t_3e">t expr
360 </a></strong>
362 <dd>
363 <p>Trace through execution of <code>expr</code>.
364 See <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html#frame_listing_output_examples">Frame Listing Output Examples in the perldebguts manpage</a> for examples.</p>
365 </dd>
366 </li>
367 <dt><strong><a name="item_b_x_3cbreakpoint_3e_x_3cdebugger_command_2c_b_3e">b
369 </a></strong>
371 <dd>
372 <p>Sets breakpoint on current line</p>
373 </dd>
374 </li>
375 <dt><strong><a name="item_b__5bline_5d__5bcondition_5d_x_3cbreakpoint_3e_x_3">b [line] [condition]
377 </a></strong>
379 <dd>
380 <p>Set a breakpoint before the given line. If a condition
381 is specified, it's evaluated each time the statement is reached: a
382 breakpoint is taken only if the condition is true. Breakpoints may
383 only be set on lines that begin an executable statement. Conditions
384 don't use <code>if</code>:</p>
385 </dd>
386 <dd>
387 <pre>
388 b 237 $x &gt; 30
389 b 237 ++$count237 &lt; 11
390 b 33 /pattern/i</pre>
391 </dd>
392 </li>
393 <dt><strong><a name="item_b_subname__5bcondition_5d_x_3cbreakpoint_3e_x_3cde">b subname [condition]
395 </a></strong>
397 <dd>
398 <p>Set a breakpoint before the first line of the named subroutine. <em>subname</em> may
399 be a variable containing a code reference (in this case <em>condition</em>
400 is not supported).</p>
401 </dd>
402 </li>
403 <dt><strong><a name="item_b_postpone_subname__5bcondition_5d_x_3cbreakpoint_">b postpone subname [condition]
405 </a></strong>
407 <dd>
408 <p>Set a breakpoint at first line of subroutine after it is compiled.</p>
409 </dd>
410 </li>
411 <dt><strong><a name="item_b_load_filename_x_3cbreakpoint_3e_x_3cdebugger_com">b load filename
413 </a></strong>
415 <dd>
416 <p>Set a breakpoint before the first executed line of the <em>filename</em>,
417 which should be a full pathname found amongst the %INC values.</p>
418 </dd>
419 </li>
420 <dt><strong><a name="item_b_compile_subname_x_3cbreakpoint_3e_x_3cdebugger_c">b compile subname
422 </a></strong>
424 <dd>
425 <p>Sets a breakpoint before the first statement executed after the specified
426 subroutine is compiled.</p>
427 </dd>
428 </li>
429 <dt><strong><a name="item_b_line_x_3cbreakpoint_3e_x_3cdebugger_command_2c_b">B line
431 </a></strong>
433 <dd>
434 <p>Delete a breakpoint from the specified <em>line</em>.</p>
435 </dd>
436 </li>
437 <dt><strong><a name="item_b__2a_x_3cbreakpoint_3e_x_3cdebugger_command_2c_b_">B *
439 </a></strong>
441 <dd>
442 <p>Delete all installed breakpoints.</p>
443 </dd>
444 </li>
445 <dt><strong><a name="item_a__5bline_5d_command_x_3cdebugger_command_2c_a_3e">a [line] command
446 </a></strong>
448 <dd>
449 <p>Set an action to be done before the line is executed. If <em>line</em> is
450 omitted, set an action on the line about to be executed.
451 The sequence of steps taken by the debugger is</p>
452 </dd>
453 <dd>
454 <pre>
455 1. check for a breakpoint at this line
456 2. print the line if necessary (tracing)
457 3. do any actions associated with that line
458 4. prompt user if at a breakpoint or in single-step
459 5. evaluate line</pre>
460 </dd>
461 <dd>
462 <p>For example, this will print out $foo every time line
463 53 is passed:</p>
464 </dd>
465 <dd>
466 <pre>
467 a 53 print &quot;DB FOUND $foo\n&quot;</pre>
468 </dd>
469 </li>
470 <dt><strong><a name="item_a_line_x_3cdebugger_command_2c_a_3e">A line
471 </a></strong>
473 <dd>
474 <p>Delete an action from the specified line.</p>
475 </dd>
476 </li>
477 <dt><strong><a name="item_a__2a_x_3cdebugger_command_2c_a_3e">A *
478 </a></strong>
480 <dd>
481 <p>Delete all installed actions.</p>
482 </dd>
483 </li>
484 <dt><strong><a name="item_w_expr_x_3cdebugger_command_2c_w_3e">w expr
485 </a></strong>
487 <dd>
488 <p>Add a global watch-expression. We hope you know what one of these
489 is, because they're supposed to be obvious.</p>
490 </dd>
491 </li>
492 <dt><strong><a name="item_w_expr_x_3cdebugger_command_2c_w_3e">W expr
493 </a></strong>
495 <dd>
496 <p>Delete watch-expression</p>
497 </dd>
498 </li>
499 <dt><strong><a name="item_w__2a_x_3cdebugger_command_2c_w_3e">W *
500 </a></strong>
502 <dd>
503 <p>Delete all watch-expressions.</p>
504 </dd>
505 </li>
506 <dt><strong><a name="item_o_x_3cdebugger_command_2c_o_3e">o
507 </a></strong>
509 <dd>
510 <p>Display all options</p>
511 </dd>
512 </li>
513 <dt><strong><a name="item_o_booloption__2e_2e_2e_x_3cdebugger_command_2c_o_3">o booloption ...
514 </a></strong>
516 <dd>
517 <p>Set each listed Boolean option to the value <code>1</code>.</p>
518 </dd>
519 </li>
520 <dt><strong><a name="item_o_anyoption_3f__2e_2e_2e_x_3cdebugger_command_2c_o">o anyoption? ...
521 </a></strong>
523 <dd>
524 <p>Print out the value of one or more options.</p>
525 </dd>
526 </li>
527 <dt><strong><a name="item_o_option_3dvalue__2e_2e_2e_x_3cdebugger_command_2c">o option=value ...
528 </a></strong>
530 <dd>
531 <p>Set the value of one or more options. If the value has internal
532 whitespace, it should be quoted. For example, you could set <code>o
533 pager=&quot;less -MQeicsNfr&quot;</code> to call <strong>less</strong> with those specific options.
534 You may use either single or double quotes, but if you do, you must
535 escape any embedded instances of same sort of quote you began with,
536 as well as any escaping any escapes that immediately precede that
537 quote but which are not meant to escape the quote itself. In other
538 words, you follow single-quoting rules irrespective of the quote;
539 eg: <code>o option='this isn\'t bad'</code> or <code>o option=&quot;She said, \&quot;Isn't
540 it?\&quot;&quot;</code>.</p>
541 </dd>
542 <dd>
543 <p>For historical reasons, the <code>=value</code> is optional, but defaults to
544 1 only where it is safe to do so--that is, mostly for Boolean
545 options. It is always better to assign a specific value using <code>=</code>.
546 The <code>option</code> can be abbreviated, but for clarity probably should
547 not be. Several options can be set together. See <a href="#configurable_options">Configurable Options</a>
548 for a list of these.</p>
549 </dd>
550 </li>
551 <dt><strong><a name="item__3c__3f_x_3c_3c_debugger_command_2c__3c__3e_3e">&lt; ?
552 &gt;</a></strong>
554 <dd>
555 <p>List out all pre-prompt Perl command actions.</p>
556 </dd>
557 </li>
558 <dt><strong><a name="item__3c__5b_command__5d_x_3c_3c_debugger_command_2c__3">&lt; [ command ]
559 &gt;</a></strong>
561 <dd>
562 <p>Set an action (Perl command) to happen before every debugger prompt.
563 A multi-line command may be entered by backslashing the newlines.</p>
564 </dd>
565 </li>
566 <dt><strong><a name="item__3c__2a_x_3c_3c_debugger_command_2c__3c__3e_3e">&lt; *
567 &gt;</a></strong>
569 <dd>
570 <p>Delete all pre-prompt Perl command actions.</p>
571 </dd>
572 </li>
573 <dt><strong><a name="item__3c_3c_command_x_3c_3c_debugger_command_2c__3c_3c_">&lt;&lt; command
574 &gt;</a></strong>
576 <dd>
577 <p>Add an action (Perl command) to happen before every debugger prompt.
578 A multi-line command may be entered by backwhacking the newlines.</p>
579 </dd>
580 </li>
581 <dt><strong><a name="item__3e__3f_x_3c_3c_debugger_command_2c__3e__3e_3e">&gt; ?
582 &gt;&gt;</a></strong>
584 <dd>
585 <p>List out post-prompt Perl command actions.</p>
586 </dd>
587 </li>
588 <dt><strong><a name="item__3e_command_x_3c_3c_debugger_command_2c__3e__3e_3e">&gt; command
589 &gt;&gt;</a></strong>
591 <dd>
592 <p>Set an action (Perl command) to happen after the prompt when you've
593 just given a command to return to executing the script. A multi-line
594 command may be entered by backslashing the newlines (we bet you
595 couldn't've guessed this by now).</p>
596 </dd>
597 </li>
598 <dt><strong><a name="item__3e__2a_x_3c_3c_debugger_command_2c__3e__3e_3e">&gt; *
599 &gt;&gt;</a></strong>
601 <dd>
602 <p>Delete all post-prompt Perl command actions.</p>
603 </dd>
604 </li>
605 <dt><strong><a name="item__3e_3e_command_x_3c_3c_3c_debugger_command_2c__3e_">&gt;&gt; command
606 &gt; &gt;&gt;&gt;</a></strong>
608 <dd>
609 <p>Adds an action (Perl command) to happen after the prompt when you've
610 just given a command to return to executing the script. A multi-line
611 command may be entered by backslashing the newlines.</p>
612 </dd>
613 </li>
614 <dt><strong><a name="item__7b__3f_x_3cdebugger_command_2c__7b_3e">{ ?
615 </a></strong>
617 <dd>
618 <p>List out pre-prompt debugger commands.</p>
619 </dd>
620 </li>
621 <dt><strong><a name="item__7b__5b_command__5d">{ [ command ]</a></strong>
623 <dd>
624 <p>Set an action (debugger command) to happen before every debugger prompt.
625 A multi-line command may be entered in the customary fashion.</p>
626 </dd>
627 <dd>
628 <p>Because this command is in some senses new, a warning is issued if
629 you appear to have accidentally entered a block instead. If that's
630 what you mean to do, write it as with <code>;{ ... }</code> or even
631 <code>do { ... }</code>.</p>
632 </dd>
633 </li>
634 <dt><strong><a name="item__7b__2a_x_3cdebugger_command_2c__7b_3e">{ *
635 </a></strong>
637 <dd>
638 <p>Delete all pre-prompt debugger commands.</p>
639 </dd>
640 </li>
641 <dt><strong><a name="item__7b_7b_command_x_3cdebugger_command_2c__7b_7b_3e">{{ command
642 </a></strong>
644 <dd>
645 <p>Add an action (debugger command) to happen before every debugger prompt.
646 A multi-line command may be entered, if you can guess how: see above.</p>
647 </dd>
648 </li>
649 <dt><strong><a name="item__21_number_x_3cdebugger_command_2c__21_3e">! number
650 </a></strong>
652 <dd>
653 <p>Redo a previous command (defaults to the previous command).</p>
654 </dd>
655 </li>
656 <dt><strong><a name="item__21__2dnumber_x_3cdebugger_command_2c__21_3e">! -number
657 </a></strong>
659 <dd>
660 <p>Redo number'th previous command.</p>
661 </dd>
662 </li>
663 <dt><strong><a name="item__21_pattern_x_3cdebugger_command_2c__21_3e">! pattern
664 </a></strong>
666 <dd>
667 <p>Redo last command that started with pattern.
668 See <code>o recallCommand</code>, too.</p>
669 </dd>
670 </li>
671 <dt><strong><a name="item__21_21_cmd_x_3cdebugger_command_2c__21_21_3e">!! cmd
672 </a></strong>
674 <dd>
675 <p>Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT) See
676 <code>o shellBang</code>, also. Note that the user's current shell (well,
677 their <code>$ENV{SHELL}</code> variable) will be used, which can interfere
678 with proper interpretation of exit status or signal and coredump
679 information.</p>
680 </dd>
681 </li>
682 <dt><strong><a name="item_source_file_x_3cdebugger_command_2c_source_3e">source file
683 </a></strong>
685 <dd>
686 <p>Read and execute debugger commands from <em>file</em>.
687 <em>file</em> may itself contain <code>source</code> commands.</p>
688 </dd>
689 </li>
690 <dt><strong><a name="item_h__2dnumber_x_3cdebugger_command_2c_h_3e">H -number
691 </a></strong>
693 <dd>
694 <p>Display last n commands. Only commands longer than one character are
695 listed. If <em>number</em> is omitted, list them all.</p>
696 </dd>
697 </li>
698 <dt><strong><a name="item_q_or__5ed_x_3cdebugger_command_2c_q_3e_x_3cdebugge">q or ^D
700 </a></strong>
702 <dd>
703 <p>Quit. (``quit'' doesn't work for this, unless you've made an alias)
704 This is the only supported way to exit the debugger, though typing
705 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exit"><code>exit</code></a> twice might work.</p>
706 </dd>
707 <dd>
708 <p>Set the <code>inhibit_exit</code> option to 0 if you want to be able to step
709 off the end the script. You may also need to set $finished to 0
710 if you want to step through global destruction.</p>
711 </dd>
712 </li>
713 <dt><strong><a name="item_r_x_3cdebugger_command_2c_r_3e">R
714 </a></strong>
716 <dd>
717 <p>Restart the debugger by <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec"><code>exec()</code></a>ing a new session. We try to maintain
718 your history across this, but internal settings and command-line options
719 may be lost.</p>
720 </dd>
721 <dd>
722 <p>The following setting are currently preserved: history, breakpoints,
723 actions, debugger options, and the Perl command-line
724 options <strong>-w</strong>, <strong>-I</strong>, and <strong>-e</strong>.</p>
725 </dd>
726 </li>
727 <dt><strong><a name="item__7cdbcmd_x_3cdebugger_command_2c__7c_3e">|dbcmd
728 </a></strong>
730 <dd>
731 <p>Run the debugger command, piping DB::OUT into your current pager.</p>
732 </dd>
733 </li>
734 <dt><strong><a name="item__7c_7cdbcmd_x_3cdebugger_command_2c__7c_7c_3e">||dbcmd
735 </a></strong>
737 <dd>
738 <p>Same as <code>|dbcmd</code> but DB::OUT is temporarily <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_select"><code>select</code></a>ed as well.</p>
739 </dd>
740 </li>
741 <dt><strong><a name="item__3d__5balias_value_5d_x_3cdebugger_command_2c__3d_">= [alias value]
742 </a></strong>
744 <dd>
745 <p>Define a command alias, like</p>
746 </dd>
747 <dd>
748 <pre>
749 = quit q</pre>
750 </dd>
751 <dd>
752 <p>or list current aliases.</p>
753 </dd>
754 </li>
755 <dt><strong><a name="item_command">command</a></strong>
757 <dd>
758 <p>Execute command as a Perl statement. A trailing semicolon will be
759 supplied. If the Perl statement would otherwise be confused for a
760 Perl debugger, use a leading semicolon, too.</p>
761 </dd>
762 </li>
763 <dt><strong><a name="item_m_expr_x_3cdebugger_command_2c_m_3e">m expr
764 </a></strong>
766 <dd>
767 <p>List which methods may be called on the result of the evaluated
768 expression. The expression may evaluated to a reference to a
769 blessed object, or to a package name.</p>
770 </dd>
771 </li>
772 <dt><strong><a name="item_m_x_3cdebugger_command_2c_m_3e">M
773 </a></strong>
775 <dd>
776 <p>Displays all loaded modules and their versions</p>
777 </dd>
778 </li>
779 <dt><strong><a name="item_man__5bmanpage_5d_x_3cdebugger_command_2c_man_3e">man [manpage]
780 </a></strong>
782 <dd>
783 <p>Despite its name, this calls your system's default documentation
784 viewer on the given page, or on the viewer itself if <em>manpage</em> is
785 omitted. If that viewer is <strong>man</strong>, the current <code>Config</code> information
786 is used to invoke <strong>man</strong> using the proper MANPATH or <strong>-M</strong>
787 <em>manpath</em> option. Failed lookups of the form <code>XXX</code> that match
788 known manpages of the form <em>perlXXX</em> will be retried. This lets
789 you type <code>man debug</code> or <code>man op</code> from the debugger.</p>
790 </dd>
791 <dd>
792 <p>On systems traditionally bereft of a usable <strong>man</strong> command, the
793 debugger invokes <strong>perldoc</strong>. Occasionally this determination is
794 incorrect due to recalcitrant vendors or rather more felicitously,
795 to enterprising users. If you fall into either category, just
796 manually set the $DB::doccmd variable to whatever viewer to view
797 the Perl documentation on your system. This may be set in an rc
798 file, or through direct assignment. We're still waiting for a
799 working example of something along the lines of:</p>
800 </dd>
801 <dd>
802 <pre>
803 $DB::doccmd = 'netscape -remote <a href="http://something.here/">http://something.here/</a>';</pre>
804 </dd>
805 </li>
806 </dl>
808 </p>
809 <h2><a name="configurable_options">Configurable Options</a></h2>
810 <p>The debugger has numerous options settable using the <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_o"><code>o</code></a> command,
811 either interactively or from the environment or an rc file.
812 (./.perldb or ~/.perldb under Unix.)</p>
813 <dl>
814 <dt><strong><a name="item_recallcommand_2c_shellbang_x_3cdebugger_option_2c_"><code>recallCommand</code>, <code>ShellBang</code>
816 </a></strong>
818 <dd>
819 <p>The characters used to recall command or spawn shell. By
820 default, both are set to <code>!</code>, which is unfortunate.</p>
821 </dd>
822 </li>
823 <dt><strong><a name="item_pager_x_3cdebugger_option_2c_pager_3e"><code>pager</code>
824 </a></strong>
826 <dd>
827 <p>Program to use for output of pager-piped commands (those beginning
828 with a <code>|</code> character.) By default, <code>$ENV{PAGER}</code> will be used.
829 Because the debugger uses your current terminal characteristics
830 for bold and underlining, if the chosen pager does not pass escape
831 sequences through unchanged, the output of some debugger commands
832 will not be readable when sent through the pager.</p>
833 </dd>
834 </li>
835 <dt><strong><a name="item_tkrunning_x_3cdebugger_option_2c_tkrunning_3e"><code>tkRunning</code>
836 </a></strong>
838 <dd>
839 <p>Run Tk while prompting (with ReadLine).</p>
840 </dd>
841 </li>
842 <dt><strong><a name="item_signallevel_2c_warnlevel_2c_dielevel_x_3cdebugger_"><code>signalLevel</code>, <code>warnLevel</code>, <code>dieLevel</code>
844 </a></strong>
846 <dd>
847 <p>Level of verbosity. By default, the debugger leaves your exceptions
848 and warnings alone, because altering them can break correctly running
849 programs. It will attempt to print a message when uncaught INT, BUS, or
850 SEGV signals arrive. (But see the mention of signals in <em>BUGS</em> below.)</p>
851 </dd>
852 <dd>
853 <p>To disable this default safe mode, set these values to something higher
854 than 0. At a level of 1, you get backtraces upon receiving any kind
855 of warning (this is often annoying) or exception (this is
856 often valuable). Unfortunately, the debugger cannot discern fatal
857 exceptions from non-fatal ones. If <code>dieLevel</code> is even 1, then your
858 non-fatal exceptions are also traced and unceremoniously altered if they
859 came from <code>eval'd</code> strings or from any kind of <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a> within modules
860 you're attempting to load. If <code>dieLevel</code> is 2, the debugger doesn't
861 care where they came from: It usurps your exception handler and prints
862 out a trace, then modifies all exceptions with its own embellishments.
863 This may perhaps be useful for some tracing purposes, but tends to hopelessly
864 destroy any program that takes its exception handling seriously.</p>
865 </dd>
866 </li>
867 <dt><strong><a name="item_autotrace_x_3cdebugger_option_2c_autotrace_3e"><code>AutoTrace</code>
868 </a></strong>
870 <dd>
871 <p>Trace mode (similar to <code>t</code> command, but can be put into
872 <code>PERLDB_OPTS</code>).</p>
873 </dd>
874 </li>
875 <dt><strong><a name="item_lineinfo_x_3cdebugger_option_2c_lineinfo_3e"><code>LineInfo</code>
876 </a></strong>
878 <dd>
879 <p>File or pipe to print line number info to. If it is a pipe (say,
880 <code>|visual_perl_db</code>), then a short message is used. This is the
881 mechanism used to interact with a slave editor or visual debugger,
882 such as the special <code>vi</code> or <code>emacs</code> hooks, or the <code>ddd</code> graphical
883 debugger.</p>
884 </dd>
885 </li>
886 <dt><strong><a name="item_inhibit_exit_x_3cdebugger_option_2c_inhibit_exit_3"><code>inhibit_exit</code>
887 </a></strong>
889 <dd>
890 <p>If 0, allows <em>stepping off</em> the end of the script.</p>
891 </dd>
892 </li>
893 <dt><strong><a name="item_printret_x_3cdebugger_option_2c_printret_3e"><code>PrintRet</code>
894 </a></strong>
896 <dd>
897 <p>Print return value after <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_r"><code>r</code></a> command if set (default).</p>
898 </dd>
899 </li>
900 <dt><strong><a name="item_ornaments_x_3cdebugger_option_2c_ornaments_3e"><code>ornaments</code>
901 </a></strong>
903 <dd>
904 <p>Affects screen appearance of the command line (see <a href="file://C|\msysgit\mingw\html/lib/Term/ReadLine.html">the Term::ReadLine manpage</a>).
905 There is currently no way to disable these, which can render
906 some output illegible on some displays, or with some pagers.
907 This is considered a bug.</p>
908 </dd>
909 </li>
910 <dt><strong><a name="item_frame_x_3cdebugger_option_2c_frame_3e"><code>frame</code>
911 </a></strong>
913 <dd>
914 <p>Affects the printing of messages upon entry and exit from subroutines. If
915 <code>frame &amp; 2</code> is false, messages are printed on entry only. (Printing
916 on exit might be useful if interspersed with other messages.)</p>
917 </dd>
918 <dd>
919 <p>If <code>frame &amp; 4</code>, arguments to functions are printed, plus context
920 and caller info. If <code>frame &amp; 8</code>, overloaded <code>stringify</code> and
921 <code>tie</code>d <code>FETCH</code> is enabled on the printed arguments. If <code>frame
922 &amp; 16</code>, the return value from the subroutine is printed.</p>
923 </dd>
924 <dd>
925 <p>The length at which the argument list is truncated is governed by the
926 next option:</p>
927 </dd>
928 </li>
929 <dt><strong><a name="item_maxtracelen_x_3cdebugger_option_2c_maxtracelen_3e"><code>maxTraceLen</code>
930 </a></strong>
932 <dd>
933 <p>Length to truncate the argument list when the <code>frame</code> option's
934 bit 4 is set.</p>
935 </dd>
936 </li>
937 <dt><strong><a name="item_windowsize_x_3cdebugger_option_2c_windowsize_3e"><code>windowSize</code>
938 </a></strong>
940 <dd>
941 <p>Change the size of code list window (default is 10 lines).</p>
942 </dd>
943 </li>
944 </dl>
945 <p>The following options affect what happens with <code>V</code>, <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_x"><code>X</code></a>, and <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_x"><code>x</code></a>
946 commands:</p>
947 <dl>
948 <dt><strong><a name="item_arraydepth_2c_hashdepth_x_3cdebugger_option_2c_arr"><code>arrayDepth</code>, <code>hashDepth</code>
949 </a></strong>
951 <dd>
952 <p>Print only first N elements ('' for all).</p>
953 </dd>
954 </li>
955 <dt><strong><a name="item_dumpdepth_x_3cdebugger_option_2c_dumpdepth_3e"><code>dumpDepth</code>
956 </a></strong>
958 <dd>
959 <p>Limit recursion depth to N levels when dumping structures.
960 Negative values are interpreted as infinity. Default: infinity.</p>
961 </dd>
962 </li>
963 <dt><strong><a name="item_compactdump_2c_verycompact_x_3cdebugger_option_2c_"><code>compactDump</code>, <code>veryCompact</code>
964 </a></strong>
966 <dd>
967 <p>Change the style of array and hash output. If <code>compactDump</code>, short array
968 may be printed on one line.</p>
969 </dd>
970 </li>
971 <dt><strong><a name="item_globprint_x_3cdebugger_option_2c_globprint_3e"><code>globPrint</code>
972 </a></strong>
974 <dd>
975 <p>Whether to print contents of globs.</p>
976 </dd>
977 </li>
978 <dt><strong><a name="item_dumpdbfiles_x_3cdebugger_option_2c_dumpdbfiles_3e"><code>DumpDBFiles</code>
979 </a></strong>
981 <dd>
982 <p>Dump arrays holding debugged files.</p>
983 </dd>
984 </li>
985 <dt><strong><a name="item_dumppackages_x_3cdebugger_option_2c_dumppackages_3"><code>DumpPackages</code>
986 </a></strong>
988 <dd>
989 <p>Dump symbol tables of packages.</p>
990 </dd>
991 </li>
992 <dt><strong><a name="item_dumpreused_x_3cdebugger_option_2c_dumpreused_3e"><code>DumpReused</code>
993 </a></strong>
995 <dd>
996 <p>Dump contents of ``reused'' addresses.</p>
997 </dd>
998 </li>
999 <dt><strong><a name="item_quote_2c_highbit_2c_undefprint_x_3cdebugger_option"><code>quote</code>, <code>HighBit</code>, <code>undefPrint</code>
1001 </a></strong>
1003 <dd>
1004 <p>Change the style of string dump. The default value for <code>quote</code>
1005 is <code>auto</code>; one can enable double-quotish or single-quotish format
1006 by setting it to <code>&quot;</code> or <code>'</code>, respectively. By default, characters
1007 with their high bit set are printed verbatim.</p>
1008 </dd>
1009 </li>
1010 <dt><strong><a name="item_usageonly_x_3cdebugger_option_2c_usageonly_3e"><code>UsageOnly</code>
1011 </a></strong>
1013 <dd>
1014 <p>Rudimentary per-package memory usage dump. Calculates total
1015 size of strings found in variables in the package. This does not
1016 include lexicals in a module's file scope, or lost in closures.</p>
1017 </dd>
1018 </li>
1019 </dl>
1020 <p>After the rc file is read, the debugger reads the <code>$ENV{PERLDB_OPTS}</code>
1021 environment variable and parses this as the remainder of a ``O ...''
1022 line as one might enter at the debugger prompt. You may place the
1023 initialization options <code>TTY</code>, <code>noTTY</code>, <code>ReadLine</code>, and <code>NonStop</code>
1024 there.</p>
1025 <p>If your rc file contains:</p>
1026 <pre>
1027 parse_options(&quot;NonStop=1 LineInfo=db.out AutoTrace&quot;);</pre>
1028 <p>then your script will run without human intervention, putting trace
1029 information into the file <em>db.out</em>. (If you interrupt it, you'd
1030 better reset <code>LineInfo</code> to <em>/dev/tty</em> if you expect to see anything.)</p>
1031 <dl>
1032 <dt><strong><a name="item_tty_x_3cdebugger_option_2c_tty_3e"><code>TTY</code>
1033 </a></strong>
1035 <dd>
1036 <p>The TTY to use for debugging I/O.</p>
1037 </dd>
1038 </li>
1039 <dt><strong><a name="item_notty_x_3cdebugger_option_2c_notty_3e"><code>noTTY</code>
1040 </a></strong>
1042 <dd>
1043 <p>If set, the debugger goes into <code>NonStop</code> mode and will not connect to a TTY. If
1044 interrupted (or if control goes to the debugger via explicit setting of
1045 $DB::signal or $DB::single from the Perl script), it connects to a TTY
1046 specified in the <code>TTY</code> option at startup, or to a tty found at
1047 runtime using the <code>Term::Rendezvous</code> module of your choice.</p>
1048 </dd>
1049 <dd>
1050 <p>This module should implement a method named <code>new</code> that returns an object
1051 with two methods: <code>IN</code> and <code>OUT</code>. These should return filehandles to use
1052 for debugging input and output correspondingly. The <code>new</code> method should
1053 inspect an argument containing the value of <code>$ENV{PERLDB_NOTTY}</code> at
1054 startup, or <code>&quot;$ENV{HOME}/.perldbtty$$&quot;</code> otherwise. This file is not
1055 inspected for proper ownership, so security hazards are theoretically
1056 possible.</p>
1057 </dd>
1058 </li>
1059 <dt><strong><a name="item_readline_x_3cdebugger_option_2c_readline_3e"><code>ReadLine</code>
1060 </a></strong>
1062 <dd>
1063 <p>If false, readline support in the debugger is disabled in order
1064 to debug applications that themselves use ReadLine.</p>
1065 </dd>
1066 </li>
1067 <dt><strong><a name="item_nonstop_x_3cdebugger_option_2c_nonstop_3e"><code>NonStop</code>
1068 </a></strong>
1070 <dd>
1071 <p>If set, the debugger goes into non-interactive mode until interrupted, or
1072 programmatically by setting $DB::signal or $DB::single.</p>
1073 </dd>
1074 </li>
1075 </dl>
1076 <p>Here's an example of using the <code>$ENV{PERLDB_OPTS}</code> variable:</p>
1077 <pre>
1078 $ PERLDB_OPTS=&quot;NonStop frame=2&quot; perl -d myprogram</pre>
1079 <p>That will run the script <strong>myprogram</strong> without human intervention,
1080 printing out the call tree with entry and exit points. Note that
1081 <code>NonStop=1 frame=2</code> is equivalent to <code>N f=2</code>, and that originally,
1082 options could be uniquely abbreviated by the first letter (modulo
1083 the <code>Dump*</code> options). It is nevertheless recommended that you
1084 always spell them out in full for legibility and future compatibility.</p>
1085 <p>Other examples include</p>
1086 <pre>
1087 $ PERLDB_OPTS=&quot;NonStop LineInfo=listing frame=2&quot; perl -d myprogram</pre>
1088 <p>which runs script non-interactively, printing info on each entry
1089 into a subroutine and each executed line into the file named <em>listing</em>.
1090 (If you interrupt it, you would better reset <code>LineInfo</code> to something
1091 ``interactive''!)</p>
1092 <p>Other examples include (using standard shell syntax to show environment
1093 variable settings):</p>
1094 <pre>
1095 $ ( PERLDB_OPTS=&quot;NonStop frame=1 AutoTrace LineInfo=tperl.out&quot;
1096 perl -d myprogram )</pre>
1097 <p>which may be useful for debugging a program that uses <code>Term::ReadLine</code>
1098 itself. Do not forget to detach your shell from the TTY in the window that
1099 corresponds to <em>/dev/ttyXX</em>, say, by issuing a command like</p>
1100 <pre>
1101 $ sleep 1000000</pre>
1102 <p>See <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html#debugger_internals">Debugger Internals in the perldebguts manpage</a> for details.</p>
1104 </p>
1105 <h2><a name="debugger_input_output">Debugger input/output</a></h2>
1106 <dl>
1107 <dt><strong><a name="item_prompt">Prompt</a></strong>
1109 <dd>
1110 <p>The debugger prompt is something like</p>
1111 </dd>
1112 <dd>
1113 <pre>
1114 DB&lt;8&gt;</pre>
1115 </dd>
1116 <dd>
1117 <p>or even</p>
1118 </dd>
1119 <dd>
1120 <pre>
1121 DB&lt;&lt;17&gt;&gt;</pre>
1122 </dd>
1123 <dd>
1124 <p>where that number is the command number, and which you'd use to
1125 access with the built-in <strong>csh</strong>-like history mechanism. For example,
1126 <code>!17</code> would repeat command number 17. The depth of the angle
1127 brackets indicates the nesting depth of the debugger. You could
1128 get more than one set of brackets, for example, if you'd already
1129 at a breakpoint and then printed the result of a function call that
1130 itself has a breakpoint, or you step into an expression via <code>s/n/t
1131 expression</code> command.</p>
1132 </dd>
1133 </li>
1134 <dt><strong><a name="item_multiline_commands">Multiline commands</a></strong>
1136 <dd>
1137 <p>If you want to enter a multi-line command, such as a subroutine
1138 definition with several statements or a format, escape the newline
1139 that would normally end the debugger command with a backslash.
1140 Here's an example:</p>
1141 </dd>
1142 <dd>
1143 <pre>
1144 DB&lt;1&gt; for (1..4) { \
1145 cont: print &quot;ok\n&quot;; \
1146 cont: }
1150 ok</pre>
1151 </dd>
1152 <dd>
1153 <p>Note that this business of escaping a newline is specific to interactive
1154 commands typed into the debugger.</p>
1155 </dd>
1156 </li>
1157 <dt><strong><a name="item_stack_backtrace_x_3cbacktrace_3e_x_3cstack_2c_back">Stack backtrace
1158 </a></strong>
1160 <dd>
1161 <p>Here's an example of what a stack backtrace via <code>T</code> command might
1162 look like:</p>
1163 </dd>
1164 <dd>
1165 <pre>
1166 $ = main::infested called from file `Ambulation.pm' line 10
1167 @ = Ambulation::legs(1, 2, 3, 4) called from file `camel_flea' line 7
1168 $ = main::pests('bactrian', 4) called from file `camel_flea' line 4</pre>
1169 </dd>
1170 <dd>
1171 <p>The left-hand character up there indicates the context in which the
1172 function was called, with <code>$</code> and <code>@</code> meaning scalar or list
1173 contexts respectively, and <code>.</code> meaning void context (which is
1174 actually a sort of scalar context). The display above says
1175 that you were in the function <code>main::infested</code> when you ran the
1176 stack dump, and that it was called in scalar context from line
1177 10 of the file <em>Ambulation.pm</em>, but without any arguments at all,
1178 meaning it was called as <code>&amp;infested</code>. The next stack frame shows
1179 that the function <code>Ambulation::legs</code> was called in list context
1180 from the <em>camel_flea</em> file with four arguments. The last stack
1181 frame shows that <code>main::pests</code> was called in scalar context,
1182 also from <em>camel_flea</em>, but from line 4.</p>
1183 </dd>
1184 <dd>
1185 <p>If you execute the <code>T</code> command from inside an active <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use</code></a>
1186 statement, the backtrace will contain both a <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_require"><code>require</code></a> frame and
1187 an <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>) frame.</p>
1188 </dd>
1189 </li>
1190 <dt><strong><a name="item_line_listing_format">Line Listing Format</a></strong>
1192 <dd>
1193 <p>This shows the sorts of output the <code>l</code> command can produce:</p>
1194 </dd>
1195 <dd>
1196 <pre>
1197 DB&lt;&lt;13&gt;&gt; l
1198 101: @i{@i} = ();
1199 102:b @isa{@i,$pack} = ()
1200 103 if(exists $i{$prevpack} || exists $isa{$pack});
1201 104 }
1203 106 next
1204 107==&gt; if(exists $isa{$pack});
1206 109:a if ($extra-- &gt; 0) {
1207 110: %isa = ($pack,1);</pre>
1208 </dd>
1209 <dd>
1210 <p>Breakable lines are marked with <code>:</code>. Lines with breakpoints are
1211 marked by <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_b"><code>b</code></a> and those with actions by <code>a</code>. The line that's
1212 about to be executed is marked by <code>==&gt;</code>.</p>
1213 </dd>
1214 <dd>
1215 <p>Please be aware that code in debugger listings may not look the same
1216 as your original source code. Line directives and external source
1217 filters can alter the code before Perl sees it, causing code to move
1218 from its original positions or take on entirely different forms.</p>
1219 </dd>
1220 </li>
1221 <dt><strong><a name="item_frame_listing">Frame listing</a></strong>
1223 <dd>
1224 <p>When the <code>frame</code> option is set, the debugger would print entered (and
1225 optionally exited) subroutines in different styles. See <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html">the perldebguts manpage</a>
1226 for incredibly long examples of these.</p>
1227 </dd>
1228 </li>
1229 </dl>
1231 </p>
1232 <h2><a name="debugging_compiletime_statements">Debugging compile-time statements</a></h2>
1233 <p>If you have compile-time executable statements (such as code within
1234 BEGIN and CHECK blocks or <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use</code></a> statements), these will <em>not</em> be
1235 stopped by debugger, although <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_require"><code>require</code></a>s and INIT blocks will, and
1236 compile-time statements can be traced with <code>AutoTrace</code> option set
1237 in <code>PERLDB_OPTS</code>). From your own Perl code, however, you can
1238 transfer control back to the debugger using the following statement,
1239 which is harmless if the debugger is not running:</p>
1240 <pre>
1241 $DB::single = 1;</pre>
1242 <p>If you set <code>$DB::single</code> to 2, it's equivalent to having
1243 just typed the <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_n"><code>n</code></a> command, whereas a value of 1 means the <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_s"><code>s</code></a>
1244 command. The <code>$DB::trace</code> variable should be set to 1 to simulate
1245 having typed the <code>t</code> command.</p>
1246 <p>Another way to debug compile-time code is to start the debugger, set a
1247 breakpoint on the <em>load</em> of some module:</p>
1248 <pre>
1249 DB&lt;7&gt; b load f:/perllib/lib/Carp.pm
1250 Will stop on load of `f:/perllib/lib/Carp.pm'.</pre>
1251 <p>and then restart the debugger using the <code>R</code> command (if possible). One can use <code>b
1252 compile subname</code> for the same purpose.</p>
1254 </p>
1255 <h2><a name="debugger_customization">Debugger Customization</a></h2>
1256 <p>The debugger probably contains enough configuration hooks that you
1257 won't ever have to modify it yourself. You may change the behaviour
1258 of debugger from within the debugger using its <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_o"><code>o</code></a> command, from
1259 the command line via the <code>PERLDB_OPTS</code> environment variable, and
1260 from customization files.</p>
1261 <p>You can do some customization by setting up a <em>.perldb</em> file, which
1262 contains initialization code. For instance, you could make aliases
1263 like these (the last one is one people expect to be there):</p>
1264 <pre>
1265 $DB::alias{'len'} = 's/^len(.*)/p length($1)/';
1266 $DB::alias{'stop'} = 's/^stop (at|in)/b/';
1267 $DB::alias{'ps'} = 's/^ps\b/p scalar /';
1268 $DB::alias{'quit'} = 's/^quit(\s*)/exit/';</pre>
1269 <p>You can change options from <em>.perldb</em> by using calls like this one;</p>
1270 <pre>
1271 parse_options(&quot;NonStop=1 LineInfo=db.out AutoTrace=1 frame=2&quot;);</pre>
1272 <p>The code is executed in the package <code>DB</code>. Note that <em>.perldb</em> is
1273 processed before processing <code>PERLDB_OPTS</code>. If <em>.perldb</em> defines the
1274 subroutine <code>afterinit</code>, that function is called after debugger
1275 initialization ends. <em>.perldb</em> may be contained in the current
1276 directory, or in the home directory. Because this file is sourced
1277 in by Perl and may contain arbitrary commands, for security reasons,
1278 it must be owned by the superuser or the current user, and writable
1279 by no one but its owner.</p>
1280 <p>You can mock TTY input to debugger by adding arbitrary commands to
1281 @DB::typeahead. For example, your <em>.perldb</em> file might contain:</p>
1282 <pre>
1283 sub afterinit { push @DB::typeahead, &quot;b 4&quot;, &quot;b 6&quot;; }</pre>
1284 <p>Which would attempt to set breakpoints on lines 4 and 6 immediately
1285 after debugger initialization. Note that @DB::typeahead is not a supported
1286 interface and is subject to change in future releases.</p>
1287 <p>If you want to modify the debugger, copy <em>perl5db.pl</em> from the
1288 Perl library to another name and hack it to your heart's content.
1289 You'll then want to set your <code>PERL5DB</code> environment variable to say
1290 something like this:</p>
1291 <pre>
1292 BEGIN { require &quot;myperl5db.pl&quot; }</pre>
1293 <p>As a last resort, you could also use <code>PERL5DB</code> to customize the debugger
1294 by directly setting internal variables or calling debugger functions.</p>
1295 <p>Note that any variables and functions that are not documented in
1296 this document (or in <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html">the perldebguts manpage</a>) are considered for internal
1297 use only, and as such are subject to change without notice.</p>
1299 </p>
1300 <h2><a name="readline_support">Readline Support</a></h2>
1301 <p>As shipped, the only command-line history supplied is a simplistic one
1302 that checks for leading exclamation points. However, if you install
1303 the Term::ReadKey and Term::ReadLine modules from CPAN, you will
1304 have full editing capabilities much like GNU <em>readline</em>(3) provides.
1305 Look for these in the <em>modules/by-module/Term</em> directory on CPAN.
1306 These do not support normal <strong>vi</strong> command-line editing, however.</p>
1307 <p>A rudimentary command-line completion is also available.
1308 Unfortunately, the names of lexical variables are not available for
1309 completion.</p>
1311 </p>
1312 <h2><a name="editor_support_for_debugging">Editor Support for Debugging</a></h2>
1313 <p>If you have the FSF's version of <strong>emacs</strong> installed on your system,
1314 it can interact with the Perl debugger to provide an integrated
1315 software development environment reminiscent of its interactions
1316 with C debuggers.</p>
1317 <p>Perl comes with a start file for making <strong>emacs</strong> act like a
1318 syntax-directed editor that understands (some of) Perl's syntax.
1319 Look in the <em>emacs</em> directory of the Perl source distribution.</p>
1320 <p>A similar setup by Tom Christiansen for interacting with any
1321 vendor-shipped <strong>vi</strong> and the X11 window system is also available.
1322 This works similarly to the integrated multiwindow support that
1323 <strong>emacs</strong> provides, where the debugger drives the editor. At the
1324 time of this writing, however, that tool's eventual location in the
1325 Perl distribution was uncertain.</p>
1326 <p>Users of <strong>vi</strong> should also look into <strong>vim</strong> and <strong>gvim</strong>, the mousey
1327 and windy version, for coloring of Perl keywords.</p>
1328 <p>Note that only perl can truly parse Perl, so all such CASE tools
1329 fall somewhat short of the mark, especially if you don't program
1330 your Perl as a C programmer might.</p>
1332 </p>
1333 <h2><a name="the_perl_profiler_x_profile__x_profiling__x_profiler_">The Perl Profiler
1334 </a></h2>
1335 <p>If you wish to supply an alternative debugger for Perl to run, just
1336 invoke your script with a colon and a package argument given to the
1337 <strong>-d</strong> flag. The most popular alternative debuggers for Perl is the
1338 Perl profiler. Devel::DProf is now included with the standard Perl
1339 distribution. To profile your Perl program in the file <em>mycode.pl</em>,
1340 just type:</p>
1341 <pre>
1342 $ perl -d:DProf mycode.pl</pre>
1343 <p>When the script terminates the profiler will dump the profile
1344 information to a file called <em>tmon.out</em>. A tool like <strong>dprofpp</strong>,
1345 also supplied with the standard Perl distribution, can be used to
1346 interpret the information in that profile.</p>
1348 </p>
1349 <hr />
1350 <h1><a name="debugging_regular_expressions_x_regular_expression__debugging__x_regex__debugging__x_regexp__debugging_">Debugging regular expressions
1352 </a></h1>
1353 <p><code>use re 'debug'</code> enables you to see the gory details of how the Perl
1354 regular expression engine works. In order to understand this typically
1355 voluminous output, one must not only have some idea about how regular
1356 expression matching works in general, but also know how Perl's regular
1357 expressions are internally compiled into an automaton. These matters
1358 are explored in some detail in
1359 <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html#debugging_regular_expressions">Debugging regular expressions in the perldebguts manpage</a>.</p>
1361 </p>
1362 <hr />
1363 <h1><a name="debugging_memory_usage_x_memory_usage_">Debugging memory usage
1364 </a></h1>
1365 <p>Perl contains internal support for reporting its own memory usage,
1366 but this is a fairly advanced concept that requires some understanding
1367 of how memory allocation works.
1368 See <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html#debugging_perl_memory_usage">Debugging Perl memory usage in the perldebguts manpage</a> for the details.</p>
1370 </p>
1371 <hr />
1372 <h1><a name="see_also">SEE ALSO</a></h1>
1373 <p>You did try the <strong>-w</strong> switch, didn't you?</p>
1374 <p><a href="file://C|\msysgit\mingw\html/pod/perldebtut.html">the perldebtut manpage</a>,
1375 <a href="file://C|\msysgit\mingw\html/pod/perldebguts.html">the perldebguts manpage</a>,
1376 <a href="file://C|\msysgit\mingw\html/lib/re.html">the re manpage</a>,
1377 <a href="file://C|\msysgit\mingw\html/lib/DB.html">the DB manpage</a>,
1378 <a href="file://C|\msysgit\mingw\html/lib/Devel/DProf.html">the Devel::DProf manpage</a>,
1379 <a href="file://C|\msysgit\mingw\html/utils/dprofpp.html">the dprofpp manpage</a>,
1380 <a href="file://C|\msysgit\mingw\html/lib/Dumpvalue.html">the Dumpvalue manpage</a>,
1382 <a href="file://C|\msysgit\mingw\html/pod/perlrun.html">the perlrun manpage</a>.</p>
1383 <p>When debugging a script that uses #! and is thus normally found in
1384 $PATH, the -S option causes perl to search $PATH for it, so you don't
1385 have to type the path or <code>which $scriptname</code>.</p>
1386 <pre>
1387 $ perl -Sd foo.pl</pre>
1389 </p>
1390 <hr />
1391 <h1><a name="bugs">BUGS</a></h1>
1392 <p>You cannot get stack frame information or in any fashion debug functions
1393 that were not compiled by Perl, such as those from C or C++ extensions.</p>
1394 <p>If you alter your @_ arguments in a subroutine (such as with <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_shift"><code>shift</code></a>
1395 or <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_pop"><code>pop</code></a>), the stack backtrace will not show the original values.</p>
1396 <p>The debugger does not currently work in conjunction with the <strong>-W</strong>
1397 command-line switch, because it itself is not free of warnings.</p>
1398 <p>If you're in a slow syscall (like <code>wait</code>ing, <code>accept</code>ing, or <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_read"><code>read</code></a>ing
1399 from your keyboard or a socket) and haven't set up your own <code>$SIG{INT}</code>
1400 handler, then you won't be able to CTRL-C your way back to the debugger,
1401 because the debugger's own <code>$SIG{INT}</code> handler doesn't understand that
1402 it needs to raise an exception to <code>longjmp(3)</code> out of slow syscalls.</p>
1403 <table border="0" width="100%" cellspacing="0" cellpadding="3">
1404 <tr><td class="block" style="background-color: #cccccc" valign="middle">
1405 <big><strong><span class="block">&nbsp;perldebug - Perl debugging</span></strong></big>
1406 </td></tr>
1407 </table>
1409 </body>
1411 </html>