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
14       If you're looking for the nitty gritty details of how the debugger is
15       implemented, you may prefer to read perldebguts.
16

The Perl Debugger

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

Debugging Regular Expressions

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

Debugging Memory Usage

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

SEE ALSO

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

BUGS

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