Debian Codegraph @

upstream/fedora-44/man1/perldebguts.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "PERLDEBGUTS 1"
61 .TH PERLDEBGUTS 1 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 perldebguts \- Guts of Perl debugging
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 This is not perldebug, which tells you how to use
71 the debugger. This manpage describes low\-level details concerning
72 the debugger\*(Aqs internals, which range from difficult to impossible
73 to understand for anyone who isn\*(Aqt incredibly intimate with Perl\*(Aqs guts.
74 Caveat lector.
75 .SH "Debugger Internals"
76 .IX Header "Debugger Internals"
77 Perl has special debugging hooks at compile\-time and run\-time used
78 to create debugging environments. These hooks are not to be confused
79 with the \fIperl \-Dxxx\fR command described in perlrun,
80 which is usable only if a special Perl is built per the instructions in
81 the \fIINSTALL\fR file in the Perl source tree.
82 .PP
83 For example, whenever you call Perl\*(Aqs built\-in \f(CW\*(C`caller\*(C'\fR function
84 from the package \f(CW\*(C`DB\*(C'\fR, the arguments that the corresponding stack
85 frame was called with are copied to the \f(CW@DB::args\fR array. These
86 mechanisms are enabled by calling Perl with the \fB\-d\fR switch.
87 Specifically, the following additional features are enabled
88 (cf. "$^P" in perlvar):
89 .IP \(bu 4
90 Perl inserts the contents of \f(CW$ENV{PERL5DB}\fR (or \f(CW\*(C`BEGIN {require
91 \&\*(Aqperl5db.pl\*(Aq}\*(C'\fR if not present) before the first line of your program.
92 .IP \(bu 4
93 If the \f(CW\*(C`\-dt\*(C'\fR switch is supplied, \f(CW\*(C`PERL5DB_THREADED=1\*(C'\fR is set in the
94 environment. \f(CW\*(C`perl5db.pl\*(C'\fR or your custom debugger can use this to
95 enable threading support.
96 .IP \(bu 4
97 Each array \f(CW\*(C`@{"_<$filename"}\*(C'\fR holds the lines of \f(CW$filename\fR for a
98 file compiled by Perl. The same is also true for \f(CW\*(C`eval\*(C'\fRed strings
99 that contain subroutines, or which are currently being executed.
100 The \f(CW$filename\fR for \f(CW\*(C`eval\*(C'\fRed strings looks like \f(CW\*(C`(eval 34)\*(C'\fR.
101 .Sp
102 Values in this array are magical in numeric context: they compare
103 equal to zero only if the line is not breakable.
104 .IP \(bu 4
105 Each hash \f(CW\*(C`%{"_<$filename"}\*(C'\fR contains breakpoints and actions keyed
106 by line number. Individual entries (as opposed to the whole hash)
107 are settable. Perl only cares about Boolean true here, although
108 the values used by \fIperl5db.pl\fR have the form
109 \&\f(CW"$break_condition\e0$action"\fR.
110 .Sp
111 The same holds for evaluated strings that contain subroutines, or
112 which are currently being executed. The \f(CW$filename\fR for \f(CW\*(C`eval\*(C'\fRed strings
113 looks like \f(CW\*(C`(eval 34)\*(C'\fR.
114 .IP \(bu 4
115 Each scalar \f(CW\*(C`${"_<$filename"}\*(C'\fR contains \f(CW$filename\fR. This is
116 also the case for evaluated strings that contain subroutines, or
117 which are currently being executed. The \f(CW$filename\fR for \f(CW\*(C`eval\*(C'\fRed
118 strings looks like \f(CW\*(C`(eval 34)\*(C'\fR.
119 .IP \(bu 4
120 After each \f(CW\*(C`require\*(C'\fRd file is compiled, but before it is executed,
121 \&\f(CWDB::postponed(*{"_<$filename"})\fR is called if the subroutine
122 \&\f(CW\*(C`DB::postponed\*(C'\fR exists. Here, the \f(CW$filename\fR is the expanded name of
123 the \f(CW\*(C`require\*(C'\fRd file, as found in the values of \f(CW%INC\fR.
124 .IP \(bu 4
125 After each subroutine \f(CW\*(C`subname\*(C'\fR is compiled, the existence of
126 \&\f(CW$DB::postponed{subname}\fR is checked. If this key exists,
127 \&\f(CWDB::postponed(subname)\fR is called if the \f(CW\*(C`DB::postponed\*(C'\fR subroutine
128 also exists.
129 .IP \(bu 4
130 A hash \f(CW%DB::sub\fR is maintained, whose keys are subroutine names
131 and whose values have the form \f(CW\*(C`filename:startline\-endline\*(C'\fR.
132 \&\f(CW\*(C`filename\*(C'\fR has the form \f(CW\*(C`(eval 34)\*(C'\fR for subroutines defined inside
133 \&\f(CW\*(C`eval\*(C'\fRs.
134 .IP \(bu 4
135 When the execution of your program reaches a point that can hold a
136 breakpoint, the \f(CWDB::DB()\fR subroutine is called if any of the variables
137 \&\f(CW$DB::trace\fR, \f(CW$DB::single\fR, or \f(CW$DB::signal\fR is true. These variables
138 are not \f(CW\*(C`local\*(C'\fRizable. This feature is disabled when executing
139 inside \f(CWDB::DB()\fR, including functions called from it
140 unless \f(CW\*(C`$^D & (1<<30)\*(C'\fR is true.
141 .IP \(bu 4
142 When execution of the program reaches a subroutine call, a call to
143 \&\f(CW&DB::sub\fR(\fIargs\fR) is made instead, with \f(CW$DB::sub\fR set to identify
144 the called subroutine. (This doesn\*(Aqt happen if the calling subroutine
145 was compiled in the \f(CW\*(C`DB\*(C'\fR package.) \f(CW$DB::sub\fR normally holds the name
146 of the called subroutine, if it has a name by which it can be looked up.
147 Failing that, \f(CW$DB::sub\fR will hold a reference to the called subroutine.
148 Either way, the \f(CW&DB::sub\fR subroutine can use \f(CW$DB::sub\fR as a reference
149 by which to call the called subroutine, which it will normally want to do.
150 .Sp
151 If the call is to an lvalue subroutine, and \f(CW&DB::lsub\fR
152 is defined \f(CW&DB::lsub\fR(\fIargs\fR) is called instead, otherwise falling
153 back to \f(CW&DB::sub\fR(\fIargs\fR).
154 .IX Xref "&DB::lsub"
155 .IP \(bu 4
156 When execution of the program uses \f(CW\*(C`goto\*(C'\fR to enter a non\-XS subroutine
157 and the 0x80 bit is set in \f(CW$^P\fR, a call to \f(CW&DB::goto\fR is made, with
158 \&\f(CW$DB::sub\fR set to identify the subroutine being entered. The call to
159 \&\f(CW&DB::goto\fR does not replace the \f(CW\*(C`goto\*(C'\fR; the requested subroutine will
160 still be entered once \f(CW&DB::goto\fR has returned. \f(CW$DB::sub\fR normally
161 holds the name of the subroutine being entered, if it has one. Failing
162 that, \f(CW$DB::sub\fR will hold a reference to the subroutine being entered.
163 Unlike when \f(CW&DB::sub\fR is called, it is not guaranteed that \f(CW$DB::sub\fR
164 can be used as a reference to operate on the subroutine being entered.
165 .PP
166 Note that if \f(CW&DB::sub\fR needs external data for it to work, no
167 subroutine call is possible without it. As an example, the standard
168 debugger\*(Aqs \f(CW&DB::sub\fR depends on the \f(CW$DB::deep\fR variable
169 (it defines how many levels of recursion deep into the debugger you can go
170 before a mandatory break). If \f(CW$DB::deep\fR is not defined, subroutine
171 calls are not possible, even though \f(CW&DB::sub\fR exists.
172 .SS "Writing Your Own Debugger"
173 .IX Subsection "Writing Your Own Debugger"
174 \fIEnvironment Variables\fR
175 .IX Subsection "Environment Variables"
176 .PP
177 The \f(CW\*(C`PERL5DB\*(C'\fR environment variable can be used to define a debugger.
178 For example, the minimal "working" debugger (it actually doesn\*(Aqt do anything)
179 consists of one line:
180 .PP
181 .Vb 1
182 \& sub DB::DB {}
183 .Ve
184 .PP
185 It can easily be defined like this:
186 .PP
187 .Vb 1
188 \& $ PERL5DB="sub DB::DB {}" perl \-d your\-script
189 .Ve
190 .PP
191 Another brief debugger, slightly more useful, can be created
192 with only the line:
193 .PP
194 .Vb 1
195 \& sub DB::DB {print ++$i; scalar <STDIN>}
196 .Ve
197 .PP
198 This debugger prints a number which increments for each statement
199 encountered and waits for you to hit a newline before continuing
200 to the next statement.
201 .PP
202 The following debugger is actually useful:
203 .PP
204 .Vb 5
205 \& {
206 \& package DB;
207 \& sub DB {}
208 \& sub sub {print ++$i, " $sub\en"; &$sub}
209 \& }
210 .Ve
211 .PP
212 It prints the sequence number of each subroutine call and the name of the
213 called subroutine. Note that \f(CW&DB::sub\fR is being compiled into the
214 package \f(CW\*(C`DB\*(C'\fR through the use of the \f(CW\*(C`package\*(C'\fR directive.
215 .PP
216 When it starts, the debugger reads your rc file (\fI./.perldb\fR or
217 \&\fI~/.perldb\fR under Unix), which can set important options.
218 (A subroutine (\f(CW&afterinit\fR) can be defined here as well; it is executed
219 after the debugger completes its own initialization.)
220 .PP
221 After the rc file is read, the debugger reads the PERLDB_OPTS
222 environment variable and uses it to set debugger options. The
223 contents of this variable are treated as if they were the argument
224 of an \f(CW\*(C`o ...\*(C'\fR debugger command (q.v. in "Configurable Options" in perldebug).
225 .PP
226 \fIDebugger Internal Variables\fR
227 .IX Subsection "Debugger Internal Variables"
228 .PP
229 In addition to the file and subroutine\-related variables mentioned above,
230 the debugger also maintains various magical internal variables.
231 .IP \(bu 4
232 \&\f(CW@DB::dbline\fR is an alias for \f(CW\*(C`@{"::_<current_file"}\*(C'\fR, which
233 holds the lines of the currently\-selected file (compiled by Perl), either
234 explicitly chosen with the debugger\*(Aqs \f(CW\*(C`f\*(C'\fR command, or implicitly by flow
235 of execution.
236 .Sp
237 Values in this array are magical in numeric context: they compare
238 equal to zero only if the line is not breakable.
239 .IP \(bu 4
240 \&\f(CW%DB::dbline\fR is an alias for \f(CW\*(C`%{"::_<current_file"}\*(C'\fR, which
241 contains breakpoints and actions keyed by line number in
242 the currently\-selected file, either explicitly chosen with the
243 debugger\*(Aqs \f(CW\*(C`f\*(C'\fR command, or implicitly by flow of execution.
244 .Sp
245 As previously noted, individual entries (as opposed to the whole hash)
246 are settable. Perl only cares about Boolean true here, although
247 the values used by \fIperl5db.pl\fR have the form
248 \&\f(CW"$break_condition\e0$action"\fR.
249 .PP
250 \fIDebugger Customization Functions\fR
251 .IX Subsection "Debugger Customization Functions"
252 .PP
253 Some functions are provided to simplify customization.
254 .IP \(bu 4
255 See "Configurable Options" in perldebug for a description of options parsed by
256 \&\f(CWDB::parse_options(string)\fR.
257 .IP \(bu 4
258 \&\f(CW\*(C`DB::dump_trace(skip[,count])\*(C'\fR skips the specified number of frames
259 and returns a list containing information about the calling frames (all
260 of them, if \f(CW\*(C`count\*(C'\fR is missing). Each entry is reference to a hash
261 with keys \f(CW\*(C`context\*(C'\fR (either \f(CW\*(C`.\*(C'\fR, \f(CW\*(C`$\*(C'\fR, or \f(CW\*(C`@\*(C'\fR), \f(CW\*(C`sub\*(C'\fR (subroutine
262 name, or info about \f(CW\*(C`eval\*(C'\fR), \f(CW\*(C`args\*(C'\fR (\f(CW\*(C`undef\*(C'\fR or a reference to
263 an array), \f(CW\*(C`file\*(C'\fR, and \f(CW\*(C`line\*(C'\fR.
264 .IP \(bu 4
265 \&\f(CW\*(C`DB::print_trace(FH, skip[, count[, short]])\*(C'\fR prints
266 formatted info about caller frames. The last two functions may be
267 convenient as arguments to \f(CW\*(C`<\*(C'\fR, \f(CW\*(C`<<\*(C'\fR commands.
268 .PP
269 Note that any variables and functions that are not documented in
270 this manpages (or in perldebug) are considered for internal
271 use only, and as such are subject to change without notice.
272 .SH "Frame Listing Output Examples"
273 .IX Header "Frame Listing Output Examples"
274 The \f(CW\*(C`frame\*(C'\fR option can be used to control the output of frame
275 information. For example, contrast this expression trace:
276 .PP
277 .Vb 2
278 \& $ perl \-de 42
279 \& Stack dump during die enabled outside of evals.
280 \&
281 \& Loading DB routines from perl5db.pl patch level 0.94
282 \& Emacs support available.
283 \&
284 \& Enter h or \*(Aqh h\*(Aq for help.
285 \&
286 \& main::(\-e:1): 0
287 \& DB<1> sub foo { 14 }
288 \&
289 \& DB<2> sub bar { 3 }
290 \&
291 \& DB<3> t print foo() * bar()
292 \& main::((eval 172):3): print foo() + bar();
293 \& main::foo((eval 168):2):
294 \& main::bar((eval 170):2):
295 \& 42
296 .Ve
297 .PP
298 with this one, once the \f(CW\*(C`o\*(C'\fRption \f(CW\*(C`frame=2\*(C'\fR has been set:
299 .PP
300 .Vb 11
301 \& DB<4> o f=2
302 \& frame = \*(Aq2\*(Aq
303 \& DB<5> t print foo() * bar()
304 \& 3: foo() * bar()
305 \& entering main::foo
306 \& 2: sub foo { 14 };
307 \& exited main::foo
308 \& entering main::bar
309 \& 2: sub bar { 3 };
310 \& exited main::bar
311 \& 42
312 .Ve
313 .PP
314 By way of demonstration, we present below a laborious listing
315 resulting from setting your \f(CW\*(C`PERLDB_OPTS\*(C'\fR environment variable to
316 the value \f(CW\*(C`f=n N\*(C'\fR, and running \fIperl \-d \-V\fR from the command line.
317 Examples using various values of \f(CW\*(C`n\*(C'\fR are shown to give you a feel
318 for the difference between settings. Long though it may be, this
319 is not a complete listing, but only excerpts.
320 .IP 1. 4
321 .Vb 10
322 \& entering main::BEGIN
323 \& entering Config::BEGIN
324 \& Package lib/Exporter.pm.
325 \& Package lib/Carp.pm.
326 \& Package lib/Config.pm.
327 \& entering Config::TIEHASH
328 \& entering Exporter::import
329 \& entering Exporter::export
330 \& entering Config::myconfig
331 \& entering Config::FETCH
332 \& entering Config::FETCH
333 \& entering Config::FETCH
334 \& entering Config::FETCH
335 .Ve
336 .IP 2. 4
337 .Vb 10
338 \& entering main::BEGIN
339 \& entering Config::BEGIN
340 \& Package lib/Exporter.pm.
341 \& Package lib/Carp.pm.
342 \& exited Config::BEGIN
343 \& Package lib/Config.pm.
344 \& entering Config::TIEHASH
345 \& exited Config::TIEHASH
346 \& entering Exporter::import
347 \& entering Exporter::export
348 \& exited Exporter::export
349 \& exited Exporter::import
350 \& exited main::BEGIN
351 \& entering Config::myconfig
352 \& entering Config::FETCH
353 \& exited Config::FETCH
354 \& entering Config::FETCH
355 \& exited Config::FETCH
356 \& entering Config::FETCH
357 .Ve
358 .IP 3. 4
359 .Vb 10
360 \& in $=main::BEGIN() from /dev/null:0
361 \& in $=Config::BEGIN() from lib/Config.pm:2
362 \& Package lib/Exporter.pm.
363 \& Package lib/Carp.pm.
364 \& Package lib/Config.pm.
365 \& in $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:644
366 \& in $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
367 \& in $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from li
368 \& in @=Config::myconfig() from /dev/null:0
369 \& in $=Config::FETCH(ref(Config), \*(Aqpackage\*(Aq) from lib/Config.pm:574
370 \& in $=Config::FETCH(ref(Config), \*(Aqbaserev\*(Aq) from lib/Config.pm:574
371 \& in $=Config::FETCH(ref(Config), \*(AqPERL_VERSION\*(Aq) from lib/Config.pm:574
372 \& in $=Config::FETCH(ref(Config), \*(AqPERL_SUBVERSION\*(Aq) from lib/Config.pm:574
373 \& in $=Config::FETCH(ref(Config), \*(Aqosname\*(Aq) from lib/Config.pm:574
374 \& in $=Config::FETCH(ref(Config), \*(Aqosvers\*(Aq) from lib/Config.pm:574
375 .Ve
376 .IP 4. 4
377 .Vb 10
378 \& in $=main::BEGIN() from /dev/null:0
379 \& in $=Config::BEGIN() from lib/Config.pm:2
380 \& Package lib/Exporter.pm.
381 \& Package lib/Carp.pm.
382 \& out $=Config::BEGIN() from lib/Config.pm:0
383 \& Package lib/Config.pm.
384 \& in $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:644
385 \& out $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:644
386 \& in $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
387 \& in $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/
388 \& out $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/
389 \& out $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
390 \& out $=main::BEGIN() from /dev/null:0
391 \& in @=Config::myconfig() from /dev/null:0
392 \& in $=Config::FETCH(ref(Config), \*(Aqpackage\*(Aq) from lib/Config.pm:574
393 \& out $=Config::FETCH(ref(Config), \*(Aqpackage\*(Aq) from lib/Config.pm:574
394 \& in $=Config::FETCH(ref(Config), \*(Aqbaserev\*(Aq) from lib/Config.pm:574
395 \& out $=Config::FETCH(ref(Config), \*(Aqbaserev\*(Aq) from lib/Config.pm:574
396 \& in $=Config::FETCH(ref(Config), \*(AqPERL_VERSION\*(Aq) from lib/Config.pm:574
397 \& out $=Config::FETCH(ref(Config), \*(AqPERL_VERSION\*(Aq) from lib/Config.pm:574
398 \& in $=Config::FETCH(ref(Config), \*(AqPERL_SUBVERSION\*(Aq) from lib/Config.pm:574
399 .Ve
400 .IP 5. 4
401 .Vb 10
402 \& in $=main::BEGIN() from /dev/null:0
403 \& in $=Config::BEGIN() from lib/Config.pm:2
404 \& Package lib/Exporter.pm.
405 \& Package lib/Carp.pm.
406 \& out $=Config::BEGIN() from lib/Config.pm:0
407 \& Package lib/Config.pm.
408 \& in $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:644
409 \& out $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:644
410 \& in $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
411 \& in $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/E
412 \& out $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/E
413 \& out $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
414 \& out $=main::BEGIN() from /dev/null:0
415 \& in @=Config::myconfig() from /dev/null:0
416 \& in $=Config::FETCH(\*(AqConfig=HASH(0x1aa444)\*(Aq, \*(Aqpackage\*(Aq) from lib/Config.pm:574
417 \& out $=Config::FETCH(\*(AqConfig=HASH(0x1aa444)\*(Aq, \*(Aqpackage\*(Aq) from lib/Config.pm:574
418 \& in $=Config::FETCH(\*(AqConfig=HASH(0x1aa444)\*(Aq, \*(Aqbaserev\*(Aq) from lib/Config.pm:574
419 \& out $=Config::FETCH(\*(AqConfig=HASH(0x1aa444)\*(Aq, \*(Aqbaserev\*(Aq) from lib/Config.pm:574
420 .Ve
421 .IP 6. 4
422 .Vb 10
423 \& in $=CODE(0x15eca4)() from /dev/null:0
424 \& in $=CODE(0x182528)() from lib/Config.pm:2
425 \& Package lib/Exporter.pm.
426 \& out $=CODE(0x182528)() from lib/Config.pm:0
427 \& scalar context return from CODE(0x182528): undef
428 \& Package lib/Config.pm.
429 \& in $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:628
430 \& out $=Config::TIEHASH(\*(AqConfig\*(Aq) from lib/Config.pm:628
431 \& scalar context return from Config::TIEHASH: empty hash
432 \& in $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
433 \& in $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/Exporter.pm:171
434 \& out $=Exporter::export(\*(AqConfig\*(Aq, \*(Aqmain\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from lib/Exporter.pm:171
435 \& scalar context return from Exporter::export: \*(Aq\*(Aq
436 \& out $=Exporter::import(\*(AqConfig\*(Aq, \*(Aqmyconfig\*(Aq, \*(Aqconfig_vars\*(Aq) from /dev/null:0
437 \& scalar context return from Exporter::import: \*(Aq\*(Aq
438 .Ve
439 .PP
440 In all cases shown above, the line indentation shows the call tree.
441 If bit 2 of \f(CW\*(C`frame\*(C'\fR is set, a line is printed on exit from a
442 subroutine as well. If bit 4 is set, the arguments are printed
443 along with the caller info. If bit 8 is set, the arguments are
444 printed even if they are tied or references. If bit 16 is set, the
445 return value is printed, too.
446 .PP
447 When a package is compiled, a line like this
448 .PP
449 .Vb 1
450 \& Package lib/Carp.pm.
451 .Ve
452 .PP
453 is printed with proper indentation.
454 .SH "Debugging Regular Expressions"
455 .IX Header "Debugging Regular Expressions"
456 There are two ways to enable debugging output for regular expressions.
457 .PP
458 If your perl is compiled with \f(CW\*(C`\-DDEBUGGING\*(C'\fR, you may use the
459 \&\fB\-Dr\fR flag on the command line, and \f(CW\*(C`\-Drv\*(C'\fR for more verbose
460 information.
461 .PP
462 Otherwise, one can \f(CW\*(C`use re \*(Aqdebug\*(Aq\*(C'\fR, which has effects at both
463 compile time and run time. Since Perl 5.9.5, this pragma is lexically
464 scoped.
465 .SS "Compile\-time Output"
466 .IX Subsection "Compile-time Output"
467 The debugging output at compile time looks like this:
468 .PP
469 .Vb 10
470 \& Compiling REx \*(Aq[bc]d(ef*g)+h[ij]k$\*(Aq
471 \& size 45 Got 364 bytes for offset annotations.
472 \& first at 1
473 \& rarest char g at 0
474 \& rarest char d at 0
475 \& 1: ANYOF[bc](12)
476 \& 12: EXACT <d>(14)
477 \& 14: CURLYX[0] {1,32767}(28)
478 \& 16: OPEN1(18)
479 \& 18: EXACT <e>(20)
480 \& 20: STAR(23)
481 \& 21: EXACT <f>(0)
482 \& 23: EXACT <g>(25)
483 \& 25: CLOSE1(27)
484 \& 27: WHILEM[1/1](0)
485 \& 28: NOTHING(29)
486 \& 29: EXACT <h>(31)
487 \& 31: ANYOF[ij](42)
488 \& 42: EXACT <k>(44)
489 \& 44: EOL(45)
490 \& 45: END(0)
491 \& anchored \*(Aqde\*(Aq at 1 floating \*(Aqgh\*(Aq at 3..2147483647 (checking floating)
492 \& stclass \*(AqANYOF[bc]\*(Aq minlen 7
493 \& Offsets: [45]
494 \& 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
495 \& 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
496 \& 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
497 \& 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
498 \& Omitting $\` $& $\*(Aq support.
499 .Ve
500 .PP
501 The first line shows the pre\-compiled form of the regex. The second
502 shows the size of the compiled form (in arbitrary units, usually
503 4\-byte words) and the total number of bytes allocated for the
504 offset/length table, usually 4+\f(CW\*(C`size\*(C'\fR*8. The next line shows the
505 label \fIid\fR of the first node that does a match.
506 .PP
507 The
508 .PP
509 .Vb 2
510 \& anchored \*(Aqde\*(Aq at 1 floating \*(Aqgh\*(Aq at 3..2147483647 (checking floating)
511 \& stclass \*(AqANYOF[bc]\*(Aq minlen 7
512 .Ve
513 .PP
514 line (split into two lines above) contains optimizer
515 information. In the example shown, the optimizer found that the match
516 should contain a substring \f(CW\*(C`de\*(C'\fR at offset 1, plus substring \f(CW\*(C`gh\*(C'\fR
517 at some offset between 3 and infinity. Moreover, when checking for
518 these substrings (to abandon impossible matches quickly), Perl will check
519 for the substring \f(CW\*(C`gh\*(C'\fR before checking for the substring \f(CW\*(C`de\*(C'\fR. The
520 optimizer may also use the knowledge that the match starts (at the
521 \&\f(CW\*(C`first\*(C'\fR \fIid\fR) with a character class, and no string
522 shorter than 7 characters can possibly match.
523 .PP
524 The fields of interest which may appear in this line are
525 .ie n .IP """anchored"" \fISTRING\fR ""at"" \fIPOS\fR" 4
526 .el .IP "\f(CWanchored\fR \fISTRING\fR \f(CWat\fR \fIPOS\fR" 4
527 .IX Item "anchored STRING at POS"
528 .PD 0
529 .ie n .IP """floating"" \fISTRING\fR ""at"" \fIPOS1..POS2\fR" 4
530 .el .IP "\f(CWfloating\fR \fISTRING\fR \f(CWat\fR \fIPOS1..POS2\fR" 4
531 .IX Item "floating STRING at POS1..POS2"
532 .PD
533 See above.
534 .ie n .IP """matching floating/anchored""" 4
535 .el .IP "\f(CWmatching floating/anchored\fR" 4
536 .IX Item "matching floating/anchored"
537 Which substring to check first.
538 .ie n .IP """minlen""" 4
539 .el .IP \f(CWminlen\fR 4
540 .IX Item "minlen"
541 The minimal length of the match.
542 .ie n .IP """stclass"" \fITYPE\fR" 4
543 .el .IP "\f(CWstclass\fR \fITYPE\fR" 4
544 .IX Item "stclass TYPE"
545 Type of first matching node.
546 .ie n .IP """noscan""" 4
547 .el .IP \f(CWnoscan\fR 4
548 .IX Item "noscan"
549 Don\*(Aqt scan for the found substrings.
550 .ie n .IP """isall""" 4
551 .el .IP \f(CWisall\fR 4
552 .IX Item "isall"
553 Means that the optimizer information is all that the regular
554 expression contains, and thus one does not need to enter the regex engine at
555 all.
556 .ie n .IP """GPOS""" 4
557 .el .IP \f(CWGPOS\fR 4
558 .IX Item "GPOS"
559 Set if the pattern contains \f(CW\*(C`\eG\*(C'\fR.
560 .ie n .IP """plus""" 4
561 .el .IP \f(CWplus\fR 4
562 .IX Item "plus"
563 Set if the pattern starts with a repeated char (as in \f(CW\*(C`x+y\*(C'\fR).
564 .ie n .IP """implicit""" 4
565 .el .IP \f(CWimplicit\fR 4
566 .IX Item "implicit"
567 Set if the pattern starts with \f(CW\*(C`.*\*(C'\fR.
568 .ie n .IP """with eval""" 4
569 .el .IP "\f(CWwith eval\fR" 4
570 .IX Item "with eval"
571 Set if the pattern contain eval\-groups, such as \f(CW\*(C`(?{ code })\*(C'\fR and
572 \&\f(CW\*(C`(??{ code })\*(C'\fR.
573 .ie n .IP anchored(TYPE) 4
574 .el .IP \f(CWanchored(TYPE)\fR 4
575 .IX Item "anchored(TYPE)"
576 If the pattern may match only at a handful of places, with \f(CW\*(C`TYPE\*(C'\fR
577 being \f(CW\*(C`SBOL\*(C'\fR, \f(CW\*(C`MBOL\*(C'\fR, or \f(CW\*(C`GPOS\*(C'\fR. See the table below.
578 .PP
579 If a substring is known to match at end\-of\-line only, it may be
580 followed by \f(CW\*(C`$\*(C'\fR, as in \f(CW\*(C`floating \*(Aqk\*(Aq$\*(C'\fR.
581 .PP
582 The optimizer\-specific information is used to avoid entering (a slow) regex
583 engine on strings that will not definitely match. If the \f(CW\*(C`isall\*(C'\fR flag
584 is set, a call to the regex engine may be avoided even when the optimizer
585 found an appropriate place for the match.
586 .PP
587 Above the optimizer section is the list of \fInodes\fR of the compiled
588 form of the regex. Each line has format
589 .PP
590 \&\f(CW\*(C` \*(C'\fR\fIid\fR: \fITYPE\fR \fIOPTIONAL\-INFO\fR (\fInext\-id\fR)
591 .SS "Types of Nodes"
592 .IX Subsection "Types of Nodes"
593 Here are the current possible types, with short descriptions:
594 .PP
595 .Vb 1
596 \& # TYPE arg\-description [regnode\-struct\-suffix] [longjump\-len] DESCRIPTION
597 \&
598 \& # Exit points
599 \&
600 \& END no End of program.
601 \& SUCCEED no Return from a subroutine, basically.
602 \&
603 \& # Line Start Anchors:
604 \& SBOL no Match "" at beginning of line: /^/, /\eA/
605 \& MBOL no Same, assuming multiline: /^/m
606 \&
607 \& # Line End Anchors:
608 \& SEOL no Match "" at end of line: /$/
609 \& MEOL no Same, assuming multiline: /$/m
610 \& EOS no Match "" at end of string: /\ez/
611 \&
612 \& # Match Start Anchors:
613 \& GPOS no Matches where last m//g left off.
614 \&
615 \& # Word Boundary Opcodes:
616 \& BOUND no Like BOUNDA for non\-utf8, otherwise like
617 \& BOUNDU
618 \& BOUNDL no Like BOUND/BOUNDU, but \ew and \eW are
619 \& defined by current locale
620 \& BOUNDU no Match "" at any boundary of a given type
621 \& using /u rules.
622 \& BOUNDA no Match "" at any boundary between \ew\eW or
623 \& \eW\ew, where \ew is [_a\-zA\-Z0\-9]
624 \& NBOUND no Like NBOUNDA for non\-utf8, otherwise like
625 \& BOUNDU
626 \& NBOUNDL no Like NBOUND/NBOUNDU, but \ew and \eW are
627 \& defined by current locale
628 \& NBOUNDU no Match "" at any non\-boundary of a given
629 \& type using /u rules.
630 \& NBOUNDA no Match "" between any \ew\ew or \eW\eW, where \ew
631 \& is [_a\-zA\-Z0\-9]
632 \&
633 \& # [Special] alternatives:
634 \& REG_ANY no Match any one character (except newline).
635 \& SANY no Match any one character.
636 \& ANYOF sv Match character in (or not in) this class,
637 \& charclass single char match only
638 \& ANYOFD sv Like ANYOF, but /d is in effect
639 \& charclass
640 \& ANYOFL sv Like ANYOF, but /l is in effect
641 \& charclass
642 \& ANYOFPOSIXL sv Like ANYOFL, but matches [[:posix:]]
643 \& charclass_ classes
644 \& posixl
645 \&
646 \& ANYOFH sv 1 Like ANYOF, but only has "High" matches,
647 \& none in the bitmap; the flags field
648 \& contains the lowest matchable UTF\-8 start
649 \& byte
650 \& ANYOFHb sv 1 Like ANYOFH, but all matches share the same
651 \& UTF\-8 start byte, given in the flags field
652 \& ANYOFHr sv 1 Like ANYOFH, but the flags field contains
653 \& packed bounds for all matchable UTF\-8 start
654 \& bytes.
655 \& ANYOFHs sv:str 1 Like ANYOFHb, but has a string field that
656 \& gives the leading matchable UTF\-8 bytes;
657 \& flags field is len
658 \& ANYOFR packed 1 Matches any character in the range given by
659 \& its packed args: upper 12 bits is the max
660 \& delta from the base lower 20; the flags
661 \& field contains the lowest matchable UTF\-8
662 \& start byte
663 \& ANYOFRb packed 1 Like ANYOFR, but all matches share the same
664 \& UTF\-8 start byte, given in the flags field
665 \&
666 \& ANYOFHbbm none bbm Like ANYOFHb, but only for 2\-byte UTF\-8
667 \& characters; uses a bitmap to match the
668 \& continuation byte
669 \&
670 \& ANYOFM byte 1 Like ANYOF, but matches an invariant byte
671 \& as determined by the mask and arg
672 \& NANYOFM byte 1 complement of ANYOFM
673 \&
674 \& # POSIX Character Classes:
675 \& POSIXD none Some [[:class:]] under /d; the FLAGS field
676 \& gives which one
677 \& POSIXL none Some [[:class:]] under /l; the FLAGS field
678 \& gives which one
679 \& POSIXU none Some [[:class:]] under /u; the FLAGS field
680 \& gives which one
681 \& POSIXA none Some [[:class:]] under /a; the FLAGS field
682 \& gives which one
683 \& NPOSIXD none complement of POSIXD, [[:^class:]]
684 \& NPOSIXL none complement of POSIXL, [[:^class:]]
685 \& NPOSIXU none complement of POSIXU, [[:^class:]]
686 \& NPOSIXA none complement of POSIXA, [[:^class:]]
687 \&
688 \& CLUMP no Match any extended grapheme cluster
689 \& sequence
690 \&
691 \& # Alternation
692 \&
693 \& # BRANCH The set of branches constituting a single choice are
694 \& # hooked together with their "next" pointers, since
695 \& # precedence prevents anything being concatenated to
696 \& # any individual branch. The "next" pointer of the last
697 \& # BRANCH in a choice points to the thing following the
698 \& # whole choice. This is also where the final "next"
699 \& # pointer of each individual branch points; each branch
700 \& # starts with the operand node of a BRANCH node.
701 \& #
702 \& BRANCH node 1 Match this alternative, or the next...
703 \&
704 \& # Literals
705 \&
706 \& EXACT str Match this string (flags field is the
707 \& length).
708 \&
709 \& # In a long string node, the U32 argument is the length, and is
710 \& # immediately followed by the string.
711 \& LEXACT len:str 1 Match this long string (preceded by length;
712 \& flags unused).
713 \& EXACTL str Like EXACT, but /l is in effect (used so
714 \& locale\-related warnings can be checked for)
715 \& EXACTF str Like EXACT, but match using /id rules;
716 \& (string not UTF\-8, ASCII folded; non\-ASCII
717 \& not)
718 \& EXACTFL str Like EXACT, but match using /il rules;
719 \& (string not likely to be folded)
720 \& EXACTFU str Like EXACT, but match using /iu rules;
721 \& (string folded)
722 \&
723 \& EXACTFAA str Like EXACT, but match using /iaa rules;
724 \& (string folded except MICRO in non\-UTF8
725 \& patterns; doesn\*(Aqt contain SHARP S unless
726 \& UTF\-8; folded length <= unfolded)
727 \& EXACTFAA_NO_TRIE str Like EXACTFAA, (string not UTF\-8, folded
728 \& except: MICRO, SHARP S; folded length <=
729 \& unfolded, not currently trie\-able)
730 \&
731 \& EXACTFUP str Like EXACT, but match using /iu rules;
732 \& (string not UTF\-8, folded except MICRO:
733 \& hence Problematic)
734 \&
735 \& EXACTFLU8 str Like EXACTFU, but use /il, UTF\-8, (string
736 \& is folded, and everything in it is above
737 \& 255
738 \& EXACT_REQ8 str Like EXACT, but only UTF\-8 encoded targets
739 \& can match
740 \& LEXACT_REQ8 len:str 1 Like LEXACT, but only UTF\-8 encoded targets
741 \& can match
742 \& EXACTFU_REQ8 str Like EXACTFU, but only UTF\-8 encoded
743 \& targets can match
744 \&
745 \& EXACTFU_S_EDGE str /di rules, but nothing in it precludes /ui,
746 \& except begins and/or ends with [Ss];
747 \& (string not UTF\-8; compile\-time only)
748 \&
749 \& # New charclass like patterns
750 \& LNBREAK none generic newline pattern
751 \&
752 \& # Trie Related
753 \&
754 \& # Behave the same as A|LIST|OF|WORDS would. The \*(Aq..C\*(Aq variants
755 \& # have inline charclass data (ascii only), the \*(AqC\*(Aq store it in the
756 \& # structure.
757 \&
758 \& TRIE trie 1 Match many EXACT(F[ALU]?)? at once.
759 \& flags==type
760 \& TRIEC trie Same as TRIE, but with embedded charclass
761 \& charclass data
762 \&
763 \& AHOCORASICK trie 1 Aho Corasick stclass. flags==type
764 \& AHOCORASICKC trie Same as AHOCORASICK, but with embedded
765 \& charclass charclass data
766 \&
767 \& # Do nothing types
768 \&
769 \& NOTHING no Match empty string.
770 \& # A variant of above which delimits a group, thus stops optimizations
771 \& TAIL no Match empty string. Can jump here from
772 \& outside.
773 \&
774 \& # Loops
775 \&
776 \& # STAR,PLUS \*(Aq?\*(Aq, and complex \*(Aq*\*(Aq and \*(Aq+\*(Aq, are implemented as
777 \& # circular BRANCH structures. Simple cases
778 \& # (one character per match) are implemented with STAR
779 \& # and PLUS for speed and to minimize recursive plunges.
780 \& #
781 \& STAR node Match this (simple) thing 0 or more times:
782 \& /A{0,}B/ where A is width 1 char
783 \& PLUS node Match this (simple) thing 1 or more times:
784 \& /A{1,}B/ where A is width 1 char
785 \&
786 \& CURLY sv 3 Match this (simple) thing {n,m} times:
787 \& /A{m,n}B/ where A is width 1 char
788 \& CURLYN no 3 Capture next\-after\-this simple thing:
789 \& /(A){m,n}B/ where A is width 1 char
790 \& CURLYM no 3 Capture this medium\-complex thing {n,m}
791 \& times: /(A){m,n}B/ where A is fixed\-length
792 \& CURLYX sv 3 Match/Capture this complex thing {n,m}
793 \& times.
794 \&
795 \& # This terminator creates a loop structure for CURLYX
796 \& WHILEM no Do curly processing and see if rest
797 \& matches.
798 \&
799 \& # Buffer related
800 \&
801 \& # OPEN,CLOSE,GROUPP ...are numbered at compile time.
802 \& OPEN num 1 Mark this point in input as start of #n.
803 \& CLOSE num 1 Close corresponding OPEN of #n.
804 \& SROPEN none Same as OPEN, but for script run
805 \& SRCLOSE none Close preceding SROPEN
806 \&
807 \& REF num 2 Match some already matched string
808 \& REFF num 2 Match already matched string, using /di
809 \& rules.
810 \& REFFL num 2 Match already matched string, using /li
811 \& rules.
812 \& REFFU num 2 Match already matched string, using /ui.
813 \& REFFA num 2 Match already matched string, using /aai
814 \& rules.
815 \&
816 \& # Named references. Code in regcomp.c assumes that these all are after
817 \& # the numbered references
818 \& REFN no\-sv 2 Match some already matched string
819 \& REFFN no\-sv 2 Match already matched string, using /di
820 \& rules.
821 \& REFFLN no\-sv 2 Match already matched string, using /li
822 \& rules.
823 \& REFFUN num 2 Match already matched string, using /ui
824 \& rules.
825 \& REFFAN num 2 Match already matched string, using /aai
826 \& rules.
827 \&
828 \& # Support for long RE
829 \& LONGJMP off 1 1 Jump far away.
830 \& BRANCHJ off 2 1 BRANCH with long offset.
831 \&
832 \& # Special Case Regops
833 \& IFMATCH off 1 1 Succeeds if the following matches; non\-zero
834 \& flags "f", next_off "o" means lookbehind
835 \& assertion starting "f..(f\-o)" characters
836 \& before current
837 \& UNLESSM off 1 1 Fails if the following matches; non\-zero
838 \& flags "f", next_off "o" means lookbehind
839 \& assertion starting "f..(f\-o)" characters
840 \& before current
841 \& SUSPEND off 1 1 "Independent" sub\-RE.
842 \& IFTHEN off 1 1 Switch, should be preceded by switcher.
843 \& GROUPP num 1 Whether the group matched.
844 \&
845 \& # The heavy worker
846 \&
847 \& EVAL evl/flags Execute some Perl code.
848 \& 2
849 \&
850 \& # Modifiers
851 \&
852 \& MINMOD no Next operator is not greedy.
853 \& LOGICAL no Next opcode should set the flag only.
854 \&
855 \& # This is not used yet
856 \& RENUM off 1 1 Group with independently numbered parens.
857 \&
858 \& # Regex Subroutines
859 \& GOSUB num/ofs 2 recurse to paren arg1 at (signed) ofs arg2
860 \&
861 \& # Special conditionals
862 \& GROUPPN no\-sv 1 Whether the group matched.
863 \& INSUBP num 1 Whether we are in a specific recurse.
864 \& DEFINEP none 1 Never execute directly.
865 \&
866 \& # Backtracking Verbs
867 \& ENDLIKE none Used only for the type field of verbs
868 \& OPFAIL no\-sv 1 Same as (?!), but with verb arg
869 \& ACCEPT no\-sv/num Accepts the current matched string, with
870 \& 2 verbar
871 \&
872 \& # Verbs With Arguments
873 \& VERB no\-sv 1 Used only for the type field of verbs
874 \& PRUNE no\-sv 1 Pattern fails at this startpoint if no\-
875 \& backtracking through this
876 \& MARKPOINT no\-sv 1 Push the current location for rollback by
877 \& cut.
878 \& SKIP no\-sv 1 On failure skip forward (to the mark)
879 \& before retrying
880 \& COMMIT no\-sv 1 Pattern fails outright if backtracking
881 \& through this
882 \& CUTGROUP no\-sv 1 On failure go to the next alternation in
883 \& the group
884 \&
885 \& # Control what to keep in $&.
886 \& KEEPS no $& begins here.
887 \&
888 \& # Validate that lookbehind IFMATCH and UNLESSM end at the right place
889 \& LOOKBEHIND_END no Return from lookbehind (IFMATCH/UNLESSM)
890 \& and validate position
891 \&
892 \& # SPECIAL REGOPS
893 \&
894 \& # This is not really a node, but an optimized away piece of a "long"
895 \& # node. To simplify debugging output, we mark it as if it were a node
896 \& OPTIMIZED off Placeholder for dump.
897 \&
898 \& # Special opcode with the property that no opcode in a compiled program
899 \& # will ever be of this type. Thus it can be used as a flag value that
900 \& # no other opcode has been seen. END is used similarly, in that an END
901 \& # node can\*(Aqt be optimized. So END implies "unoptimizable" and PSEUDO
902 \& # mean "not seen anything to optimize yet".
903 \& PSEUDO off Pseudo opcode for internal use.
904 \&
905 \& REGEX_SET depth p Regex set, temporary node used in pre\-
906 \& optimization compilation
907 .Ve
908 .PP
909 Following the optimizer information is a dump of the offset/length
910 table, here split across several lines:
911 .PP
912 .Vb 5
913 \& Offsets: [45]
914 \& 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
915 \& 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
916 \& 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
917 \& 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
918 .Ve
919 .PP
920 The first line here indicates that the offset/length table contains 45
921 entries. Each entry is a pair of integers, denoted by \f(CW\*(C`offset[length]\*(C'\fR.
922 Entries are numbered starting with 1, so entry #1 here is \f(CW\*(C`1[4]\*(C'\fR and
923 entry #12 is \f(CW\*(C`5[1]\*(C'\fR. \f(CW\*(C`1[4]\*(C'\fR indicates that the node labeled \f(CW\*(C`1:\*(C'\fR
924 (the \f(CW\*(C`1: ANYOF[bc]\*(C'\fR) begins at character position 1 in the
925 pre\-compiled form of the regex, and has a length of 4 characters.
926 \&\f(CW\*(C`5[1]\*(C'\fR in position 12
927 indicates that the node labeled \f(CW\*(C`12:\*(C'\fR
928 (the \f(CW\*(C`12: EXACT <d>\*(C'\fR) begins at character position 5 in the
929 pre\-compiled form of the regex, and has a length of 1 character.
930 \&\f(CW\*(C`12[1]\*(C'\fR in position 14
931 indicates that the node labeled \f(CW\*(C`14:\*(C'\fR
932 (the \f(CW\*(C`14: CURLYX[0] {1,32767}\*(C'\fR) begins at character position 12 in the
933 pre\-compiled form of the regex, and has a length of 1 character\-\-\-that
934 is, it corresponds to the \f(CW\*(C`+\*(C'\fR symbol in the precompiled regex.
935 .PP
936 \&\f(CW\*(C`0[0]\*(C'\fR items indicate that there is no corresponding node.
937 .SS "Run\-time Output"
938 .IX Subsection "Run-time Output"
939 First of all, when doing a match, one may get no run\-time output even
940 if debugging is enabled. This means that the regex engine was never
941 entered and that all of the job was therefore done by the optimizer.
942 .PP
943 If the regex engine was entered, the output may look like this:
944 .PP
945 .Vb 10
946 \& Matching \*(Aq[bc]d(ef*g)+h[ij]k$\*(Aq against \*(Aqabcdefg_\|_gh_\|_\*(Aq
947 \& Setting an EVAL scope, savestack=3
948 \& 2 <ab> <cdefg_\|_gh_> | 1: ANYOF
949 \& 3 <abc> <defg_\|_gh_> | 11: EXACT <d>
950 \& 4 <abcd> <efg_\|_gh_> | 13: CURLYX {1,32767}
951 \& 4 <abcd> <efg_\|_gh_> | 26: WHILEM
952 \& 0 out of 1..32767 cc=effff31c
953 \& 4 <abcd> <efg_\|_gh_> | 15: OPEN1
954 \& 4 <abcd> <efg_\|_gh_> | 17: EXACT <e>
955 \& 5 <abcde> <fg_\|_gh_> | 19: STAR
956 \& EXACT <f> can match 1 times out of 32767...
957 \& Setting an EVAL scope, savestack=3
958 \& 6 <bcdef> <g_\|_gh_\|_> | 22: EXACT <g>
959 \& 7 <bcdefg> <_\|_gh_\|_> | 24: CLOSE1
960 \& 7 <bcdefg> <_\|_gh_\|_> | 26: WHILEM
961 \& 1 out of 1..32767 cc=effff31c
962 \& Setting an EVAL scope, savestack=12
963 \& 7 <bcdefg> <_\|_gh_\|_> | 15: OPEN1
964 \& 7 <bcdefg> <_\|_gh_\|_> | 17: EXACT <e>
965 \& restoring \e1 to 4(4)..7
966 \& failed, try continuation...
967 \& 7 <bcdefg> <_\|_gh_\|_> | 27: NOTHING
968 \& 7 <bcdefg> <_\|_gh_\|_> | 28: EXACT <h>
969 \& failed...
970 \& failed...
971 .Ve
972 .PP
973 The most significant information in the output is about the particular \fInode\fR
974 of the compiled regex that is currently being tested against the target string.
975 The format of these lines is
976 .PP
977 \&\f(CW\*(C` \*(C'\fR\fISTRING\-OFFSET\fR <\fIPRE\-STRING\fR> <\fIPOST\-STRING\fR> |\fIID\fR: \fITYPE\fR
978 .PP
979 The \fITYPE\fR info is indented with respect to the backtracking level.
980 Other incidental information appears interspersed within.
981 .SH "Debugging Perl Memory Usage"
982 .IX Header "Debugging Perl Memory Usage"
983 Perl is a profligate wastrel when it comes to memory use. There
984 is a saying that to estimate memory usage of Perl, assume a reasonable
985 algorithm for memory allocation, multiply that estimate by 10, and
986 while you still may miss the mark, at least you won\*(Aqt be quite so
987 astonished. This is not absolutely true, but may provide a good
988 grasp of what happens.
989 .PP
990 Assume that an integer cannot take less than 20 bytes of memory, a
991 float cannot take less than 24 bytes, a string cannot take less
992 than 32 bytes (all these examples assume 32\-bit architectures, the
993 results are quite a bit worse on 64\-bit architectures). If a variable
994 is accessed in two of three different ways (which require an integer,
995 a float, or a string), the memory footprint may increase yet another
996 20 bytes. A sloppy \fBmalloc\fR\|(3) implementation can inflate these
997 numbers dramatically.
998 .PP
999 On the opposite end of the scale, a declaration like
1000 .PP
1001 .Vb 1
1002 \& sub foo;
1003 .Ve
1004 .PP
1005 may take up to 500 bytes of memory, depending on which release of Perl
1006 you\*(Aqre running.
1007 .PP
1008 Anecdotal estimates of source\-to\-compiled code bloat suggest an
1009 eightfold increase. This means that the compiled form of reasonable
1010 (normally commented, properly indented etc.) code will take
1011 about eight times more space in memory than the code took
1012 on disk.
1013 .PP
1014 The \fB\-DL\fR command\-line switch is obsolete since circa Perl 5.6.0
1015 (it was available only if Perl was built with \f(CW\*(C`\-DDEBUGGING\*(C'\fR).
1016 The switch was used to track Perl\*(Aqs memory allocations and possible
1017 memory leaks. These days the use of malloc debugging tools like
1018 \&\fIPurify\fR or \fIvalgrind\fR is suggested instead. See also
1019 "PERL_MEM_LOG" in perlhacktips.
1020 .PP
1021 One way to find out how much memory is being used by Perl data
1022 structures is to install the Devel::Size module from CPAN: it gives
1023 you the minimum number of bytes required to store a particular data
1024 structure. Please be mindful of the difference between the \fBsize()\fR
1025 and \fBtotal_size()\fR.
1026 .PP
1027 If Perl has been compiled using Perl\*(Aqs malloc you can analyze Perl
1028 memory usage by setting \f(CW$ENV\fR{PERL_DEBUG_MSTATS}.
1029 .ie n .SS "Using $ENV{PERL_DEBUG_MSTATS}"
1030 .el .SS "Using \f(CW$ENV{PERL_DEBUG_MSTATS}\fP"
1031 .IX Subsection "Using $ENV{PERL_DEBUG_MSTATS}"
1032 If your perl is using Perl\*(Aqs \fBmalloc()\fR and was compiled with the
1033 necessary switches (this is the default), then it will print memory
1034 usage statistics after compiling your code when \f(CW\*(C`$ENV{PERL_DEBUG_MSTATS}
1035 > 1\*(C'\fR, and before termination of the program when \f(CW\*(C`$ENV{PERL_DEBUG_MSTATS} >= 1\*(C'\fR. The report format is similar to
1036 the following example:
1037 .PP
1038 .Vb 10
1039 \& $ PERL_DEBUG_MSTATS=2 perl \-e "require Carp"
1040 \& Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
1041 \& 14216 free: 130 117 28 7 9 0 2 2 1 0 0
1042 \& 437 61 36 0 5
1043 \& 60924 used: 125 137 161 55 7 8 6 16 2 0 1
1044 \& 74 109 304 84 20
1045 \& Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048.
1046 \& Memory allocation statistics after execution: (buckets 4(4)..8188(8192)
1047 \& 30888 free: 245 78 85 13 6 2 1 3 2 0 1
1048 \& 315 162 39 42 11
1049 \& 175816 used: 265 176 1112 111 26 22 11 27 2 1 1
1050 \& 196 178 1066 798 39
1051 \& Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.
1052 .Ve
1053 .PP
1054 It is possible to ask for such a statistic at arbitrary points in
1055 your execution using the \fBmstat()\fR function out of the standard
1056 Devel::Peek module.
1057 .PP
1058 Here is some explanation of that format:
1059 .ie n .IP """buckets SMALLEST(APPROX)..GREATEST(APPROX)""" 4
1060 .el .IP "\f(CWbuckets SMALLEST(APPROX)..GREATEST(APPROX)\fR" 4
1061 .IX Item "buckets SMALLEST(APPROX)..GREATEST(APPROX)"
1062 Perl\*(Aqs \fBmalloc()\fR uses bucketed allocations. Every request is rounded
1063 up to the closest bucket size available, and a bucket is taken from
1064 the pool of buckets of that size.
1065 .Sp
1066 The line above describes the limits of buckets currently in use.
1067 Each bucket has two sizes: memory footprint and the maximal size
1068 of user data that can fit into this bucket. Suppose in the above
1069 example that the smallest bucket were size 4. The biggest bucket
1070 would have usable size 8188, and the memory footprint would be 8192.
1071 .Sp
1072 In a Perl built for debugging, some buckets may have negative usable
1073 size. This means that these buckets cannot (and will not) be used.
1074 For larger buckets, the memory footprint may be one page greater
1075 than a power of 2. If so, the corresponding power of two is
1076 printed in the \f(CW\*(C`APPROX\*(C'\fR field above.
1077 .IP Free/Used 4
1078 .IX Item "Free/Used"
1079 The 1 or 2 rows of numbers following that correspond to the number
1080 of buckets of each size between \f(CW\*(C`SMALLEST\*(C'\fR and \f(CW\*(C`GREATEST\*(C'\fR. In
1081 the first row, the sizes (memory footprints) of buckets are powers
1082 of two\-\-or possibly one page greater. In the second row, if present,
1083 the memory footprints of the buckets are between the memory footprints
1084 of two buckets "above".
1085 .Sp
1086 For example, suppose under the previous example, the memory footprints
1087 were
1088 .Sp
1089 .Vb 2
1090 \& free: 8 16 32 64 128 256 512 1024 2048 4096 8192
1091 \& 4 12 24 48 80
1092 .Ve
1093 .Sp
1094 With a non\-\f(CW\*(C`DEBUGGING\*(C'\fR perl, the buckets starting from \f(CW128\fR have
1095 a 4\-byte overhead, and thus an 8192\-long bucket may take up to
1096 8188\-byte allocations.
1097 .ie n .IP """Total sbrk(): SBRKed/SBRKs:CONTINUOUS""" 4
1098 .el .IP "\f(CWTotal sbrk(): SBRKed/SBRKs:CONTINUOUS\fR" 4
1099 .IX Item "Total sbrk(): SBRKed/SBRKs:CONTINUOUS"
1100 The first two fields give the total amount of memory perl \fBsbrk\fR\|(2)ed
1101 (ess\-broken? :\-) and number of \fBsbrk\fR\|(2)s used. The third number is
1102 what perl thinks about continuity of returned chunks. So long as
1103 this number is positive, \fBmalloc()\fR will assume that it is probable
1104 that \fBsbrk\fR\|(2) will provide continuous memory.
1105 .Sp
1106 Memory allocated by external libraries is not counted.
1107 .ie n .IP """pad: 0""" 4
1108 .el .IP "\f(CWpad: 0\fR" 4
1109 .IX Item "pad: 0"
1110 The amount of \fBsbrk\fR\|(2)ed memory needed to keep buckets aligned.
1111 .ie n .IP """heads: 2192""" 4
1112 .el .IP "\f(CWheads: 2192\fR" 4
1113 .IX Item "heads: 2192"
1114 Although memory overhead of bigger buckets is kept inside the bucket, for
1115 smaller buckets, it is kept in separate areas. This field gives the
1116 total size of these areas.
1117 .ie n .IP """chain: 0""" 4
1118 .el .IP "\f(CWchain: 0\fR" 4
1119 .IX Item "chain: 0"
1120 \&\fBmalloc()\fR may want to subdivide a bigger bucket into smaller buckets.
1121 If only a part of the deceased bucket is left unsubdivided, the rest
1122 is kept as an element of a linked list. This field gives the total
1123 size of these chunks.
1124 .ie n .IP """tail: 6144""" 4
1125 .el .IP "\f(CWtail: 6144\fR" 4
1126 .IX Item "tail: 6144"
1127 To minimize the number of \fBsbrk\fR\|(2)s, \fBmalloc()\fR asks for more memory. This
1128 field gives the size of the yet unused part, which is \fBsbrk\fR\|(2)ed, but
1129 never touched.
1130 .SH "SEE ALSO"
1131 .IX Header "SEE ALSO"
1132 perldebug,
1133 perl5db.pl,
1134 perlguts,
1135 perlrun,
1136 re,
1137 and
1138 Devel::DProf.