{
    "content": [
        {
            "type": "text",
            "text": "# perldebug (man)\n\n## NAME\n\nperldebug - Perl debugging\n\n## DESCRIPTION\n\nFirst of all, have you tried using \"use strict;\" and \"use warnings;\"?\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION** (12 subsections)\n- **SEE ALSO**\n- **BUGS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "perldebug",
        "section": "",
        "mode": "man",
        "summary": "perldebug - Perl debugging",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 11,
                "subsections": [
                    {
                        "name": "The Perl Debugger",
                        "lines": 34
                    },
                    {
                        "name": "Calling the Debugger",
                        "lines": 14
                    },
                    {
                        "name": "Debugger Commands",
                        "lines": 342
                    },
                    {
                        "name": "Configurable Options",
                        "lines": 172
                    },
                    {
                        "name": "Debugger Input/Output",
                        "lines": 81
                    },
                    {
                        "name": "Debugging Compile-Time Statements",
                        "lines": 21
                    },
                    {
                        "name": "Debugger Customization",
                        "lines": 47
                    },
                    {
                        "name": "Readline Support / History in the Debugger",
                        "lines": 13
                    },
                    {
                        "name": "Editor Support for Debugging",
                        "lines": 13
                    },
                    {
                        "name": "The Perl Profiler",
                        "lines": 10
                    },
                    {
                        "name": "Debugging Regular Expressions",
                        "lines": 6
                    },
                    {
                        "name": "Debugging Memory Usage",
                        "lines": 4
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 17,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "perldebug - Perl debugging\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "First of all, have you tried using \"use strict;\" and \"use warnings;\"?\n\nIf you're new to the Perl debugger, you may prefer to read perldebtut, which is a tutorial\nintroduction to the debugger.\n\nIf you're looking for the nitty gritty details of how the debugger is implemented, you may\nprefer to read perldebguts.\n\nFor in-depth technical usage details, see perl5db.pl, the documentation of the debugger\nitself.\n",
                "subsections": [
                    {
                        "name": "The Perl Debugger",
                        "content": "If you invoke Perl with the -d switch, your script runs under the Perl source debugger.  This\nworks like an interactive Perl environment, prompting for debugger commands that let you\nexamine source code, set breakpoints, get stack backtraces, change the values of variables,\netc.  This is so convenient that you often fire up the debugger all by itself just to test\nout Perl constructs interactively to see what they do.  For example:\n\n$ perl -d -e 42\n\nIn Perl, the debugger is not a separate program the way it usually is in the typical compiled\nenvironment.  Instead, the -d flag tells the compiler to insert source information into the\nparse trees it's about to hand off to the interpreter.  That means your code must first\ncompile correctly for the debugger to work on it.  Then when the interpreter starts up, it\npreloads a special Perl library file containing the debugger.\n\nThe program will halt right before the first run-time executable statement (but see below\nregarding compile-time statements) and ask you to enter a debugger command.  Contrary to\npopular expectations, whenever the debugger halts and shows you a line of code, it always\ndisplays the line it's about to execute, rather than the one it has just executed.\n\nAny command not recognized by the debugger is directly executed (\"eval\"'d) as Perl code in\nthe current package.  (The debugger uses the DB package for keeping its own state\ninformation.)\n\nNote that the said \"eval\" is bound by an implicit scope. As a result any newly introduced\nlexical variable or any modified capture buffer content is lost after the eval. The debugger\nis a nice environment to learn Perl, but if you interactively experiment using material which\nshould be in the same scope, stuff it in one line.\n\nFor any text entered at the debugger prompt, leading and trailing whitespace is first\nstripped before further processing.  If a debugger command coincides with some function in\nyour own program, merely precede the function with something that doesn't look like a\ndebugger command, such as a leading \";\" or perhaps a \"+\", or by wrapping it with parentheses\nor braces.\n"
                    },
                    {
                        "name": "Calling the Debugger",
                        "content": "There are several ways to call the debugger:\n\nperl -d programname\nOn the given program identified by \"programname\".\n\nperl -d -e 0\nInteractively supply an arbitrary \"expression\" using \"-e\".\n\nperl -d:ptkdb programname\nDebug a given program via the \"Devel::ptkdb\" GUI.\n\nperl -dt threadedprogramname\nDebug a given program using threads (experimental).\n"
                    },
                    {
                        "name": "Debugger Commands",
                        "content": "The interactive debugger understands the following commands:\n\nh           Prints out a summary help message\n\nh [command] Prints out a help message for the given debugger command.\n\nh h         The special argument of \"h h\" produces the entire help page, which is quite long.\n\nIf the output of the \"h h\" command (or any command, for that matter) scrolls past\nyour screen, precede the command with a leading pipe symbol so that it's run\nthrough your pager, as in\n\nDB> |h h\n\nYou may change the pager which is used via \"o pager=...\" command.\n\np expr      Same as \"print {$DB::OUT} expr\" in the current package.  In particular, because\nthis is just Perl's own \"print\" function, this means that nested data structures\nand objects are not dumped, unlike with the \"x\" command.\n\nThe \"DB::OUT\" filehandle is opened to /dev/tty, regardless of where STDOUT may be\nredirected to.\n\nx [maxdepth] expr\nEvaluates its expression in list context and dumps out the result in a pretty-\nprinted fashion.  Nested data structures are printed out recursively, unlike the\nreal \"print\" function in Perl.  When dumping hashes, you'll probably prefer 'x\n\\%h' rather than 'x %h'.  See Dumpvalue if you'd like to do this yourself.\n\nThe output format is governed by multiple options described under \"Configurable\nOptions\".\n\nIf the \"maxdepth\" is included, it must be a numeral N; the value is dumped only N\nlevels deep, as if the \"dumpDepth\" option had been temporarily set to N.\n\nV [pkg [vars]]\nDisplay all (or some) variables in package (defaulting to \"main\") using a data\npretty-printer (hashes show their keys and values so you see what's what, control\ncharacters are made printable, etc.).  Make sure you don't put the type specifier\n(like \"$\") there, just the symbol names, like this:\n\nV DB filename line\n\nUse \"~pattern\" and \"!pattern\" for positive and negative regexes.\n\nThis is similar to calling the \"x\" command on each applicable var.\n\nX [vars]    Same as \"V currentpackage [vars]\".\n\ny [level [vars]]\nDisplay all (or some) lexical variables (mnemonic: \"mY\" variables) in the current\nscope or level scopes higher.  You can limit the variables that you see with vars\nwhich works exactly as it does for the \"V\" and \"X\" commands.  Requires the\n\"PadWalker\" module version 0.08 or higher; will warn if this isn't installed.\nOutput is pretty-printed in the same style as for \"V\" and the format is\ncontrolled by the same options.\n\nT           Produce a stack backtrace.  See below for details on its output.\n\ns [expr]    Single step.  Executes until the beginning of another statement, descending into\nsubroutine calls.  If an expression is supplied that includes function calls, it\ntoo will be single-stepped.\n\nn [expr]    Next.  Executes over subroutine calls, until the beginning of the next statement.\nIf an expression is supplied that includes function calls, those functions will\nbe executed with stops before each statement.\n\nr           Continue until the return from the current subroutine.  Dump the return value if\nthe \"PrintRet\" option is set (default).\n\n<CR>        Repeat last \"n\" or \"s\" command.\n\nc [line|sub]\nContinue, optionally inserting a one-time-only breakpoint at the specified line\nor subroutine.\n\nl           List next window of lines.\n\nl min+incr  List \"incr+1\" lines starting at \"min\".\n\nl min-max   List lines \"min\" through \"max\".  \"l -\" is synonymous to \"-\".\n\nl line      List a single line.\n\nl subname   List first window of lines from subroutine.  subname may be a variable that\ncontains a code reference.\n\n-           List previous window of lines.\n\nv [line]    View a few lines of code around the current line.\n\n.           Return the internal debugger pointer to the line last executed, and print out\nthat line.\n\nf filename  Switch to viewing a different file or \"eval\" statement.  If filename is not a\nfull pathname found in the values of %INC, it is considered a regex.\n\n\"eval\"ed strings (when accessible) are considered to be filenames: \"f (eval 7)\"\nand \"f eval 7\\b\" access the body of the 7th \"eval\"ed string (in the order of\nexecution).  The bodies of the currently executed \"eval\" and of \"eval\"ed strings\nthat define subroutines are saved and thus accessible.\n\n/pattern/   Search forwards for pattern (a Perl regex); final / is optional.  The search is\ncase-insensitive by default.\n\n?pattern?   Search backwards for pattern; final ? is optional.  The search is case-\ninsensitive by default.\n\nL [abw]     List (default all) actions, breakpoints and watch expressions\n\nS [[!]regex]\nList subroutine names [not] matching the regex.\n\nt [n]       Toggle trace mode (see also the \"AutoTrace\" option).  Optional argument is the\nmaximum number of levels to trace below the current one; anything deeper than\nthat will be silent.\n\nt [n] expr  Trace through execution of \"expr\".  Optional first argument is the maximum number\nof levels to trace below the current one; anything deeper than that will be\nsilent.  See \"Frame Listing Output Examples\" in perldebguts for examples.\n\nb           Sets breakpoint on current line\n\nb [line] [condition]\nSet a breakpoint before the given line.  If a condition is specified, it's\nevaluated each time the statement is reached: a breakpoint is taken only if the\ncondition is true.  Breakpoints may only be set on lines that begin an executable\nstatement.  Conditions don't use \"if\":\n\nb 237 $x > 30\nb 237 ++$count237 < 11\nb 33 /pattern/i\n\nIf the line number is \".\", sets a breakpoint on the current line:\n\nb . $n > 100\n\nb [file]:[line] [condition]\nSet a breakpoint before the given line in a (possibly different) file.  If a\ncondition is specified, it's evaluated each time the statement is reached: a\nbreakpoint is taken only if the condition is true.  Breakpoints may only be set\non lines that begin an executable statement.  Conditions don't use \"if\":\n\nb lib/MyModule.pm:237 $x > 30\nb /usr/lib/perl5/siteperl/CGI.pm:100 ++$count100 < 11\n\nb subname [condition]\nSet a breakpoint before the first line of the named subroutine.  subname may be a\nvariable containing a code reference (in this case condition is not supported).\n\nb postpone subname [condition]\nSet a breakpoint at first line of subroutine after it is compiled.\n\nb load filename\nSet a breakpoint before the first executed line of the filename, which should be\na full pathname found amongst the %INC values.\n\nb compile subname\nSets a breakpoint before the first statement executed after the specified\nsubroutine is compiled.\n\nB line      Delete a breakpoint from the specified line.\n\nB *         Delete all installed breakpoints.\n\ndisable [file]:[line]\nDisable the breakpoint so it won't stop the execution of the program.\nBreakpoints are enabled by default and can be re-enabled using the \"enable\"\ncommand.\n\ndisable [line]\nDisable the breakpoint so it won't stop the execution of the program.\nBreakpoints are enabled by default and can be re-enabled using the \"enable\"\ncommand.\n\nThis is done for a breakpoint in the current file.\n\nenable [file]:[line]\nEnable the breakpoint so it will stop the execution of the program.\n\nenable [line]\nEnable the breakpoint so it will stop the execution of the program.\n\nThis is done for a breakpoint in the current file.\n\na [line] command\nSet an action to be done before the line is executed.  If line is omitted, set an\naction on the line about to be executed.  The sequence of steps taken by the\ndebugger is\n\n1. check for a breakpoint at this line\n2. print the line if necessary (tracing)\n3. do any actions associated with that line\n4. prompt user if at a breakpoint or in single-step\n5. evaluate line\n\nFor example, this will print out $foo every time line 53 is passed:\n\na 53 print \"DB FOUND $foo\\n\"\n\nA line      Delete an action from the specified line.\n\nA *         Delete all installed actions.\n\nw expr      Add a global watch-expression. Whenever a watched global changes the debugger\nwill stop and display the old and new values.\n\nW expr      Delete watch-expression\n\nW *         Delete all watch-expressions.\n\no           Display all options.\n\no booloption ...\nSet each listed Boolean option to the value 1.\n\no anyoption? ...\nPrint out the value of one or more options.\n\no option=value ...\nSet the value of one or more options.  If the value has internal whitespace, it\nshould be quoted.  For example, you could set \"o pager=\"less -MQeicsNfr\"\" to call\nless with those specific options.  You may use either single or double quotes,\nbut if you do, you must escape any embedded instances of same sort of quote you\nbegan with, as well as any escaping any escapes that immediately precede that\nquote but which are not meant to escape the quote itself.  In other words, you\nfollow single-quoting rules irrespective of the quote; eg: \"o option='this isn\\'t\nbad'\" or \"o option=\"She said, \\\"Isn't it?\\\"\"\".\n\nFor historical reasons, the \"=value\" is optional, but defaults to 1 only where it\nis safe to do so--that is, mostly for Boolean options.  It is always better to\nassign a specific value using \"=\".  The \"option\" can be abbreviated, but for\nclarity probably should not be.  Several options can be set together.  See\n\"Configurable Options\" for a list of these.\n\n< ?         List out all pre-prompt Perl command actions.\n\n< [ command ]\nSet an action (Perl command) to happen before every debugger prompt.  A multi-\nline command may be entered by backslashing the newlines.\n\n< *         Delete all pre-prompt Perl command actions.\n\n<< command  Add an action (Perl command) to happen before every debugger prompt.  A multi-\nline command may be entered by backwhacking the newlines.\n\n> ?         List out post-prompt Perl command actions.\n\n> command   Set an action (Perl command) to happen after the prompt when you've just given a\ncommand to return to executing the script.  A multi-line command may be entered\nby backslashing the newlines (we bet you couldn't have guessed this by now).\n\n> *         Delete all post-prompt Perl command actions.\n\n>> command  Adds an action (Perl command) to happen after the prompt when you've just given a\ncommand to return to executing the script.  A multi-line command may be entered\nby backslashing the newlines.\n\n{ ?         List out pre-prompt debugger commands.\n\n{ [ command ]\nSet an action (debugger command) to happen before every debugger prompt.  A\nmulti-line command may be entered in the customary fashion.\n\nBecause this command is in some senses new, a warning is issued if you appear to\nhave accidentally entered a block instead.  If that's what you mean to do, write\nit as with \";{ ... }\" or even \"do { ... }\".\n\n{ *         Delete all pre-prompt debugger commands.\n\n{{ command  Add an action (debugger command) to happen before every debugger prompt.  A\nmulti-line command may be entered, if you can guess how: see above.\n\n! number    Redo a previous command (defaults to the previous command).\n\n! -number   Redo number'th previous command.\n\n! pattern   Redo last command that started with pattern.  See \"o recallCommand\", too.\n\n!! cmd      Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT) See \"o shellBang\",\nalso.  Note that the user's current shell (well, their $ENV{SHELL} variable) will\nbe used, which can interfere with proper interpretation of exit status or signal\nand coredump information.\n\nsource file Read and execute debugger commands from file.  file may itself contain \"source\"\ncommands.\n\nH -number   Display last n commands.  Only commands longer than one character are listed.  If\nnumber is omitted, list them all.\n\nq or ^D     Quit.  (\"quit\" doesn't work for this, unless you've made an alias) This is the\nonly supported way to exit the debugger, though typing \"exit\" twice might work.\n\nSet the \"inhibitexit\" option to 0 if you want to be able to step off the end the\nscript.  You may also need to set $finished to 0 if you want to step through\nglobal destruction.\n\nR           Restart the debugger by \"exec()\"ing a new session.  We try to maintain your\nhistory across this, but internal settings and command-line options may be lost.\n\nThe following setting are currently preserved: history, breakpoints, actions,\ndebugger options, and the Perl command-line options -w, -I, and -e.\n\n|dbcmd      Run the debugger command, piping DB::OUT into your current pager.\n\n||dbcmd     Same as \"|dbcmd\" but DB::OUT is temporarily \"select\"ed as well.\n\n= [alias value]\nDefine a command alias, like\n\n= quit q\n\nor list current aliases.\n\ncommand     Execute command as a Perl statement.  A trailing semicolon will be supplied.  If\nthe Perl statement would otherwise be confused for a Perl debugger, use a leading\nsemicolon, too.\n\nm expr      List which methods may be called on the result of the evaluated expression.  The\nexpression may evaluated to a reference to a blessed object, or to a package\nname.\n\nM           Display all loaded modules and their versions.\n\nman [manpage]\nDespite its name, this calls your system's default documentation viewer on the\ngiven page, or on the viewer itself if manpage is omitted.  If that viewer is\nman, the current \"Config\" information is used to invoke man using the proper\nMANPATH or -M manpath option.  Failed lookups of the form \"XXX\" that match known\nmanpages of the form perlXXX will be retried.  This lets you type \"man debug\" or\n\"man op\" from the debugger.\n\nOn systems traditionally bereft of a usable man command, the debugger invokes\nperldoc.  Occasionally this determination is incorrect due to recalcitrant\nvendors or rather more felicitously, to enterprising users.  If you fall into\neither category, just manually set the $DB::doccmd variable to whatever viewer to\nview the Perl documentation on your system.  This may be set in an rc file, or\nthrough direct assignment.  We're still waiting for a working example of\nsomething along the lines of:\n\n$DB::doccmd = 'netscape -remote http://something.here/';\n"
                    },
                    {
                        "name": "Configurable Options",
                        "content": "The debugger has numerous options settable using the \"o\" command, either interactively or\nfrom the environment or an rc file. The file is named ./.perldb or ~/.perldb under Unix with\n/dev/tty, perldb.ini otherwise.\n\n\"recallCommand\", \"ShellBang\"\nThe characters used to recall a command or spawn a shell.  By default, both are\nset to \"!\", which is unfortunate.\n\n\"pager\"     Program to use for output of pager-piped commands (those beginning with a \"|\"\ncharacter.)  By default, $ENV{PAGER} will be used.  Because the debugger uses\nyour current terminal characteristics for bold and underlining, if the chosen\npager does not pass escape sequences through unchanged, the output of some\ndebugger commands will not be readable when sent through the pager.\n\n\"tkRunning\" Run Tk while prompting (with ReadLine).\n\n\"signalLevel\", \"warnLevel\", \"dieLevel\"\nLevel of verbosity.  By default, the debugger leaves your exceptions and warnings\nalone, because altering them can break correctly running programs.  It will\nattempt to print a message when uncaught INT, BUS, or SEGV signals arrive.  (But\nsee the mention of signals in \"BUGS\" below.)\n\nTo disable this default safe mode, set these values to something higher than 0.\nAt a level of 1, you get backtraces upon receiving any kind of warning (this is\noften annoying) or exception (this is often valuable).  Unfortunately, the\ndebugger cannot discern fatal exceptions from non-fatal ones.  If \"dieLevel\" is\neven 1, then your non-fatal exceptions are also traced and unceremoniously\naltered if they came from \"eval'ed\" strings or from any kind of \"eval\" within\nmodules you're attempting to load.  If \"dieLevel\" is 2, the debugger doesn't care\nwhere they came from:  It usurps your exception handler and prints out a trace,\nthen modifies all exceptions with its own embellishments.  This may perhaps be\nuseful for some tracing purposes, but tends to hopelessly destroy any program\nthat takes its exception handling seriously.\n\n\"AutoTrace\" Trace mode (similar to \"t\" command, but can be put into \"PERLDBOPTS\").\n\n\"LineInfo\"  File or pipe to print line number info to.  If it is a pipe (say,\n\"|visualperldb\"), then a short message is used.  This is the mechanism used to\ninteract with a slave editor or visual debugger, such as the special \"vi\" or\n\"emacs\" hooks, or the \"ddd\" graphical debugger.\n\n\"inhibitexit\"\nIf 0, allows stepping off the end of the script.\n\n\"PrintRet\"  Print return value after \"r\" command if set (default).\n\n\"ornaments\" Affects screen appearance of the command line (see Term::ReadLine).  There is\ncurrently no way to disable these, which can render some output illegible on some\ndisplays, or with some pagers.  This is considered a bug.\n\n\"frame\"     Affects the printing of messages upon entry and exit from subroutines.  If \"frame\n& 2\" is false, messages are printed on entry only. (Printing on exit might be\nuseful if interspersed with other messages.)\n\nIf \"frame & 4\", arguments to functions are printed, plus context and caller info.\nIf \"frame & 8\", overloaded \"stringify\" and \"tie\"d \"FETCH\" is enabled on the\nprinted arguments.  If \"frame & 16\", the return value from the subroutine is\nprinted.\n\nThe length at which the argument list is truncated is governed by the next\noption:\n\n\"maxTraceLen\"\nLength to truncate the argument list when the \"frame\" option's bit 4 is set.\n\n\"windowSize\"\nChange the size of code list window (default is 10 lines).\n\nThe following options affect what happens with \"V\", \"X\", and \"x\" commands:\n\n\"arrayDepth\", \"hashDepth\"\nPrint only first N elements ('' for all).\n\n\"dumpDepth\" Limit recursion depth to N levels when dumping structures.  Negative values are\ninterpreted as infinity.  Default: infinity.\n\n\"compactDump\", \"veryCompact\"\nChange the style of array and hash output.  If \"compactDump\", short array may be\nprinted on one line.\n\n\"globPrint\" Whether to print contents of globs.\n\n\"DumpDBFiles\"\nDump arrays holding debugged files.\n\n\"DumpPackages\"\nDump symbol tables of packages.\n\n\"DumpReused\"\nDump contents of \"reused\" addresses.\n\n\"quote\", \"HighBit\", \"undefPrint\"\nChange the style of string dump.  The default value for \"quote\" is \"auto\"; one\ncan enable double-quotish or single-quotish format by setting it to \"\"\" or \"'\",\nrespectively.  By default, characters with their high bit set are printed\nverbatim.\n\n\"UsageOnly\" Rudimentary per-package memory usage dump.  Calculates total size of strings\nfound in variables in the package.  This does not include lexicals in a module's\nfile scope, or lost in closures.\n\n\"HistFile\"  The path of the file from which the history (assuming a usable Term::ReadLine\nbackend) will be read on the debugger's startup, and to which it will be saved on\nshutdown (for persistence across sessions). Similar in concept to Bash's\n\".bashhistory\" file.\n\n\"HistSize\"  The count of the saved lines in the history (assuming \"HistFile\" above).\n\nAfter the rc file is read, the debugger reads the $ENV{PERLDBOPTS} environment variable and\nparses this as the remainder of a \"O ...\"  line as one might enter at the debugger prompt.\nYou may place the initialization options \"TTY\", \"noTTY\", \"ReadLine\", and \"NonStop\" there.\n\nIf your rc file contains:\n\nparseoptions(\"NonStop=1 LineInfo=db.out AutoTrace\");\n\nthen your script will run without human intervention, putting trace information into the file\ndb.out.  (If you interrupt it, you'd better reset \"LineInfo\" to /dev/tty if you expect to see\nanything.)\n\n\"TTY\"       The TTY to use for debugging I/O.\n\n\"noTTY\"     If set, the debugger goes into \"NonStop\" mode and will not connect to a TTY.  If\ninterrupted (or if control goes to the debugger via explicit setting of\n$DB::signal or $DB::single from the Perl script), it connects to a TTY specified\nin the \"TTY\" option at startup, or to a tty found at runtime using the\n\"Term::Rendezvous\" module of your choice.\n\nThis module should implement a method named \"new\" that returns an object with two\nmethods: \"IN\" and \"OUT\".  These should return filehandles to use for debugging\ninput and output correspondingly.  The \"new\" method should inspect an argument\ncontaining the value of $ENV{PERLDBNOTTY} at startup, or\n\"$ENV{HOME}/.perldbtty$$\" otherwise.  This file is not inspected for proper\nownership, so security hazards are theoretically possible.\n\n\"ReadLine\"  If false, readline support in the debugger is disabled in order to debug\napplications that themselves use ReadLine.\n\n\"NonStop\"   If set, the debugger goes into non-interactive mode until interrupted, or\nprogrammatically by setting $DB::signal or $DB::single.\n\nHere's an example of using the $ENV{PERLDBOPTS} variable:\n\n$ PERLDBOPTS=\"NonStop frame=2\" perl -d myprogram\n\nThat will run the script myprogram without human intervention, printing out the call tree\nwith entry and exit points.  Note that \"NonStop=1 frame=2\" is equivalent to \"N f=2\", and that\noriginally, options could be uniquely abbreviated by the first letter (modulo the \"Dump*\"\noptions).  It is nevertheless recommended that you always spell them out in full for\nlegibility and future compatibility.\n\nOther examples include\n\n$ PERLDBOPTS=\"NonStop LineInfo=listing frame=2\" perl -d myprogram\n\nwhich runs script non-interactively, printing info on each entry into a subroutine and each\nexecuted line into the file named listing.  (If you interrupt it, you would better reset\n\"LineInfo\" to something \"interactive\"!)\n\nOther examples include (using standard shell syntax to show environment variable settings):\n\n$ ( PERLDBOPTS=\"NonStop frame=1 AutoTrace LineInfo=tperl.out\"\nperl -d myprogram )\n\nwhich may be useful for debugging a program that uses \"Term::ReadLine\" itself.  Do not forget\nto detach your shell from the TTY in the window that corresponds to /dev/ttyXX, say, by\nissuing a command like\n\n$ sleep 1000000\n\nSee \"Debugger Internals\" in perldebguts for details.\n"
                    },
                    {
                        "name": "Debugger Input/Output",
                        "content": "Prompt  The debugger prompt is something like\n\nDB<8>\n\nor even\n\nDB<<17>>\n\nwhere that number is the command number, and which you'd use to access with the\nbuilt-in csh-like history mechanism.  For example, \"!17\" would repeat command number\n17.  The depth of the angle brackets indicates the nesting depth of the debugger.\nYou could get more than one set of brackets, for example, if you'd already at a\nbreakpoint and then printed the result of a function call that itself has a\nbreakpoint, or you step into an expression via \"s/n/t expression\" command.\n\nMultiline commands\nIf you want to enter a multi-line command, such as a subroutine definition with\nseveral statements or a format, escape the newline that would normally end the\ndebugger command with a backslash.  Here's an example:\n\nDB<1> for (1..4) {         \\\ncont:     print \"ok\\n\";   \\\ncont: }\nok\nok\nok\nok\n\nNote that this business of escaping a newline is specific to interactive commands\ntyped into the debugger.\n\nStack backtrace\nHere's an example of what a stack backtrace via \"T\" command might look like:\n\n$ = main::infested called from file 'Ambulation.pm' line 10\n@ = Ambulation::legs(1, 2, 3, 4) called from file 'camelflea'\nline 7\n$ = main::pests('bactrian', 4) called from file 'camelflea'\nline 4\n\nThe left-hand character up there indicates the context in which the function was\ncalled, with \"$\" and \"@\" meaning scalar or list contexts respectively, and \".\"\nmeaning void context (which is actually a sort of scalar context).  The display above\nsays that you were in the function \"main::infested\" when you ran the stack dump, and\nthat it was called in scalar context from line 10 of the file Ambulation.pm, but\nwithout any arguments at all, meaning it was called as &infested.  The next stack\nframe shows that the function \"Ambulation::legs\" was called in list context from the\ncamelflea file with four arguments.  The last stack frame shows that \"main::pests\"\nwas called in scalar context, also from camelflea, but from line 4.\n\nIf you execute the \"T\" command from inside an active \"use\" statement, the backtrace\nwill contain both a \"require\" frame and an \"eval\" frame.\n\nLine Listing Format\nThis shows the sorts of output the \"l\" command can produce:\n\nDB<<13>> l\n101:        @i{@i} = ();\n102:b       @isa{@i,$pack} = ()\n103             if(exists $i{$prevpack} || exists $isa{$pack});\n104     }\n105\n106     next\n107==>      if(exists $isa{$pack});\n108\n109:a   if ($extra-- > 0) {\n110:        %isa = ($pack,1);\n\nBreakable lines are marked with \":\".  Lines with breakpoints are marked by \"b\" and\nthose with actions by \"a\".  The line that's about to be executed is marked by \"==>\".\n\nPlease be aware that code in debugger listings may not look the same as your original\nsource code.  Line directives and external source filters can alter the code before\nPerl sees it, causing code to move from its original positions or take on entirely\ndifferent forms.\n\nFrame listing\nWhen the \"frame\" option is set, the debugger would print entered (and optionally\nexited) subroutines in different styles.  See perldebguts for incredibly long\nexamples of these.\n"
                    },
                    {
                        "name": "Debugging Compile-Time Statements",
                        "content": "If you have compile-time executable statements (such as code within BEGIN, UNITCHECK and\nCHECK blocks or \"use\" statements), these will not be stopped by debugger, although \"require\"s\nand INIT blocks will, and compile-time statements can be traced with the \"AutoTrace\" option\nset in \"PERLDBOPTS\").  From your own Perl code, however, you can transfer control back to\nthe debugger using the following statement, which is harmless if the debugger is not running:\n\n$DB::single = 1;\n\nIf you set $DB::single to 2, it's equivalent to having just typed the \"n\" command, whereas a\nvalue of 1 means the \"s\" command.  The $DB::trace  variable should be set to 1 to simulate\nhaving typed the \"t\" command.\n\nAnother way to debug compile-time code is to start the debugger, set a breakpoint on the load\nof some module:\n\nDB<7> b load f:/perllib/lib/Carp.pm\nWill stop on load of 'f:/perllib/lib/Carp.pm'.\n\nand then restart the debugger using the \"R\" command (if possible).  One can use \"b compile\nsubname\" for the same purpose.\n"
                    },
                    {
                        "name": "Debugger Customization",
                        "content": "The debugger probably contains enough configuration hooks that you won't ever have to modify\nit yourself.  You may change the behaviour of the debugger from within the debugger using its\n\"o\" command, from the command line via the \"PERLDBOPTS\" environment variable, and from\ncustomization files.\n\nYou can do some customization by setting up a .perldb file, which contains initialization\ncode.  For instance, you could make aliases like these (the last one is one people expect to\nbe there):\n\n$DB::alias{'len'}  = 's/^len(.*)/p length($1)/';\n$DB::alias{'stop'} = 's/^stop (at|in)/b/';\n$DB::alias{'ps'}   = 's/^ps\\b/p scalar /';\n$DB::alias{'quit'} = 's/^quit(\\s*)/exit/';\n\nYou can change options from .perldb by using calls like this one;\n\nparseoptions(\"NonStop=1 LineInfo=db.out AutoTrace=1 frame=2\");\n\nThe code is executed in the package \"DB\".  Note that .perldb is processed before processing\n\"PERLDBOPTS\".  If .perldb defines the subroutine \"afterinit\", that function is called after\ndebugger initialization ends.  .perldb may be contained in the current directory, or in the\nhome directory.  Because this file is sourced in by Perl and may contain arbitrary commands,\nfor security reasons, it must be owned by the superuser or the current user, and writable by\nno one but its owner.\n\nYou can mock TTY input to debugger by adding arbitrary commands to @DB::typeahead. For\nexample, your .perldb file might contain:\n\nsub afterinit { push @DB::typeahead, \"b 4\", \"b 6\"; }\n\nWhich would attempt to set breakpoints on lines 4 and 6 immediately after debugger\ninitialization. Note that @DB::typeahead is not a supported interface and is subject to\nchange in future releases.\n\nIf you want to modify the debugger, copy perl5db.pl from the Perl library to another name and\nhack it to your heart's content.  You'll then want to set your \"PERL5DB\" environment variable\nto say something like this:\n\nBEGIN { require \"myperl5db.pl\" }\n\nAs a last resort, you could also use \"PERL5DB\" to customize the debugger by directly setting\ninternal variables or calling debugger functions.\n\nNote that any variables and functions that are not documented in this document (or in\nperldebguts) are considered for internal use only, and as such are subject to change without\nnotice.\n"
                    },
                    {
                        "name": "Readline Support / History in the Debugger",
                        "content": "As shipped, the only command-line history supplied is a simplistic one that checks for\nleading exclamation points.  However, if you install the Term::ReadKey and Term::ReadLine\nmodules from CPAN (such as Term::ReadLine::Gnu, Term::ReadLine::Perl, ...) you will have full\nediting capabilities much like those GNU readline(3) provides.  Look for these in the\nmodules/by-module/Term directory on CPAN.  These do not support normal vi command-line\nediting, however.\n\nA rudimentary command-line completion is also available, including lexical variables in the\ncurrent scope if the \"PadWalker\" module is installed.\n\nWithout Readline support you may see the symbols \"^[[A\", \"^[[C\", \"^[[B\", \"^[[D\"\", \"^H\", ...\nwhen using the arrow keys and/or the backspace key.\n"
                    },
                    {
                        "name": "Editor Support for Debugging",
                        "content": "If you have the GNU's version of emacs installed on your system, it can interact with the\nPerl debugger to provide an integrated software development environment reminiscent of its\ninteractions with C debuggers.\n\nRecent versions of Emacs come with a start file for making emacs act like a syntax-directed\neditor that understands (some of) Perl's syntax.  See perlfaq3.\n\nUsers of vi should also look into vim and gvim, the mousey and windy version, for coloring of\nPerl keywords.\n\nNote that only perl can truly parse Perl, so all such CASE tools fall somewhat short of the\nmark, especially if you don't program your Perl as a C programmer might.\n"
                    },
                    {
                        "name": "The Perl Profiler",
                        "content": "If you wish to supply an alternative debugger for Perl to run, invoke your script with a\ncolon and a package argument given to the -d flag.  Perl's alternative debuggers include a\nPerl profiler, Devel::NYTProf, which is available separately as a CPAN distribution.  To\nprofile your Perl program in the file mycode.pl, just type:\n\n$ perl -d:NYTProf mycode.pl\n\nWhen the script terminates the profiler will create a database of the profile information\nthat you can turn into reports using the profiler's tools. See <perlperf> for details.\n"
                    },
                    {
                        "name": "Debugging Regular Expressions",
                        "content": "\"use re 'debug'\" enables you to see the gory details of how the Perl regular expression\nengine works. In order to understand this typically voluminous output, one must not only have\nsome idea about how regular expression matching works in general, but also know how Perl's\nregular expressions are internally compiled into an automaton. These matters are explored in\nsome detail in \"Debugging Regular Expressions\" in perldebguts.\n"
                    },
                    {
                        "name": "Debugging Memory Usage",
                        "content": "Perl contains internal support for reporting its own memory usage, but this is a fairly\nadvanced concept that requires some understanding of how memory allocation works.  See\n\"Debugging Perl Memory Usage\" in perldebguts for the details.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "You do have \"use strict\" and \"use warnings\" enabled, don't you?\n\nperldebtut, perldebguts, perl5db.pl, re, DB, Devel::NYTProf, Dumpvalue, and perlrun.\n\nWhen debugging a script that uses #! and is thus normally found in $PATH, the -S option\ncauses perl to search $PATH for it, so you don't have to type the path or \"which\n$scriptname\".\n\n$ perl -Sd foo.pl\n",
                "subsections": []
            },
            "BUGS": {
                "content": "You cannot get stack frame information or in any fashion debug functions that were not\ncompiled by Perl, such as those from C or C++ extensions.\n\nIf you alter your @ arguments in a subroutine (such as with \"shift\" or \"pop\"), the stack\nbacktrace will not show the original values.\n\nThe debugger does not currently work in conjunction with the -W command-line switch, because\nit itself is not free of warnings.\n\nIf you're in a slow syscall (like \"wait\"ing, \"accept\"ing, or \"read\"ing from your keyboard or\na socket) and haven't set up your own $SIG{INT} handler, then you won't be able to CTRL-C\nyour way back to the debugger, because the debugger's own $SIG{INT} handler doesn't\nunderstand that it needs to raise an exception to longjmp(3) out of slow syscalls.\n\n\n\nperl v5.34.0                                 2025-07-25                                 PERLDEBUG(1)",
                "subsections": []
            }
        }
    }
}