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 "Configurable 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 contains
147 breakpoints and actions keyed by line number in the currently-
148 selected file, either explicitly chosen with the debugger's "f"
149 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 using
218 various values of "n" are shown to give you a feel for the difference
219 between settings. Long though it may be, this is not a complete
220 listing, but 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
474 BOL no Match "" at beginning of line.
475 MBOL no Same, assuming multiline.
476 SBOL no Same, assuming singleline.
477 EOS no Match "" at end of string.
478 EOL no Match "" at end of line.
479 MEOL no Same, assuming multiline.
480 SEOL no Same, assuming singleline.
481 BOUND no Match "" at any word boundary using native charset
482 semantics for non-utf8
483 BOUNDL no Match "" at any locale word boundary
484 BOUNDU no Match "" at any word boundary using Unicode semantics
485 BOUNDA no Match "" at any word boundary using ASCII semantics
486 NBOUND no Match "" at any word non-boundary using native charset
487 semantics for non-utf8
488 NBOUNDL no Match "" at any locale word non-boundary
489 NBOUNDU no Match "" at any word non-boundary using Unicode semantics
490 NBOUNDA no Match "" at any word non-boundary using ASCII semantics
491 GPOS no Matches where last m//g left off.
492
493 # [Special] alternatives:
494
495 REG_ANY no Match any one character (except newline).
496 SANY no Match any one character.
497 CANY no Match any one byte.
498 ANYOF sv Match character in (or not in) this class, single char
499 match only
500 ANYOFV sv Match character in (or not in) this class, can
501 match-multiple chars
502 ALNUM no Match any alphanumeric character using native charset
503 semantics for non-utf8
504 ALNUML no Match any alphanumeric char in locale
505 ALNUMU no Match any alphanumeric char using Unicode semantics
506 ALNUMA no Match [A-Za-z_0-9]
507 NALNUM no Match any non-alphanumeric character using native charset
508 semantics for non-utf8
509 NALNUML no Match any non-alphanumeric char in locale
510 NALNUMU no Match any non-alphanumeric char using Unicode semantics
511 NALNUMA no Match [^A-Za-z_0-9]
512 SPACE no Match any whitespace character using native charset
513 semantics for non-utf8
514 SPACEL no Match any whitespace char in locale
515 SPACEU no Match any whitespace char using Unicode semantics
516 SPACEA no Match [ \t\n\f\r]
517 NSPACE no Match any non-whitespace character using native charset
518 semantics for non-utf8
519 NSPACEL no Match any non-whitespace char in locale
520 NSPACEU no Match any non-whitespace char using Unicode semantics
521 NSPACEA no Match [^ \t\n\f\r]
522 DIGIT no Match any numeric character using native charset semantics
523 for non-utf8
524 DIGITL no Match any numeric character in locale
525 DIGITA no Match [0-9]
526 NDIGIT no Match any non-numeric character using native charset
527 i semantics for non-utf8
528 NDIGITL no Match any non-numeric character in locale
529 NDIGITA no Match [^0-9]
530 CLUMP no Match any extended grapheme cluster sequence
531
532 # Alternation
533
534 # BRANCH The set of branches constituting a single choice are hooked
535 # together with their "next" pointers, since precedence prevents
536 # anything being concatenated to any individual branch. The
537 # "next" pointer of the last BRANCH in a choice points to the
538 # thing following the whole choice. This is also where the
539 # final "next" pointer of each individual branch points; each
540 # branch starts with the operand node of a BRANCH node.
541 #
542 BRANCH node Match this alternative, or the next...
543
544 # Back pointer
545
546 # BACK Normal "next" pointers all implicitly point forward; BACK
547 # exists to make loop structures possible.
548 # not used
549 BACK no Match "", "next" ptr points backward.
550
551 # Literals
552
553 EXACT str Match this string (preceded by length).
554 EXACTF str Match this string, folded, native charset semantics for
555 non-utf8 (prec. by length).
556 EXACTFL str Match this string, folded in locale (w/len).
557 EXACTFU str Match this string, folded, Unicode semantics for non-utf8
558 (prec. by length).
559 EXACTFA str Match this string, folded, Unicode semantics for non-utf8,
560 but no ASCII-range character matches outside ASCII (prec.
561 by length),.
562
563 # Do nothing types
564
565 NOTHING no Match empty string.
566 # A variant of above which delimits a group, thus stops optimizations
567 TAIL no Match empty string. Can jump here from outside.
568
569 # Loops
570
571 # STAR,PLUS '?', and complex '*' and '+', are implemented as circular
572 # BRANCH structures using BACK. Simple cases (one character
573 # per match) are implemented with STAR and PLUS for speed
574 # and to minimize recursive plunges.
575 #
576 STAR node Match this (simple) thing 0 or more times.
577 PLUS node Match this (simple) thing 1 or more times.
578
579 CURLY sv 2 Match this simple thing {n,m} times.
580 CURLYN no 2 Capture next-after-this simple thing
581 CURLYM no 2 Capture this medium-complex thing {n,m} times.
582 CURLYX sv 2 Match this complex thing {n,m} times.
583
584 # This terminator creates a loop structure for CURLYX
585 WHILEM no Do curly processing and see if rest matches.
586
587 # Buffer related
588
589 # OPEN,CLOSE,GROUPP ...are numbered at compile time.
590 OPEN num 1 Mark this point in input as start of #n.
591 CLOSE num 1 Analogous to OPEN.
592
593 REF num 1 Match some already matched string
594 REFF num 1 Match already matched string, folded using native charset
595 semantics for non-utf8
596 REFFL num 1 Match already matched string, folded in loc.
597 REFFU num 1 Match already matched string, folded using unicode
598 semantics for non-utf8
599 REFFA num 1 Match already matched string, folded using unicode
600 semantics for non-utf8, no mixing ASCII, non-ASCII
601
602 # Named references. Code in regcomp.c assumes that these all are after the
603 # numbered references
604 NREF no-sv 1 Match some already matched string
605 NREFF no-sv 1 Match already matched string, folded using native charset
606 semantics for non-utf8
607 NREFFL no-sv 1 Match already matched string, folded in loc.
608 NREFFU num 1 Match already matched string, folded using unicode
609 semantics for non-utf8
610 NREFFA num 1 Match already matched string, folded using unicode
611 semantics for non-utf8, no mixing ASCII, non-ASCII
612
613 IFMATCH off 1 2 Succeeds if the following matches.
614 UNLESSM off 1 2 Fails if the following matches.
615 SUSPEND off 1 1 "Independent" sub-RE.
616 IFTHEN off 1 1 Switch, should be preceded by switcher.
617 GROUPP num 1 Whether the group matched.
618
619 # Support for long RE
620
621 LONGJMP off 1 1 Jump far away.
622 BRANCHJ off 1 1 BRANCH with long offset.
623
624 # The heavy worker
625
626 EVAL evl 1 Execute some Perl code.
627
628 # Modifiers
629
630 MINMOD no Next operator is not greedy.
631 LOGICAL no Next opcode should set the flag only.
632
633 # This is not used yet
634 RENUM off 1 1 Group with independently numbered parens.
635
636 # Trie Related
637
638 # Behave the same as A|LIST|OF|WORDS would. The '..C' variants have
639 # inline charclass data (ascii only), the 'C' store it in the structure.
640 # NOTE: the relative order of the TRIE-like regops is significant
641
642 TRIE trie 1 Match many EXACT(F[ALU]?)? at once. flags==type
643 TRIEC charclass Same as TRIE, but with embedded charclass data
644
645 # For start classes, contains an added fail table.
646 AHOCORASICK trie 1 Aho Corasick stclass. flags==type
647 AHOCORASICKC charclass Same as AHOCORASICK, but with embedded charclass data
648
649 # Regex Subroutines
650 GOSUB num/ofs 2L recurse to paren arg1 at (signed) ofs arg2
651 GOSTART no recurse to start of pattern
652
653 # Special conditionals
654 NGROUPP no-sv 1 Whether the group matched.
655 INSUBP num 1 Whether we are in a specific recurse.
656 DEFINEP none 1 Never execute directly.
657
658 # Backtracking Verbs
659 ENDLIKE none Used only for the type field of verbs
660 OPFAIL none Same as (?!)
661 ACCEPT parno 1 Accepts the current matched string.
662
663
664 # Verbs With Arguments
665 VERB no-sv 1 Used only for the type field of verbs
666 PRUNE no-sv 1 Pattern fails at this startpoint if no-backtracking through this
667 MARKPOINT no-sv 1 Push the current location for rollback by cut.
668 SKIP no-sv 1 On failure skip forward (to the mark) before retrying
669 COMMIT no-sv 1 Pattern fails outright if backtracking through this
670 CUTGROUP no-sv 1 On failure go to the next alternation in the group
671
672 # Control what to keep in $&.
673 KEEPS no $& begins here.
674
675 # New charclass like patterns
676 LNBREAK none generic newline pattern
677 VERTWS none vertical whitespace (Perl 6)
678 NVERTWS none not vertical whitespace (Perl 6)
679 HORIZWS none horizontal whitespace (Perl 6)
680 NHORIZWS none not horizontal whitespace (Perl 6)
681
682 FOLDCHAR codepoint 1 codepoint with tricky case folding properties.
683
684 # SPECIAL REGOPS
685
686 # This is not really a node, but an optimized away piece of a "long" node.
687 # To simplify debugging output, we mark it as if it were a node
688 OPTIMIZED off Placeholder for dump.
689
690 # Special opcode with the property that no opcode in a compiled program
691 # will ever be of this type. Thus it can be used as a flag value that
692 # no other opcode has been seen. END is used similarly, in that an END
693 # node cant be optimized. So END implies "unoptimizable" and PSEUDO mean
694 # "not seen anything to optimize yet".
695 PSEUDO off Pseudo opcode for internal use.
696
697 Following the optimizer information is a dump of the offset/length
698 table, here split across several lines:
699
700 Offsets: [45]
701 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
702 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
703 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
704 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
705
706 The first line here indicates that the offset/length table contains 45
707 entries. Each entry is a pair of integers, denoted by
708 "offset[length]". Entries are numbered starting with 1, so entry #1
709 here is "1[4]" and entry #12 is "5[1]". "1[4]" indicates that the node
710 labeled "1:" (the "1: ANYOF[bc]") begins at character position 1 in the
711 pre-compiled form of the regex, and has a length of 4 characters.
712 "5[1]" in position 12 indicates that the node labeled "12:" (the "12:
713 EXACT <d>") begins at character position 5 in the pre-compiled form of
714 the regex, and has a length of 1 character. "12[1]" in position 14
715 indicates that the node labeled "14:" (the "14: CURLYX[0] {1,32767}")
716 begins at character position 12 in the pre-compiled form of the regex,
717 and has a length of 1 character---that is, it corresponds to the "+"
718 symbol in the precompiled regex.
719
720 "0[0]" items indicate that there is no corresponding node.
721
722 Run-time Output
723 First of all, when doing a match, one may get no run-time output even
724 if debugging is enabled. This means that the regex engine was never
725 entered and that all of the job was therefore done by the optimizer.
726
727 If the regex engine was entered, the output may look like this:
728
729 Matching '[bc]d(ef*g)+h[ij]k$' against 'abcdefg__gh__'
730 Setting an EVAL scope, savestack=3
731 2 <ab> <cdefg__gh_> | 1: ANYOF
732 3 <abc> <defg__gh_> | 11: EXACT <d>
733 4 <abcd> <efg__gh_> | 13: CURLYX {1,32767}
734 4 <abcd> <efg__gh_> | 26: WHILEM
735 0 out of 1..32767 cc=effff31c
736 4 <abcd> <efg__gh_> | 15: OPEN1
737 4 <abcd> <efg__gh_> | 17: EXACT <e>
738 5 <abcde> <fg__gh_> | 19: STAR
739 EXACT <f> can match 1 times out of 32767...
740 Setting an EVAL scope, savestack=3
741 6 <bcdef> <g__gh__> | 22: EXACT <g>
742 7 <bcdefg> <__gh__> | 24: CLOSE1
743 7 <bcdefg> <__gh__> | 26: WHILEM
744 1 out of 1..32767 cc=effff31c
745 Setting an EVAL scope, savestack=12
746 7 <bcdefg> <__gh__> | 15: OPEN1
747 7 <bcdefg> <__gh__> | 17: EXACT <e>
748 restoring \1 to 4(4)..7
749 failed, try continuation...
750 7 <bcdefg> <__gh__> | 27: NOTHING
751 7 <bcdefg> <__gh__> | 28: EXACT <h>
752 failed...
753 failed...
754
755 The most significant information in the output is about the particular
756 node of the compiled regex that is currently being tested against the
757 target string. The format of these lines is
758
759 " "STRING-OFFSET <PRE-STRING> <POST-STRING> |ID: TYPE
760
761 The TYPE info is indented with respect to the backtracking level.
762 Other incidental information appears interspersed within.
763
765 Perl is a profligate wastrel when it comes to memory use. There is a
766 saying that to estimate memory usage of Perl, assume a reasonable
767 algorithm for memory allocation, multiply that estimate by 10, and
768 while you still may miss the mark, at least you won't be quite so
769 astonished. This is not absolutely true, but may provide a good grasp
770 of what happens.
771
772 Assume that an integer cannot take less than 20 bytes of memory, a
773 float cannot take less than 24 bytes, a string cannot take less than 32
774 bytes (all these examples assume 32-bit architectures, the result are
775 quite a bit worse on 64-bit architectures). If a variable is accessed
776 in two of three different ways (which require an integer, a float, or a
777 string), the memory footprint may increase yet another 20 bytes. A
778 sloppy malloc(3) implementation can inflate these numbers dramatically.
779
780 On the opposite end of the scale, a declaration like
781
782 sub foo;
783
784 may take up to 500 bytes of memory, depending on which release of Perl
785 you're running.
786
787 Anecdotal estimates of source-to-compiled code bloat suggest an
788 eightfold increase. This means that the compiled form of reasonable
789 (normally commented, properly indented etc.) code will take about eight
790 times more space in memory than the code took on disk.
791
792 The -DL command-line switch is obsolete since circa Perl 5.6.0 (it was
793 available only if Perl was built with "-DDEBUGGING"). The switch was
794 used to track Perl's memory allocations and possible memory leaks.
795 These days the use of malloc debugging tools like Purify or valgrind is
796 suggested instead. See also "PERL_MEM_LOG" in perlhacktips.
797
798 One way to find out how much memory is being used by Perl data
799 structures is to install the Devel::Size module from CPAN: it gives you
800 the minimum number of bytes required to store a particular data
801 structure. Please be mindful of the difference between the size() and
802 total_size().
803
804 If Perl has been compiled using Perl's malloc you can analyze Perl
805 memory usage by setting $ENV{PERL_DEBUG_MSTATS}.
806
807 Using $ENV{PERL_DEBUG_MSTATS}
808 If your perl is using Perl's malloc() and was compiled with the
809 necessary switches (this is the default), then it will print memory
810 usage statistics after compiling your code when
811 "$ENV{PERL_DEBUG_MSTATS} > 1", and before termination of the program
812 when "$ENV{PERL_DEBUG_MSTATS} >= 1". The report format is similar to
813 the following example:
814
815 $ PERL_DEBUG_MSTATS=2 perl -e "require Carp"
816 Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
817 14216 free: 130 117 28 7 9 0 2 2 1 0 0
818 437 61 36 0 5
819 60924 used: 125 137 161 55 7 8 6 16 2 0 1
820 74 109 304 84 20
821 Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048.
822 Memory allocation statistics after execution: (buckets 4(4)..8188(8192)
823 30888 free: 245 78 85 13 6 2 1 3 2 0 1
824 315 162 39 42 11
825 175816 used: 265 176 1112 111 26 22 11 27 2 1 1
826 196 178 1066 798 39
827 Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.
828
829 It is possible to ask for such a statistic at arbitrary points in your
830 execution using the mstat() function out of the standard Devel::Peek
831 module.
832
833 Here is some explanation of that format:
834
835 "buckets SMALLEST(APPROX)..GREATEST(APPROX)"
836 Perl's malloc() uses bucketed allocations. Every request is
837 rounded up to the closest bucket size available, and a bucket is
838 taken from the pool of buckets of that size.
839
840 The line above describes the limits of buckets currently in use.
841 Each bucket has two sizes: memory footprint and the maximal size of
842 user data that can fit into this bucket. Suppose in the above
843 example that the smallest bucket were size 4. The biggest bucket
844 would have usable size 8188, and the memory footprint would be
845 8192.
846
847 In a Perl built for debugging, some buckets may have negative
848 usable size. This means that these buckets cannot (and will not)
849 be used. For larger buckets, the memory footprint may be one page
850 greater than a power of 2. If so, the corresponding power of two
851 is printed in the "APPROX" field above.
852
853 Free/Used
854 The 1 or 2 rows of numbers following that correspond to the number
855 of buckets of each size between "SMALLEST" and "GREATEST". In the
856 first row, the sizes (memory footprints) of buckets are powers of
857 two--or possibly one page greater. In the second row, if present,
858 the memory footprints of the buckets are between the memory
859 footprints of two buckets "above".
860
861 For example, suppose under the previous example, the memory
862 footprints were
863
864 free: 8 16 32 64 128 256 512 1024 2048 4096 8192
865 4 12 24 48 80
866
867 With a non-"DEBUGGING" perl, the buckets starting from 128 have a
868 4-byte overhead, and thus an 8192-long bucket may take up to
869 8188-byte allocations.
870
871 "Total sbrk(): SBRKed/SBRKs:CONTINUOUS"
872 The first two fields give the total amount of memory perl sbrk(2)ed
873 (ess-broken? :-) and number of sbrk(2)s used. The third number is
874 what perl thinks about continuity of returned chunks. So long as
875 this number is positive, malloc() will assume that it is probable
876 that sbrk(2) will provide continuous memory.
877
878 Memory allocated by external libraries is not counted.
879
880 "pad: 0"
881 The amount of sbrk(2)ed memory needed to keep buckets aligned.
882
883 "heads: 2192"
884 Although memory overhead of bigger buckets is kept inside the
885 bucket, for smaller buckets, it is kept in separate areas. This
886 field gives the total size of these areas.
887
888 "chain: 0"
889 malloc() may want to subdivide a bigger bucket into smaller
890 buckets. If only a part of the deceased bucket is left
891 unsubdivided, the rest is kept as an element of a linked list.
892 This field gives the total size of these chunks.
893
894 "tail: 6144"
895 To minimize the number of sbrk(2)s, malloc() asks for more memory.
896 This field gives the size of the yet unused part, which is
897 sbrk(2)ed, but never touched.
898
900 perldebug, perlguts, perlrun re, and Devel::DProf.
901
902
903
904perl v5.16.3 2013-03-04 PERLDEBGUTS(1)