1PERLDEBGUTS(1) Perl Programmers Reference Guide PERLDEBGUTS(1)
2
3
4
6 perldebguts - Guts of Perl debugging
7
9 This is not perldebug, which tells you how to use the debugger. This
10 manpage describes low-level details concerning the debugger's
11 internals, which range from difficult to impossible to understand for
12 anyone who isn't incredibly intimate with Perl's guts. Caveat lector.
13
15 Perl has special debugging hooks at compile-time and run-time used to
16 create debugging environments. These hooks are not to be confused with
17 the perl -Dxxx command described in perlrun, which is usable only if a
18 special Perl is built per the instructions in the INSTALL podpage in
19 the Perl source tree.
20
21 For example, whenever you call Perl's built-in "caller" function from
22 the package "DB", the arguments that the corresponding stack frame was
23 called with are copied to the @DB::args array. These mechanisms are
24 enabled by calling Perl with the -d switch. Specifically, the
25 following additional features are enabled (cf. "$^P" in perlvar):
26
27 · Perl inserts the contents of $ENV{PERL5DB} (or "BEGIN {require
28 'perl5db.pl'}" if not present) before the first line of your
29 program.
30
31 · Each array "@{"_<$filename"}" holds the lines of $filename for a
32 file compiled by Perl. The same is also true for "eval"ed strings
33 that contain subroutines, or which are currently being executed.
34 The $filename for "eval"ed strings looks like "(eval 34)". Code
35 assertions in regexes look like "(re_eval 19)".
36
37 Values in this array are magical in numeric context: they compare
38 equal to zero only if the line is not breakable.
39
40 · Each hash "%{"_<$filename"}" contains breakpoints and actions keyed
41 by line number. Individual entries (as opposed to the whole hash)
42 are settable. Perl only cares about Boolean true here, although
43 the values used by perl5db.pl have the form
44 "$break_condition\0$action".
45
46 The same holds for evaluated strings that contain subroutines, or
47 which are currently being executed. The $filename for "eval"ed
48 strings looks like "(eval 34)" or "(re_eval 19)".
49
50 · Each scalar "${"_<$filename"}" contains "_<$filename". This is
51 also the case for evaluated strings that contain subroutines, or
52 which are currently being executed. The $filename for "eval"ed
53 strings looks like "(eval 34)" or "(re_eval 19)".
54
55 · After each "require"d file is compiled, but before it is executed,
56 "DB::postponed(*{"_<$filename"})" is called if the subroutine
57 "DB::postponed" exists. Here, the $filename is the expanded name
58 of the "require"d file, as found in the values of %INC.
59
60 · After each subroutine "subname" is compiled, the existence of
61 $DB::postponed{subname} is checked. If this key exists,
62 "DB::postponed(subname)" is called if the "DB::postponed"
63 subroutine also exists.
64
65 · A hash %DB::sub is maintained, whose keys are subroutine names and
66 whose values have the form "filename:startline-endline".
67 "filename" has the form "(eval 34)" for subroutines defined inside
68 "eval"s, or "(re_eval 19)" for those within regex code assertions.
69
70 · When the execution of your program reaches a point that can hold a
71 breakpoint, the "DB::DB()" subroutine is called if any of the
72 variables $DB::trace, $DB::single, or $DB::signal is true. These
73 variables are not "local"izable. This feature is disabled when
74 executing inside "DB::DB()", including functions called from it
75 unless "$^D & (1<<30)" is true.
76
77 · When execution of the program reaches a subroutine call, a call to
78 &DB::sub(args) is made instead, with $DB::sub holding the name of
79 the called subroutine. (This doesn't happen if the subroutine was
80 compiled in the "DB" package.)
81
82 Note that if &DB::sub needs external data for it to work, no subroutine
83 call is possible without it. As an example, the standard debugger's
84 &DB::sub depends on the $DB::deep variable (it defines how many levels
85 of recursion deep into the debugger you can go before a mandatory
86 break). If $DB::deep is not defined, subroutine calls are not
87 possible, even though &DB::sub exists.
88
89 Writing Your Own Debugger
90 Environment Variables
91
92 The "PERL5DB" environment variable can be used to define a debugger.
93 For example, the minimal "working" debugger (it actually doesn't do
94 anything) consists of one line:
95
96 sub DB::DB {}
97
98 It can easily be defined like this:
99
100 $ PERL5DB="sub DB::DB {}" perl -d your-script
101
102 Another brief debugger, slightly more useful, can be created with only
103 the line:
104
105 sub DB::DB {print ++$i; scalar <STDIN>}
106
107 This debugger prints a number which increments for each statement
108 encountered and waits for you to hit a newline before continuing to the
109 next statement.
110
111 The following debugger is actually useful:
112
113 {
114 package DB;
115 sub DB {}
116 sub sub {print ++$i, " $sub\n"; &$sub}
117 }
118
119 It prints the sequence number of each subroutine call and the name of
120 the called subroutine. Note that &DB::sub is being compiled into the
121 package "DB" through the use of the "package" directive.
122
123 When it starts, the debugger reads your rc file (./.perldb or ~/.perldb
124 under Unix), which can set important options. (A subroutine
125 (&afterinit) can be defined here as well; it is executed after the
126 debugger completes its own initialization.)
127
128 After the rc file is read, the debugger reads the PERLDB_OPTS
129 environment variable and uses it to set debugger options. The contents
130 of this variable are treated as if they were the argument of an "o ..."
131 debugger command (q.v. in "Options" in perldebug).
132
133 Debugger internal variables
134
135 In addition to the file and subroutine-related variables mentioned
136 above, the debugger also maintains various magical internal variables.
137
138 · @DB::dbline is an alias for "@{"::_<current_file"}", which holds
139 the lines of the currently-selected file (compiled by Perl), either
140 explicitly chosen with the debugger's "f" command, or implicitly by
141 flow of execution.
142
143 Values in this array are magical in numeric context: they compare
144 equal to zero only if the line is not breakable.
145
146 · %DB::dbline, is an alias for "%{"::_<current_file"}", which
147 contains breakpoints and actions keyed by line number in the
148 currently-selected file, either explicitly chosen with the
149 debugger's "f" command, or implicitly by flow of execution.
150
151 As previously noted, individual entries (as opposed to the whole
152 hash) are settable. Perl only cares about Boolean true here,
153 although the values used by perl5db.pl have the form
154 "$break_condition\0$action".
155
156 Debugger customization functions
157
158 Some functions are provided to simplify customization.
159
160 · See "Configurable Options" in perldebug for a description of
161 options parsed by "DB::parse_options(string)".
162
163 · "DB::dump_trace(skip[,count])" skips the specified number of frames
164 and returns a list containing information about the calling frames
165 (all of them, if "count" is missing). Each entry is reference to a
166 hash with keys "context" (either ".", "$", or "@"), "sub"
167 (subroutine name, or info about "eval"), "args" ("undef" or a
168 reference to an array), "file", and "line".
169
170 · "DB::print_trace(FH, skip[, count[, short]])" prints formatted info
171 about caller frames. The last two functions may be convenient as
172 arguments to "<", "<<" commands.
173
174 Note that any variables and functions that are not documented in this
175 manpages (or in perldebug) are considered for internal use only, and as
176 such are subject to change without notice.
177
179 The "frame" option can be used to control the output of frame
180 information. For example, contrast this expression trace:
181
182 $ perl -de 42
183 Stack dump during die enabled outside of evals.
184
185 Loading DB routines from perl5db.pl patch level 0.94
186 Emacs support available.
187
188 Enter h or `h h' for help.
189
190 main::(-e:1): 0
191 DB<1> sub foo { 14 }
192
193 DB<2> sub bar { 3 }
194
195 DB<3> t print foo() * bar()
196 main::((eval 172):3): print foo() + bar();
197 main::foo((eval 168):2):
198 main::bar((eval 170):2):
199 42
200
201 with this one, once the "o"ption "frame=2" has been set:
202
203 DB<4> o f=2
204 frame = '2'
205 DB<5> t print foo() * bar()
206 3: foo() * bar()
207 entering main::foo
208 2: sub foo { 14 };
209 exited main::foo
210 entering main::bar
211 2: sub bar { 3 };
212 exited main::bar
213 42
214
215 By way of demonstration, we present below a laborious listing resulting
216 from setting your "PERLDB_OPTS" environment variable to the value "f=n
217 N", and running perl -d -V from the command line. Examples use various
218 values of "n" are shown to give you a feel for the difference between
219 settings. Long those it may be, this is not a complete listing, but
220 only excerpts.
221
222 1.
223 entering main::BEGIN
224 entering Config::BEGIN
225 Package lib/Exporter.pm.
226 Package lib/Carp.pm.
227 Package lib/Config.pm.
228 entering Config::TIEHASH
229 entering Exporter::import
230 entering Exporter::export
231 entering Config::myconfig
232 entering Config::FETCH
233 entering Config::FETCH
234 entering Config::FETCH
235 entering Config::FETCH
236
237 2.
238 entering main::BEGIN
239 entering Config::BEGIN
240 Package lib/Exporter.pm.
241 Package lib/Carp.pm.
242 exited Config::BEGIN
243 Package lib/Config.pm.
244 entering Config::TIEHASH
245 exited Config::TIEHASH
246 entering Exporter::import
247 entering Exporter::export
248 exited Exporter::export
249 exited Exporter::import
250 exited main::BEGIN
251 entering Config::myconfig
252 entering Config::FETCH
253 exited Config::FETCH
254 entering Config::FETCH
255 exited Config::FETCH
256 entering Config::FETCH
257
258 3.
259 in $=main::BEGIN() from /dev/null:0
260 in $=Config::BEGIN() from lib/Config.pm:2
261 Package lib/Exporter.pm.
262 Package lib/Carp.pm.
263 Package lib/Config.pm.
264 in $=Config::TIEHASH('Config') from lib/Config.pm:644
265 in $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
266 in $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from li
267 in @=Config::myconfig() from /dev/null:0
268 in $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
269 in $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
270 in $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
271 in $=Config::FETCH(ref(Config), 'PERL_SUBVERSION') from lib/Config.pm:574
272 in $=Config::FETCH(ref(Config), 'osname') from lib/Config.pm:574
273 in $=Config::FETCH(ref(Config), 'osvers') from lib/Config.pm:574
274
275 4.
276 in $=main::BEGIN() from /dev/null:0
277 in $=Config::BEGIN() from lib/Config.pm:2
278 Package lib/Exporter.pm.
279 Package lib/Carp.pm.
280 out $=Config::BEGIN() from lib/Config.pm:0
281 Package lib/Config.pm.
282 in $=Config::TIEHASH('Config') from lib/Config.pm:644
283 out $=Config::TIEHASH('Config') from lib/Config.pm:644
284 in $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
285 in $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
286 out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
287 out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
288 out $=main::BEGIN() from /dev/null:0
289 in @=Config::myconfig() from /dev/null:0
290 in $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
291 out $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
292 in $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
293 out $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
294 in $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
295 out $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
296 in $=Config::FETCH(ref(Config), 'PERL_SUBVERSION') from lib/Config.pm:574
297
298 5.
299 in $=main::BEGIN() from /dev/null:0
300 in $=Config::BEGIN() from lib/Config.pm:2
301 Package lib/Exporter.pm.
302 Package lib/Carp.pm.
303 out $=Config::BEGIN() from lib/Config.pm:0
304 Package lib/Config.pm.
305 in $=Config::TIEHASH('Config') from lib/Config.pm:644
306 out $=Config::TIEHASH('Config') from lib/Config.pm:644
307 in $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
308 in $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
309 out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
310 out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
311 out $=main::BEGIN() from /dev/null:0
312 in @=Config::myconfig() from /dev/null:0
313 in $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
314 out $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
315 in $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574
316 out $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574
317
318 6.
319 in $=CODE(0x15eca4)() from /dev/null:0
320 in $=CODE(0x182528)() from lib/Config.pm:2
321 Package lib/Exporter.pm.
322 out $=CODE(0x182528)() from lib/Config.pm:0
323 scalar context return from CODE(0x182528): undef
324 Package lib/Config.pm.
325 in $=Config::TIEHASH('Config') from lib/Config.pm:628
326 out $=Config::TIEHASH('Config') from lib/Config.pm:628
327 scalar context return from Config::TIEHASH: empty hash
328 in $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
329 in $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
330 out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
331 scalar context return from Exporter::export: ''
332 out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
333 scalar context return from Exporter::import: ''
334
335 In all cases shown above, the line indentation shows the call tree. If
336 bit 2 of "frame" is set, a line is printed on exit from a subroutine as
337 well. If bit 4 is set, the arguments are printed along with the caller
338 info. If bit 8 is set, the arguments are printed even if they are tied
339 or references. If bit 16 is set, the return value is printed, too.
340
341 When a package is compiled, a line like this
342
343 Package lib/Carp.pm.
344
345 is printed with proper indentation.
346
348 There are two ways to enable debugging output for regular expressions.
349
350 If your perl is compiled with "-DDEBUGGING", you may use the -Dr flag
351 on the command line.
352
353 Otherwise, one can "use re 'debug'", which has effects at compile time
354 and run time. Since Perl 5.9.5, this pragma is lexically scoped.
355
356 Compile-time output
357 The debugging output at compile time looks like this:
358
359 Compiling REx `[bc]d(ef*g)+h[ij]k$'
360 size 45 Got 364 bytes for offset annotations.
361 first at 1
362 rarest char g at 0
363 rarest char d at 0
364 1: ANYOF[bc](12)
365 12: EXACT <d>(14)
366 14: CURLYX[0] {1,32767}(28)
367 16: OPEN1(18)
368 18: EXACT <e>(20)
369 20: STAR(23)
370 21: EXACT <f>(0)
371 23: EXACT <g>(25)
372 25: CLOSE1(27)
373 27: WHILEM[1/1](0)
374 28: NOTHING(29)
375 29: EXACT <h>(31)
376 31: ANYOF[ij](42)
377 42: EXACT <k>(44)
378 44: EOL(45)
379 45: END(0)
380 anchored `de' at 1 floating `gh' at 3..2147483647 (checking floating)
381 stclass `ANYOF[bc]' minlen 7
382 Offsets: [45]
383 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
384 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
385 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
386 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
387 Omitting $` $& $' support.
388
389 The first line shows the pre-compiled form of the regex. The second
390 shows the size of the compiled form (in arbitrary units, usually 4-byte
391 words) and the total number of bytes allocated for the offset/length
392 table, usually 4+"size"*8. The next line shows the label id of the
393 first node that does a match.
394
395 The
396
397 anchored `de' at 1 floating `gh' at 3..2147483647 (checking floating)
398 stclass `ANYOF[bc]' minlen 7
399
400 line (split into two lines above) contains optimizer information. In
401 the example shown, the optimizer found that the match should contain a
402 substring "de" at offset 1, plus substring "gh" at some offset between
403 3 and infinity. Moreover, when checking for these substrings (to
404 abandon impossible matches quickly), Perl will check for the substring
405 "gh" before checking for the substring "de". The optimizer may also
406 use the knowledge that the match starts (at the "first" id) with a
407 character class, and no string shorter than 7 characters can possibly
408 match.
409
410 The fields of interest which may appear in this line are
411
412 "anchored" STRING "at" POS
413 "floating" STRING "at" POS1..POS2
414 See above.
415
416 "matching floating/anchored"
417 Which substring to check first.
418
419 "minlen"
420 The minimal length of the match.
421
422 "stclass" TYPE
423 Type of first matching node.
424
425 "noscan"
426 Don't scan for the found substrings.
427
428 "isall"
429 Means that the optimizer information is all that the regular
430 expression contains, and thus one does not need to enter the regex
431 engine at all.
432
433 "GPOS"
434 Set if the pattern contains "\G".
435
436 "plus"
437 Set if the pattern starts with a repeated char (as in "x+y").
438
439 "implicit"
440 Set if the pattern starts with ".*".
441
442 "with eval"
443 Set if the pattern contain eval-groups, such as "(?{ code })" and
444 "(??{ code })".
445
446 "anchored(TYPE)"
447 If the pattern may match only at a handful of places, (with "TYPE"
448 being "BOL", "MBOL", or "GPOS". See the table below.
449
450 If a substring is known to match at end-of-line only, it may be
451 followed by "$", as in "floating `k'$".
452
453 The optimizer-specific information is used to avoid entering (a slow)
454 regex engine on strings that will not definitely match. If the "isall"
455 flag is set, a call to the regex engine may be avoided even when the
456 optimizer found an appropriate place for the match.
457
458 Above the optimizer section is the list of nodes of the compiled form
459 of the regex. Each line has format
460
461 " "id: TYPE OPTIONAL-INFO (next-id)
462
463 Types of nodes
464 Here are the possible types, with short descriptions:
465
466 # TYPE arg-description [num-args] [longjump-len] DESCRIPTION
467
468 # Exit points
469 END no End of program.
470 SUCCEED no Return from a subroutine, basically.
471
472 # Anchors:
473 BOL no Match "" at beginning of line.
474 MBOL no Same, assuming multiline.
475 SBOL no Same, assuming singleline.
476 EOS no Match "" at end of string.
477 EOL no Match "" at end of line.
478 MEOL no Same, assuming multiline.
479 SEOL no Same, assuming singleline.
480 BOUND no Match "" at any word boundary
481 BOUNDL no Match "" at any word boundary
482 NBOUND no Match "" at any word non-boundary
483 NBOUNDL no Match "" at any word non-boundary
484 GPOS no Matches where last m//g left off.
485
486 # [Special] alternatives
487 ANY no Match any one character (except newline).
488 SANY no Match any one character.
489 ANYOF sv Match character in (or not in) this class.
490 ALNUM no Match any alphanumeric character
491 ALNUML no Match any alphanumeric char in locale
492 NALNUM no Match any non-alphanumeric character
493 NALNUML no Match any non-alphanumeric char in locale
494 SPACE no Match any whitespace character
495 SPACEL no Match any whitespace char in locale
496 NSPACE no Match any non-whitespace character
497 NSPACEL no Match any non-whitespace char in locale
498 DIGIT no Match any numeric character
499 NDIGIT no Match any non-numeric character
500
501 # BRANCH The set of branches constituting a single choice are hooked
502 # together with their "next" pointers, since precedence prevents
503 # anything being concatenated to any individual branch. The
504 # "next" pointer of the last BRANCH in a choice points to the
505 # thing following the whole choice. This is also where the
506 # final "next" pointer of each individual branch points; each
507 # branch starts with the operand node of a BRANCH node.
508 #
509 BRANCH node Match this alternative, or the next...
510
511 # BACK Normal "next" pointers all implicitly point forward; BACK
512 # exists to make loop structures possible.
513 # not used
514 BACK no Match "", "next" ptr points backward.
515
516 # Literals
517 EXACT sv Match this string (preceded by length).
518 EXACTF sv Match this string, folded (prec. by length).
519 EXACTFL sv Match this string, folded in locale (w/len).
520
521 # Do nothing
522 NOTHING no Match empty string.
523 # A variant of above which delimits a group, thus stops optimizations
524 TAIL no Match empty string. Can jump here from outside.
525
526 # STAR,PLUS '?', and complex '*' and '+', are implemented as circular
527 # BRANCH structures using BACK. Simple cases (one character
528 # per match) are implemented with STAR and PLUS for speed
529 # and to minimize recursive plunges.
530 #
531 STAR node Match this (simple) thing 0 or more times.
532 PLUS node Match this (simple) thing 1 or more times.
533
534 CURLY sv 2 Match this simple thing {n,m} times.
535 CURLYN no 2 Match next-after-this simple thing
536 # {n,m} times, set parens.
537 CURLYM no 2 Match this medium-complex thing {n,m} times.
538 CURLYX sv 2 Match this complex thing {n,m} times.
539
540 # This terminator creates a loop structure for CURLYX
541 WHILEM no Do curly processing and see if rest matches.
542
543 # OPEN,CLOSE,GROUPP ...are numbered at compile time.
544 OPEN num 1 Mark this point in input as start of #n.
545 CLOSE num 1 Analogous to OPEN.
546
547 REF num 1 Match some already matched string
548 REFF num 1 Match already matched string, folded
549 REFFL num 1 Match already matched string, folded in loc.
550
551 # grouping assertions
552 IFMATCH off 1 2 Succeeds if the following matches.
553 UNLESSM off 1 2 Fails if the following matches.
554 SUSPEND off 1 1 "Independent" sub-regex.
555 IFTHEN off 1 1 Switch, should be preceded by switcher .
556 GROUPP num 1 Whether the group matched.
557
558 # Support for long regex
559 LONGJMP off 1 1 Jump far away.
560 BRANCHJ off 1 1 BRANCH with long offset.
561
562 # The heavy worker
563 EVAL evl 1 Execute some Perl code.
564
565 # Modifiers
566 MINMOD no Next operator is not greedy.
567 LOGICAL no Next opcode should set the flag only.
568
569 # This is not used yet
570 RENUM off 1 1 Group with independently numbered parens.
571
572 # This is not really a node, but an optimized away piece of a "long" node.
573 # To simplify debugging output, we mark it as if it were a node
574 OPTIMIZED off Placeholder for dump.
575
576 Following the optimizer information is a dump of the offset/length
577 table, here split across several lines:
578
579 Offsets: [45]
580 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
581 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
582 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
583 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
584
585 The first line here indicates that the offset/length table contains 45
586 entries. Each entry is a pair of integers, denoted by
587 "offset[length]". Entries are numbered starting with 1, so entry #1
588 here is "1[4]" and entry #12 is "5[1]". "1[4]" indicates that the node
589 labeled "1:" (the "1: ANYOF[bc]") begins at character position 1 in the
590 pre-compiled form of the regex, and has a length of 4 characters.
591 "5[1]" in position 12 indicates that the node labeled "12:" (the "12:
592 EXACT <d>") begins at character position 5 in the pre-compiled form of
593 the regex, and has a length of 1 character. "12[1]" in position 14
594 indicates that the node labeled "14:" (the "14: CURLYX[0] {1,32767}")
595 begins at character position 12 in the pre-compiled form of the regex,
596 and has a length of 1 character---that is, it corresponds to the "+"
597 symbol in the precompiled regex.
598
599 "0[0]" items indicate that there is no corresponding node.
600
601 Run-time output
602 First of all, when doing a match, one may get no run-time output even
603 if debugging is enabled. This means that the regex engine was never
604 entered and that all of the job was therefore done by the optimizer.
605
606 If the regex engine was entered, the output may look like this:
607
608 Matching `[bc]d(ef*g)+h[ij]k$' against `abcdefg__gh__'
609 Setting an EVAL scope, savestack=3
610 2 <ab> <cdefg__gh_> | 1: ANYOF
611 3 <abc> <defg__gh_> | 11: EXACT <d>
612 4 <abcd> <efg__gh_> | 13: CURLYX {1,32767}
613 4 <abcd> <efg__gh_> | 26: WHILEM
614 0 out of 1..32767 cc=effff31c
615 4 <abcd> <efg__gh_> | 15: OPEN1
616 4 <abcd> <efg__gh_> | 17: EXACT <e>
617 5 <abcde> <fg__gh_> | 19: STAR
618 EXACT <f> can match 1 times out of 32767...
619 Setting an EVAL scope, savestack=3
620 6 <bcdef> <g__gh__> | 22: EXACT <g>
621 7 <bcdefg> <__gh__> | 24: CLOSE1
622 7 <bcdefg> <__gh__> | 26: WHILEM
623 1 out of 1..32767 cc=effff31c
624 Setting an EVAL scope, savestack=12
625 7 <bcdefg> <__gh__> | 15: OPEN1
626 7 <bcdefg> <__gh__> | 17: EXACT <e>
627 restoring \1 to 4(4)..7
628 failed, try continuation...
629 7 <bcdefg> <__gh__> | 27: NOTHING
630 7 <bcdefg> <__gh__> | 28: EXACT <h>
631 failed...
632 failed...
633
634 The most significant information in the output is about the particular
635 node of the compiled regex that is currently being tested against the
636 target string. The format of these lines is
637
638 " "STRING-OFFSET <PRE-STRING> <POST-STRING> |ID: TYPE
639
640 The TYPE info is indented with respect to the backtracking level.
641 Other incidental information appears interspersed within.
642
644 Perl is a profligate wastrel when it comes to memory use. There is a
645 saying that to estimate memory usage of Perl, assume a reasonable
646 algorithm for memory allocation, multiply that estimate by 10, and
647 while you still may miss the mark, at least you won't be quite so
648 astonished. This is not absolutely true, but may provide a good grasp
649 of what happens.
650
651 Assume that an integer cannot take less than 20 bytes of memory, a
652 float cannot take less than 24 bytes, a string cannot take less than 32
653 bytes (all these examples assume 32-bit architectures, the result are
654 quite a bit worse on 64-bit architectures). If a variable is accessed
655 in two of three different ways (which require an integer, a float, or a
656 string), the memory footprint may increase yet another 20 bytes. A
657 sloppy malloc(3) implementation can inflate these numbers dramatically.
658
659 On the opposite end of the scale, a declaration like
660
661 sub foo;
662
663 may take up to 500 bytes of memory, depending on which release of Perl
664 you're running.
665
666 Anecdotal estimates of source-to-compiled code bloat suggest an
667 eightfold increase. This means that the compiled form of reasonable
668 (normally commented, properly indented etc.) code will take about eight
669 times more space in memory than the code took on disk.
670
671 The -DL command-line switch is obsolete since circa Perl 5.6.0 (it was
672 available only if Perl was built with "-DDEBUGGING"). The switch was
673 used to track Perl's memory allocations and possible memory leaks.
674 These days the use of malloc debugging tools like Purify or valgrind is
675 suggested instead. See also "PERL_MEM_LOG" in perlhack.
676
677 One way to find out how much memory is being used by Perl data
678 structures is to install the Devel::Size module from CPAN: it gives you
679 the minimum number of bytes required to store a particular data
680 structure. Please be mindful of the difference between the size() and
681 total_size().
682
683 If Perl has been compiled using Perl's malloc you can analyze Perl
684 memory usage by setting the $ENV{PERL_DEBUG_MSTATS}.
685
686 Using $ENV{PERL_DEBUG_MSTATS}
687 If your perl is using Perl's malloc() and was compiled with the
688 necessary switches (this is the default), then it will print memory
689 usage statistics after compiling your code when
690 "$ENV{PERL_DEBUG_MSTATS} > 1", and before termination of the program
691 when "$ENV{PERL_DEBUG_MSTATS} >= 1". The report format is similar to
692 the following example:
693
694 $ PERL_DEBUG_MSTATS=2 perl -e "require Carp"
695 Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
696 14216 free: 130 117 28 7 9 0 2 2 1 0 0
697 437 61 36 0 5
698 60924 used: 125 137 161 55 7 8 6 16 2 0 1
699 74 109 304 84 20
700 Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048.
701 Memory allocation statistics after execution: (buckets 4(4)..8188(8192)
702 30888 free: 245 78 85 13 6 2 1 3 2 0 1
703 315 162 39 42 11
704 175816 used: 265 176 1112 111 26 22 11 27 2 1 1
705 196 178 1066 798 39
706 Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.
707
708 It is possible to ask for such a statistic at arbitrary points in your
709 execution using the mstat() function out of the standard Devel::Peek
710 module.
711
712 Here is some explanation of that format:
713
714 "buckets SMALLEST(APPROX)..GREATEST(APPROX)"
715 Perl's malloc() uses bucketed allocations. Every request is
716 rounded up to the closest bucket size available, and a bucket is
717 taken from the pool of buckets of that size.
718
719 The line above describes the limits of buckets currently in use.
720 Each bucket has two sizes: memory footprint and the maximal size of
721 user data that can fit into this bucket. Suppose in the above
722 example that the smallest bucket were size 4. The biggest bucket
723 would have usable size 8188, and the memory footprint would be
724 8192.
725
726 In a Perl built for debugging, some buckets may have negative
727 usable size. This means that these buckets cannot (and will not)
728 be used. For larger buckets, the memory footprint may be one page
729 greater than a power of 2. If so, case the corresponding power of
730 two is printed in the "APPROX" field above.
731
732 Free/Used
733 The 1 or 2 rows of numbers following that correspond to the number
734 of buckets of each size between "SMALLEST" and "GREATEST". In the
735 first row, the sizes (memory footprints) of buckets are powers of
736 two--or possibly one page greater. In the second row, if present,
737 the memory footprints of the buckets are between the memory
738 footprints of two buckets "above".
739
740 For example, suppose under the previous example, the memory
741 footprints were
742
743 free: 8 16 32 64 128 256 512 1024 2048 4096 8192
744 4 12 24 48 80
745
746 With non-"DEBUGGING" perl, the buckets starting from 128 have a
747 4-byte overhead, and thus an 8192-long bucket may take up to
748 8188-byte allocations.
749
750 "Total sbrk(): SBRKed/SBRKs:CONTINUOUS"
751 The first two fields give the total amount of memory perl sbrk(2)ed
752 (ess-broken? :-) and number of sbrk(2)s used. The third number is
753 what perl thinks about continuity of returned chunks. So long as
754 this number is positive, malloc() will assume that it is probable
755 that sbrk(2) will provide continuous memory.
756
757 Memory allocated by external libraries is not counted.
758
759 "pad: 0"
760 The amount of sbrk(2)ed memory needed to keep buckets aligned.
761
762 "heads: 2192"
763 Although memory overhead of bigger buckets is kept inside the
764 bucket, for smaller buckets, it is kept in separate areas. This
765 field gives the total size of these areas.
766
767 "chain: 0"
768 malloc() may want to subdivide a bigger bucket into smaller
769 buckets. If only a part of the deceased bucket is left
770 unsubdivided, the rest is kept as an element of a linked list.
771 This field gives the total size of these chunks.
772
773 "tail: 6144"
774 To minimize the number of sbrk(2)s, malloc() asks for more memory.
775 This field gives the size of the yet unused part, which is
776 sbrk(2)ed, but never touched.
777
779 perldebug, perlguts, perlrun re, and Devel::DProf.
780
781
782
783perl v5.12.4 2011-06-07 PERLDEBGUTS(1)