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

Debugging Perl Memory Usage

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

SEE ALSO

1000       perldebug, perl5db.pl, perlguts, perlrun, re, and Devel::DProf.
1001
1002
1003
1004perl v5.38.2                      2023-11-30                    PERLDEBGUTS(1)
Impressum