Debian Codegraph @

upstream/mageia-cauldron/man1/perldebug.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "PERLDEBUG 1"
61 .TH PERLDEBUG 1 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 perldebug \- Perl debugging
68 .IX Xref "debug debugger"
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 First of all, have you tried using \f(CW\*(C`use strict;\*(C'\fR and
72 \&\f(CW\*(C`use warnings;\*(C'\fR?
73 .PP
74 If you\*(Aqre new to the Perl debugger, you may prefer to read
75 perldebtut, which is a tutorial introduction to the debugger.
76 .PP
77 If you\*(Aqre looking for the nitty gritty details of how the debugger is
78 \&\fIimplemented\fR, you may prefer to read perldebguts.
79 .PP
80 For in\-depth technical usage details, see perl5db.pl, the documentation
81 of the debugger itself.
82 .SH "The Perl Debugger"
83 .IX Header "The Perl Debugger"
84 If you invoke Perl with the \fB\-d\fR switch, your script runs under the
85 Perl source debugger. This works like an interactive Perl
86 environment, prompting for debugger commands that let you examine
87 source code, set breakpoints, get stack backtraces, change the values of
88 variables, etc. This is so convenient that you often fire up
89 the debugger all by itself just to test out Perl constructs
90 interactively to see what they do. For example:
91 .IX Xref "-d"
92 .PP
93 .Vb 1
94 \& $ perl \-d \-e 42
95 .Ve
96 .PP
97 In Perl, the debugger is not a separate program the way it usually is in the
98 typical compiled environment. Instead, the \fB\-d\fR flag tells the compiler
99 to insert source information into the parse trees it\*(Aqs about to hand off
100 to the interpreter. That means your code must first compile correctly
101 for the debugger to work on it. Then when the interpreter starts up, it
102 preloads a special Perl library file containing the debugger.
103 .PP
104 The program will halt \fIright before\fR the first run\-time executable
105 statement (but see below regarding compile\-time statements) and ask you
106 to enter a debugger command. Contrary to popular expectations, whenever
107 the debugger halts and shows you a line of code, it always displays the
108 line it\*(Aqs \fIabout\fR to execute, rather than the one it has just executed.
109 .PP
110 Any command not recognized by the debugger is directly executed
111 (\f(CW\*(C`eval\*(C'\fR\*(Aqd) as Perl code in the current package. (The debugger
112 uses the DB package for keeping its own state information.)
113 .PP
114 Note that the said \f(CW\*(C`eval\*(C'\fR is bound by an implicit scope. As a
115 result any newly introduced lexical variable or any modified
116 capture buffer content is lost after the eval. The debugger is a
117 nice environment to learn Perl, but if you interactively experiment using
118 material which should be in the same scope, stuff it in one line.
119 .PP
120 For any text entered at the debugger prompt, leading and trailing whitespace
121 is first stripped before further processing. If a debugger command
122 coincides with some function in your own program, merely precede the
123 function with something that doesn\*(Aqt look like a debugger command, such
124 as a leading \f(CW\*(C`;\*(C'\fR or perhaps a \f(CW\*(C`+\*(C'\fR, or by wrapping it with parentheses
125 or braces.
126 .SS "Calling the Debugger"
127 .IX Subsection "Calling the Debugger"
128 There are several ways to call the debugger:
129 .IP "perl \-d program_name" 4
130 .IX Item "perl -d program_name"
131 On the given program identified by \f(CW\*(C`program_name\*(C'\fR.
132 .IP "perl \-d \-e 0" 4
133 .IX Item "perl -d -e 0"
134 Interactively supply an arbitrary \f(CW\*(C`expression\*(C'\fR using \f(CW\*(C`\-e\*(C'\fR.
135 .IP "perl \-d:ptkdb program_name" 4
136 .IX Item "perl -d:ptkdb program_name"
137 Debug a given program via the Devel::ptkdb GUI.
138 .IP "perl \-dt threaded_program_name" 4
139 .IX Item "perl -dt threaded_program_name"
140 Debug a given program using threads (experimental).
141 .PP
142 If Perl is called with the \f(CW\*(C`\-d\*(C'\fR switch, the variable \f(CW$^P\fR will hold a true
143 value. This is useful if you need to know if your code is running under the
144 debugger:
145 .PP
146 .Vb 3
147 \& if ( $^P ) {
148 \& # running under the debugger
149 \& }
150 .Ve
151 .PP
152 See "$^P" in perlvar for more information on the variable.
153 .SS "Debugger Commands"
154 .IX Subsection "Debugger Commands"
155 The interactive debugger understands the following commands:
156 .IP h 12
157 .IX Xref "debugger command, h"
158 .IX Item "h"
159 Prints out a summary help message
160 .IP "h [command]" 12
161 .IX Item "h [command]"
162 Prints out a help message for the given debugger command.
163 .IP "h h" 12
164 .IX Item "h h"
165 The special argument of \f(CW\*(C`h h\*(C'\fR produces the entire help page, which is quite long.
166 .Sp
167 If the output of the \f(CW\*(C`h h\*(C'\fR command (or any command, for that matter) scrolls
168 past your screen, precede the command with a leading pipe symbol so
169 that it\*(Aqs run through your pager, as in
170 .Sp
171 .Vb 1
172 \& DB> |h h
173 .Ve
174 .Sp
175 You may change the pager which is used via \f(CW\*(C`o pager=...\*(C'\fR command.
176 .IP "p expr" 12
177 .IX Xref "debugger command, p"
178 .IX Item "p expr"
179 Same as \f(CW\*(C`print {$DB::OUT} expr\*(C'\fR in the current package. In particular,
180 because this is just Perl\*(Aqs own \f(CW\*(C`print\*(C'\fR function, this means that nested
181 data structures and objects are not dumped, unlike with the \f(CW\*(C`x\*(C'\fR command.
182 .Sp
183 The \f(CW\*(C`DB::OUT\*(C'\fR filehandle is opened to \fI/dev/tty\fR, regardless of
184 where STDOUT may be redirected to.
185 .IP "x [maxdepth] expr" 12
186 .IX Xref "debugger command, x"
187 .IX Item "x [maxdepth] expr"
188 Evaluates its expression in list context and dumps out the result in a
189 pretty\-printed fashion. Nested data structures are printed out
190 recursively, unlike the real \f(CW\*(C`print\*(C'\fR function in Perl. When dumping
191 hashes, you\*(Aqll probably prefer \*(Aqx \e%h\*(Aq rather than \*(Aqx \f(CW%h\fR\*(Aq.
192 See Dumpvalue if you\*(Aqd like to do this yourself.
193 .Sp
194 The output format is governed by multiple options described under
195 "Configurable Options".
196 .Sp
197 If the \f(CW\*(C`maxdepth\*(C'\fR is included, it must be a numeral \fIN\fR; the value is
198 dumped only \fIN\fR levels deep, as if the \f(CW\*(C`dumpDepth\*(C'\fR option had been
199 temporarily set to \fIN\fR.
200 .IP "V [pkg [vars]]" 12
201 .IX Xref "debugger command, V"
202 .IX Item "V [pkg [vars]]"
203 Display all (or some) variables in package (defaulting to \f(CW\*(C`main\*(C'\fR)
204 using a data pretty\-printer (hashes show their keys and values so
205 you see what\*(Aqs what, control characters are made printable, etc.).
206 Make sure you don\*(Aqt put the type specifier (like \f(CW\*(C`$\*(C'\fR) there, just
207 the symbol names, like this:
208 .Sp
209 .Vb 1
210 \& V DB filename line
211 .Ve
212 .Sp
213 Use \f(CW\*(C`~pattern\*(C'\fR and \f(CW\*(C`!pattern\*(C'\fR for positive and negative regexes.
214 .Sp
215 This is similar to calling the \f(CW\*(C`x\*(C'\fR command on each applicable var.
216 .IP "X [vars]" 12
217 .IX Xref "debugger command, X"
218 .IX Item "X [vars]"
219 Same as \f(CW\*(C`V currentpackage [vars]\*(C'\fR.
220 .IP "y [level [vars]]" 12
221 .IX Xref "debugger command, y"
222 .IX Item "y [level [vars]]"
223 Display all (or some) lexical variables (mnemonic: \f(CW\*(C`mY\*(C'\fR variables)
224 in the current scope or \fIlevel\fR scopes higher. You can limit the
225 variables that you see with \fIvars\fR which works exactly as it does
226 for the \f(CW\*(C`V\*(C'\fR and \f(CW\*(C`X\*(C'\fR commands. Requires the PadWalker module
227 version 0.08 or higher; will warn if this isn\*(Aqt installed. Output
228 is pretty\-printed in the same style as for \f(CW\*(C`V\*(C'\fR and the format is
229 controlled by the same options.
230 .IP T 12
231 .IX Xref "debugger command, T backtrace stack, backtrace"
232 .IX Item "T"
233 Produce a stack backtrace. See below for details on its output.
234 .IP "s [expr]" 12
235 .IX Xref "debugger command, s step"
236 .IX Item "s [expr]"
237 Single step. Executes until the beginning of another
238 statement, descending into subroutine calls. If an expression is
239 supplied that includes function calls, it too will be single\-stepped.
240 .IP "n [expr]" 12
241 .IX Xref "debugger command, n"
242 .IX Item "n [expr]"
243 Next. Executes over subroutine calls, until the beginning
244 of the next statement. If an expression is supplied that includes
245 function calls, those functions will be executed with stops before
246 each statement.
247 .IP r 12
248 .IX Xref "debugger command, r"
249 .IX Item "r"
250 Continue until the return from the current subroutine.
251 Dump the return value if the \f(CW\*(C`PrintRet\*(C'\fR option is set (default).
252 .IP <CR> 12
253 .IX Item "<CR>"
254 Repeat last \f(CW\*(C`n\*(C'\fR or \f(CW\*(C`s\*(C'\fR command.
255 .IP "c [line|sub]" 12
256 .IX Xref "debugger command, c"
257 .IX Item "c [line|sub]"
258 Continue, optionally inserting a one\-time\-only breakpoint
259 at the specified line or subroutine.
260 .IP l 12
261 .IX Xref "debugger command, l"
262 .IX Item "l"
263 List next window of lines.
264 .IP "l min+incr" 12
265 .IX Item "l min+incr"
266 List \f(CW\*(C`incr+1\*(C'\fR lines starting at \f(CW\*(C`min\*(C'\fR.
267 .IP "l min\-max" 12
268 .IX Item "l min-max"
269 List lines \f(CW\*(C`min\*(C'\fR through \f(CW\*(C`max\*(C'\fR. \f(CW\*(C`l \-\*(C'\fR is synonymous to \f(CW\*(C`\-\*(C'\fR.
270 .IP "l line" 12
271 .IX Item "l line"
272 List a single line.
273 .IP "l subname" 12
274 .IX Item "l subname"
275 List first window of lines from subroutine. \fIsubname\fR may
276 be a variable that contains a code reference.
277 .IP \- 12
278 .IX Xref "debugger command, -"
279 List previous window of lines.
280 .IP "v [line]" 12
281 .IX Xref "debugger command, v"
282 .IX Item "v [line]"
283 View a few lines of code around the current line.
284 .IP . 12
285 .IX Xref "debugger command, ."
286 Return the internal debugger pointer to the line last
287 executed, and print out that line.
288 .IP "f filename" 12
289 .IX Xref "debugger command, f"
290 .IX Item "f filename"
291 Switch to viewing a different file or \f(CW\*(C`eval\*(C'\fR statement. If \fIfilename\fR
292 is not a full pathname found in the values of \f(CW%INC\fR, it is considered
293 a regex.
294 .Sp
295 \&\f(CW\*(C`eval\*(C'\fRed strings (when accessible) are considered to be filenames:
296 \&\f(CW\*(C`f (eval 7)\*(C'\fR and \f(CW\*(C`f eval 7\eb\*(C'\fR access the body of the 7th \f(CW\*(C`eval\*(C'\fRed string
297 (in the order of execution). The bodies of the currently executed \f(CW\*(C`eval\*(C'\fR
298 and of \f(CW\*(C`eval\*(C'\fRed strings that define subroutines are saved and thus
299 accessible.
300 .IP /pattern/ 12
301 .IX Item "/pattern/"
302 Search forwards for pattern (a Perl regex); final / is optional.
303 The search is case\-insensitive by default.
304 .IP ?pattern? 12
305 .IX Item "?pattern?"
306 Search backwards for pattern; final ? is optional.
307 The search is case\-insensitive by default.
308 .IP "L [abw]" 12
309 .IX Xref "debugger command, L"
310 .IX Item "L [abw]"
311 List (default all) actions, breakpoints and watch expressions
312 .IP "S [[!]regex]" 12
313 .IX Xref "debugger command, S"
314 .IX Item "S [[!]regex]"
315 List subroutine names [not] matching the regex.
316 .IP "t [n]" 12
317 .IX Xref "debugger command, t"
318 .IX Item "t [n]"
319 Toggle trace mode (see also the \f(CW\*(C`AutoTrace\*(C'\fR option).
320 Optional argument is the maximum number of levels to trace below
321 the current one; anything deeper than that will be silent.
322 .IP "t [n] expr" 12
323 .IX Xref "debugger command, t"
324 .IX Item "t [n] expr"
325 Trace through execution of \f(CW\*(C`expr\*(C'\fR.
326 Optional first argument is the maximum number of levels to trace below
327 the current one; anything deeper than that will be silent.
328 See "Frame Listing Output Examples" in perldebguts for examples.
329 .IP b 12
330 .IX Xref "breakpoint debugger command, b"
331 .IX Item "b"
332 Sets breakpoint on current line
333 .IP "b [line] [condition]" 12
334 .IX Xref "breakpoint debugger command, b"
335 .IX Item "b [line] [condition]"
336 Set a breakpoint before the given line. If a condition
337 is specified, it\*(Aqs evaluated each time the statement is reached: a
338 breakpoint is taken only if the condition is true. Breakpoints may
339 only be set on lines that begin an executable statement. Conditions
340 don\*(Aqt use \f(CW\*(C`if\*(C'\fR:
341 .Sp
342 .Vb 3
343 \& b 237 $x > 30
344 \& b 237 ++$count237 < 11
345 \& b 33 /pattern/i
346 .Ve
347 .Sp
348 If the line number is \f(CW\*(C`.\*(C'\fR, sets a breakpoint on the current line:
349 .Sp
350 .Vb 1
351 \& b . $n > 100
352 .Ve
353 .IP "b [file]:[line] [condition]" 12
354 .IX Xref "breakpoint debugger command, b"
355 .IX Item "b [file]:[line] [condition]"
356 Set a breakpoint before the given line in a (possibly different) file. If a
357 condition is specified, it\*(Aqs evaluated each time the statement is reached: a
358 breakpoint is taken only if the condition is true. Breakpoints may only be set
359 on lines that begin an executable statement. Conditions don\*(Aqt use \f(CW\*(C`if\*(C'\fR:
360 .Sp
361 .Vb 2
362 \& b lib/MyModule.pm:237 $x > 30
363 \& b /usr/lib/perl5/site_perl/CGI.pm:100 ++$count100 < 11
364 .Ve
365 .IP "b subname [condition]" 12
366 .IX Xref "breakpoint debugger command, b"
367 .IX Item "b subname [condition]"
368 Set a breakpoint before the first line of the named subroutine. \fIsubname\fR may
369 be a variable containing a code reference (in this case \fIcondition\fR
370 is not supported).
371 .IP "b postpone subname [condition]" 12
372 .IX Xref "breakpoint debugger command, b"
373 .IX Item "b postpone subname [condition]"
374 Set a breakpoint at first line of subroutine after it is compiled.
375 .IP "b load filename" 12
376 .IX Xref "breakpoint debugger command, b"
377 .IX Item "b load filename"
378 Set a breakpoint before the first executed line of the \fIfilename\fR,
379 which should be a full pathname found amongst the \f(CW%INC\fR values.
380 .IP "b compile subname" 12
381 .IX Xref "breakpoint debugger command, b"
382 .IX Item "b compile subname"
383 Sets a breakpoint before the first statement executed after the specified
384 subroutine is compiled.
385 .IP "B line" 12
386 .IX Xref "breakpoint debugger command, B"
387 .IX Item "B line"
388 Delete a breakpoint from the specified \fIline\fR.
389 .IP "B *" 12
390 .IX Xref "breakpoint debugger command, B"
391 .IX Item "B *"
392 Delete all installed breakpoints.
393 .IP "disable [file]:[line]" 12
394 .IX Xref "breakpoint debugger command, disable disable"
395 .IX Item "disable [file]:[line]"
396 Disable the breakpoint so it won\*(Aqt stop the execution of the program.
397 Breakpoints are enabled by default and can be re\-enabled using the \f(CW\*(C`enable\*(C'\fR
398 command.
399 .IP "disable [line]" 12
400 .IX Xref "breakpoint debugger command, disable disable"
401 .IX Item "disable [line]"
402 Disable the breakpoint so it won\*(Aqt stop the execution of the program.
403 Breakpoints are enabled by default and can be re\-enabled using the \f(CW\*(C`enable\*(C'\fR
404 command.
405 .Sp
406 This is done for a breakpoint in the current file.
407 .IP "enable [file]:[line]" 12
408 .IX Xref "breakpoint debugger command, disable disable"
409 .IX Item "enable [file]:[line]"
410 Enable the breakpoint so it will stop the execution of the program.
411 .IP "enable [line]" 12
412 .IX Xref "breakpoint debugger command, disable disable"
413 .IX Item "enable [line]"
414 Enable the breakpoint so it will stop the execution of the program.
415 .Sp
416 This is done for a breakpoint in the current file.
417 .IP "a [line] command" 12
418 .IX Xref "debugger command, a"
419 .IX Item "a [line] command"
420 Set an action to be done before the line is executed. If \fIline\fR is
421 omitted, set an action on the line about to be executed.
422 The sequence of steps taken by the debugger is
423 .Sp
424 .Vb 5
425 \& 1. check for a breakpoint at this line
426 \& 2. print the line if necessary (tracing)
427 \& 3. do any actions associated with that line
428 \& 4. prompt user if at a breakpoint or in single\-step
429 \& 5. evaluate line
430 .Ve
431 .Sp
432 For example, this will print out \f(CW$foo\fR every time line
433 53 is passed:
434 .Sp
435 .Vb 1
436 \& a 53 print "DB FOUND $foo\en"
437 .Ve
438 .IP "A line" 12
439 .IX Xref "debugger command, A"
440 .IX Item "A line"
441 Delete an action from the specified line.
442 .IP "A *" 12
443 .IX Xref "debugger command, A"
444 .IX Item "A *"
445 Delete all installed actions.
446 .IP "w expr" 12
447 .IX Xref "debugger command, w"
448 .IX Item "w expr"
449 Add a global watch\-expression. Whenever a watched global changes the
450 debugger will stop and display the old and new values.
451 .IP "W expr" 12
452 .IX Xref "debugger command, W"
453 .IX Item "W expr"
454 Delete watch\-expression
455 .IP "W *" 12
456 .IX Xref "debugger command, W"
457 .IX Item "W *"
458 Delete all watch\-expressions.
459 .IP o 12
460 .IX Xref "debugger command, o"
461 .IX Item "o"
462 Display all options.
463 .IP "o booloption ..." 12
464 .IX Xref "debugger command, o"
465 .IX Item "o booloption ..."
466 Set each listed Boolean option to the value \f(CW1\fR.
467 .IP "o anyoption? ..." 12
468 .IX Xref "debugger command, o"
469 .IX Item "o anyoption? ..."
470 Print out the value of one or more options.
471 .IP "o option=value ..." 12
472 .IX Xref "debugger command, o"
473 .IX Item "o option=value ..."
474 Set the value of one or more options. If the value has internal
475 whitespace, it should be quoted. For example, you could set \f(CW\*(C`o
476 pager="less \-MQeicsNfr"\*(C'\fR to call \fBless\fR with those specific options.
477 You may use either single or double quotes, but if you do, you must
478 escape any embedded instances of same sort of quote you began with,
479 as well as any escaping any escapes that immediately precede that
480 quote but which are not meant to escape the quote itself. In other
481 words, you follow single\-quoting rules irrespective of the quote;
482 eg: \f(CW\*(C`o option=\*(Aqthis isn\e\*(Aqt bad\*(Aq\*(C'\fR or \f(CW\*(C`o option="She said, \e"Isn\*(Aqt
483 it?\e""\*(C'\fR.
484 .Sp
485 For historical reasons, the \f(CW\*(C`=value\*(C'\fR is optional, but defaults to
486 1 only where it is safe to do so\-\-that is, mostly for Boolean
487 options. It is always better to assign a specific value using \f(CW\*(C`=\*(C'\fR.
488 The \f(CW\*(C`option\*(C'\fR can be abbreviated, but for clarity probably should
489 not be. Several options can be set together. See "Configurable Options"
490 for a list of these.
491 .IP "< ?" 12
492 .IX Xref "debugger command, <"
493 List out all pre\-prompt Perl command actions.
494 .IP "< [ command ]" 12
495 .IX Xref "debugger command, <"
496 .IX Item "< [ command ]"
497 Set an action (Perl command) to happen before every debugger prompt.
498 A multi\-line command may be entered by backslashing the newlines.
499 .IP "< *" 12
500 .IX Xref "debugger command, <"
501 Delete all pre\-prompt Perl command actions.
502 .IP "<< command" 12
503 .IX Xref "debugger command, <<"
504 .IX Item "<< command"
505 Add an action (Perl command) to happen before every debugger prompt.
506 A multi\-line command may be entered by backwhacking the newlines.
507 .IP "> ?" 12
508 .IX Xref "debugger command, >"
509 List out post\-prompt Perl command actions.
510 .IP "> command" 12
511 .IX Xref "debugger command, >"
512 .IX Item "> command"
513 Set an action (Perl command) to happen after the prompt when you\*(Aqve
514 just given a command to return to executing the script. A multi\-line
515 command may be entered by backslashing the newlines (we bet you
516 couldn\*(Aqt have guessed this by now).
517 .IP "> *" 12
518 .IX Xref "debugger command, >"
519 Delete all post\-prompt Perl command actions.
520 .IP ">> command" 12
521 .IX Xref "debugger command, >>"
522 .IX Item ">> command"
523 Adds an action (Perl command) to happen after the prompt when you\*(Aqve
524 just given a command to return to executing the script. A multi\-line
525 command may be entered by backslashing the newlines.
526 .IP "{ ?" 12
527 .IX Xref "debugger command, {"
528 List out pre\-prompt debugger commands.
529 .IP "{ [ command ]" 12
530 .IX Item "{ [ command ]"
531 Set an action (debugger command) to happen before every debugger prompt.
532 A multi\-line command may be entered in the customary fashion.
533 .Sp
534 Because this command is in some senses new, a warning is issued if
535 you appear to have accidentally entered a block instead. If that\*(Aqs
536 what you mean to do, write it as with \f(CW\*(C`;{ ... }\*(C'\fR or even
537 \&\f(CW\*(C`do { ... }\*(C'\fR.
538 .IP "{ *" 12
539 .IX Xref "debugger command, {"
540 Delete all pre\-prompt debugger commands.
541 .IP "{{ command" 12
542 .IX Xref "debugger command, {{"
543 .IX Item "{{ command"
544 Add an action (debugger command) to happen before every debugger prompt.
545 A multi\-line command may be entered, if you can guess how: see above.
546 .IP "! number" 12
547 .IX Xref "debugger command, !"
548 .IX Item "! number"
549 Redo a previous command (defaults to the previous command).
550 .IP "! \-number" 12
551 .IX Xref "debugger command, !"
552 .IX Item "! -number"
553 Redo number\*(Aqth previous command.
554 .IP "! pattern" 12
555 .IX Xref "debugger command, !"
556 .IX Item "! pattern"
557 Redo last command that started with pattern.
558 See \f(CW\*(C`o\ recallCommand\*(C'\fR, too.
559 .IP "!! cmd" 12
560 .IX Xref "debugger command, !!"
561 .IX Item "!! cmd"
562 Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT) See
563 \&\f(CW\*(C`o\ shellBang\*(C'\fR, also. Note that the user\*(Aqs current shell (well,
564 their \f(CW$ENV{SHELL}\fR variable) will be used, which can interfere
565 with proper interpretation of exit status or signal and coredump
566 information.
567 .IP "source file" 12
568 .IX Xref "debugger command, source"
569 .IX Item "source file"
570 Read and execute debugger commands from \fIfile\fR.
571 \&\fIfile\fR may itself contain \f(CW\*(C`source\*(C'\fR commands.
572 .IP "H \-number" 12
573 .IX Xref "debugger command, H"
574 .IX Item "H -number"
575 Display last n commands. Only commands longer than one character are
576 listed. If \fInumber\fR is omitted, list them all.
577 .IP "q or ^D" 12
578 .IX Xref "debugger command, q debugger command, ^D"
579 .IX Item "q or ^D"
580 Quit. ("quit" doesn\*(Aqt work for this, unless you\*(Aqve made an alias)
581 This is the only supported way to exit the debugger, though typing
582 \&\f(CW\*(C`exit\*(C'\fR twice might work.
583 .Sp
584 Set the \f(CW\*(C`inhibit_exit\*(C'\fR option to 0 if you want to be able to step
585 off the end the script. You may also need to set \f(CW$finished\fR to 0
586 if you want to step through global destruction.
587 .IP R 12
588 .IX Xref "debugger command, R"
589 .IX Item "R"
590 Restart the debugger by \f(CWexec()\fRing a new session. We try to maintain
591 your history across this, but internal settings and command\-line options
592 may be lost.
593 .Sp
594 The following settings are currently preserved: history, breakpoints,
595 actions, debugger options, and the Perl command\-line
596 options \fB\-w\fR, \fB\-I\fR, and \fB\-e\fR.
597 .IP |dbcmd 12
598 .IX Xref "debugger command, |"
599 .IX Item "|dbcmd"
600 Run the debugger command, piping DB::OUT into your current pager.
601 .IP ||dbcmd 12
602 .IX Xref "debugger command, ||"
603 .IX Item "||dbcmd"
604 Same as \f(CW\*(C`|dbcmd\*(C'\fR but DB::OUT is temporarily \f(CW\*(C`select\*(C'\fRed as well.
605 .IP "= [alias value]" 12
606 .IX Xref "debugger command, ="
607 .IX Item "= [alias value]"
608 Define a command alias, like
609 .Sp
610 .Vb 1
611 \& = quit q
612 .Ve
613 .Sp
614 or list current aliases.
615 .IP command 12
616 .IX Item "command"
617 Execute command as a Perl statement. A trailing semicolon will be
618 supplied. If the Perl statement would otherwise be confused for a
619 Perl debugger, use a leading semicolon, too.
620 .IP "m expr" 12
621 .IX Xref "debugger command, m"
622 .IX Item "m expr"
623 List which methods may be called on the result of the evaluated
624 expression. The expression may be evaluated to a reference to a
625 blessed object, or to a package name.
626 .IP M 12
627 .IX Xref "debugger command, M"
628 .IX Item "M"
629 Display all loaded modules and their versions.
630 .IP "man [manpage]" 12
631 .IX Xref "debugger command, man"
632 .IX Item "man [manpage]"
633 Despite its name, this calls your system\*(Aqs default documentation
634 viewer on the given page, or on the viewer itself if \fImanpage\fR is
635 omitted. If that viewer is \fBman\fR, the current \f(CW\*(C`Config\*(C'\fR information
636 is used to invoke \fBman\fR using the proper MANPATH or \fB\-M\fR\ \fImanpath\fR option. Failed lookups of the form \f(CW\*(C`XXX\*(C'\fR that match
637 known manpages of the form \fIperlXXX\fR will be retried. This lets
638 you type \f(CW\*(C`man debug\*(C'\fR or \f(CW\*(C`man op\*(C'\fR from the debugger.
639 .Sp
640 On systems traditionally bereft of a usable \fBman\fR command, the
641 debugger invokes \fBperldoc\fR. Occasionally this determination is
642 incorrect due to recalcitrant vendors or rather more felicitously,
643 to enterprising users. If you fall into either category, just
644 manually set the \f(CW$DB::doccmd\fR variable to whatever viewer to view
645 the Perl documentation on your system. This may be set in an rc
646 file, or through direct assignment. We\*(Aqre still waiting for a
647 working example of something along the lines of:
648 .Sp
649 .Vb 1
650 \& $DB::doccmd = \*(Aqnetscape \-remote http://something.here/\*(Aq;
651 .Ve
652 .SS "Configurable Options"
653 .IX Subsection "Configurable Options"
654 The debugger has numerous options settable using the \f(CW\*(C`o\*(C'\fR command,
655 either interactively or from the environment or an rc file. The file
656 is named \fI./.perldb\fR or \fI~/.perldb\fR under Unix with \fI/dev/tty\fR,
657 \&\fIperldb.ini\fR otherwise.
658 .ie n .IP """recallCommand"", ""ShellBang""" 12
659 .el .IP "\f(CWrecallCommand\fR, \f(CWShellBang\fR" 12
660 .IX Xref "debugger option, recallCommand debugger option, ShellBang"
661 .IX Item "recallCommand, ShellBang"
662 The characters used to recall a command or spawn a shell. By
663 default, both are set to \f(CW\*(C`!\*(C'\fR, which is unfortunate.
664 .ie n .IP """pager""" 12
665 .el .IP \f(CWpager\fR 12
666 .IX Xref "debugger option, pager"
667 .IX Item "pager"
668 Program to use for output of pager\-piped commands (those beginning
669 with a \f(CW\*(C`|\*(C'\fR character.) By default, \f(CW$ENV{PAGER}\fR will be used.
670 Because the debugger uses your current terminal characteristics
671 for bold and underlining, if the chosen pager does not pass escape
672 sequences through unchanged, the output of some debugger commands
673 will not be readable when sent through the pager.
674 .ie n .IP """tkRunning""" 12
675 .el .IP \f(CWtkRunning\fR 12
676 .IX Xref "debugger option, tkRunning"
677 .IX Item "tkRunning"
678 Run Tk while prompting (with ReadLine).
679 .ie n .IP """signalLevel"", ""warnLevel"", ""dieLevel""" 12
680 .el .IP "\f(CWsignalLevel\fR, \f(CWwarnLevel\fR, \f(CWdieLevel\fR" 12
681 .IX Xref "debugger option, signalLevel debugger option, warnLevel debugger option, dieLevel"
682 .IX Item "signalLevel, warnLevel, dieLevel"
683 Level of verbosity. By default, the debugger leaves your exceptions
684 and warnings alone, because altering them can break correctly running
685 programs. It will attempt to print a message when uncaught INT, BUS, or
686 SEGV signals arrive. (But see the mention of signals in "BUGS" below.)
687 .Sp
688 To disable this default safe mode, set these values to something higher
689 than 0. At a level of 1, you get backtraces upon receiving any kind
690 of warning (this is often annoying) or exception (this is
691 often valuable). Unfortunately, the debugger cannot discern fatal
692 exceptions from non\-fatal ones. If \f(CW\*(C`dieLevel\*(C'\fR is even 1, then your
693 non\-fatal exceptions are also traced and unceremoniously altered if they
694 came from \f(CW\*(C`eval\*(Aqed\*(C'\fR strings or from any kind of \f(CW\*(C`eval\*(C'\fR within modules
695 you\*(Aqre attempting to load. If \f(CW\*(C`dieLevel\*(C'\fR is 2, the debugger doesn\*(Aqt
696 care where they came from: It usurps your exception handler and prints
697 out a trace, then modifies all exceptions with its own embellishments.
698 This may perhaps be useful for some tracing purposes, but tends to hopelessly
699 destroy any program that takes its exception handling seriously.
700 .ie n .IP """AutoTrace""" 12
701 .el .IP \f(CWAutoTrace\fR 12
702 .IX Xref "debugger option, AutoTrace"
703 .IX Item "AutoTrace"
704 Trace mode (similar to \f(CW\*(C`t\*(C'\fR command, but can be put into
705 \&\f(CW\*(C`PERLDB_OPTS\*(C'\fR).
706 .ie n .IP """LineInfo""" 12
707 .el .IP \f(CWLineInfo\fR 12
708 .IX Xref "debugger option, LineInfo"
709 .IX Item "LineInfo"
710 File or pipe to print line number info to. If it is a pipe (say,
711 \&\f(CW\*(C`|visual_perl_db\*(C'\fR), then a short message is used. This is the
712 mechanism used to interact with a client editor or visual debugger,
713 such as the special \f(CW\*(C`vi\*(C'\fR or \f(CW\*(C`emacs\*(C'\fR hooks, or the \f(CW\*(C`ddd\*(C'\fR graphical
714 debugger.
715 .ie n .IP """inhibit_exit""" 12
716 .el .IP \f(CWinhibit_exit\fR 12
717 .IX Xref "debugger option, inhibit_exit"
718 .IX Item "inhibit_exit"
719 If 0, allows \fIstepping off\fR the end of the script.
720 .ie n .IP """PrintRet""" 12
721 .el .IP \f(CWPrintRet\fR 12
722 .IX Xref "debugger option, PrintRet"
723 .IX Item "PrintRet"
724 Print return value after \f(CW\*(C`r\*(C'\fR command if set (default).
725 .ie n .IP """ornaments""" 12
726 .el .IP \f(CWornaments\fR 12
727 .IX Xref "debugger option, ornaments"
728 .IX Item "ornaments"
729 Affects screen appearance of the command line (see Term::ReadLine).
730 There is currently no way to disable these, which can render
731 some output illegible on some displays, or with some pagers.
732 This is considered a bug.
733 .ie n .IP """frame""" 12
734 .el .IP \f(CWframe\fR 12
735 .IX Xref "debugger option, frame"
736 .IX Item "frame"
737 Affects the printing of messages upon entry and exit from subroutines. If
738 \&\f(CW\*(C`frame & 2\*(C'\fR is false, messages are printed on entry only. (Printing
739 on exit might be useful if interspersed with other messages.)
740 .Sp
741 If \f(CW\*(C`frame & 4\*(C'\fR, arguments to functions are printed, plus context
742 and caller info. If \f(CW\*(C`frame & 8\*(C'\fR, overloaded \f(CW\*(C`stringify\*(C'\fR and
743 \&\f(CW\*(C`tie\*(C'\fRd \f(CW\*(C`FETCH\*(C'\fR is enabled on the printed arguments. If \f(CW\*(C`frame
744 & 16\*(C'\fR, the return value from the subroutine is printed.
745 .Sp
746 The length at which the argument list is truncated is governed by the
747 next option:
748 .ie n .IP """maxTraceLen""" 12
749 .el .IP \f(CWmaxTraceLen\fR 12
750 .IX Xref "debugger option, maxTraceLen"
751 .IX Item "maxTraceLen"
752 Length to truncate the argument list when the \f(CW\*(C`frame\*(C'\fR option\*(Aqs
753 bit 4 is set.
754 .ie n .IP """windowSize""" 12
755 .el .IP \f(CWwindowSize\fR 12
756 .IX Xref "debugger option, windowSize"
757 .IX Item "windowSize"
758 Change the size of code list window (default is 10 lines).
759 .PP
760 The following options affect what happens with \f(CW\*(C`V\*(C'\fR, \f(CW\*(C`X\*(C'\fR, and \f(CW\*(C`x\*(C'\fR
761 commands:
762 .ie n .IP """arrayDepth"", ""hashDepth""" 12
763 .el .IP "\f(CWarrayDepth\fR, \f(CWhashDepth\fR" 12
764 .IX Xref "debugger option, arrayDepth debugger option, hashDepth"
765 .IX Item "arrayDepth, hashDepth"
766 Print only first N elements (\*(Aq\*(Aq for all).
767 .ie n .IP """dumpDepth""" 12
768 .el .IP \f(CWdumpDepth\fR 12
769 .IX Xref "debugger option, dumpDepth"
770 .IX Item "dumpDepth"
771 Limit recursion depth to N levels when dumping structures.
772 Negative values are interpreted as infinity. Default: infinity.
773 .ie n .IP """compactDump"", ""veryCompact""" 12
774 .el .IP "\f(CWcompactDump\fR, \f(CWveryCompact\fR" 12
775 .IX Xref "debugger option, compactDump debugger option, veryCompact"
776 .IX Item "compactDump, veryCompact"
777 Change the style of array and hash output. If \f(CW\*(C`compactDump\*(C'\fR, short array
778 may be printed on one line.
779 .ie n .IP """globPrint""" 12
780 .el .IP \f(CWglobPrint\fR 12
781 .IX Xref "debugger option, globPrint"
782 .IX Item "globPrint"
783 Whether to print contents of globs.
784 .ie n .IP """DumpDBFiles""" 12
785 .el .IP \f(CWDumpDBFiles\fR 12
786 .IX Xref "debugger option, DumpDBFiles"
787 .IX Item "DumpDBFiles"
788 Dump arrays holding debugged files.
789 .ie n .IP """DumpPackages""" 12
790 .el .IP \f(CWDumpPackages\fR 12
791 .IX Xref "debugger option, DumpPackages"
792 .IX Item "DumpPackages"
793 Dump symbol tables of packages.
794 .ie n .IP """DumpReused""" 12
795 .el .IP \f(CWDumpReused\fR 12
796 .IX Xref "debugger option, DumpReused"
797 .IX Item "DumpReused"
798 Dump contents of "reused" addresses.
799 .ie n .IP """quote"", ""HighBit"", ""undefPrint""" 12
800 .el .IP "\f(CWquote\fR, \f(CWHighBit\fR, \f(CWundefPrint\fR" 12
801 .IX Xref "debugger option, quote debugger option, HighBit debugger option, undefPrint"
802 .IX Item "quote, HighBit, undefPrint"
803 Change the style of string dump. The default value for \f(CW\*(C`quote\*(C'\fR
804 is \f(CW\*(C`auto\*(C'\fR; one can enable double\-quotish or single\-quotish format
805 by setting it to \f(CW\*(C`"\*(C'\fR or \f(CW\*(C`\*(Aq\*(C'\fR, respectively. By default, characters
806 with their high bit set are printed verbatim.
807 .ie n .IP """UsageOnly""" 12
808 .el .IP \f(CWUsageOnly\fR 12
809 .IX Xref "debugger option, UsageOnly"
810 .IX Item "UsageOnly"
811 Rudimentary per\-package memory usage dump. Calculates total
812 size of strings found in variables in the package. This does not
813 include lexicals in a module\*(Aqs file scope, or lost in closures.
814 .ie n .IP """HistFile""" 12
815 .el .IP \f(CWHistFile\fR 12
816 .IX Xref "debugger option, history, HistFile"
817 .IX Item "HistFile"
818 The path of the file from which the history (assuming a usable
819 Term::ReadLine backend) will be read on the debugger\*(Aqs startup, and to which
820 it will be saved on shutdown (for persistence across sessions). Similar in
821 concept to Bash\*(Aqs \f(CW\*(C`.bash_history\*(C'\fR file.
822 .ie n .IP """HistSize""" 12
823 .el .IP \f(CWHistSize\fR 12
824 .IX Xref "debugger option, history, HistSize"
825 .IX Item "HistSize"
826 The count of the saved lines in the history (assuming \f(CW\*(C`HistFile\*(C'\fR above).
827 .PP
828 After the rc file is read, the debugger reads the \f(CW$ENV{PERLDB_OPTS}\fR
829 environment variable and parses this as the remainder of a "O ..."
830 line as one might enter at the debugger prompt. You may place the
831 initialization options \f(CW\*(C`TTY\*(C'\fR, \f(CW\*(C`noTTY\*(C'\fR, \f(CW\*(C`ReadLine\*(C'\fR, and \f(CW\*(C`NonStop\*(C'\fR
832 there.
833 .PP
834 If your rc file contains:
835 .PP
836 .Vb 1
837 \& parse_options("NonStop=1 LineInfo=db.out AutoTrace");
838 .Ve
839 .PP
840 then your script will run without human intervention, putting trace
841 information into the file \fIdb.out\fR. (If you interrupt it, you\*(Aqd
842 better reset \f(CW\*(C`LineInfo\*(C'\fR to \fI/dev/tty\fR if you expect to see anything.)
843 .ie n .IP """TTY""" 12
844 .el .IP \f(CWTTY\fR 12
845 .IX Xref "debugger option, TTY"
846 .IX Item "TTY"
847 The TTY to use for debugging I/O.
848 .ie n .IP """noTTY""" 12
849 .el .IP \f(CWnoTTY\fR 12
850 .IX Xref "debugger option, noTTY"
851 .IX Item "noTTY"
852 If set, the debugger goes into \f(CW\*(C`NonStop\*(C'\fR mode and will not connect to a TTY. If
853 interrupted (or if control goes to the debugger via explicit setting of
854 \&\f(CW$DB::signal\fR or \f(CW$DB::single\fR from the Perl script), it connects to a TTY
855 specified in the \f(CW\*(C`TTY\*(C'\fR option at startup, or to a tty found at
856 runtime using the \f(CW\*(C`Term::Rendezvous\*(C'\fR module of your choice.
857 .Sp
858 This module should implement a method named \f(CW\*(C`new\*(C'\fR that returns an object
859 with two methods: \f(CW\*(C`IN\*(C'\fR and \f(CW\*(C`OUT\*(C'\fR. These should return filehandles to use
860 for debugging input and output correspondingly. The \f(CW\*(C`new\*(C'\fR method should
861 inspect an argument containing the value of \f(CW$ENV{PERLDB_NOTTY}\fR at
862 startup, or \f(CW"$ENV{HOME}/.perldbtty$$"\fR otherwise. This file is not
863 inspected for proper ownership, so security hazards are theoretically
864 possible.
865 .ie n .IP """ReadLine""" 12
866 .el .IP \f(CWReadLine\fR 12
867 .IX Xref "debugger option, ReadLine"
868 .IX Item "ReadLine"
869 If false, readline support in the debugger is disabled in order
870 to debug applications that themselves use ReadLine.
871 .ie n .IP """NonStop""" 12
872 .el .IP \f(CWNonStop\fR 12
873 .IX Xref "debugger option, NonStop"
874 .IX Item "NonStop"
875 If set, the debugger goes into non\-interactive mode until interrupted, or
876 programmatically by setting \f(CW$DB::signal\fR or \f(CW$DB::single\fR.
877 .PP
878 Here\*(Aqs an example of using the \f(CW$ENV{PERLDB_OPTS}\fR variable:
879 .PP
880 .Vb 1
881 \& $ PERLDB_OPTS="NonStop frame=2" perl \-d myprogram
882 .Ve
883 .PP
884 That will run the script \fBmyprogram\fR without human intervention,
885 printing out the call tree with entry and exit points. Note that
886 \&\f(CW\*(C`NonStop=1 frame=2\*(C'\fR is equivalent to \f(CW\*(C`N f=2\*(C'\fR, and that originally,
887 options could be uniquely abbreviated by the first letter (modulo
888 the \f(CW\*(C`Dump*\*(C'\fR options). It is nevertheless recommended that you
889 always spell them out in full for legibility and future compatibility.
890 .PP
891 Other examples include
892 .PP
893 .Vb 1
894 \& $ PERLDB_OPTS="NonStop LineInfo=listing frame=2" perl \-d myprogram
895 .Ve
896 .PP
897 which runs script non\-interactively, printing info on each entry
898 into a subroutine and each executed line into the file named \fIlisting\fR.
899 (If you interrupt it, you would better reset \f(CW\*(C`LineInfo\*(C'\fR to something
900 "interactive"!)
901 .PP
902 Other examples include (using standard shell syntax to show environment
903 variable settings):
904 .PP
905 .Vb 2
906 \& $ ( PERLDB_OPTS="NonStop frame=1 AutoTrace LineInfo=tperl.out"
907 \& perl \-d myprogram )
908 .Ve
909 .PP
910 which may be useful for debugging a program that uses Term::ReadLine
911 itself. Do not forget to detach your shell from the TTY in the window that
912 corresponds to \fI/dev/ttyXX\fR, say, by issuing a command like
913 .PP
914 .Vb 1
915 \& $ sleep 1000000
916 .Ve
917 .PP
918 See "Debugger Internals" in perldebguts for details.
919 .SS "Debugger Input/Output"
920 .IX Subsection "Debugger Input/Output"
921 .IP Prompt 8
922 .IX Item "Prompt"
923 The debugger prompt is something like
924 .Sp
925 .Vb 1
926 \& DB<8>
927 .Ve
928 .Sp
929 or even
930 .Sp
931 .Vb 1
932 \& DB<<17>>
933 .Ve
934 .Sp
935 where that number is the command number, and which you\*(Aqd use to
936 access with the built\-in \fBcsh\fR\-like history mechanism. For example,
937 \&\f(CW\*(C`!17\*(C'\fR would repeat command number 17. The depth of the angle
938 brackets indicates the nesting depth of the debugger. You could
939 get more than one set of brackets, for example, if you\*(Aqd already
940 at a breakpoint and then printed the result of a function call that
941 itself has a breakpoint, or you step into an expression via \f(CW\*(C`s/n/t
942 expression\*(C'\fR command.
943 .IP "Multiline commands" 8
944 .IX Item "Multiline commands"
945 If you want to enter a multi\-line command, such as a subroutine
946 definition with several statements or a format, escape the newline
947 that would normally end the debugger command with a backslash.
948 Here\*(Aqs an example:
949 .Sp
950 .Vb 7
951 \& DB<1> for (1..4) { \e
952 \& cont: print "ok\en"; \e
953 \& cont: }
954 \& ok
955 \& ok
956 \& ok
957 \& ok
958 .Ve
959 .Sp
960 Note that this business of escaping a newline is specific to interactive
961 commands typed into the debugger.
962 .IP "Stack backtrace" 8
963 .IX Xref "backtrace stack, backtrace"
964 .IX Item "Stack backtrace"
965 Here\*(Aqs an example of what a stack backtrace via \f(CW\*(C`T\*(C'\fR command might
966 look like:
967 .Sp
968 .Vb 5
969 \& $ = main::infested called from file \*(AqAmbulation.pm\*(Aq line 10
970 \& @ = Ambulation::legs(1, 2, 3, 4) called from file \*(Aqcamel_flea\*(Aq
971 \& line 7
972 \& $ = main::pests(\*(Aqbactrian\*(Aq, 4) called from file \*(Aqcamel_flea\*(Aq
973 \& line 4
974 .Ve
975 .Sp
976 The left\-hand character up there indicates the context in which the
977 function was called, with \f(CW\*(C`$\*(C'\fR and \f(CW\*(C`@\*(C'\fR meaning scalar or list
978 contexts respectively, and \f(CW\*(C`.\*(C'\fR meaning void context (which is
979 actually a sort of scalar context). The display above says
980 that you were in the function \f(CW\*(C`main::infested\*(C'\fR when you ran the
981 stack dump, and that it was called in scalar context from line
982 10 of the file \fIAmbulation.pm\fR, but without any arguments at all,
983 meaning it was called as \f(CW&infested\fR. The next stack frame shows
984 that the function \f(CW\*(C`Ambulation::legs\*(C'\fR was called in list context
985 from the \fIcamel_flea\fR file with four arguments. The last stack
986 frame shows that \f(CW\*(C`main::pests\*(C'\fR was called in scalar context,
987 also from \fIcamel_flea\fR, but from line 4.
988 .Sp
989 If you execute the \f(CW\*(C`T\*(C'\fR command from inside an active \f(CW\*(C`use\*(C'\fR
990 statement, the backtrace will contain both a \f(CW\*(C`require\*(C'\fR frame and
991 an \f(CW\*(C`eval\*(C'\fR frame.
992 .IP "Line Listing Format" 8
993 .IX Item "Line Listing Format"
994 This shows the sorts of output the \f(CW\*(C`l\*(C'\fR command can produce:
995 .Sp
996 .Vb 11
997 \& DB<<13>> l
998 \& 101: @i{@i} = ();
999 \& 102:b @isa{@i,$pack} = ()
1000 \& 103 if(exists $i{$prevpack} || exists $isa{$pack});
1001 \& 104 }
1002 \& 105
1003 \& 106 next
1004 \& 107==> if(exists $isa{$pack});
1005 \& 108
1006 \& 109:a if ($extra\-\- > 0) {
1007 \& 110: %isa = ($pack,1);
1008 .Ve
1009 .Sp
1010 Breakable lines are marked with \f(CW\*(C`:\*(C'\fR. Lines with breakpoints are
1011 marked by \f(CW\*(C`b\*(C'\fR and those with actions by \f(CW\*(C`a\*(C'\fR. The line that\*(Aqs
1012 about to be executed is marked by \f(CW\*(C`==>\*(C'\fR.
1013 .Sp
1014 Please be aware that code in debugger listings may not look the same
1015 as your original source code. Line directives and external source
1016 filters can alter the code before Perl sees it, causing code to move
1017 from its original positions or take on entirely different forms.
1018 .IP "Frame listing" 8
1019 .IX Item "Frame listing"
1020 When the \f(CW\*(C`frame\*(C'\fR option is set, the debugger would print entered (and
1021 optionally exited) subroutines in different styles. See perldebguts
1022 for incredibly long examples of these.
1023 .SS "Debugging Compile\-Time Statements"
1024 .IX Subsection "Debugging Compile-Time Statements"
1025 If you have compile\-time executable statements (such as code within
1026 BEGIN, UNITCHECK and CHECK blocks or \f(CW\*(C`use\*(C'\fR statements), these will
1027 \&\fInot\fR be stopped by debugger, although \f(CW\*(C`require\*(C'\fRs and INIT blocks
1028 will, and compile\-time statements can be traced with the \f(CW\*(C`AutoTrace\*(C'\fR
1029 option set in \f(CW\*(C`PERLDB_OPTS\*(C'\fR). From your own Perl code, however, you
1030 can transfer control back to the debugger using the following
1031 statement, which is harmless if the debugger is not running:
1032 .PP
1033 .Vb 1
1034 \& $DB::single = 1;
1035 .Ve
1036 .PP
1037 If you set \f(CW$DB::single\fR to 2, it\*(Aqs equivalent to having
1038 just typed the \f(CW\*(C`n\*(C'\fR command, whereas a value of 1 means the \f(CW\*(C`s\*(C'\fR
1039 command. The \f(CW$DB::trace\fR variable should be set to 1 to simulate
1040 having typed the \f(CW\*(C`t\*(C'\fR command.
1041 .PP
1042 Another way to debug compile\-time code is to start the debugger, set a
1043 breakpoint on the \fIload\fR of some module:
1044 .PP
1045 .Vb 2
1046 \& DB<7> b load f:/perllib/lib/Carp.pm
1047 \& Will stop on load of \*(Aqf:/perllib/lib/Carp.pm\*(Aq.
1048 .Ve
1049 .PP
1050 and then restart the debugger using the \f(CW\*(C`R\*(C'\fR command (if possible). One can use \f(CW\*(C`b
1051 compile subname\*(C'\fR for the same purpose.
1052 .SS "Debugger Customization"
1053 .IX Subsection "Debugger Customization"
1054 The debugger probably contains enough configuration hooks that you
1055 won\*(Aqt ever have to modify it yourself. You may change the behaviour
1056 of the debugger from within the debugger using its \f(CW\*(C`o\*(C'\fR command, from
1057 the command line via the \f(CW\*(C`PERLDB_OPTS\*(C'\fR environment variable, and
1058 from customization files.
1059 .PP
1060 You can do some customization by setting up a \fI.perldb\fR file, which
1061 contains initialization code. For instance, you could make aliases
1062 like these (the last one is one people expect to be there):
1063 .PP
1064 .Vb 4
1065 \& $DB::alias{\*(Aqlen\*(Aq} = \*(Aqs/^len(.*)/p length($1)/\*(Aq;
1066 \& $DB::alias{\*(Aqstop\*(Aq} = \*(Aqs/^stop (at|in)/b/\*(Aq;
1067 \& $DB::alias{\*(Aqps\*(Aq} = \*(Aqs/^ps\eb/p scalar /\*(Aq;
1068 \& $DB::alias{\*(Aqquit\*(Aq} = \*(Aqs/^quit(\es*)/exit/\*(Aq;
1069 .Ve
1070 .PP
1071 You can change options from \fI.perldb\fR by using calls like this one;
1072 .PP
1073 .Vb 1
1074 \& parse_options("NonStop=1 LineInfo=db.out AutoTrace=1 frame=2");
1075 .Ve
1076 .PP
1077 The code is executed in the package \f(CW\*(C`DB\*(C'\fR. Note that \fI.perldb\fR is
1078 processed before processing \f(CW\*(C`PERLDB_OPTS\*(C'\fR. If \fI.perldb\fR defines the
1079 subroutine \f(CW\*(C`afterinit\*(C'\fR, that function is called after debugger
1080 initialization ends. \fI.perldb\fR may be contained in the current
1081 directory, or in the home directory. Because this file is sourced
1082 in by Perl and may contain arbitrary commands, for security reasons,
1083 it must be owned by the superuser or the current user, and writable
1084 by no one but its owner.
1085 .PP
1086 You can mock TTY input to debugger by adding arbitrary commands to
1087 \&\f(CW@DB::typeahead\fR. For example, your \fI.perldb\fR file might contain:
1088 .PP
1089 .Vb 1
1090 \& sub afterinit { push @DB::typeahead, "b 4", "b 6"; }
1091 .Ve
1092 .PP
1093 Which would attempt to set breakpoints on lines 4 and 6 immediately
1094 after debugger initialization. Note that \f(CW@DB::typeahead\fR is not a supported
1095 interface and is subject to change in future releases.
1096 .PP
1097 If you want to modify the debugger, copy \fIperl5db.pl\fR from the
1098 Perl library to another name and hack it to your heart\*(Aqs content.
1099 You\*(Aqll then want to set your \f(CW\*(C`PERL5DB\*(C'\fR environment variable to say
1100 something like this:
1101 .PP
1102 .Vb 1
1103 \& BEGIN { require "myperl5db.pl" }
1104 .Ve
1105 .PP
1106 As a last resort, you could also use \f(CW\*(C`PERL5DB\*(C'\fR to customize the debugger
1107 by directly setting internal variables or calling debugger functions.
1108 .PP
1109 Note that any variables and functions that are not documented in
1110 this document (or in perldebguts) are considered for internal
1111 use only, and as such are subject to change without notice.
1112 .SS "Readline Support / History in the Debugger"
1113 .IX Subsection "Readline Support / History in the Debugger"
1114 As shipped, the only command\-line history supplied is a simplistic one
1115 that checks for leading exclamation points. However, if you install
1116 the Term::ReadKey and one of the \f(CW\*(C`Term::ReadLine::*\*(C'\fR modules from CPAN (such as
1117 Term::ReadLine::Gnu, Term::ReadLine::Perl, ...) you will
1118 have full editing capabilities much like those GNU \fIreadline\fR(3) provides.
1119 Look for these in the \fImodules/by\-module/Term\fR directory on CPAN.
1120 These do not support normal \fBvi\fR command\-line editing, however.
1121 .PP
1122 A rudimentary command\-line completion is also available, including
1123 lexical variables in the current scope if the PadWalker module
1124 is installed.
1125 .PP
1126 Without Readline support you may see the symbols "^[[A", "^[[C", "^[[B",
1127 "^[[D"", "^H", ... when using the arrow keys and/or the backspace key.
1128 .SS "Editor Support for Debugging"
1129 .IX Subsection "Editor Support for Debugging"
1130 If you have the GNU\*(Aqs version of \fBemacs\fR installed on your system,
1131 it can interact with the Perl debugger to provide an integrated
1132 software development environment reminiscent of its interactions
1133 with C debuggers.
1134 .PP
1135 Recent versions of Emacs come with a
1136 start file for making \fBemacs\fR act like a
1137 syntax\-directed editor that understands (some of) Perl\*(Aqs syntax.
1138 See perlfaq3.
1139 .PP
1140 Users of \fBvi\fR should also look into \fBvim\fR and \fBgvim\fR, the mousey
1141 and windy version, for coloring of Perl keywords.
1142 .PP
1143 Note that only perl can truly parse Perl, so all such CASE tools
1144 fall somewhat short of the mark, especially if you don\*(Aqt program
1145 your Perl as a C programmer might.
1146 .SS "The Perl Profiler"
1147 .IX Xref "profile profiling profiler"
1148 .IX Subsection "The Perl Profiler"
1149 If you wish to supply an alternative debugger for Perl to run,
1150 invoke your script with a colon and a package argument given to the
1151 \&\fB\-d\fR flag. Perl\*(Aqs alternative debuggers include a Perl profiler,
1152 Devel::NYTProf, which is available separately as a CPAN
1153 distribution. To profile your Perl program in the file \fImycode.pl\fR,
1154 just type:
1155 .PP
1156 .Vb 1
1157 \& $ perl \-d:NYTProf mycode.pl
1158 .Ve
1159 .PP
1160 When the script terminates the profiler will create a database of the
1161 profile information that you can turn into reports using the profiler\*(Aqs
1162 tools. See <perlperf> for details.
1163 .SH "Debugging Regular Expressions"
1164 .IX Xref "regular expression, debugging regex, debugging regexp, debugging"
1165 .IX Header "Debugging Regular Expressions"
1166 \&\f(CW\*(C`use re \*(Aqdebug\*(Aq\*(C'\fR enables you to see the gory details of how the Perl
1167 regular expression engine works. In order to understand this typically
1168 voluminous output, one must not only have some idea about how regular
1169 expression matching works in general, but also know how Perl\*(Aqs regular
1170 expressions are internally compiled into an automaton. These matters
1171 are explored in some detail in
1172 "Debugging Regular Expressions" in perldebguts.
1173 .SH "Debugging Memory Usage"
1174 .IX Xref "memory usage"
1175 .IX Header "Debugging Memory Usage"
1176 Perl contains internal support for reporting its own memory usage,
1177 but this is a fairly advanced concept that requires some understanding
1178 of how memory allocation works.
1179 See "Debugging Perl Memory Usage" in perldebguts for the details.
1180 .SH "SEE ALSO"
1181 .IX Header "SEE ALSO"
1182 You do have \f(CW\*(C`use strict\*(C'\fR and \f(CW\*(C`use warnings\*(C'\fR enabled, don\*(Aqt you?
1183 .PP
1184 perldebtut,
1185 perldebguts,
1186 perl5db.pl,
1187 re,
1188 DB,
1189 Devel::NYTProf,
1190 Dumpvalue,
1191 and
1192 perlrun.
1193 .PP
1194 When debugging a script that uses #! and is thus normally found in
1195 \&\f(CW$PATH\fR, the \-S option causes perl to search \f(CW$PATH\fR for it, so you don\*(Aqt
1196 have to type the path or \f(CW\*(C`which $scriptname\*(C'\fR.
1197 .PP
1198 .Vb 1
1199 \& $ perl \-Sd foo.pl
1200 .Ve
1201 .SH BUGS
1202 .IX Header "BUGS"
1203 You cannot get stack frame information or in any fashion debug functions
1204 that were not compiled by Perl, such as those from C or C++ extensions.
1205 .PP
1206 If you alter your \f(CW@_\fR arguments in a subroutine (such as with \f(CW\*(C`shift\*(C'\fR
1207 or \f(CW\*(C`pop\*(C'\fR), the stack backtrace will not show the original values.
1208 .PP
1209 The debugger does not currently work in conjunction with the \fB\-W\fR
1210 command\-line switch, because it itself is not free of warnings.
1211 .PP
1212 If you\*(Aqre in a slow syscall (like \f(CW\*(C`wait\*(C'\fRing, \f(CW\*(C`accept\*(C'\fRing, or \f(CW\*(C`read\*(C'\fRing
1213 from your keyboard or a socket) and haven\*(Aqt set up your own \f(CW$SIG{INT}\fR
1214 handler, then you won\*(Aqt be able to CTRL\-C your way back to the debugger,
1215 because the debugger\*(Aqs own \f(CW$SIG{INT}\fR handler doesn\*(Aqt understand that
1216 it needs to raise an exception to \fBlongjmp\fR\|(3) out of slow syscalls.