home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / perlman / man / perldebug.txt < prev    next >
Encoding:
Text File  |  1999-09-09  |  7.6 KB  |  203 lines

  1. NAME
  2.        perldebug - Perl debugging
  3.  
  4. DESCRIPTION
  5.        First of all, have you tried using the -w switch?
  6.  
  7.        Debugging
  8.  
  9.        If you invoke Perl with a -d switch, your script will be
  10.        run under the debugger.  However, the Perl debugger is not
  11.        a separate program as it is in a C environment.  Instead,
  12.        the -d flag tells the compiler to insert source
  13.        information into the pseudocode it's about to hand to the
  14.        interpreter.  (That means your code must compile correctly
  15.        for the debugger to work on it.)  Then when the
  16.        interpreter starts up, it pre-loads a Perl library file
  17.        containing the debugger itself.  The program will halt
  18.        before the first executable statement (but see below) and
  19.        ask you for one of the following commands:
  20.  
  21.        h           Prints out a help message.
  22.  
  23.        T           Stack trace.  If you do bizarre things to your
  24.                    @_ arguments in a subroutine, the stack
  25.                    backtrace will not always show the original
  26.                    values.
  27.  
  28.        s           Single step.  Executes until it reaches the
  29.                    beginning of another statement.
  30.  
  31.        n           Next.  Executes over subroutine calls, until
  32.                    it reaches the beginning of the next
  33.                    statement.
  34.  
  35.        f           Finish.  Executes statements until it has
  36.                    finished the current subroutine.
  37.  
  38.        c           Continue.  Executes until the next breakpoint
  39.                    is reached.
  40.  
  41.        c line      Continue to the specified line.  Inserts a
  42.                    one-time-only breakpoint at the specified
  43.                    line.
  44.  
  45.        <CR>        Repeat last n or s.
  46.  
  47.        l min+incr  List incr+1 lines starting at min.  If min is
  48.                    omitted, starts where last listing left off.
  49.                    If incr is omitted, previous value of incr is
  50.                    used.
  51.  
  52.        l min-max   List lines in the indicated range.
  53.  
  54.        l line      List just the indicated line.
  55.  
  56.        l           List next window.
  57.  
  58.        -           List previous window.
  59.  
  60.        w line      List window (a few lines worth of code) around
  61.                    line.
  62.  
  63.        l subname   List subroutine.  If it's a long subroutine it
  64.                    just lists the beginning.  Use "l" to list
  65.                    more.
  66.  
  67.        /pattern/   Regular expression search forward in the
  68.                    source code for pattern; the final / is
  69.                    optional.
  70.  
  71.        ?pattern?   Regular expression search backward in the
  72.                    source code for pattern; the final ? is
  73.                    optional.
  74.  
  75.        L           List lines that have breakpoints or actions.
  76.  
  77.        S           Lists the names of all subroutines.
  78.  
  79.        t           Toggle trace mode on or off.
  80.  
  81.        b line [ condition ]
  82.                    Set a breakpoint.  If line is omitted, sets a
  83.                    breakpoint on the line that is about to be
  84.                    executed.  If a condition is specified, it is
  85.                    evaluated each time the statement is reached
  86.                    and a breakpoint is taken only if the
  87.                    condition is true.  Breakpoints may only be
  88.                    set on lines that begin an executable
  89.                    statement.  Conditions don't use if:
  90.  
  91.                        b 237 $x > 30
  92.                        b 33 /pattern/i
  93.  
  94.        b subname [ condition ]
  95.                    Set breakpoint at first executable line of
  96.                    subroutine.
  97.  
  98.        d line      Delete breakpoint.  If line is omitted,
  99.                    deletes the breakpoint on the line that is
  100.                    about to be executed.
  101.  
  102.        D           Delete all breakpoints.
  103.  
  104.        a line command
  105.                    Set an action for line.  A multiline command
  106.                    may be entered by backslashing the newlines.
  107.                    This command is Perl code, not another
  108.                    debugger command.
  109.  
  110.        A           Delete all line actions.
  111.  
  112.        < command   Set an action to happen before every debugger
  113.                    prompt.  A multiline command may be entered by
  114.                    backslashing the newlines.
  115.  
  116.        > command   Set an action to happen after the prompt when
  117.                    you've just given a command to return to
  118.                    executing the script.  A multiline command may
  119.                    be entered by backslashing the newlines.
  120.  
  121.        V package [symbols]
  122.                    Display all (or some) variables in package
  123.                    (defaulting to the main package) using a data
  124.                    pretty-printer (hashes show their keys and
  125.                    values so you see what's what, control
  126.                    characters are made printable, etc.).  Make
  127.                    sure you don't put the type specifier (like $)
  128.                    there, just the symbol names, like this:
  129.  
  130.                        V DB filename line
  131.  
  132.        X [symbols] Same as as "V" command, but within the current
  133.                    package.
  134.  
  135.        ! number    Redo a debugging command.  If number is
  136.                    omitted, redoes the previous command.
  137.  
  138.        ! -number   Redo the command that was that many commands
  139.                    ago.
  140.  
  141.        H -number   Display last n commands.  Only commands longer
  142.                    than one character are listed.  If number is
  143.                    omitted, lists them all.
  144.  
  145.        q or ^D     Quit.  ("quit" doesn't work for this.)
  146.  
  147.        command     Execute command as a Perl statement.  A
  148.                    missing semicolon will be supplied.
  149.  
  150.        p expr      Same as print DB::OUT expr.  The DB::OUT
  151.                    filehandle is opened to /dev/tty, regardless
  152.                    of where STDOUT may be redirected to.
  153.  
  154.        Any command you type in that isn't recognized by the
  155.        debugger will be directly executed (eval'd) as Perl code.
  156.        Leading white space will cause the debugger to think it's
  157.        NOT a debugger command.
  158.  
  159.        If you have any compile-time executable statements (code
  160.        within a BEGIN block or a use statement), these will NOT
  161.        be stopped by debugger, although requires will.  From your
  162.        own code, however, you can transfer control back to the
  163.        debugger using the following statement, which is harmless
  164.        if the debugger is not running:
  165.  
  166.            $DB::single = 1;
  167.  
  168.        Customization
  169.  
  170.        If you want to modify the debugger, copy perl5db.pl from
  171.        the Perl library to another name and modify it as
  172.        necessary.  You'll also want to set environment variable
  173.        PERL5DB to say something like this:
  174.  
  175.            BEGIN { require "myperl5db.pl" }
  176.  
  177.        You can do some customization by setting up a .perldb file
  178.        which contains initialization code.  For instance, you
  179.        could make aliases like these (the last one in particular
  180.        most people seem to expect to be there):
  181.  
  182.            $DB::alias{'len'} = 's/^len(.*)/p length($1)/';
  183.            $DB::alias{'stop'} = 's/^stop (at|in)/b/';
  184.            $DB::alias{'.'} = 's/^\./p '
  185.                            . '"\$DB::sub(\$DB::filename:\$DB::line):\t"'
  186.                            . ',\$DB::dbline[\$DB::line]/' ;
  187.  
  188.        Other resources
  189.  
  190.        You did try the -w switch, didn't you?
  191.  
  192. BUGS
  193.        If your program exit()s or die()s, so does the debugger.
  194.  
  195.        There's no builtin way to restart the debugger without
  196.        exiting and coming back into it.  You could use an alias
  197.        like this:
  198.  
  199.            $DB::alias{'rerun'} = 'exec "perl -d $DB::filename"';
  200.  
  201.        But you'd lose any pending breakpoint information, and
  202.        that might not be the right path, etc.
  203.