1PERLDEBGUTS(1)         Perl Programmers Reference Guide         PERLDEBGUTS(1)
2
3
4

NAME

6       perldebguts - Guts of Perl debugging
7

DESCRIPTION

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

Debugger Internals

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 also
50           the case for evaluated strings that contain subroutines, or which
51           are currently being executed.  The $filename for "eval"ed strings
52           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

Frame Listing Output Examples

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

Debugging Regular Expressions

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 [regnode-struct-suffix] [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 like
506                                    BOUNDU
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 like
514                                    BOUNDU
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
535        ANYOFH           sv 1       Like ANYOF, but only has "High" matches,
536                                    none in the bitmap; the flags field
537                                    contains the lowest matchable UTF-8 start
538                                    byte
539        ANYOFHb          sv 1       Like ANYOFH, but all matches share the same
540                                    UTF-8 start byte, given in the flags field
541        ANYOFHr          sv 1       Like ANYOFH, but the flags field contains
542                                    packed bounds for all matchable UTF-8 start
543                                    bytes.
544        ANYOFHs          sv 1       Like ANYOFHb, but has a string field that
545                                    gives the leading matchable UTF-8 bytes;
546                                    flags field is len
547        ANYOFR           packed 1   Matches any character in the range given by
548                                    its packed args: upper 12 bits is the max
549                                    delta from the base lower 20; the flags
550                                    field contains the lowest matchable UTF-8
551                                    start byte
552        ANYOFRb          packed 1   Like ANYOFR, but all matches share the same
553                                    UTF-8 start byte, given in the flags field
554
555        ANYOFM           byte 1     Like ANYOF, but matches an invariant byte
556                                    as determined by the mask and arg
557        NANYOFM          byte 1     complement of ANYOFM
558
559        # POSIX Character Classes:
560        POSIXD           none       Some [[:class:]] under /d; the FLAGS field
561                                    gives which one
562        POSIXL           none       Some [[:class:]] under /l; the FLAGS field
563                                    gives which one
564        POSIXU           none       Some [[:class:]] under /u; the FLAGS field
565                                    gives which one
566        POSIXA           none       Some [[:class:]] under /a; the FLAGS field
567                                    gives which one
568        NPOSIXD          none       complement of POSIXD, [[:^class:]]
569        NPOSIXL          none       complement of POSIXL, [[:^class:]]
570        NPOSIXU          none       complement of POSIXU, [[:^class:]]
571        NPOSIXA          none       complement of POSIXA, [[:^class:]]
572
573        CLUMP            no         Match any extended grapheme cluster
574                                    sequence
575
576        # Alternation
577
578        # BRANCH        The set of branches constituting a single choice are
579        #               hooked together with their "next" pointers, since
580        #               precedence prevents anything being concatenated to
581        #               any individual branch.  The "next" pointer of the last
582        #               BRANCH in a choice points to the thing following the
583        #               whole choice.  This is also where the final "next"
584        #               pointer of each individual branch points; each branch
585        #               starts with the operand node of a BRANCH node.
586        #
587        BRANCH           node       Match this alternative, or the next...
588
589        # Literals
590
591        EXACT            str        Match this string (flags field is the
592                                    length).
593
594        # In a long string node, the U32 argument is the length, and is
595        # immediately followed by the string.
596        LEXACT           len:str 1  Match this long string (preceded by length;
597                                    flags unused).
598        EXACTL           str        Like EXACT, but /l is in effect (used so
599                                    locale-related warnings can be checked for)
600        EXACTF           str        Like EXACT, but match using /id rules;
601                                    (string not UTF-8, ASCII folded; non-ASCII
602                                    not)
603        EXACTFL          str        Like EXACT, but match using /il rules;
604                                    (string not likely to be folded)
605        EXACTFU          str        Like EXACT, but match using /iu rules;
606                                    (string folded)
607
608        EXACTFAA         str        Like EXACT, but match using /iaa rules;
609                                    (string folded except MICRO in non-UTF8
610                                    patterns; doesn't contain SHARP S unless
611                                    UTF-8; folded length <= unfolded)
612        EXACTFAA_NO_TRIE str        Like EXACTFAA, (string not UTF-8, folded
613                                    except: MICRO, SHARP S; folded length <=
614                                    unfolded, not currently trie-able)
615
616        EXACTFUP         str        Like EXACT, but match using /iu rules;
617                                    (string not UTF-8, folded except MICRO:
618                                    hence Problematic)
619
620        EXACTFLU8        str        Like EXACTFU, but use /il, UTF-8, (string
621                                    is folded, and everything in it is above
622                                    255
623        EXACT_REQ8       str        Like EXACT, but only UTF-8 encoded targets
624                                    can match
625        LEXACT_REQ8      len:str 1  Like LEXACT, but only UTF-8 encoded targets
626                                    can match
627        EXACTFU_REQ8     str        Like EXACTFU, but only UTF-8 encoded
628                                    targets can match
629
630        EXACTFU_S_EDGE   str        /di rules, but nothing in it precludes /ui,
631                                    except begins and/or ends with [Ss];
632                                    (string not UTF-8; compile-time only)
633
634        # New charclass like patterns
635        LNBREAK          none       generic newline pattern
636
637        # Trie Related
638
639        # Behave the same as A|LIST|OF|WORDS would. The '..C' variants
640        # have inline charclass data (ascii only), the 'C' store it in the
641        # structure.
642
643        TRIE             trie 1     Match many EXACT(F[ALU]?)? at once.
644                                    flags==type
645        TRIEC            trie       Same as TRIE, but with embedded charclass
646                         charclass  data
647
648        AHOCORASICK      trie 1     Aho Corasick stclass. flags==type
649        AHOCORASICKC     trie       Same as AHOCORASICK, but with embedded
650                         charclass  charclass data
651
652        # Do nothing types
653
654        NOTHING          no         Match empty string.
655        # A variant of above which delimits a group, thus stops optimizations
656        TAIL             no         Match empty string. Can jump here from
657                                    outside.
658
659        # Loops
660
661        # STAR,PLUS    '?', and complex '*' and '+', are implemented as
662        #               circular BRANCH structures.  Simple cases
663        #               (one character per match) are implemented with STAR
664        #               and PLUS for speed and to minimize recursive plunges.
665        #
666        STAR             node       Match this (simple) thing 0 or more times.
667        PLUS             node       Match this (simple) thing 1 or more times.
668
669        CURLY            sv 2       Match this simple thing {n,m} times.
670        CURLYN           no 2       Capture next-after-this simple thing
671        CURLYM           no 2       Capture this medium-complex thing {n,m}
672                                    times.
673        CURLYX           sv 2       Match this complex thing {n,m} times.
674
675        # This terminator creates a loop structure for CURLYX
676        WHILEM           no         Do curly processing and see if rest
677                                    matches.
678
679        # Buffer related
680
681        # OPEN,CLOSE,GROUPP     ...are numbered at compile time.
682        OPEN             num 1      Mark this point in input as start of #n.
683        CLOSE            num 1      Close corresponding OPEN of #n.
684        SROPEN           none       Same as OPEN, but for script run
685        SRCLOSE          none       Close preceding SROPEN
686
687        REF              num 1      Match some already matched string
688        REFF             num 1      Match already matched string, using /di
689                                    rules.
690        REFFL            num 1      Match already matched string, using /li
691                                    rules.
692        REFFU            num 1      Match already matched string, usng /ui.
693        REFFA            num 1      Match already matched string, using /aai
694                                    rules.
695
696        # Named references.  Code in regcomp.c assumes that these all are after
697        # the numbered references
698        REFN             no-sv 1    Match some already matched string
699        REFFN            no-sv 1    Match already matched string, using /di
700                                    rules.
701        REFFLN           no-sv 1    Match already matched string, using /li
702                                    rules.
703        REFFUN           num 1      Match already matched string, using /ui
704                                    rules.
705        REFFAN           num 1      Match already matched string, using /aai
706                                    rules.
707
708        # Support for long RE
709        LONGJMP          off 1 1    Jump far away.
710        BRANCHJ          off 1 1    BRANCH with long offset.
711
712        # Special Case Regops
713        IFMATCH          off 1 1    Succeeds if the following matches; non-zero
714                                    flags "f", next_off "o" means lookbehind
715                                    assertion starting "f..(f-o)" characters
716                                    before current
717        UNLESSM          off 1 1    Fails if the following matches; non-zero
718                                    flags "f", next_off "o" means lookbehind
719                                    assertion starting "f..(f-o)" characters
720                                    before current
721        SUSPEND          off 1 1    "Independent" sub-RE.
722        IFTHEN           off 1 1    Switch, should be preceded by switcher.
723        GROUPP           num 1      Whether the group matched.
724
725        # The heavy worker
726
727        EVAL             evl/flags  Execute some Perl code.
728                         2L
729
730        # Modifiers
731
732        MINMOD           no         Next operator is not greedy.
733        LOGICAL          no         Next opcode should set the flag only.
734
735        # This is not used yet
736        RENUM            off 1 1    Group with independently numbered parens.
737
738        # Regex Subroutines
739        GOSUB            num/ofs 2L recurse to paren arg1 at (signed) ofs arg2
740
741        # Special conditionals
742        GROUPPN          no-sv 1    Whether the group matched.
743        INSUBP           num 1      Whether we are in a specific recurse.
744        DEFINEP          none 1     Never execute directly.
745
746        # Backtracking Verbs
747        ENDLIKE          none       Used only for the type field of verbs
748        OPFAIL           no-sv 1    Same as (?!), but with verb arg
749        ACCEPT           no-sv/num  Accepts the current matched string, with
750                         2L         verbar
751
752        # Verbs With Arguments
753        VERB             no-sv 1    Used only for the type field of verbs
754        PRUNE            no-sv 1    Pattern fails at this startpoint if no-
755                                    backtracking through this
756        MARKPOINT        no-sv 1    Push the current location for rollback by
757                                    cut.
758        SKIP             no-sv 1    On failure skip forward (to the mark)
759                                    before retrying
760        COMMIT           no-sv 1    Pattern fails outright if backtracking
761                                    through this
762        CUTGROUP         no-sv 1    On failure go to the next alternation in
763                                    the group
764
765        # Control what to keep in $&.
766        KEEPS            no         $& begins here.
767
768        # SPECIAL  REGOPS
769
770        # This is not really a node, but an optimized away piece of a "long"
771        # node.  To simplify debugging output, we mark it as if it were a node
772        OPTIMIZED        off        Placeholder for dump.
773
774        # Special opcode with the property that no opcode in a compiled program
775        # will ever be of this type. Thus it can be used as a flag value that
776        # no other opcode has been seen. END is used similarly, in that an END
777        # node cant be optimized. So END implies "unoptimizable" and PSEUDO
778        # mean "not seen anything to optimize yet".
779        PSEUDO           off        Pseudo opcode for internal use.
780
781        REGEX_SET        depth p    Regex set, temporary node used in pre-
782                                    optimization compilation
783
784       Following the optimizer information is a dump of the offset/length
785       table, here split across several lines:
786
787         Offsets: [45]
788               1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
789               0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
790               11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
791               0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
792
793       The first line here indicates that the offset/length table contains 45
794       entries.  Each entry is a pair of integers, denoted by
795       "offset[length]".  Entries are numbered starting with 1, so entry #1
796       here is "1[4]" and entry #12 is "5[1]".  "1[4]" indicates that the node
797       labeled "1:" (the "1: ANYOF[bc]") begins at character position 1 in the
798       pre-compiled form of the regex, and has a length of 4 characters.
799       "5[1]" in position 12 indicates that the node labeled "12:" (the "12:
800       EXACT <d>") begins at character position 5 in the pre-compiled form of
801       the regex, and has a length of 1 character.  "12[1]" in position 14
802       indicates that the node labeled "14:" (the "14: CURLYX[0] {1,32767}")
803       begins at character position 12 in the pre-compiled form of the regex,
804       and has a length of 1 character---that is, it corresponds to the "+"
805       symbol in the precompiled regex.
806
807       "0[0]" items indicate that there is no corresponding node.
808
809   Run-time Output
810       First of all, when doing a match, one may get no run-time output even
811       if debugging is enabled.  This means that the regex engine was never
812       entered and that all of the job was therefore done by the optimizer.
813
814       If the regex engine was entered, the output may look like this:
815
816         Matching '[bc]d(ef*g)+h[ij]k$' against 'abcdefg__gh__'
817           Setting an EVAL scope, savestack=3
818            2 <ab> <cdefg__gh_>    |  1: ANYOF
819            3 <abc> <defg__gh_>    | 11: EXACT <d>
820            4 <abcd> <efg__gh_>    | 13: CURLYX {1,32767}
821            4 <abcd> <efg__gh_>    | 26:   WHILEM
822                                       0 out of 1..32767  cc=effff31c
823            4 <abcd> <efg__gh_>    | 15:     OPEN1
824            4 <abcd> <efg__gh_>    | 17:     EXACT <e>
825            5 <abcde> <fg__gh_>    | 19:     STAR
826                                    EXACT <f> can match 1 times out of 32767...
827           Setting an EVAL scope, savestack=3
828            6 <bcdef> <g__gh__>    | 22:       EXACT <g>
829            7 <bcdefg> <__gh__>    | 24:       CLOSE1
830            7 <bcdefg> <__gh__>    | 26:       WHILEM
831                                           1 out of 1..32767  cc=effff31c
832           Setting an EVAL scope, savestack=12
833            7 <bcdefg> <__gh__>    | 15:         OPEN1
834            7 <bcdefg> <__gh__>    | 17:         EXACT <e>
835              restoring \1 to 4(4)..7
836                                           failed, try continuation...
837            7 <bcdefg> <__gh__>    | 27:         NOTHING
838            7 <bcdefg> <__gh__>    | 28:         EXACT <h>
839                                           failed...
840                                       failed...
841
842       The most significant information in the output is about the particular
843       node of the compiled regex that is currently being tested against the
844       target string.  The format of these lines is
845
846       "    "STRING-OFFSET <PRE-STRING> <POST-STRING>   |ID:  TYPE
847
848       The TYPE info is indented with respect to the backtracking level.
849       Other incidental information appears interspersed within.
850

Debugging Perl Memory Usage

852       Perl is a profligate wastrel when it comes to memory use.  There is a
853       saying that to estimate memory usage of Perl, assume a reasonable
854       algorithm for memory allocation, multiply that estimate by 10, and
855       while you still may miss the mark, at least you won't be quite so
856       astonished.  This is not absolutely true, but may provide a good grasp
857       of what happens.
858
859       Assume that an integer cannot take less than 20 bytes of memory, a
860       float cannot take less than 24 bytes, a string cannot take less than 32
861       bytes (all these examples assume 32-bit architectures, the result are
862       quite a bit worse on 64-bit architectures).  If a variable is accessed
863       in two of three different ways (which require an integer, a float, or a
864       string), the memory footprint may increase yet another 20 bytes.  A
865       sloppy malloc(3) implementation can inflate these numbers dramatically.
866
867       On the opposite end of the scale, a declaration like
868
869         sub foo;
870
871       may take up to 500 bytes of memory, depending on which release of Perl
872       you're running.
873
874       Anecdotal estimates of source-to-compiled code bloat suggest an
875       eightfold increase.  This means that the compiled form of reasonable
876       (normally commented, properly indented etc.) code will take about eight
877       times more space in memory than the code took on disk.
878
879       The -DL command-line switch is obsolete since circa Perl 5.6.0 (it was
880       available only if Perl was built with "-DDEBUGGING").  The switch was
881       used to track Perl's memory allocations and possible memory leaks.
882       These days the use of malloc debugging tools like Purify or valgrind is
883       suggested instead.  See also "PERL_MEM_LOG" in perlhacktips.
884
885       One way to find out how much memory is being used by Perl data
886       structures is to install the Devel::Size module from CPAN: it gives you
887       the minimum number of bytes required to store a particular data
888       structure.  Please be mindful of the difference between the size() and
889       total_size().
890
891       If Perl has been compiled using Perl's malloc you can analyze Perl
892       memory usage by setting $ENV{PERL_DEBUG_MSTATS}.
893
894   Using $ENV{PERL_DEBUG_MSTATS}
895       If your perl is using Perl's malloc() and was compiled with the
896       necessary switches (this is the default), then it will print memory
897       usage statistics after compiling your code when
898       "$ENV{PERL_DEBUG_MSTATS} > 1", and before termination of the program
899       when "$ENV{PERL_DEBUG_MSTATS} >= 1".  The report format is similar to
900       the following example:
901
902        $ PERL_DEBUG_MSTATS=2 perl -e "require Carp"
903        Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
904           14216 free:   130   117    28     7     9   0   2     2   1 0 0
905                       437    61    36     0     5
906           60924 used:   125   137   161    55     7   8   6    16   2 0 1
907                        74   109   304    84    20
908        Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048.
909        Memory allocation statistics after execution:   (buckets 4(4)..8188(8192)
910           30888 free:   245    78    85    13     6   2   1     3   2 0 1
911                       315   162    39    42    11
912          175816 used:   265   176  1112   111    26  22  11    27   2 1 1
913                       196   178  1066   798    39
914        Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.
915
916       It is possible to ask for such a statistic at arbitrary points in your
917       execution using the mstat() function out of the standard Devel::Peek
918       module.
919
920       Here is some explanation of that format:
921
922       "buckets SMALLEST(APPROX)..GREATEST(APPROX)"
923           Perl's malloc() uses bucketed allocations.  Every request is
924           rounded up to the closest bucket size available, and a bucket is
925           taken from the pool of buckets of that size.
926
927           The line above describes the limits of buckets currently in use.
928           Each bucket has two sizes: memory footprint and the maximal size of
929           user data that can fit into this bucket.  Suppose in the above
930           example that the smallest bucket were size 4.  The biggest bucket
931           would have usable size 8188, and the memory footprint would be
932           8192.
933
934           In a Perl built for debugging, some buckets may have negative
935           usable size.  This means that these buckets cannot (and will not)
936           be used.  For larger buckets, the memory footprint may be one page
937           greater than a power of 2.  If so, the corresponding power of two
938           is printed in the "APPROX" field above.
939
940       Free/Used
941           The 1 or 2 rows of numbers following that correspond to the number
942           of buckets of each size between "SMALLEST" and "GREATEST".  In the
943           first row, the sizes (memory footprints) of buckets are powers of
944           two--or possibly one page greater.  In the second row, if present,
945           the memory footprints of the buckets are between the memory
946           footprints of two buckets "above".
947
948           For example, suppose under the previous example, the memory
949           footprints were
950
951              free:    8     16    32    64    128  256 512 1024 2048 4096 8192
952                      4     12    24    48    80
953
954           With a non-"DEBUGGING" perl, the buckets starting from 128 have a
955           4-byte overhead, and thus an 8192-long bucket may take up to
956           8188-byte allocations.
957
958       "Total sbrk(): SBRKed/SBRKs:CONTINUOUS"
959           The first two fields give the total amount of memory perl sbrk(2)ed
960           (ess-broken? :-) and number of sbrk(2)s used.  The third number is
961           what perl thinks about continuity of returned chunks.  So long as
962           this number is positive, malloc() will assume that it is probable
963           that sbrk(2) will provide continuous memory.
964
965           Memory allocated by external libraries is not counted.
966
967       "pad: 0"
968           The amount of sbrk(2)ed memory needed to keep buckets aligned.
969
970       "heads: 2192"
971           Although memory overhead of bigger buckets is kept inside the
972           bucket, for smaller buckets, it is kept in separate areas.  This
973           field gives the total size of these areas.
974
975       "chain: 0"
976           malloc() may want to subdivide a bigger bucket into smaller
977           buckets.  If only a part of the deceased bucket is left
978           unsubdivided, the rest is kept as an element of a linked list.
979           This field gives the total size of these chunks.
980
981       "tail: 6144"
982           To minimize the number of sbrk(2)s, malloc() asks for more memory.
983           This field gives the size of the yet unused part, which is
984           sbrk(2)ed, but never touched.
985

SEE ALSO

987       perldebug, perl5db.pl, perlguts, perlrun, re, and Devel::DProf.
988
989
990
991perl v5.34.0                      2021-10-18                    PERLDEBGUTS(1)
Impressum