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