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