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
50           also the case for evaluated strings that contain subroutines, or
51           which are currently being executed.  The $filename for "eval"ed
52           strings looks like "(eval 34)".
53
54       ·   After each "require"d file is compiled, but before it is executed,
55           "DB::postponed(*{"_<$filename"})" is called if the subroutine
56           "DB::postponed" exists.  Here, the $filename is the expanded name
57           of the "require"d file, as found in the values of %INC.
58
59       ·   After each subroutine "subname" is compiled, the existence of
60           $DB::postponed{subname} is checked.  If this key exists,
61           "DB::postponed(subname)" is called if the "DB::postponed"
62           subroutine also exists.
63
64       ·   A hash %DB::sub is maintained, whose keys are subroutine names and
65           whose values have the form "filename:startline-endline".
66           "filename" has the form "(eval 34)" for subroutines defined inside
67           "eval"s.
68
69       ·   When the execution of your program reaches a point that can hold a
70           breakpoint, the "DB::DB()" subroutine is called if any of the
71           variables $DB::trace, $DB::single, or $DB::signal is true.  These
72           variables are not "local"izable.  This feature is disabled when
73           executing inside "DB::DB()", including functions called from it
74           unless "$^D & (1<<30)" is true.
75
76       ·   When execution of the program reaches a subroutine call, a call to
77           &DB::sub(args) is made instead, with $DB::sub set to identify the
78           called subroutine.  (This doesn't happen if the calling subroutine
79           was compiled in the "DB" package.)  $DB::sub normally holds the
80           name of the called subroutine, if it has a name by which it can be
81           looked up.  Failing that, $DB::sub will hold a reference to the
82           called subroutine.  Either way, the &DB::sub subroutine can use
83           $DB::sub as a reference by which to call the called subroutine,
84           which it will normally want to do.
85
86           If the call is to an lvalue subroutine, and &DB::lsub is defined
87           &DB::lsub(args) is called instead, otherwise falling back to
88           &DB::sub(args).
89
90       ·   When execution of the program uses "goto" to enter a non-XS
91           subroutine and the 0x80 bit is set in $^P, a call to &DB::goto is
92           made, with $DB::sub set to identify the subroutine being entered.
93           The call to &DB::goto does not replace the "goto"; the requested
94           subroutine will still be entered once &DB::goto has returned.
95           $DB::sub normally holds the name of the subroutine being entered,
96           if it has one.  Failing that, $DB::sub will hold a reference to the
97           subroutine being entered.  Unlike when &DB::sub is called, it is
98           not guaranteed that $DB::sub can be used as a reference to operate
99           on the subroutine being entered.
100
101       Note that if &DB::sub needs external data for it to work, no subroutine
102       call is possible without it. As an example, the standard debugger's
103       &DB::sub depends on the $DB::deep variable (it defines how many levels
104       of recursion deep into the debugger you can go before a mandatory
105       break).  If $DB::deep is not defined, subroutine calls are not
106       possible, even though &DB::sub exists.
107
108   Writing Your Own Debugger
109       Environment Variables
110
111       The "PERL5DB" environment variable can be used to define a debugger.
112       For example, the minimal "working" debugger (it actually doesn't do
113       anything) consists of one line:
114
115         sub DB::DB {}
116
117       It can easily be defined like this:
118
119         $ PERL5DB="sub DB::DB {}" perl -d your-script
120
121       Another brief debugger, slightly more useful, can be created with only
122       the line:
123
124         sub DB::DB {print ++$i; scalar <STDIN>}
125
126       This debugger prints a number which increments for each statement
127       encountered and waits for you to hit a newline before continuing to the
128       next statement.
129
130       The following debugger is actually useful:
131
132         {
133           package DB;
134           sub DB  {}
135           sub sub {print ++$i, " $sub\n"; &$sub}
136         }
137
138       It prints the sequence number of each subroutine call and the name of
139       the called subroutine.  Note that &DB::sub is being compiled into the
140       package "DB" through the use of the "package" directive.
141
142       When it starts, the debugger reads your rc file (./.perldb or ~/.perldb
143       under Unix), which can set important options.  (A subroutine
144       (&afterinit) can be defined here as well; it is executed after the
145       debugger completes its own initialization.)
146
147       After the rc file is read, the debugger reads the PERLDB_OPTS
148       environment variable and uses it to set debugger options. The contents
149       of this variable are treated as if they were the argument of an "o ..."
150       debugger command (q.v. in "Configurable Options" in perldebug).
151
152       Debugger Internal Variables
153
154       In addition to the file and subroutine-related variables mentioned
155       above, the debugger also maintains various magical internal variables.
156
157       ·   @DB::dbline is an alias for "@{"::_<current_file"}", which holds
158           the lines of the currently-selected file (compiled by Perl), either
159           explicitly chosen with the debugger's "f" command, or implicitly by
160           flow of execution.
161
162           Values in this array are magical in numeric context: they compare
163           equal to zero only if the line is not breakable.
164
165       ·   %DB::dbline is an alias for "%{"::_<current_file"}", which contains
166           breakpoints and actions keyed by line number in the currently-
167           selected file, either explicitly chosen with the debugger's "f"
168           command, or implicitly by flow of execution.
169
170           As previously noted, individual entries (as opposed to the whole
171           hash) are settable.  Perl only cares about Boolean true here,
172           although the values used by perl5db.pl have the form
173           "$break_condition\0$action".
174
175       Debugger Customization Functions
176
177       Some functions are provided to simplify customization.
178
179       ·   See "Configurable Options" in perldebug for a description of
180           options parsed by "DB::parse_options(string)".
181
182       ·   "DB::dump_trace(skip[,count])" skips the specified number of frames
183           and returns a list containing information about the calling frames
184           (all of them, if "count" is missing).  Each entry is reference to a
185           hash with keys "context" (either ".", "$", or "@"), "sub"
186           (subroutine name, or info about "eval"), "args" ("undef" or a
187           reference to an array), "file", and "line".
188
189       ·   "DB::print_trace(FH, skip[, count[, short]])" prints formatted info
190           about caller frames.  The last two functions may be convenient as
191           arguments to "<", "<<" commands.
192
193       Note that any variables and functions that are not documented in this
194       manpages (or in perldebug) are considered for internal use only, and as
195       such are subject to change without notice.
196

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.
371
372       Otherwise, one can "use re 'debug'", which has effects at compile time
373       and run time.  Since Perl 5.9.5, this pragma is lexically scoped.
374
375   Compile-time Output
376       The debugging output at compile time looks like this:
377
378         Compiling REx '[bc]d(ef*g)+h[ij]k$'
379         size 45 Got 364 bytes for offset annotations.
380         first at 1
381         rarest char g at 0
382         rarest char d at 0
383            1: ANYOF[bc](12)
384           12: EXACT <d>(14)
385           14: CURLYX[0] {1,32767}(28)
386           16:   OPEN1(18)
387           18:     EXACT <e>(20)
388           20:     STAR(23)
389           21:       EXACT <f>(0)
390           23:     EXACT <g>(25)
391           25:   CLOSE1(27)
392           27:   WHILEM[1/1](0)
393           28: NOTHING(29)
394           29: EXACT <h>(31)
395           31: ANYOF[ij](42)
396           42: EXACT <k>(44)
397           44: EOL(45)
398           45: END(0)
399         anchored 'de' at 1 floating 'gh' at 3..2147483647 (checking floating)
400               stclass 'ANYOF[bc]' minlen 7
401         Offsets: [45]
402               1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
403               0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
404               11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
405               0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
406         Omitting $` $& $' support.
407
408       The first line shows the pre-compiled form of the regex.  The second
409       shows the size of the compiled form (in arbitrary units, usually 4-byte
410       words) and the total number of bytes allocated for the offset/length
411       table, usually 4+"size"*8.  The next line shows the label id of the
412       first node that does a match.
413
414       The
415
416         anchored 'de' at 1 floating 'gh' at 3..2147483647 (checking floating)
417               stclass 'ANYOF[bc]' minlen 7
418
419       line (split into two lines above) contains optimizer information.  In
420       the example shown, the optimizer found that the match should contain a
421       substring "de" at offset 1, plus substring "gh" at some offset between
422       3 and infinity.  Moreover, when checking for these substrings (to
423       abandon impossible matches quickly), Perl will check for the substring
424       "gh" before checking for the substring "de".  The optimizer may also
425       use the knowledge that the match starts (at the "first" id) with a
426       character class, and no string shorter than 7 characters can possibly
427       match.
428
429       The fields of interest which may appear in this line are
430
431       "anchored" STRING "at" POS
432       "floating" STRING "at" POS1..POS2
433           See above.
434
435       "matching floating/anchored"
436           Which substring to check first.
437
438       "minlen"
439           The minimal length of the match.
440
441       "stclass" TYPE
442           Type of first matching node.
443
444       "noscan"
445           Don't scan for the found substrings.
446
447       "isall"
448           Means that the optimizer information is all that the regular
449           expression contains, and thus one does not need to enter the regex
450           engine at all.
451
452       "GPOS"
453           Set if the pattern contains "\G".
454
455       "plus"
456           Set if the pattern starts with a repeated char (as in "x+y").
457
458       "implicit"
459           Set if the pattern starts with ".*".
460
461       "with eval"
462           Set if the pattern contain eval-groups, such as "(?{ code })" and
463           "(??{ code })".
464
465       "anchored(TYPE)"
466           If the pattern may match only at a handful of places, with "TYPE"
467           being "SBOL", "MBOL", or "GPOS".  See the table below.
468
469       If a substring is known to match at end-of-line only, it may be
470       followed by "$", as in "floating 'k'$".
471
472       The optimizer-specific information is used to avoid entering (a slow)
473       regex engine on strings that will not definitely match.  If the "isall"
474       flag is set, a call to the regex engine may be avoided even when the
475       optimizer found an appropriate place for the match.
476
477       Above the optimizer section is the list of nodes of the compiled form
478       of the regex.  Each line has format
479
480       "   "id: TYPE OPTIONAL-INFO (next-id)
481
482   Types of Nodes
483       Here are the current possible types, with short descriptions:
484
485        # TYPE arg-description [num-args] [longjump-len] DESCRIPTION
486
487        # Exit points
488
489        END              no         End of program.
490        SUCCEED          no         Return from a subroutine, basically.
491
492        # Line Start Anchors:
493        SBOL             no         Match "" at beginning of line: /^/, /\A/
494        MBOL             no         Same, assuming multiline: /^/m
495
496        # Line End Anchors:
497        SEOL             no         Match "" at end of line: /$/
498        MEOL             no         Same, assuming multiline: /$/m
499        EOS              no         Match "" at end of string: /\z/
500
501        # Match Start Anchors:
502        GPOS             no         Matches where last m//g left off.
503
504        # Word Boundary Opcodes:
505        BOUND            no         Like BOUNDA for non-utf8, otherwise match
506                                    "" between any Unicode \w\W or \W\w
507        BOUNDL           no         Like BOUND/BOUNDU, but \w and \W are
508                                    defined by current locale
509        BOUNDU           no         Match "" at any boundary of a given type
510                                    using Unicode rules
511        BOUNDA           no         Match "" at any boundary between \w\W or
512                                    \W\w, where \w is [_a-zA-Z0-9]
513        NBOUND           no         Like NBOUNDA for non-utf8, otherwise match
514                                    "" between any Unicode \w\w or \W\W
515        NBOUNDL          no         Like NBOUND/NBOUNDU, but \w and \W are
516                                    defined by current locale
517        NBOUNDU          no         Match "" at any non-boundary of a given
518                                    type using using Unicode 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 1       Match character in (or not in) this class,
526                                    single char match only
527        ANYOFD           sv 1       Like ANYOF, but /d is in effect
528        ANYOFL           sv 1       Like ANYOF, but /l is in effect
529        ANYOFM           byte 1     Like ANYOF, but matches an invariant byte
530                                    as determined by the mask and arg
531
532        # POSIX Character Classes:
533        POSIXD           none       Some [[:class:]] under /d; the FLAGS field
534                                    gives which one
535        POSIXL           none       Some [[:class:]] under /l; the FLAGS field
536                                    gives which one
537        POSIXU           none       Some [[:class:]] under /u; the FLAGS field
538                                    gives which one
539        POSIXA           none       Some [[:class:]] under /a; the FLAGS field
540                                    gives which one
541        NPOSIXD          none       complement of POSIXD, [[:^class:]]
542        NPOSIXL          none       complement of POSIXL, [[:^class:]]
543        NPOSIXU          none       complement of POSIXU, [[:^class:]]
544        NPOSIXA          none       complement of POSIXA, [[:^class:]]
545
546        ASCII            none       [[:ascii:]]
547        NASCII           none       [[:^ascii:]]
548
549        CLUMP            no         Match any extended grapheme cluster
550                                    sequence
551
552        # Alternation
553
554        # BRANCH        The set of branches constituting a single choice are
555        #               hooked together with their "next" pointers, since
556        #               precedence prevents anything being concatenated to
557        #               any individual branch.  The "next" pointer of the last
558        #               BRANCH in a choice points to the thing following the
559        #               whole choice.  This is also where the final "next"
560        #               pointer of each individual branch points; each branch
561        #               starts with the operand node of a BRANCH node.
562        #
563        BRANCH           node       Match this alternative, or the next...
564
565        # Literals
566
567        EXACT            str        Match this string (preceded by length).
568        EXACTL           str        Like EXACT, but /l is in effect (used so
569                                    locale-related warnings can be checked
570                                    for).
571        EXACTF           str        Match this non-UTF-8 string (not guaranteed
572                                    to be folded) using /id rules (w/len).
573        EXACTFL          str        Match this string (not guaranteed to be
574                                    folded) using /il rules (w/len).
575        EXACTFU          str        Match this string (folded iff in UTF-8,
576                                    length in folding doesn't change if not in
577                                    UTF-8) using /iu rules (w/len).
578        EXACTFAA         str        Match this string (not guaranteed to be
579                                    folded) using /iaa rules (w/len).
580
581        EXACTFU_SS       str        Match this string (folded iff in UTF-8,
582                                    length in folding may change even if not in
583                                    UTF-8) using /iu rules (w/len).
584        EXACTFLU8        str        Rare circumstances: like EXACTFU, but is
585                                    under /l, UTF-8, folded, and everything in
586                                    it is above 255.
587        EXACTFAA_NO_TRIE str        Match this string (which is not trie-able;
588                                    not guaranteed to be folded) using /iaa
589                                    rules (w/len).
590
591        # Do nothing types
592
593        NOTHING          no         Match empty string.
594        # A variant of above which delimits a group, thus stops optimizations
595        TAIL             no         Match empty string. Can jump here from
596                                    outside.
597
598        # Loops
599
600        # STAR,PLUS    '?', and complex '*' and '+', are implemented as
601        #               circular BRANCH structures.  Simple cases
602        #               (one character per match) are implemented with STAR
603        #               and PLUS for speed and to minimize recursive plunges.
604        #
605        STAR             node       Match this (simple) thing 0 or more times.
606        PLUS             node       Match this (simple) thing 1 or more times.
607
608        CURLY            sv 2       Match this simple thing {n,m} times.
609        CURLYN           no 2       Capture next-after-this simple thing
610        CURLYM           no 2       Capture this medium-complex thing {n,m}
611                                    times.
612        CURLYX           sv 2       Match this complex thing {n,m} times.
613
614        # This terminator creates a loop structure for CURLYX
615        WHILEM           no         Do curly processing and see if rest
616                                    matches.
617
618        # Buffer related
619
620        # OPEN,CLOSE,GROUPP     ...are numbered at compile time.
621        OPEN             num 1      Mark this point in input as start of #n.
622        CLOSE            num 1      Close corresponding OPEN of #n.
623        SROPEN           none       Same as OPEN, but for script run
624        SRCLOSE          none       Close preceding SROPEN
625
626        REF              num 1      Match some already matched string
627        REFF             num 1      Match already matched string, folded using
628                                    native charset rules for non-utf8
629        REFFL            num 1      Match already matched string, folded in
630                                    loc.
631        REFFU            num 1      Match already matched string, folded using
632                                    unicode rules for non-utf8
633        REFFA            num 1      Match already matched string, folded using
634                                    unicode rules for non-utf8, no mixing
635                                    ASCII, non-ASCII
636
637        # Named references.  Code in regcomp.c assumes that these all are after
638        # the numbered references
639        NREF             no-sv 1    Match some already matched string
640        NREFF            no-sv 1    Match already matched string, folded using
641                                    native charset rules for non-utf8
642        NREFFL           no-sv 1    Match already matched string, folded in
643                                    loc.
644        NREFFU           num 1      Match already matched string, folded using
645                                    unicode rules for non-utf8
646        NREFFA           num 1      Match already matched string, folded using
647                                    unicode rules for non-utf8, no mixing
648                                    ASCII, non-ASCII
649
650        # Support for long RE
651        LONGJMP          off 1 1    Jump far away.
652        BRANCHJ          off 1 1    BRANCH with long offset.
653
654        # Special Case Regops
655        IFMATCH          off 1 2    Succeeds if the following matches.
656        UNLESSM          off 1 2    Fails if the following matches.
657        SUSPEND          off 1 1    "Independent" sub-RE.
658        IFTHEN           off 1 1    Switch, should be preceded by switcher.
659        GROUPP           num 1      Whether the group matched.
660
661        # The heavy worker
662
663        EVAL             evl/flags  Execute some Perl code.
664                         2L
665
666        # Modifiers
667
668        MINMOD           no         Next operator is not greedy.
669        LOGICAL          no         Next opcode should set the flag only.
670
671        # This is not used yet
672        RENUM            off 1 1    Group with independently numbered parens.
673
674        # Trie Related
675
676        # Behave the same as A|LIST|OF|WORDS would. The '..C' variants
677        # have inline charclass data (ascii only), the 'C' store it in the
678        # structure.
679
680        TRIE             trie 1     Match many EXACT(F[ALU]?)? at once.
681                                    flags==type
682        TRIEC            trie       Same as TRIE, but with embedded charclass
683                         charclass  data
684
685        AHOCORASICK      trie 1     Aho Corasick stclass. flags==type
686        AHOCORASICKC     trie       Same as AHOCORASICK, but with embedded
687                         charclass  charclass data
688
689        # Regex Subroutines
690        GOSUB            num/ofs 2L recurse to paren arg1 at (signed) ofs arg2
691
692        # Special conditionals
693        NGROUPP          no-sv 1    Whether the group matched.
694        INSUBP           num 1      Whether we are in a specific recurse.
695        DEFINEP          none 1     Never execute directly.
696
697        # Backtracking Verbs
698        ENDLIKE          none       Used only for the type field of verbs
699        OPFAIL           no-sv 1    Same as (?!), but with verb arg
700        ACCEPT           no-sv/num  Accepts the current matched string, with
701                         2L         verbar
702
703        # Verbs With Arguments
704        VERB             no-sv 1    Used only for the type field of verbs
705        PRUNE            no-sv 1    Pattern fails at this startpoint if no-
706                                    backtracking through this
707        MARKPOINT        no-sv 1    Push the current location for rollback by
708                                    cut.
709        SKIP             no-sv 1    On failure skip forward (to the mark)
710                                    before retrying
711        COMMIT           no-sv 1    Pattern fails outright if backtracking
712                                    through this
713        CUTGROUP         no-sv 1    On failure go to the next alternation in
714                                    the group
715
716        # Control what to keep in $&.
717        KEEPS            no         $& begins here.
718
719        # New charclass like patterns
720        LNBREAK          none       generic newline pattern
721
722        # SPECIAL  REGOPS
723
724        # This is not really a node, but an optimized away piece of a "long"
725        # node.  To simplify debugging output, we mark it as if it were a node
726        OPTIMIZED        off        Placeholder for dump.
727
728        # Special opcode with the property that no opcode in a compiled program
729        # will ever be of this type. Thus it can be used as a flag value that
730        # no other opcode has been seen. END is used similarly, in that an END
731        # node cant be optimized. So END implies "unoptimizable" and PSEUDO
732        # mean "not seen anything to optimize yet".
733        PSEUDO           off        Pseudo opcode for internal use.
734
735       Following the optimizer information is a dump of the offset/length
736       table, here split across several lines:
737
738         Offsets: [45]
739               1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1]
740               0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0]
741               11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0]
742               0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0]
743
744       The first line here indicates that the offset/length table contains 45
745       entries.  Each entry is a pair of integers, denoted by
746       "offset[length]".  Entries are numbered starting with 1, so entry #1
747       here is "1[4]" and entry #12 is "5[1]".  "1[4]" indicates that the node
748       labeled "1:" (the "1: ANYOF[bc]") begins at character position 1 in the
749       pre-compiled form of the regex, and has a length of 4 characters.
750       "5[1]" in position 12 indicates that the node labeled "12:" (the "12:
751       EXACT <d>") begins at character position 5 in the pre-compiled form of
752       the regex, and has a length of 1 character.  "12[1]" in position 14
753       indicates that the node labeled "14:" (the "14: CURLYX[0] {1,32767}")
754       begins at character position 12 in the pre-compiled form of the regex,
755       and has a length of 1 character---that is, it corresponds to the "+"
756       symbol in the precompiled regex.
757
758       "0[0]" items indicate that there is no corresponding node.
759
760   Run-time Output
761       First of all, when doing a match, one may get no run-time output even
762       if debugging is enabled.  This means that the regex engine was never
763       entered and that all of the job was therefore done by the optimizer.
764
765       If the regex engine was entered, the output may look like this:
766
767         Matching '[bc]d(ef*g)+h[ij]k$' against 'abcdefg__gh__'
768           Setting an EVAL scope, savestack=3
769            2 <ab> <cdefg__gh_>    |  1: ANYOF
770            3 <abc> <defg__gh_>    | 11: EXACT <d>
771            4 <abcd> <efg__gh_>    | 13: CURLYX {1,32767}
772            4 <abcd> <efg__gh_>    | 26:   WHILEM
773                                       0 out of 1..32767  cc=effff31c
774            4 <abcd> <efg__gh_>    | 15:     OPEN1
775            4 <abcd> <efg__gh_>    | 17:     EXACT <e>
776            5 <abcde> <fg__gh_>    | 19:     STAR
777                                    EXACT <f> can match 1 times out of 32767...
778           Setting an EVAL scope, savestack=3
779            6 <bcdef> <g__gh__>    | 22:       EXACT <g>
780            7 <bcdefg> <__gh__>    | 24:       CLOSE1
781            7 <bcdefg> <__gh__>    | 26:       WHILEM
782                                           1 out of 1..32767  cc=effff31c
783           Setting an EVAL scope, savestack=12
784            7 <bcdefg> <__gh__>    | 15:         OPEN1
785            7 <bcdefg> <__gh__>    | 17:         EXACT <e>
786              restoring \1 to 4(4)..7
787                                           failed, try continuation...
788            7 <bcdefg> <__gh__>    | 27:         NOTHING
789            7 <bcdefg> <__gh__>    | 28:         EXACT <h>
790                                           failed...
791                                       failed...
792
793       The most significant information in the output is about the particular
794       node of the compiled regex that is currently being tested against the
795       target string.  The format of these lines is
796
797       "    "STRING-OFFSET <PRE-STRING> <POST-STRING>   |ID:  TYPE
798
799       The TYPE info is indented with respect to the backtracking level.
800       Other incidental information appears interspersed within.
801

Debugging Perl Memory Usage

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

SEE ALSO

938       perldebug, perlguts, perlrun re, and Devel::DProf.
939
940
941
942perl v5.28.2                      2018-11-01                    PERLDEBGUTS(1)
Impressum