home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _5488abaf4fc679c579b865ae09e425ed < prev    next >
Text File  |  2000-03-23  |  44KB  |  879 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE>perldebguts - Guts of Perl debugging</TITLE>
  4. <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
  5. <LINK REV="made" HREF="mailto:">
  6. </HEAD>
  7.  
  8. <BODY>
  9. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  10. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  11. <STRONG><P CLASS=block> perldebguts - Guts of Perl debugging</P></STRONG>
  12. </TD></TR>
  13. </TABLE>
  14.  
  15. <A NAME="__index__"></A>
  16. <!-- INDEX BEGIN -->
  17.  
  18. <UL>
  19.  
  20.     <LI><A HREF="#name">NAME</A></LI>
  21.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  22.     <LI><A HREF="#debugger internals">Debugger Internals</A></LI>
  23.     <UL>
  24.  
  25.         <LI><A HREF="#writing your own debugger">Writing Your Own Debugger</A></LI>
  26.     </UL>
  27.  
  28.     <LI><A HREF="#frame listing output examples">Frame Listing Output Examples</A></LI>
  29.     <LI><A HREF="#debugging regular expressions">Debugging regular expressions</A></LI>
  30.     <UL>
  31.  
  32.         <LI><A HREF="#compiletime output">Compile-time output</A></LI>
  33.         <LI><A HREF="#types of nodes">Types of nodes</A></LI>
  34.         <LI><A HREF="#runtime output">Run-time output</A></LI>
  35.     </UL>
  36.  
  37.     <LI><A HREF="#debugging perl memory usage">Debugging Perl memory usage</A></LI>
  38.     <UL>
  39.  
  40.         <LI><A HREF="#using $env{perl_debug_mstats}">Using <CODE>$ENV{PERL_DEBUG_MSTATS}</CODE></A></LI>
  41.         <LI><A HREF="#example of using dl switch">Example of using <STRONG>-DL</STRONG> switch</A></LI>
  42.         <LI><A HREF="#dl details"><STRONG>-DL</STRONG> details</A></LI>
  43.         <LI><A HREF="#limitations of dl statistics">Limitations of <STRONG>-DL</STRONG> statistics</A></LI>
  44.     </UL>
  45.  
  46.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  47. </UL>
  48. <!-- INDEX END -->
  49.  
  50. <HR>
  51. <P>
  52. <H1><A NAME="name">NAME</A></H1>
  53. <P>perldebguts - Guts of Perl debugging</P>
  54. <P>
  55. <HR>
  56. <H1><A NAME="description">DESCRIPTION</A></H1>
  57. <P>This is not the <CODE>perldebug(1)</CODE> manpage, which tells you how to use
  58. the debugger.  This manpage describes low-level details ranging
  59. between difficult and impossible for anyone who isn't incredibly
  60. intimate with Perl's guts to understand.  Caveat lector.</P>
  61. <P>
  62. <HR>
  63. <H1><A NAME="debugger internals">Debugger Internals</A></H1>
  64. <P>Perl has special debugging hooks at compile-time and run-time used
  65. to create debugging environments.  These hooks are not to be confused
  66. with the <EM>perl -Dxxx</EM> command described in <A HREF="../../lib/Pod/perlrun.html">the perlrun manpage</A>, which are
  67. usable only if a special Perl built per the instructions the
  68. <EM>INSTALL</EM> podpage in the Perl source tree.</P>
  69. <P>For example, whenever you call Perl's built-in <A HREF="../../lib/Pod/perlfunc.html#item_caller"><CODE>caller</CODE></A> function
  70. from the package DB, the arguments that the corresponding stack
  71. frame was called with are copied to the the @DB::args array.  The
  72. general mechanisms is enabled by calling Perl with the <STRONG>-d</STRONG> switch, the
  73. following additional features are enabled (cf. <A HREF="../../lib/Pod/perlvar.html#$^p">$^P in the perlvar manpage</A>):</P>
  74. <UL>
  75. <LI>
  76. Perl inserts the contents of <CODE>$ENV{PERL5DB}</CODE> (or <CODE>BEGIN {require
  77. 'perl5db.pl'}</CODE> if not present) before the first line of your program.
  78. <P></P>
  79. <LI>
  80. The array <CODE>@{"_<$filename"}</CODE> holds the lines of $filename for all
  81. files compiled by Perl.  The same for <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>ed strings that contain
  82. subroutines, or which are currently being executed.  The $filename
  83. for <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>ed strings looks like <CODE>(eval 34)</CODE>.   Code assertions
  84. in regexes look like <CODE>(re_eval 19)</CODE>.
  85. <P></P>
  86. <LI>
  87. The hash <CODE>%{"_<$filename"}</CODE> contains breakpoints and actions keyed
  88. by line number.  Individual entries (as opposed to the whole hash)
  89. are settable.  Perl only cares about Boolean true here, although
  90. the values used by <EM>perl5db.pl</EM> have the form
  91. <CODE>"$break_condition\0$action"</CODE>.  Values in this hash are magical
  92. in numeric context: they are zeros if the line is not breakable.
  93. <P>The same holds for evaluated strings that contain subroutines, or
  94. which are currently being executed.  The $filename for <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>ed strings
  95. looks like <CODE>(eval 34)</CODE> or  <CODE>(re_eval 19)</CODE>.</P>
  96. <P></P>
  97. <LI>
  98. The scalar <CODE>${"_<$filename"}</CODE> contains <CODE>"_<$filename"</CODE>.  This is
  99. also the case for evaluated strings that contain subroutines, or
  100. which are currently being executed.  The $filename for <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>ed
  101. strings looks like <CODE>(eval 34)</CODE> or <CODE>(re_eval 19)</CODE>.
  102. <P></P>
  103. <LI>
  104. After each <A HREF="../../lib/Pod/perlfunc.html#item_require"><CODE>require</CODE></A>d file is compiled, but before it is executed,
  105. <CODE>DB::postponed(*{"_<$filename"})</CODE> is called if the subroutine
  106. <CODE>DB::postponed</CODE> exists.  Here, the $filename is the expanded name of
  107. the <A HREF="../../lib/Pod/perlfunc.html#item_require"><CODE>require</CODE></A>d file, as found in the values of %INC.
  108. <P></P>
  109. <LI>
  110. After each subroutine <CODE>subname</CODE> is compiled, the existence of
  111. <CODE>$DB::postponed{subname}</CODE> is checked.  If this key exists,
  112. <CODE>DB::postponed(subname)</CODE> is called if the <CODE>DB::postponed</CODE> subroutine
  113. also exists.
  114. <P></P>
  115. <LI>
  116. A hash <CODE>%DB::sub</CODE> is maintained, whose keys are subroutine names
  117. and whose values have the form <CODE>filename:startline-endline</CODE>.
  118. <CODE>filename</CODE> has the form <CODE>(eval 34)</CODE> for subroutines defined inside
  119. <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>s, or <CODE>(re_eval 19)</CODE> for those within regex code assertions.
  120. <P></P>
  121. <LI>
  122. When the execution of your program reaches a point that can hold a
  123. breakpoint, the <CODE>DB::DB()</CODE> subroutine is called any of the variables
  124. $DB::trace, $DB::single, or $DB::signal is true.  These variables
  125. are not <A HREF="../../lib/Pod/perlfunc.html#item_local"><CODE>local</CODE></A>izable.  This feature is disabled when executing
  126. inside <CODE>DB::DB()</CODE>, including functions called from it 
  127. unless <CODE>$^D & (1<<30)</CODE> is true.
  128. <P></P>
  129. <LI>
  130. When execution of the program reaches a subroutine call, a call to
  131. <CODE>&DB::sub</CODE>(<EM>args</EM>) is made instead, with <CODE>$DB::sub</CODE> holding the
  132. name of the called subroutine.  This doesn't happen if the subroutine
  133. was compiled in the <CODE>DB</CODE> package.)
  134. <P></P></UL>
  135. <P>Note that if <CODE>&DB::sub</CODE> needs external data for it to work, no
  136. subroutine call is possible until this is done.  For the standard
  137. debugger, the  <CODE>$DB::deep</CODE> variable (how many levels of recursion
  138. deep into the debugger you can go before a mandatory break) gives
  139. an example of such a dependency.</P>
  140. <P>
  141. <H2><A NAME="writing your own debugger">Writing Your Own Debugger</A></H2>
  142. <P>The minimal working debugger consists of one line</P>
  143. <PRE>
  144.   sub DB::DB {}</PRE>
  145. <P>which is quite handy as contents of <A HREF="../../lib/Pod/perlrun.html#item_PERL5DB"><CODE>PERL5DB</CODE></A> environment
  146. variable:</P>
  147. <PRE>
  148.   $ PERL5DB="sub DB::DB {}" perl -d your-script</PRE>
  149. <P>Another brief debugger, slightly more useful, could be created
  150. with only the line:</P>
  151. <PRE>
  152.   sub DB::DB {print ++$i; scalar <STDIN>}</PRE>
  153. <P>This debugger would print the sequential number of encountered
  154. statement, and would wait for you to hit a newline before continuing.</P>
  155. <P>The following debugger is quite functional:</P>
  156. <PRE>
  157.   {
  158.     package DB;
  159.     sub DB  {}
  160.     sub sub {print ++$i, " $sub\n"; &$sub}
  161.   }</PRE>
  162. <P>It prints the sequential number of subroutine call and the name of the
  163. called subroutine.  Note that <CODE>&DB::sub</CODE> should be compiled into the
  164. package <CODE>DB</CODE>.</P>
  165. <P>At the start, the debugger reads your rc file (<EM>./.perldb</EM> or
  166. <EM>~/.perldb</EM> under Unix), which can set important options.  This file may
  167. define a subroutine <CODE>&afterinit</CODE> to be executed after the debugger is
  168. initialized.</P>
  169. <P>After the rc file is read, the debugger reads the PERLDB_OPTS
  170. environment variable and parses this as the remainder of a <CODE>O ...</CODE>
  171. line as one might enter at the debugger prompt.</P>
  172. <P>The debugger also maintains magical internal variables, such as
  173. <CODE>@DB::dbline</CODE>, <CODE>%DB::dbline</CODE>, which are aliases for
  174. <CODE>@{"::_<current_file"}</CODE> <CODE>%{"::_<current_file"}</CODE>.  Here <CODE>current_file</CODE>
  175. is the currently selected file, either explicitly chosen with the
  176. debugger's <CODE>f</CODE> command, or implicitly by flow of execution.</P>
  177. <P>Some functions are provided to simplify customization.  See
  178. <A HREF="../../lib/Pod/perldebug.html#options">Options in the perldebug manpage</A> for description of options parsed by
  179. <CODE>DB::parse_options(string)</CODE>.  The function <CODE>DB::dump_trace(skip[,
  180. count])</CODE> skips the specified number of frames and returns a list
  181. containing information about the calling frames (all of them, if
  182. <CODE>count</CODE> is missing).  Each entry is reference to a a hash with
  183. keys <CODE>context</CODE> (either <CODE>.</CODE>, <CODE>$</CODE>, or <CODE>@</CODE>), <A HREF="../../lib/Pod/perlfunc.html#item_sub"><CODE>sub</CODE></A> (subroutine
  184. name, or info about <A HREF="../../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>), <CODE>args</CODE> (<A HREF="../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> or a reference to
  185. an array), <CODE>file</CODE>, and <CODE>line</CODE>.</P>
  186. <P>The function <CODE>DB::print_trace(FH, skip[, count[, short]])</CODE> prints
  187. formatted info about caller frames.  The last two functions may be
  188. convenient as arguments to <CODE><</CODE>, <CODE><<</CODE> commands.</P>
  189. <P>Note that any variables and functions that are not documented in
  190. this manpages (or in <A HREF="../../lib/Pod/perldebug.html">the perldebug manpage</A>) are considered for internal   
  191. use only, and as such are subject to change without notice.</P>
  192. <P>
  193. <HR>
  194. <H1><A NAME="frame listing output examples">Frame Listing Output Examples</A></H1>
  195. <P>The <CODE>frame</CODE> option can be used to control the output of frame 
  196. information.  For example, contrast this expression trace:</P>
  197. <PRE>
  198.  $ perl -de 42
  199.  Stack dump during die enabled outside of evals.</PRE>
  200. <PRE>
  201.  Loading DB routines from perl5db.pl patch level 0.94
  202.  Emacs support available.</PRE>
  203. <PRE>
  204.  Enter h or `h h' for help.</PRE>
  205. <PRE>
  206.  main::(-e:1):   0
  207.    DB<1> sub foo { 14 }</PRE>
  208. <PRE>
  209.    DB<2> sub bar { 3 }</PRE>
  210. <PRE>
  211.    DB<3> t print foo() * bar()
  212.  main::((eval 172):3):   print foo() + bar();
  213.  main::foo((eval 168):2):
  214.  main::bar((eval 170):2):
  215.  42</PRE>
  216. <P>with this one, once the <CODE>O</CODE>ption <CODE>frame=2</CODE> has been set:</P>
  217. <PRE>
  218.    DB<4> O f=2
  219.                 frame = '2'
  220.    DB<5> t print foo() * bar()
  221.  3:      foo() * bar()
  222.  entering main::foo
  223.   2:     sub foo { 14 };
  224.  exited main::foo
  225.  entering main::bar
  226.   2:     sub bar { 3 };
  227.  exited main::bar
  228.  42</PRE>
  229. <P>By way of demonstration, we present below a laborious listing
  230. resulting from setting your <CODE>PERLDB_OPTS</CODE> environment variable to
  231. the value <CODE>f=n N</CODE>, and running <EM>perl -d -V</EM> from the command line.
  232. Examples use various values of <CODE>n</CODE> are shown to give you a feel
  233. for the difference between settings.  Long those it may be, this
  234. is not a complete listing, but only excerpts.</P>
  235. <OL>
  236. <LI>
  237. <PRE>
  238.   entering main::BEGIN
  239.    entering Config::BEGIN
  240.     Package lib/Exporter.pm.
  241.     Package lib/Carp.pm.
  242.    Package lib/Config.pm.
  243.    entering Config::TIEHASH
  244.    entering Exporter::import
  245.     entering Exporter::export
  246.   entering Config::myconfig
  247.    entering Config::FETCH
  248.    entering Config::FETCH
  249.    entering Config::FETCH
  250.    entering Config::FETCH</PRE>
  251. <LI>
  252. <PRE>
  253.   entering main::BEGIN
  254.    entering Config::BEGIN
  255.     Package lib/Exporter.pm.
  256.     Package lib/Carp.pm.
  257.    exited Config::BEGIN
  258.    Package lib/Config.pm.
  259.    entering Config::TIEHASH
  260.    exited Config::TIEHASH
  261.    entering Exporter::import
  262.     entering Exporter::export
  263.     exited Exporter::export
  264.    exited Exporter::import
  265.   exited main::BEGIN
  266.   entering Config::myconfig
  267.    entering Config::FETCH
  268.    exited Config::FETCH
  269.    entering Config::FETCH
  270.    exited Config::FETCH
  271.    entering Config::FETCH</PRE>
  272. <LI>
  273. <PRE>
  274.   in  $=main::BEGIN() from /dev/null:0
  275.    in  $=Config::BEGIN() from lib/Config.pm:2
  276.     Package lib/Exporter.pm.
  277.     Package lib/Carp.pm.
  278.    Package lib/Config.pm.
  279.    in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  280.    in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  281.     in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from li
  282.   in  @=Config::myconfig() from /dev/null:0
  283.    in  $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  284.    in  $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  285.    in  $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
  286.    in  $=Config::FETCH(ref(Config), 'PERL_SUBVERSION') from lib/Config.pm:574
  287.    in  $=Config::FETCH(ref(Config), 'osname') from lib/Config.pm:574
  288.    in  $=Config::FETCH(ref(Config), 'osvers') from lib/Config.pm:574</PRE>
  289. <LI>
  290. <PRE>
  291.   in  $=main::BEGIN() from /dev/null:0
  292.    in  $=Config::BEGIN() from lib/Config.pm:2
  293.     Package lib/Exporter.pm.
  294.     Package lib/Carp.pm.
  295.    out $=Config::BEGIN() from lib/Config.pm:0
  296.    Package lib/Config.pm.
  297.    in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  298.    out $=Config::TIEHASH('Config') from lib/Config.pm:644
  299.    in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  300.     in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
  301.     out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/
  302.    out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  303.   out $=main::BEGIN() from /dev/null:0
  304.   in  @=Config::myconfig() from /dev/null:0
  305.    in  $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  306.    out $=Config::FETCH(ref(Config), 'package') from lib/Config.pm:574
  307.    in  $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  308.    out $=Config::FETCH(ref(Config), 'baserev') from lib/Config.pm:574
  309.    in  $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
  310.    out $=Config::FETCH(ref(Config), 'PERL_VERSION') from lib/Config.pm:574
  311.    in  $=Config::FETCH(ref(Config), 'PERL_SUBVERSION') from lib/Config.pm:574</PRE>
  312. <LI>
  313. <PRE>
  314.   in  $=main::BEGIN() from /dev/null:0
  315.    in  $=Config::BEGIN() from lib/Config.pm:2
  316.     Package lib/Exporter.pm.
  317.     Package lib/Carp.pm.
  318.    out $=Config::BEGIN() from lib/Config.pm:0
  319.    Package lib/Config.pm.
  320.    in  $=Config::TIEHASH('Config') from lib/Config.pm:644
  321.    out $=Config::TIEHASH('Config') from lib/Config.pm:644
  322.    in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  323.     in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
  324.     out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/E
  325.    out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  326.   out $=main::BEGIN() from /dev/null:0
  327.   in  @=Config::myconfig() from /dev/null:0
  328.    in  $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
  329.    out $=Config::FETCH('Config=HASH(0x1aa444)', 'package') from lib/Config.pm:574
  330.    in  $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574
  331.    out $=Config::FETCH('Config=HASH(0x1aa444)', 'baserev') from lib/Config.pm:574</PRE>
  332. <LI>
  333. <PRE>
  334.   in  $=CODE(0x15eca4)() from /dev/null:0
  335.    in  $=CODE(0x182528)() from lib/Config.pm:2
  336.     Package lib/Exporter.pm.
  337.    out $=CODE(0x182528)() from lib/Config.pm:0
  338.    scalar context return from CODE(0x182528): undef
  339.    Package lib/Config.pm.
  340.    in  $=Config::TIEHASH('Config') from lib/Config.pm:628
  341.    out $=Config::TIEHASH('Config') from lib/Config.pm:628
  342.    scalar context return from Config::TIEHASH:   empty hash
  343.    in  $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  344.     in  $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
  345.     out $=Exporter::export('Config', 'main', 'myconfig', 'config_vars') from lib/Exporter.pm:171
  346.     scalar context return from Exporter::export: ''
  347.    out $=Exporter::import('Config', 'myconfig', 'config_vars') from /dev/null:0
  348.    scalar context return from Exporter::import: ''</PRE>
  349. </OL>
  350. <P>In all cases shown above, the line indentation shows the call tree.
  351. If bit 2 of <CODE>frame</CODE> is set, a line is printed on exit from a
  352. subroutine as well.  If bit 4 is set, the arguments are printed
  353. along with the caller info.  If bit 8 is set, the arguments are
  354. printed even if they are tied or references.  If bit 16 is set, the
  355. return value is printed, too.</P>
  356. <P>When a package is compiled, a line like this</P>
  357. <PRE>
  358.     Package lib/Carp.pm.</PRE>
  359. <P>is printed with proper indentation.</P>
  360. <P>
  361. <HR>
  362. <H1><A NAME="debugging regular expressions">Debugging regular expressions</A></H1>
  363. <P>There are two ways to enable debugging output for regular expressions.</P>
  364. <P>If your perl is compiled with <CODE>-DDEBUGGING</CODE>, you may use the
  365. <STRONG>-Dr</STRONG> flag on the command line.</P>
  366. <P>Otherwise, one can <CODE>use re 'debug'</CODE>, which has effects at
  367. compile time and run time.  It is not lexically scoped.</P>
  368. <P>
  369. <H2><A NAME="compiletime output">Compile-time output</A></H2>
  370. <P>The debugging output at compile time looks like this:</P>
  371. <PRE>
  372.   compiling RE `[bc]d(ef*g)+h[ij]k$'
  373.   size 43 first at 1
  374.      1: ANYOF(11)
  375.     11: EXACT <d>(13)
  376.     13: CURLYX {1,32767}(27)
  377.     15:   OPEN1(17)
  378.     17:     EXACT <e>(19)
  379.     19:     STAR(22)
  380.     20:       EXACT <f>(0)
  381.     22:     EXACT <g>(24)
  382.     24:   CLOSE1(26)
  383.     26:   WHILEM(0)
  384.     27: NOTHING(28)
  385.     28: EXACT <h>(30)
  386.     30: ANYOF(40)
  387.     40: EXACT <k>(42)
  388.     42: EOL(43)
  389.     43: END(0)
  390.   anchored `de' at 1 floating `gh' at 3..2147483647 (checking floating)
  391.                                     stclass `ANYOF' minlen 7</PRE>
  392. <P>The first line shows the pre-compiled form of the regex.  The second
  393. shows the size of the compiled form (in arbitrary units, usually
  394. 4-byte words) and the label <EM>id</EM> of the first node that does a
  395. match.</P>
  396. <P>The last line (split into two lines above) contains optimizer
  397. information.  In the example shown, the optimizer found that the match 
  398. should contain a substring <CODE>de</CODE> at offset 1, plus substring <CODE>gh</CODE>
  399. at some offset between 3 and infinity.  Moreover, when checking for
  400. these substrings (to abandon impossible matches quickly), Perl will check
  401. for the substring <CODE>gh</CODE> before checking for the substring <CODE>de</CODE>.  The
  402. optimizer may also use the knowledge that the match starts (at the
  403. <CODE>first</CODE> <EM>id</EM>) with a character class, and the match cannot be
  404. shorter than 7 chars.</P>
  405. <P>The fields of interest which may appear in the last line are</P>
  406. <DL>
  407. <DT><STRONG><A NAME="item_anchored_STRING_at_POS"><A HREF="#item_anchored"><CODE>anchored</CODE></A> <EM>STRING</EM> <CODE>at</CODE> <EM>POS</EM></A></STRONG><BR>
  408. <DD>
  409. <DT><STRONG><A NAME="item_floating_STRING_at_POS1%2E%2EPOS2"><CODE>floating</CODE> <EM>STRING</EM> <CODE>at</CODE> <EM>POS1..POS2</EM></A></STRONG><BR>
  410. <DD>
  411. See above.
  412. <P></P>
  413. <DT><STRONG><A NAME="item_matching_floating%2Fanchored"><CODE>matching floating/anchored</CODE></A></STRONG><BR>
  414. <DD>
  415. Which substring to check first.
  416. <P></P>
  417. <DT><STRONG><A NAME="item_minlen"><CODE>minlen</CODE></A></STRONG><BR>
  418. <DD>
  419. The minimal length of the match.
  420. <P></P>
  421. <DT><STRONG><A NAME="item_stclass"><CODE>stclass</CODE> <EM>TYPE</EM></A></STRONG><BR>
  422. <DD>
  423. Type of first matching node.
  424. <P></P>
  425. <DT><STRONG><A NAME="item_noscan"><CODE>noscan</CODE></A></STRONG><BR>
  426. <DD>
  427. Don't scan for the found substrings.
  428. <P></P>
  429. <DT><STRONG><A NAME="item_isall"><CODE>isall</CODE></A></STRONG><BR>
  430. <DD>
  431. Means that the optimizer info is all that the regular
  432. expression contains, and thus one does not need to enter the regex engine at
  433. all.
  434. <P></P>
  435. <DT><STRONG><A NAME="item_GPOS"><CODE>GPOS</CODE></A></STRONG><BR>
  436. <DD>
  437. Set if the pattern contains <CODE>\G</CODE>.
  438. <P></P>
  439. <DT><STRONG><A NAME="item_plus"><CODE>plus</CODE></A></STRONG><BR>
  440. <DD>
  441. Set if the pattern starts with a repeated char (as in <CODE>x+y</CODE>).
  442. <P></P>
  443. <DT><STRONG><A NAME="item_implicit"><CODE>implicit</CODE></A></STRONG><BR>
  444. <DD>
  445. Set if the pattern starts with <CODE>.*</CODE>.
  446. <P></P>
  447. <DT><STRONG><A NAME="item_with_eval"><CODE>with eval</CODE></A></STRONG><BR>
  448. <DD>
  449. Set if the pattern contain eval-groups, such as <CODE>(?{ code })</CODE> and
  450. <CODE>(??{ code })</CODE>.
  451. <P></P>
  452. <DT><STRONG><A NAME="item_anchored"><CODE>anchored(TYPE)</CODE></A></STRONG><BR>
  453. <DD>
  454. If the pattern may match only at a handful of places, (with <CODE>TYPE</CODE>
  455. being <CODE>BOL</CODE>, <CODE>MBOL</CODE>, or <A HREF="#item_GPOS"><CODE>GPOS</CODE></A>.  See the table below.
  456. <P></P></DL>
  457. <P>If a substring is known to match at end-of-line only, it may be
  458. followed by <CODE>$</CODE>, as in <CODE>floating `k'$</CODE>.</P>
  459. <P>The optimizer-specific info is used to avoid entering (a slow) regex
  460. engine on strings that will not definitely match.  If <A HREF="#item_isall"><CODE>isall</CODE></A> flag
  461. is set, a call to the regex engine may be avoided even when the optimizer
  462. found an appropriate place for the match.</P>
  463. <P>The rest of the output contains the list of <EM>nodes</EM> of the compiled
  464. form of the regex.  Each line has format</P>
  465. <P><CODE>   </CODE><EM>id</EM>: <EM>TYPE</EM> <EM>OPTIONAL-INFO</EM> (<EM>next-id</EM>)</P>
  466. <P>
  467. <H2><A NAME="types of nodes">Types of nodes</A></H2>
  468. <P>Here are the possible types, with short descriptions:</P>
  469. <PRE>
  470.     # TYPE arg-description [num-args] [longjump-len] DESCRIPTION</PRE>
  471. <PRE>
  472.     # Exit points
  473.     END         no      End of program.
  474.     SUCCEED     no      Return from a subroutine, basically.</PRE>
  475. <PRE>
  476.     # Anchors:
  477.     BOL         no      Match "" at beginning of line.
  478.     MBOL        no      Same, assuming multiline.
  479.     SBOL        no      Same, assuming singleline.
  480.     EOS         no      Match "" at end of string.
  481.     EOL         no      Match "" at end of line.
  482.     MEOL        no      Same, assuming multiline.
  483.     SEOL        no      Same, assuming singleline.
  484.     BOUND       no      Match "" at any word boundary
  485.     BOUNDL      no      Match "" at any word boundary
  486.     NBOUND      no      Match "" at any word non-boundary
  487.     NBOUNDL     no      Match "" at any word non-boundary
  488.     GPOS        no      Matches where last m//g left off.</PRE>
  489. <PRE>
  490.     # [Special] alternatives
  491.     ANY         no      Match any one character (except newline).
  492.     SANY        no      Match any one character.
  493.     ANYOF       sv      Match character in (or not in) this class.
  494.     ALNUM       no      Match any alphanumeric character
  495.     ALNUML      no      Match any alphanumeric char in locale
  496.     NALNUM      no      Match any non-alphanumeric character
  497.     NALNUML     no      Match any non-alphanumeric char in locale
  498.     SPACE       no      Match any whitespace character
  499.     SPACEL      no      Match any whitespace char in locale
  500.     NSPACE      no      Match any non-whitespace character
  501.     NSPACEL     no      Match any non-whitespace char in locale
  502.     DIGIT       no      Match any numeric character
  503.     NDIGIT      no      Match any non-numeric character</PRE>
  504. <PRE>
  505.     # BRANCH    The set of branches constituting a single choice are hooked
  506.     #           together with their "next" pointers, since precedence prevents
  507.     #           anything being concatenated to any individual branch.  The
  508.     #           "next" pointer of the last BRANCH in a choice points to the
  509.     #           thing following the whole choice.  This is also where the
  510.     #           final "next" pointer of each individual branch points; each
  511.     #           branch starts with the operand node of a BRANCH node.
  512.     #
  513.     BRANCH      node    Match this alternative, or the next...</PRE>
  514. <PRE>
  515.     # BACK      Normal "next" pointers all implicitly point forward; BACK
  516.     #           exists to make loop structures possible.
  517.     # not used
  518.     BACK        no      Match "", "next" ptr points backward.</PRE>
  519. <PRE>
  520.     # Literals
  521.     EXACT       sv      Match this string (preceded by length).
  522.     EXACTF      sv      Match this string, folded (prec. by length).
  523.     EXACTFL     sv      Match this string, folded in locale (w/len).</PRE>
  524. <PRE>
  525.     # Do nothing
  526.     NOTHING     no      Match empty string.
  527.     # A variant of above which delimits a group, thus stops optimizations
  528.     TAIL        no      Match empty string. Can jump here from outside.</PRE>
  529. <PRE>
  530.     # STAR,PLUS '?', and complex '*' and '+', are implemented as circular
  531.     #           BRANCH structures using BACK.  Simple cases (one character
  532.     #           per match) are implemented with STAR and PLUS for speed
  533.     #           and to minimize recursive plunges.
  534.     #
  535.     STAR        node    Match this (simple) thing 0 or more times.
  536.     PLUS        node    Match this (simple) thing 1 or more times.</PRE>
  537. <PRE>
  538.     CURLY       sv 2    Match this simple thing {n,m} times.
  539.     CURLYN      no 2    Match next-after-this simple thing 
  540.     #                   {n,m} times, set parens.
  541.     CURLYM      no 2    Match this medium-complex thing {n,m} times.
  542.     CURLYX      sv 2    Match this complex thing {n,m} times.</PRE>
  543. <PRE>
  544.     # This terminator creates a loop structure for CURLYX
  545.     WHILEM      no      Do curly processing and see if rest matches.</PRE>
  546. <PRE>
  547.     # OPEN,CLOSE,GROUPP ...are numbered at compile time.
  548.     OPEN        num 1   Mark this point in input as start of #n.
  549.     CLOSE       num 1   Analogous to OPEN.</PRE>
  550. <PRE>
  551.     REF         num 1   Match some already matched string
  552.     REFF        num 1   Match already matched string, folded
  553.     REFFL       num 1   Match already matched string, folded in loc.</PRE>
  554. <PRE>
  555.     # grouping assertions
  556.     IFMATCH     off 1 2 Succeeds if the following matches.
  557.     UNLESSM     off 1 2 Fails if the following matches.
  558.     SUSPEND     off 1 1 "Independent" sub-regex.
  559.     IFTHEN      off 1 1 Switch, should be preceded by switcher .
  560.     GROUPP      num 1   Whether the group matched.</PRE>
  561. <PRE>
  562.     # Support for long regex
  563.     LONGJMP     off 1 1 Jump far away.
  564.     BRANCHJ     off 1 1 BRANCH with long offset.</PRE>
  565. <PRE>
  566.     # The heavy worker
  567.     EVAL        evl 1   Execute some Perl code.</PRE>
  568. <PRE>
  569.     # Modifiers
  570.     MINMOD      no      Next operator is not greedy.
  571.     LOGICAL     no      Next opcode should set the flag only.</PRE>
  572. <PRE>
  573.     # This is not used yet
  574.     RENUM       off 1 1 Group with independently numbered parens.</PRE>
  575. <PRE>
  576.     # This is not really a node, but an optimized away piece of a "long" node.
  577.     # To simplify debugging output, we mark it as if it were a node
  578.     OPTIMIZED   off     Placeholder for dump.</PRE>
  579. <P>
  580. <H2><A NAME="runtime output">Run-time output</A></H2>
  581. <P>First of all, when doing a match, one may get no run-time output even
  582. if debugging is enabled.  This means that the regex engine was never
  583. entered and that all of the job was therefore done by the optimizer.</P>
  584. <P>If the regex engine was entered, the output may look like this:</P>
  585. <PRE>
  586.   Matching `[bc]d(ef*g)+h[ij]k$' against `abcdefg__gh__'
  587.     Setting an EVAL scope, savestack=3
  588.      2 <ab> <cdefg__gh_>    |  1: ANYOF
  589.      3 <abc> <defg__gh_>    | 11: EXACT <d>
  590.      4 <abcd> <efg__gh_>    | 13: CURLYX {1,32767}
  591.      4 <abcd> <efg__gh_>    | 26:   WHILEM
  592.                                 0 out of 1..32767  cc=effff31c
  593.      4 <abcd> <efg__gh_>    | 15:     OPEN1
  594.      4 <abcd> <efg__gh_>    | 17:     EXACT <e>
  595.      5 <abcde> <fg__gh_>    | 19:     STAR
  596.                              EXACT <f> can match 1 times out of 32767...
  597.     Setting an EVAL scope, savestack=3
  598.      6 <bcdef> <g__gh__>    | 22:       EXACT <g>
  599.      7 <bcdefg> <__gh__>    | 24:       CLOSE1
  600.      7 <bcdefg> <__gh__>    | 26:       WHILEM
  601.                                     1 out of 1..32767  cc=effff31c
  602.     Setting an EVAL scope, savestack=12
  603.      7 <bcdefg> <__gh__>    | 15:         OPEN1
  604.      7 <bcdefg> <__gh__>    | 17:         EXACT <e>
  605.        restoring \1 to 4(4)..7
  606.                                     failed, try continuation...
  607.      7 <bcdefg> <__gh__>    | 27:         NOTHING
  608.      7 <bcdefg> <__gh__>    | 28:         EXACT <h>
  609.                                     failed...
  610.                                 failed...</PRE>
  611. <P>The most significant information in the output is about the particular <EM>node</EM>
  612. of the compiled regex that is currently being tested against the target string.
  613. The format of these lines is</P>
  614. <P><CODE>    </CODE><EM>STRING-OFFSET</EM> <<EM>PRE-STRING</EM>> <<EM>POST-STRING</EM>>   |<EM>ID</EM>:  <EM>TYPE</EM></P>
  615. <P>The <EM>TYPE</EM> info is indented with respect to the backtracking level.
  616. Other incidental information appears interspersed within.</P>
  617. <P>
  618. <HR>
  619. <H1><A NAME="debugging perl memory usage">Debugging Perl memory usage</A></H1>
  620. <P>Perl is a profligate wastrel when it comes to memory use.  There
  621. is a saying that to estimate memory usage of Perl, assume a reasonable
  622. algorithm for memory allocation, multiply that estimate by 10, and
  623. while you still may miss the mark, at least you won't be quite so
  624. astonished.  This is not absolutely true, but may prvide a good
  625. grasp of what happens.</P>
  626. <P>Assume that an integer cannot take less than 20 bytes of memory, a
  627. float cannot take less than 24 bytes, a string cannot take less
  628. than 32 bytes (all these examples assume 32-bit architectures, the
  629. result are quite a bit worse on 64-bit architectures).  If a variable
  630. is accessed in two of three different ways (which require an integer,
  631. a float, or a string), the memory footprint may increase yet another
  632. 20 bytes.  A sloppy <CODE>malloc(3)</CODE> implementation can make inflate these
  633. numbers dramatically.</P>
  634. <P>On the opposite end of the scale, a declaration like</P>
  635. <PRE>
  636.   sub foo;</PRE>
  637. <P>may take up to 500 bytes of memory, depending on which release of Perl
  638. you're running.</P>
  639. <P>Anecdotal estimates of source-to-compiled code bloat suggest an
  640. eightfold increase.  This means that the compiled form of reasonable
  641. (normally commented, properly indented etc.) code will take
  642. about eight times more space in memory than the code took
  643. on disk.</P>
  644. <P>There are two Perl-specific ways to analyze memory usage:
  645. $ENV{PERL_DEBUG_MSTATS} and <STRONG>-DL</STRONG> command-line switch.  The first
  646. is available only if Perl is compiled with Perl's malloc(); the
  647. second only if Perl was built with <CODE>-DDEBUGGING</CODE>.  See the
  648. instructions for how to do this in the <EM>INSTALL</EM> podpage at 
  649. the top level of the Perl source tree.</P>
  650. <P>
  651. <H2><A NAME="using $env{perl_debug_mstats}">Using <CODE>$ENV{PERL_DEBUG_MSTATS}</CODE></A></H2>
  652. <P>If your perl is using Perl's <CODE>malloc()</CODE> and was compiled with the
  653. necessary switches (this is the default), then it will print memory
  654. usage statistics after compiling your code hwen <CODE>$ENV{PERL_DEBUG_MSTATS}
  655. > 1</CODE>, and before termination of the program when <CODE><
  656. $ENV{PERL_DEBUG_MSTATS} </CODE>= 1 >>.  The report format is similar to
  657. the following example:</P>
  658. <PRE>
  659.   $ PERL_DEBUG_MSTATS=2 perl -e "require Carp"
  660.   Memory allocation statistics after compilation: (buckets 4(4)..8188(8192)
  661.      14216 free:   130   117    28     7     9   0   2     2   1 0 0
  662.                 437    61    36     0     5
  663.      60924 used:   125   137   161    55     7   8   6    16   2 0 1
  664.                  74   109   304    84    20
  665.   Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048.
  666.   Memory allocation statistics after execution:   (buckets 4(4)..8188(8192)
  667.      30888 free:   245    78    85    13     6   2   1     3   2 0 1
  668.                 315   162    39    42    11
  669.     175816 used:   265   176  1112   111    26  22  11    27   2 1 1
  670.                 196   178  1066   798    39
  671.   Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.</PRE>
  672. <P>It is possible to ask for such a statistic at arbitrary points in
  673. your execution using the <CODE>mstats()</CODE> function out of the standard
  674. Devel::Peek module.</P>
  675. <P>Here is some explanation of that format:</P>
  676. <DL>
  677. <DT><STRONG><A NAME="item_SMALLEST"><CODE>buckets SMALLEST(APPROX)..GREATEST(APPROX)</CODE></A></STRONG><BR>
  678. <DD>
  679. Perl's <CODE>malloc()</CODE> uses bucketed allocations.  Every request is rounded
  680. up to the closest bucket size available, and a bucket is taken from
  681. the pool of buckets of that size.
  682. <P>The line above describes the limits of buckets currently in use.
  683. Each bucket has two sizes: memory footprint and the maximal size
  684. of user data that can fit into this bucket.  Suppose in the above
  685. example that the smallest bucket were size 4.  The biggest bucket
  686. would have usable size 8188, and the memory footprint would be 8192.</P>
  687. <P>In a Perl built for debugging, some buckets may have negative usable
  688. size.  This means that these buckets cannot (and will not) be used.
  689. For larger buckets, the memory footprint may be one page greater
  690. than a power of 2.  If so, case the corresponding power of two is
  691. printed in the <CODE>APPROX</CODE> field above.</P>
  692. <P></P>
  693. <DT><STRONG><A NAME="item_Free%2FUsed">Free/Used</A></STRONG><BR>
  694. <DD>
  695. The 1 or 2 rows of numbers following that correspond to the number
  696. of buckets of each size between <A HREF="#item_SMALLEST"><CODE>SMALLEST</CODE></A> and <CODE>GREATEST</CODE>.  In
  697. the first row, the sizes (memory footprints) of buckets are powers
  698. of two--or possibly one page greater.  In the second row, if present,
  699. the memory footprints of the buckets are between the memory footprints
  700. of two buckets ``above''.
  701. <P>For example, suppose under the pervious example, the memory footprints
  702. were</P>
  703. <PRE>
  704.      free:    8     16    32    64    128  256 512 1024 2048 4096 8192
  705.            4     12    24    48    80</PRE>
  706. <P>With non-<CODE>DEBUGGING</CODE> perl, the buckets starting from <CODE>128</CODE> have
  707. a 4-byte overhead, and thus a 8192-long bucket may take up to
  708. 8188-byte allocations.</P>
  709. <P></P>
  710. <DT><STRONG><A NAME="item_sbrk"><CODE>Total sbrk(): SBRKed/SBRKs:CONTINUOUS</CODE></A></STRONG><BR>
  711. <DD>
  712. The first two fields give the total amount of memory perl sbrk(2)ed
  713. (ess-broken? :-) and number of sbrk(2)s used.  The third number is
  714. what perl thinks about continuity of returned chunks.  So long as
  715. this number is positive, <CODE>malloc()</CODE> will assume that it is probable
  716. that <A HREF="#item_sbrk"><CODE>sbrk(2)</CODE></A> will provide continuous memory.
  717. <P>Memory allocated by external libraries is not counted.</P>
  718. <P></P>
  719. <DT><STRONG><A NAME="item_pad%3A_0"><CODE>pad: 0</CODE></A></STRONG><BR>
  720. <DD>
  721. The amount of sbrk(2)ed memory needed to keep buckets aligned.
  722. <P></P>
  723. <DT><STRONG><A NAME="item_heads%3A_2192"><CODE>heads: 2192</CODE></A></STRONG><BR>
  724. <DD>
  725. Although memory overhead of bigger buckets is kept inside the bucket, for
  726. smaller buckets, it is kept in separate areas.  This field gives the
  727. total size of these areas.
  728. <P></P>
  729. <DT><STRONG><A NAME="item_chain%3A_0"><CODE>chain: 0</CODE></A></STRONG><BR>
  730. <DD>
  731. <CODE>malloc()</CODE> may want to subdivide a bigger bucket into smaller buckets.
  732. If only a part of the deceased bucket is left unsubdivided, the rest
  733. is kept as an element of a linked list.  This field gives the total
  734. size of these chunks.
  735. <P></P>
  736. <DT><STRONG><A NAME="item_tail%3A_6144"><CODE>tail: 6144</CODE></A></STRONG><BR>
  737. <DD>
  738. To minimize the number of sbrk(2)s, <CODE>malloc()</CODE> asks for more memory.  This
  739. field gives the size of the yet unused part, which is sbrk(2)ed, but
  740. never touched.
  741. <P></P></DL>
  742. <P>
  743. <H2><A NAME="example of using dl switch">Example of using <STRONG>-DL</STRONG> switch</A></H2>
  744. <P>Below we show how to analyse memory usage by</P>
  745. <PRE>
  746.   do 'lib/auto/POSIX/autosplit.ix';</PRE>
  747. <P>The file in question contains a header and 146 lines similar to</P>
  748. <PRE>
  749.   sub getcwd;</PRE>
  750. <P><STRONG>WARNING</STRONG>: The discussion below supposes 32-bit architecture.  In 
  751. newer releases of Perl, memory usage of the constructs discussed
  752. here is greatly improved, but the story discussed below is a real-life
  753. story.  This story is mercilessly terse, and assumes rather more than cursory
  754. knowledge of Perl internals.  Type space to continue, `q' to quit. 
  755. (Actually, you just want to skip to the next section.)</P>
  756. <P>Here is the itemized list of Perl allocations performed during parsing
  757. of this file:</P>
  758. <PRE>
  759.  !!! "after" at test.pl line 3.
  760.     Id  subtot   4   8  12  16  20  24  28  32  36  40  48  56  64  72  80 80+
  761.   0 02   13752   .   .   .   . 294   .   .   .   .   .   .   .   .   .   .   4
  762.   0 54    5545   .   .   8 124  16   .   .   .   1   1   .   .   .   .   .   3
  763.   5 05      32   .   .   .   .   .   .   .   1   .   .   .   .   .   .   .   .
  764.   6 02    7152   .   .   .   .   .   .   .   .   .   . 149   .   .   .   .   .
  765.   7 02    3600   .   .   .   .   . 150   .   .   .   .   .   .   .   .   .   .
  766.   7 03      64   .  -1   .   1   .   .   2   .   .   .   .   .   .   .   .   .
  767.   7 04    7056   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   7
  768.   7 17   38404   .   .   .   .   .   .   .   1   .   . 442 149   .   . 147   .
  769.   9 03    2078  17 249  32   .   .   .   .   2   .   .   .   .   .   .   .   .</PRE>
  770. <P>To see this list, insert two <A HREF="../../lib/Pod/perlfunc.html#item_warn"><CODE>warn('!...')</CODE></A> statements around the call:</P>
  771. <PRE>
  772.   warn('!');
  773.   do 'lib/auto/POSIX/autosplit.ix';
  774.   warn('!!! "after"');</PRE>
  775. <P>and run it with PErl's <STRONG>-DL</STRONG> option.  The first <A HREF="../../lib/Pod/perlfunc.html#item_warn"><CODE>warn()</CODE></A> will print
  776. memory allocation info before parsing the file and will memorize
  777. the statistics at this point (we ignore what it prints).  The second
  778. <A HREF="../../lib/Pod/perlfunc.html#item_warn"><CODE>warn()</CODE></A> prints increments with respect to these memorized data.  This
  779. is the printout shown above.</P>
  780. <P>Different <EM>Id</EM>s on the left correspond to different subsystems of
  781. the perl interpreter.  They are just the first argument given to
  782. the perl memory allocation API named New().  To find what <CODE>9 03</CODE>
  783. means, just <STRONG>grep</STRONG> the perl source for <CODE>903</CODE>.  You'll find it in
  784. <EM>util.c</EM>, function savepvn().  (I know, you wonder why we told you
  785. to <STRONG>grep</STRONG> and then gave away the answer.  That's because grepping
  786. the source is good for the soul.)  This function is used to store
  787. a copy of an existing chunk of memory.  Using a C debugger, one can
  788. see that the function was called either directly from <CODE>gv_init()</CODE> or
  789. via sv_magic(), and that <CODE>gv_init()</CODE> is called from gv_fetchpv()--which
  790. was itself called from newSUB().  Please stop to catch your breath now.</P>
  791. <P><STRONG>NOTE</STRONG>: To reach this point in the debugger and skip the calls to
  792. <CODE>savepvn()</CODE> during the compilation of the main program, you should
  793. set a C breakpoint
  794. in Perl_warn(), continue until this point is reached, and <EM>then</EM> set
  795. a C breakpoint in Perl_savepvn().  Note that you may need to skip a
  796. handful of <CODE>Perl_savepvn()</CODE> calls that do not correspond to mass production
  797. of CVs (there are more <CODE>903</CODE> allocations than 146 similar lines of
  798. <EM>lib/auto/POSIX/autosplit.ix</EM>).  Note also that <CODE>Perl_</CODE> prefixes are
  799. added by macroization code in perl header files to avoid conflicts
  800. with external libraries.</P>
  801. <P>Anyway, we see that <CODE>903</CODE> ids correspond to creation of globs, twice
  802. per glob - for glob name, and glob stringification magic.</P>
  803. <P>Here are explanations for other <EM>Id</EM>s above:</P>
  804. <OL>
  805. <LI>
  806. CReates bigger <CODE>XPV*</CODE> structures.  In the case above, it
  807. creates 3 <A HREF="../../lib/Pod/perlguts.html#item_AV"><CODE>AV</CODE></A>s per subroutine, one for a list of lexical variable
  808. names, one for a scratchpad (which contains lexical variables and
  809. <CODE>targets</CODE>), and one for the array of scratchpads needed for
  810. recursion.
  811. <P>It also creates a <CODE>GV</CODE> and a <CODE>CV</CODE> per subroutine, all called from
  812. start_subparse().</P>
  813. <P></P>
  814. <LI>
  815. Creates a C array corresponding to the <A HREF="../../lib/Pod/perlguts.html#item_AV"><CODE>AV</CODE></A> of scratchpads and the
  816. scratchpad itself.  The first fake entry of this scratchpad is
  817. created though the subroutine itself is not defined yet.
  818. <P>It also creates C arrays to keep data for the stash.  This is one HV,
  819. but it grows; thus, there are 4 big allocations: the big chunks are not
  820. freed, but are kept as additional arenas for <A HREF="../../lib/Pod/perlguts.html#item_SV"><CODE>SV</CODE></A> allocations.</P>
  821. <P></P>
  822. <LI>
  823. Creates a <CODE>HEK</CODE> for the name of the glob for the subroutine.  This
  824. name is a key in a <EM>stash</EM>.
  825. <P>Big allocations with this <EM>Id</EM> correspond to allocations of new
  826. arenas to keep <CODE>HE</CODE>.</P>
  827. <P></P>
  828. <LI>
  829. Creates a <CODE>GP</CODE> for the glob for the subroutine.
  830. <P></P>
  831. <LI>
  832. Creates the <CODE>MAGIC</CODE> for the glob for the subroutine.
  833. <P></P>
  834. <LI>
  835. Creates <EM>arenas</EM> which keep SVs.
  836. <P></P></OL>
  837. <P>
  838. <H2><A NAME="dl details"><STRONG>-DL</STRONG> details</A></H2>
  839. <P>If Perl is run with <STRONG>-DL</STRONG> option, then warn()s that start with `!'
  840. behave specially.  They print a list of <EM>categories</EM> of memory
  841. allocations, and statistics of allocations of different sizes for
  842. these categories.</P>
  843. <P>If <A HREF="../../lib/Pod/perlfunc.html#item_warn"><CODE>warn()</CODE></A> string starts with</P>
  844. <DL>
  845. <DT><STRONG><A NAME="item_%21%21%21"><CODE>!!!</CODE></A></STRONG><BR>
  846. <DD>
  847. print changed categories only, print the differences in counts of allocations.
  848. <P></P>
  849. <DT><STRONG><A NAME="item_%21%21"><CODE>!!</CODE></A></STRONG><BR>
  850. <DD>
  851. print grown categories only; print the absolute values of counts, and totals.
  852. <P></P>
  853. <DT><STRONG><A NAME="item_%21"><CODE>!</CODE></A></STRONG><BR>
  854. <DD>
  855. print nonempty categories, print the absolute values of counts and totals.
  856. <P></P></DL>
  857. <P>
  858. <H2><A NAME="limitations of dl statistics">Limitations of <STRONG>-DL</STRONG> statistics</A></H2>
  859. <P>If an extension or external library does not use the Perl API to
  860. allocate memory, such allocations are not counted.</P>
  861. <P>
  862. <HR>
  863. <H1><A NAME="see also">SEE ALSO</A></H1>
  864. <P><A HREF="../../lib/Pod/perldebug.html">the perldebug manpage</A>,
  865. <A HREF="../../lib/Pod/perlguts.html">the perlguts manpage</A>,
  866. <A HREF="../../lib/Pod/perlrun.html">the perlrun manpage</A>
  867. <A HREF="../../lib/re.html">the re manpage</A>,
  868. and
  869. <A HREF="../../Devel/Dprof.html">the Devel::Dprof manpage</A>.</P>
  870. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  871. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  872. <STRONG><P CLASS=block> perldebguts - Guts of Perl debugging</P></STRONG>
  873. </TD></TR>
  874. </TABLE>
  875.  
  876. </BODY>
  877.  
  878. </HTML>
  879.