source: trunk/essentials/dev-lang/perl/pod/perldebug.pod@ 3298

Last change on this file since 3298 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 35.9 KB
Line 
1=head1 NAME
2X<debug> X<debugger>
3
4perldebug - Perl debugging
5
6=head1 DESCRIPTION
7
8First of all, have you tried using the B<-w> switch?
9
10
11If you're new to the Perl debugger, you may prefer to read
12L<perldebtut>, which is a tutorial introduction to the debugger .
13
14=head1 The Perl Debugger
15
16If you invoke Perl with the B<-d> switch, your script runs under the
17Perl source debugger. This works like an interactive Perl
18environment, prompting for debugger commands that let you examine
19source code, set breakpoints, get stack backtraces, change the values of
20variables, etc. This is so convenient that you often fire up
21the debugger all by itself just to test out Perl constructs
22interactively to see what they do. For example:
23X<-d>
24
25 $ perl -d -e 42
26
27In Perl, the debugger is not a separate program the way it usually is in the
28typical compiled environment. Instead, the B<-d> flag tells the compiler
29to insert source information into the parse trees it's about to hand off
30to the interpreter. That means your code must first compile correctly
31for the debugger to work on it. Then when the interpreter starts up, it
32preloads a special Perl library file containing the debugger.
33
34The program will halt I<right before> the first run-time executable
35statement (but see below regarding compile-time statements) and ask you
36to enter a debugger command. Contrary to popular expectations, whenever
37the debugger halts and shows you a line of code, it always displays the
38line it's I<about> to execute, rather than the one it has just executed.
39
40Any command not recognized by the debugger is directly executed
41(C<eval>'d) as Perl code in the current package. (The debugger
42uses the DB package for keeping its own state information.)
43
44Note that the said C<eval> is bound by an implicit scope. As a
45result any newly introduced lexical variable or any modified
46capture buffer content is lost after the eval. The debugger is a
47nice environment to learn Perl, but if you interactively experiment using
48material which should be in the same scope, stuff it in one line.
49
50For any text entered at the debugger prompt, leading and trailing whitespace
51is first stripped before further processing. If a debugger command
52coincides with some function in your own program, merely precede the
53function with something that doesn't look like a debugger command, such
54as a leading C<;> or perhaps a C<+>, or by wrapping it with parentheses
55or braces.
56
57=head2 Debugger Commands
58
59The debugger understands the following commands:
60
61=over 12
62
63=item h
64X<debugger command, h>
65
66Prints out a summary help message
67
68=item h [command]
69
70Prints out a help message for the given debugger command.
71
72=item h h
73
74The special argument of C<h h> produces the entire help page, which is quite long.
75
76If the output of the C<h h> command (or any command, for that matter) scrolls
77past your screen, precede the command with a leading pipe symbol so
78that it's run through your pager, as in
79
80 DB> |h h
81
82You may change the pager which is used via C<o pager=...> command.
83
84
85=item p expr
86X<debugger command, p>
87
88Same as C<print {$DB::OUT} expr> in the current package. In particular,
89because this is just Perl's own C<print> function, this means that nested
90data structures and objects are not dumped, unlike with the C<x> command.
91
92The C<DB::OUT> filehandle is opened to F</dev/tty>, regardless of
93where STDOUT may be redirected to.
94
95=item x [maxdepth] expr
96X<debugger command, x>
97
98Evaluates its expression in list context and dumps out the result in a
99pretty-printed fashion. Nested data structures are printed out
100recursively, unlike the real C<print> function in Perl. When dumping
101hashes, you'll probably prefer 'x \%h' rather than 'x %h'.
102See L<Dumpvalue> if you'd like to do this yourself.
103
104The output format is governed by multiple options described under
105L<"Configurable Options">.