perl5db.html

来自「perl教程」· HTML 代码 · 共 1,157 行 · 第 1/5 页

HTML
1,157 行
字号

<li><strong><a name="item_1__2d_print_entering_messages_on_subroutine_entry">1 - Print <em>entering</em> messages on subroutine entry</a></strong>

<li><strong><a name="item_2__2d_adds_exit_messages_on_subroutine_exit_2e_if_">2 - Adds exit messages on subroutine exit. If no other flag is on, acts like 1+2.</a></strong>

<li><strong><a name="item_4__2d_extended_messages_3a__3cin_7cout_3e_context_">4 - Extended messages: <code>&lt;in|out&gt; context=fully-qualified sub name from file:line</code>. If no other flag is on, acts like 1+4.</a></strong>

<li><strong><a name="item_8__2d_adds_parameter_information_to_messages_2c_an">8 - Adds parameter information to messages, and overloaded stringify and tied FETCH is enabled on the printed arguments. Ignored if <code>4</code> is not on.</a></strong>

<li><strong><a name="item_16__2d_adds_context_return_from_subname_3a_value_m">16 - Adds <code>context return from subname: value</code> messages on subroutine/eval exit. Ignored if <code>4</code> is is not on.</a></strong>

</ul>
<p>To get everything, use <code>$frame=30</code> (or <code>o f=30</code> as a debugger command).
The debugger internally juggles the value of <code>$frame</code> during execution to
protect external modules that the debugger uses from getting traced.</p>
<p>
</p>
<h4><a name="_level"><code>$level</code></a></h4>
<p>Tracks current debugger nesting level. Used to figure out how many 
<code>&lt;&gt;</code> pairs to surround the line number with when the debugger 
outputs a prompt. Also used to help determine if the program has finished
during command parsing.</p>
<p>
</p>
<h4><a name="_onetimedump"><a href="#item__onetimedump"><code>$onetimeDump</code></a></a></h4>
<p>Controls what (if anything) <a href="#item_eval"><code>DB::eval()</code></a> will print after evaluating an
expression.</p>
<ul>
<li><strong><a name="item_undef__2d_don_27t_print_anything"><a href="../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> - don't print anything</a></strong>

<li><strong><a name="item_dump__2d_use_dumpvar_2epl_to_display_the_value_ret"><a href="../lib/Pod/perlfunc.html#item_dump"><code>dump</code></a> - use <code>dumpvar.pl</code> to display the value returned</a></strong>

<li><strong><a name="item_methods__2d_print_the_methods_callable_on_the_firs"><code>methods</code> - print the methods callable on the first item returned</a></strong>

</ul>
<p>
</p>
<h4><a name="_onetimedumpdepth"><code>$onetimeDumpDepth</code></a></h4>
<p>Controls how far down <code>dumpvar.pl</code> will go before printing <code>...</code> while
dumping a structure. Numeric. If <a href="../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a>, print all levels.</p>
<p>
</p>
<h4><a name="_signal"><code>$signal</code></a></h4>
<p>Used to track whether or not an <code>INT</code> signal has been detected. <code>DB::DB()</code>,
which is called before every statement, checks this and puts the user into
command mode if it finds <code>$signal</code> set to a true value.</p>
<p>
</p>
<h4><a name="_single"><a href="#item__single"><code>$single</code></a></a></h4>
<p>Controls behavior during single-stepping. Stacked in <code>@stack</code> on entry to
each subroutine; popped again at the end of each subroutine.</p>
<ul>
<li><strong><a name="item_0__2d_run_continuously_2e">0 - run continuously.</a></strong>

<li><strong><a name="item_1__2d_single_2dstep_2c_go_into_subs_2e_the_s_comma">1 - single-step, go into subs. The <a href="../lib/Pod/perlguts.html#item_s"><code>s</code></a> command.</a></strong>

<li><strong><a name="item_2__2d_single_2dstep_2c_don_27t_go_into_subs_2e_the">2 - single-step, don't go into subs. The <a href="../lib/Pod/perlguts.html#item_n"><code>n</code></a> command.</a></strong>

