{
    "content": [
        {
            "type": "text",
            "text": "# perldebug (perldoc)\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**\n- **The Perl Debugger** (7 subsections)\n- **Debugging Regular Expressions**\n- **Debugging Memory Usage**\n- **SEE ALSO**\n- **BUGS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "perldebug",
        "section": "",
        "mode": "perldoc",
        "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": 10,
                "subsections": []
            },
            {
                "name": "The Perl Debugger",
                "lines": 32,
                "subsections": [
                    {
                        "name": "Calling the Debugger",
                        "lines": 14
                    },
                    {
                        "name": "Debugger Commands",
                        "lines": 339
                    },
                    {
                        "name": "Configurable Options",
                        "lines": 249
                    },
                    {
                        "name": "Debugging Compile-Time Statements",
                        "lines": 21
                    },
                    {
                        "name": "Debugger Customization",
                        "lines": 60
                    },
                    {
                        "name": "Editor Support for Debugging",
                        "lines": 13
                    },
                    {
                        "name": "The Perl Profiler",
                        "lines": 10
                    }
                ]
            },
            {
                "name": "Debugging Regular Expressions",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "Debugging Memory Usage",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 14,
                "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 itself.\n",
                "subsections": []
            },
            "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 examine\nsource code, set breakpoints, get stack backtraces, change the values of variables, etc. This is\nso convenient that you often fire up the debugger all by itself just to test out Perl constructs\ninteractively 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 parse\ntrees it's about to hand off to the interpreter. That means your code must first compile\ncorrectly for the debugger to work on it. Then when the interpreter starts up, it preloads a\nspecial 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 popular\nexpectations, whenever the debugger halts and shows you a line of code, it always displays the\nline 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 the\ncurrent package. (The debugger uses the DB package for keeping its own state information.)\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 is\na 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 stripped\nbefore further processing. If a debugger command coincides with some function in your own\nprogram, merely precede the function with something that doesn't look like a debugger command,\nsuch as a leading \";\" or perhaps a \"+\", or by wrapping it with parentheses or braces.\n",
                "subsections": [
                    {
                        "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 through\nyour 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 this\nis just Perl's own \"print\" function, this means that nested data structures and\nobjects 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\npretty-printed fashion. Nested data structures are printed out recursively, unlike\nthe real \"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*N* levels 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. Output\nis pretty-printed in the same style as for \"V\" and the format is controlled by the\nsame 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 too\nwill be single-stepped.\n\nn [expr]    Next. Executes over subroutine calls, until the beginning of the next statement. If\nan expression is supplied that includes function calls, those functions will be\nexecuted with stops before each statement.\n\nr           Continue until the return from the current subroutine. Dump the return value if the\n\"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 or\nsubroutine.\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 that\nline.\n\nf filename  Switch to viewing a different file or \"eval\" statement. If *filename* is not a full\npathname 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)\" and\n\"f eval 7\\b\" access the body of the 7th \"eval\"ed string (in the order of execution).\nThe bodies of the currently executed \"eval\" and of \"eval\"ed strings that define\nsubroutines 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-insensitive by\ndefault.\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 that\nwill be silent.\n\nt [n] expr  Trace through execution of \"expr\". Optional first argument is the maximum number of\nlevels to trace below the current one; anything deeper than that will be silent. See\n\"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 evaluated\neach time the statement is reached: a breakpoint is taken only if the condition is\ntrue. Breakpoints may only be set on lines that begin an executable statement.\nConditions 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 on\nlines 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 a\nfull pathname found amongst the %INC values.\n\nb compile subname\nSets a breakpoint before the first statement executed after the specified subroutine\nis 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. Breakpoints\nare enabled by default and can be re-enabled using the \"enable\" command.\n\ndisable [line]\nDisable the breakpoint so it won't stop the execution of the program. Breakpoints\nare enabled by default and can be re-enabled using the \"enable\" command.\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 debugger\nis\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 will\nstop 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, but if\nyou do, you must escape any embedded instances of same sort of quote you began with,\nas well as any escaping any escapes that immediately precede that quote but which\nare not meant to escape the quote itself. In other words, you follow single-quoting\nrules irrespective of the quote; eg: \"o option='this isn\\'t bad'\" or \"o option=\"She\nsaid, \\\"Isn't it?\\\"\"\".\n\nFor historical reasons, the \"=value\" is optional, but defaults to 1 only where it is\nsafe to do so--that is, mostly for Boolean options. It is always better to assign a\nspecific value using \"=\". The \"option\" can be abbreviated, but for clarity probably\nshould not be. Several options can be set together. See \"Configurable Options\" for a\nlist 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-line\ncommand 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-line\ncommand 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 by\nbackslashing 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 by\nbackslashing 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 it\nas 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 be\nused, which can interfere with proper interpretation of exit status or signal and\ncoredump 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\n*number* 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 only\nsupported 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 global\ndestruction.\n\nR           Restart the debugger by \"exec()\"ing a new session. We try to maintain your history\nacross 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 the\nPerl 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 name.\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 given\npage, or on the viewer itself if *manpage* is omitted. If that viewer is man, the\ncurrent \"Config\" information is used to invoke man using the proper MANPATH or\n-M *manpath* option. Failed lookups of the form \"XXX\" that match known manpages of\nthe form *perlXXX* will be retried. This lets you type \"man debug\" or \"man op\" from\nthe debugger.\n\nOn systems traditionally bereft of a usable man command, the debugger invokes\nperldoc. Occasionally this determination is incorrect due to recalcitrant vendors or\nrather more felicitously, to enterprising users. If you fall into either category,\njust manually set the $DB::doccmd variable to whatever viewer to view the Perl\ndocumentation on your system. This may be set in an rc file, or through direct\nassignment. We're still waiting for a working example of something along the lines\nof:\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 from\nthe 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 set\nto \"!\", 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 your\ncurrent terminal characteristics for bold and underlining, if the chosen pager does\nnot pass escape sequences through unchanged, the output of some debugger commands\nwill 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 attempt\nto print a message when uncaught INT, BUS, or SEGV signals arrive. (But see the\nmention of signals in \"BUGS\" below.)\n\nTo disable this default safe mode, set these values to something higher than 0. At a\nlevel of 1, you get backtraces upon receiving any kind of warning (this is often\nannoying) or exception (this is often valuable). Unfortunately, the debugger cannot\ndiscern fatal exceptions from non-fatal ones. If \"dieLevel\" is even 1, then your\nnon-fatal exceptions are also traced and unceremoniously altered if they came from\n\"eval'ed\" strings or from any kind of \"eval\" within modules you're attempting to\nload. If \"dieLevel\" is 2, the debugger doesn't care where they came from: It usurps\nyour exception handler and prints out a trace, then modifies all exceptions with its\nown embellishments. This may perhaps be useful for some tracing purposes, but tends\nto hopelessly destroy any program that 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, \"|visualperldb\"),\nthen a short message is used. This is the mechanism used to interact with a slave\neditor or visual debugger, such as the special \"vi\" or \"emacs\" hooks, or the \"ddd\"\ngraphical 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 &\n2\" is false, messages are printed on entry only. (Printing on exit might be useful\nif interspersed with other messages.)\n\nIf \"frame & 4\", arguments to functions are printed, plus context and caller info. If\n\"frame & 8\", overloaded \"stringify\" and \"tie\"d \"FETCH\" is enabled on the printed\narguments. If \"frame & 16\", the return value from the subroutine is printed.\n\nThe length at which the argument list is truncated is governed by the next option:\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 can\nenable double-quotish or single-quotish format by setting it to \"\"\" or \"'\",\nrespectively. By default, characters with their high bit set are printed verbatim.\n\n\"UsageOnly\" Rudimentary per-package memory usage dump. Calculates total size of strings found in\nvariables in the package. This does not include lexicals in a module's file scope,\nor 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. You\nmay 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\n*db.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 $DB::signal\nor $DB::single from the Perl script), it connects to a TTY specified in the \"TTY\"\noption at startup, or to a tty found at runtime using the \"Term::Rendezvous\" module\nof 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 input\nand output correspondingly. The \"new\" method should inspect an argument containing\nthe value of $ENV{PERLDBNOTTY} at startup, or \"$ENV{HOME}/.perldbtty$$\" otherwise.\nThis file is not inspected for proper ownership, so security hazards are\ntheoretically 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 with\nentry 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 legibility\nand 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 to\ndetach your shell from the TTY in the window that corresponds to /dev/ttyXX, say, by issuing a\ncommand like\n\n$ sleep 1000000\n\nSee \"Debugger Internals\" in perldebguts for details.\n\nDebugger Input/Output\nPrompt  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 built-in\ncsh-like history mechanism. For example, \"!17\" would repeat command number 17. The depth\nof the angle brackets indicates the nesting depth of the debugger. You could get more\nthan one set of brackets, for example, if you'd already at a breakpoint and then printed\nthe result of a function call that itself has a breakpoint, or you step into an\nexpression via \"s/n/t expression\" command.\n\nMultiline commands\nIf you want to enter a multi-line command, such as a subroutine definition with several\nstatements or a format, escape the newline that would normally end the debugger command\nwith 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 typed\ninto 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 called,\nwith \"$\" and \"@\" meaning scalar or list contexts respectively, and \".\" meaning void\ncontext (which is actually a sort of scalar context). The display above says that you\nwere in the function \"main::infested\" when you ran the stack dump, and that it was\ncalled in scalar context from line 10 of the file *Ambulation.pm*, but without any\narguments at all, meaning it was called as &infested. The next stack frame shows that\nthe function \"Ambulation::legs\" was called in list context from the *camelflea* file\nwith four arguments. The last stack frame shows that \"main::pests\" was called in scalar\ncontext, also from *camelflea*, but from line 4.\n\nIf you execute the \"T\" command from inside an active \"use\" statement, the backtrace will\ncontain 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 those\nwith 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 Perl\nsees it, causing code to move from its original positions or take on entirely different\nforms.\n\nFrame listing\nWhen the \"frame\" option is set, the debugger would print entered (and optionally exited)\nsubroutines in different styles. See perldebguts for incredibly long examples of these.\n"
                    },
                    {
                        "name": "Debugging Compile-Time Statements",
                        "content": "If you have compile-time executable statements (such as code within BEGIN, UNITCHECK and CHECK\nblocks or \"use\" statements), these will *not* be stopped by debugger, although \"require\"s and\nINIT blocks will, and compile-time statements can be traced with the \"AutoTrace\" option set in\n\"PERLDBOPTS\"). From your own Perl code, however, you can transfer control back to the debugger\nusing 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 having\ntyped 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 it\nyourself. You may change the behaviour of the debugger from within the debugger using its \"o\"\ncommand, 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 code.\nFor instance, you could make aliases like these (the last one is one people expect to be 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 home\ndirectory. Because this file is sourced in by Perl and may contain arbitrary commands, for\nsecurity reasons, it must be owned by the superuser or the current user, and writable by no one\nbut its owner.\n\nYou can mock TTY input to debugger by adding arbitrary commands to @DB::typeahead. For example,\nyour .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 change\nin 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 to\nsay 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\nReadline Support / History in the Debugger\nAs shipped, the only command-line history supplied is a simplistic one that checks for leading\nexclamation points. However, if you install the Term::ReadKey and Term::ReadLine modules from\nCPAN (such as Term::ReadLine::Gnu, Term::ReadLine::Perl, ...) you will have full editing\ncapabilities 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 editing,\nhowever.\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\", ... when\nusing 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 Perl\ndebugger 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 colon\nand a package argument given to the -d flag. Perl's alternative debuggers include a Perl\nprofiler, Devel::NYTProf, which is available separately as a CPAN distribution. To profile your\nPerl 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 that\nyou can turn into reports using the profiler's tools. See <perlperf> for details.\n"
                    }
                ]
            },
            "Debugging Regular Expressions": {
                "content": "\"use re 'debug'\" enables you to see the gory details of how the Perl regular expression engine\nworks. In order to understand this typically voluminous output, one must not only have some idea\nabout how regular expression matching works in general, but also know how Perl's regular\nexpressions are internally compiled into an automaton. These matters are explored in some detail\nin \"Debugging Regular Expressions\" in perldebguts.\n",
                "subsections": []
            },
            "Debugging Memory Usage": {
                "content": "Perl contains internal support for reporting its own memory usage, but this is a fairly advanced\nconcept that requires some understanding of how memory allocation works. See \"Debugging Perl\nMemory Usage\" in perldebguts for the details.\n",
                "subsections": []
            },
            "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 causes\nperl to search $PATH for it, so you don't have to type the path or \"which $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 compiled\nby 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 it\nitself 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 a\nsocket) and haven't set up your own $SIG{INT} handler, then you won't be able to CTRL-C your way\nback to the debugger, because the debugger's own $SIG{INT} handler doesn't understand that it\nneeds to raise an exception to longjmp(3) out of slow syscalls.\n",
                "subsections": []
            }
        }
    }
}