1PERLDEBUG(1)           Perl Programmers Reference Guide           PERLDEBUG(1)
2
3
4

NAME

6       perldebug - Perl debugging
7

DESCRIPTION

9       First of all, have you tried using "use strict;" and "use warnings;"?
10
11       If you're new to the Perl debugger, you may prefer to read perldebtut,
12       which is a tutorial introduction to the debugger.
13

The Perl Debugger

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

Debugging Regular Expressions

894       "use re 'debug'" enables you to see the gory details of how the Perl
895       regular expression engine works. In order to understand this typically
896       voluminous output, one must not only have some idea about how regular
897       expression matching works in general, but also know how Perl's regular
898       expressions are internally compiled into an automaton. These matters
899       are explored in some detail in "Debugging Regular Expressions" in
900       perldebguts.
901

Debugging Memory Usage

903       Perl contains internal support for reporting its own memory usage, but
904       this is a fairly advanced concept that requires some understanding of
905       how memory allocation works.  See "Debugging Perl Memory Usage" in
906       perldebguts for the details.
907

SEE ALSO

909       You do have "use strict" and "use warnings" enabled, don't you?
910
911       perldebtut, perldebguts, re, DB, Devel::NYTProf, Dumpvalue, and
912       perlrun.
913
914       When debugging a script that uses #! and is thus normally found in
915       $PATH, the -S option causes perl to search $PATH for it, so you don't
916       have to type the path or "which $scriptname".
917
918         $ perl -Sd foo.pl
919

BUGS

921       You cannot get stack frame information or in any fashion debug
922       functions that were not compiled by Perl, such as those from C or C++
923       extensions.
924
925       If you alter your @_ arguments in a subroutine (such as with "shift" or
926       "pop"), the stack backtrace will not show the original values.
927
928       The debugger does not currently work in conjunction with the -W
929       command-line switch, because it itself is not free of warnings.
930
931       If you're in a slow syscall (like "wait"ing, "accept"ing, or "read"ing
932       from your keyboard or a socket) and haven't set up your own $SIG{INT}
933       handler, then you won't be able to CTRL-C your way back to the
934       debugger, because the debugger's own $SIG{INT} handler doesn't
935       understand that it needs to raise an exception to longjmp(3) out of
936       slow syscalls.
937
938
939
940perl v5.26.3                      2018-03-23                      PERLDEBUG(1)
Impressum