<li><strong><a name="item_depth">4 - print current sub depth (turned on to force this when <code>too much
recursion</code> occurs.</a></strong>

</ul>
<p>
</p>
<h4><a name="_trace"><a href="#item__trace"><code>$trace</code></a></a></h4>
<p>Controls the output of trace information.</p>
<ul>
<li><strong><a name="item_tracing">1 - The <code>t</code> command was entered to turn on tracing (every line executed is printed)</a></strong>

<li><strong><a name="item_2__2d_watch_expressions_are_active">2 - watch expressions are active</a></strong>

<li><strong><a name="item_watchfunction">4 - user defined a <code>watchfunction()</code> in <code>afterinit()</code></a></strong>

</ul>
<p>
</p>
<h4><a name="_slave_editor"><code>$slave_editor</code></a></h4>
<p>1 if <code>LINEINFO</code> was directed to a pipe; 0 otherwise.</p>
<p>
</p>
<h4><a name="_cmdfhs"><code>@cmdfhs</code></a></h4>
<p>Stack of filehandles that <a href="../lib/Pod/perlfunc.html#item_readline"><code>DB::readline()</code></a> will read commands from.
Manipulated by the debugger's <code>source</code> command and <a href="../lib/Pod/perlfunc.html#item_readline"><code>DB::readline()</code></a> itself.</p>
<p>
</p>
<h4><a name="_dbline"><code>@dbline</code></a></h4>
<p>Local alias to the magical line array, <code>@{$main::{'_&lt;'.$filename}}</code> , 
supplied by the Perl interpreter to the debugger. Contains the source.</p>
<p>
</p>
<h4><a name="_old_watch"><code>@old_watch</code></a></h4>
<p>Previous values of watch expressions. First set when the expression is
entered; reset whenever the watch expression changes.</p>
<p>
</p>
<h4><a name="_saved"><code>@saved</code></a></h4>
<p>Saves important globals (<a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$!</code></a>, <a href="../lib/Pod/perlvar.html#item___e"><code>$^E</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$,</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$/</code></a>, <a href="#item___"><code>$\</code></a>, <a href="../lib/Pod/perlvar.html#item___w"><code>$^W</code></a>)
so that the debugger can substitute safe values while it's running, and
restore them when it returns control.</p>
<p>
</p>
<h4><a name="_stack"><code>@stack</code></a></h4>
<p>Saves the current value of <a href="#item__single"><code>$single</code></a> on entry to a subroutine.
Manipulated by the <code>c</code> command to turn off tracing in all subs above the
current one.</p>
<p>
</p>
<h4><a name="_to_watch"><code>@to_watch</code></a></h4>
<p>The 'watch' expressions: to be evaluated before each line is executed.</p>
<p>
</p>
<h4><a name="_typeahead"><code>@typeahead</code></a></h4>
<p>The typeahead buffer, used by <code>DB::readline</code>.</p>
<p>
</p>
<h4><a name="_alias"><code>%alias</code></a></h4>
<p>Command aliases. Stored as character strings to be substituted for a command
entered.</p>
<p>
</p>
<h4><a name="_break_on_load"><code>%break_on_load</code></a></h4>
<p>Keys are file names, values are 1 (break when this file is loaded) or undef
(don't break when it is loaded).</p>
<p>
</p>
<h4><a name="_dbline"><code>%dbline</code></a></h4>
<p>Keys are line numbers, values are <code>condition\0action</code>. If used in numeric
context, values are 0 if not breakable, 1 if breakable, no matter what is
in the actual hash entry.</p>
<p>
</p>
<h4><a name="_had_breakpoints"><code>%had_breakpoints</code></a></h4>
<p>Keys are file names; values are bitfields:</p>
<ul>
<li><strong><a name="item_1__2d_file_has_a_breakpoint_in_it_2e">1 - file has a breakpoint in it.</a></strong>

<li><strong><a name="item_2__2d_file_has_an_action_in_it_2e">2 - file has an action in it.</a></strong>

</ul>
<p>A zero or undefined value means this file has neither.</p>
<p>
</p>
<h4><a name="_option"><code>%option</code></a></h4>
<p>Stores the debugger options. These are character string values.</p>
<p>
</p>
<h4><a name="_postponed"><code>%postponed</code></a></h4>
<p>Saves breakpoints for code that hasn't been compiled yet.
Keys are subroutine names, values are:</p>
<ul>
<li><strong><a name="item_compile__2d_break_when_this_sub_is_compiled"><code>compile</code> - break when this sub is compiled</a></strong>

<li><strong><a name="item_break"><code>break +0 if &lt;condition&gt;</code> - break (conditionally) at the start of this routine. The condition will be '1' if no condition was specified.</a></strong>

</ul>
<p>
</p>
<h4><a name="_postponed_file"><code>%postponed_file</code></a></h4>
<p>This hash keeps track of breakpoints that need to be set for files that have
not yet been compiled. Keys are filenames; values are references to hashes.
Each of these hashes is keyed by line number, and its values are breakpoint
definitions (<code>condition\0action</code>).</p>
<p>
</p>
<hr />
<h1><a name="debugger_initialization">DEBUGGER INITIALIZATION</a></h1>
<p>The debugger's initialization actually jumps all over the place inside this
package. This is because there are several BEGIN blocks (which of course 
execute immediately) spread through the code. Why is that?</p>
<p>The debugger needs to be able to change some things and set some things up 
before the debugger code is compiled; most notably, the <code>$deep</code> variable that
<code>DB::sub</code> uses to tell when a program has recursed deeply. In addition, the
debugger has to turn off warnings while the debugger code is compiled, but then
restore them to their original setting before the program being debugged begins
executing.</p>
<p>The first <code>BEGIN</code> block simply turns off warnings by saving the current
setting of <a href="../lib/Pod/perlvar.html#item___w"><code>$^W</code></a> and then setting it to zero. The second one initializes
the debugger variables that are needed before the debugger begins executing.
The third one puts <a href="../lib/Pod/perlvar.html#item___x"><code>$^X</code></a> back to its former value.</p>
<p>We'll detail the second <code>BEGIN</code> block later; just remember that if you need
to initialize something before the debugger starts really executing, that's
where it has to go.</p>
<p>
</p>
<hr />
<h1><a name="debugger_routines">DEBUGGER ROUTINES</a></h1>
<p>
</p>
<h2><a name="db__eval__"><a href="#item_eval"><code>DB::eval()</code></a></a></h2>
<p>This function replaces straight <a href="#item_eval"><code>eval()</code></a> inside the debugger; it simplifies
the process of evaluating code in the user's context.</p>
<p>The code to be evaluated is passed via the package global variable 
<code>$DB::evalarg</code>; this is done to avoid fiddling with the contents of <a href="../lib/Pod/perlvar.html#item___"><code>@_</code></a>.</p>
<p>Before we do the <a href="#item_eval"><code>eval()</code></a>, we preserve the current settings of <a href="#item__trace"><code>$trace</code></a>,
<a href="#item__single"><code>$single</code></a>, <a href="../lib/Pod/perlvar.html#item___d"><code>$^D</code></a> and <code>$usercontext</code>.  The latter contains the
preserved values of <a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$!</code></a>, <a href="../lib/Pod/perlvar.html#item___e"><code>$^E</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$,</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$/</code></a>, <a href="#item___"><code>$\</code></a>, <a href="../lib/Pod/perlvar.html#item___w"><code>$^W</code></a> and the
user's current package, grabbed when <code>DB::DB</code> got control.  This causes the
proper context to be used when the eval is actually done.  Afterward, we
restore <a href="#item__trace"><code>$trace</code></a>, <a href="#item__single"><code>$single</code></a>, and <a href="../lib/Pod/perlvar.html#item___d"><code>$^D</code></a>.</p>
<p>Next we need to handle <a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a> without getting confused. We save <a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a> in a
local lexical, localize <a href="#item__saved_0_"><code>$saved[0]</code></a> (which is where <code>save()</code> will put 
<a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a>), and then call <code>save()</code> to capture <a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$!</code></a>, <a href="../lib/Pod/perlvar.html#item___e"><code>$^E</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$,</code></a>, 
<a href="../lib/Pod/perlvar.html#item___"><code>$/</code></a>, <a href="#item___"><code>$\</code></a>, and <a href="../lib/Pod/perlvar.html#item___w"><code>$^W</code></a>) and set <a href="../lib/Pod/perlvar.html#item___"><code>$,</code></a>, <a href="../lib/Pod/perlvar.html#item___"><code>$/</code></a>, <a href="#item___"><code>$\</code></a>, and <a href="../lib/Pod/perlvar.html#item___w"><code>$^W</code></a> to values
considered sane by the debugger. If there was an <a href="#item_eval"><code>eval()</code></a> error, we print 
it on the debugger's output. If <code>$onetimedump</code> is defined, we call 
<a href="#item_dumpit"><code>dumpit</code></a> if it's set to 'dump', or <code>methods</code> if it's set to 
'methods'. Setting it to something else causes the debugger to do the eval 
but not print the result - handy if you want to do something else with it 
(the &quot;watch expressions&quot; code does this to get the value of the watch
expression but not show it unless it matters).</p>
<p>In any case, we then return the list of output from <a href="#item_eval"><code>eval</code></a> to the caller, 
and unwinding restores the former version of <a href="../lib/Pod/perlvar.html#item___"><code>$@</code></a> in <code>@saved</code> as well 
(the localization of <a href="#item__saved_0_"><code>$saved[0]</code></a> goes away at the end of this scope).</p>
<p>
</p>
<h3><a name="parameters_and_variables_influencing_execution_of_db__eval__">Parameters and variables influencing execution of DB::eval()</a></h3>
<p><code>DB::eval</code> isn't parameterized in the standard way; this is to keep the
debugger's calls to <a href="#item_eval"><code>DB::eval()</code></a> from mucking with <a href="../lib/Pod/perlvar.html#item___"><code>@_</code></a>, among other things.
The variables listed below influence <a href="#item_eval"><code>DB::eval()</code></a>'s execution directly.</p>
<dl>
<dt><strong><a name="item__evalarg"><code>$evalarg</code> - the thing to actually be eval'ed</a></strong>

<dt><strong><a name="item__trace"><code>$trace</code> - Current state of execution tracing</a></strong>

<dt><strong><a name="item__single"><code>$single</code> - Current state of single-stepping</a></strong>

<dt><strong><a name="item__onetimedump"><code>$onetimeDump</code> - what is to be displayed after the evaluation</a></strong>

<dt><strong><a name="item_dumpit"><code>$onetimeDumpDepth</code> - how deep <code>dumpit()</code> should go when dumping results</a></strong>

</dl>
<p>The following variables are altered by <a href="#item_eval"><code>DB::eval()</code></a> during its execution. They

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?