⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch20_03.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html><head><title>Debugger Customization (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Debugger Customization"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch20_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch20_01.htm">Chapter 20: The Perl Debugger</a></td><td align="right" valign="top" width="172"><a href="ch20_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">20.3. Debugger Customization</h2><p><a name="INDEX-3582"></a><a name="INDEX-3583"></a><a name="INDEX-3584"></a>The debugger probably contains enough configuration hooks that you'llnever have to modify it yourself.  You may change the behaviorof debugger from within the debugger using its <tt class="literal">O</tt> command, fromthe command line via the <tt class="literal">PERLDB_OPTS</tt> environment variable, and by running any preset commands stored in <em class="emphasis">rc</em> files.</p><h3 class="sect2">20.3.1. Editor Support for Debugging</h3><p><a name="INDEX-3585"></a><a name="INDEX-3586"></a><a name="INDEX-3587"></a><a name="INDEX-3588"></a>The debugger's command-line history mechanism doesn't providecommand-line editing like many shells do: you can't retrieve previouslines with <tt class="literal">^p</tt>, or move to the beginning of the line with <tt class="literal">^a</tt>,although you can execute previous lines with using the exclamationpoint syntax familiar to shell users.  However, if you install the<tt class="literal">Term::ReadKey</tt> and <tt class="literal">Term::ReadLine</tt> modules from CPAN, you will have fullediting capabilities similar to what GNU <em class="emphasis">readline</em>(3) provides.</p><p><a name="INDEX-3589"></a><a name="INDEX-3590"></a>If you have <em class="emphasis">emacs</em> installed on your system, it can interact withthe Perl debugger to provide an integrated software developmentenvironment reminiscent of its interactions with C debuggers.  Perlcomes with a start file for making <em class="emphasis">emacs</em> act like a syntax-directededitor that understands (some of) Perl's syntax.  Look in the <em class="emphasis">emacs</em>directory of the Perl source distribution.  Users of <em class="emphasis">vi</em> should alsolook into <em class="emphasis">vim</em> (and <em class="emphasis">gvim</em>, the mousey and windy version) forcoloring of Perl keywords.</p><p>A similar setup by one of us (Tom) for interacting with anyvendor-shipped <em class="emphasis">vi</em> and the X11 window system is also available.This works similarly to the integrated multiwindow support that<em class="emphasis">emacs</em> provides, where the debugger drives the editor.  However,at the time of this writing, its eventual location in the Perldistribution is uncertain.  But we thought you should know of thepossibility.</p><h3 class="sect2">20.3.2. Customizing with Init Files</h3><p><a name="INDEX-3591"></a><a name="INDEX-3592"></a>You can do some customization by setting up either a <em class="emphasis">.perldb</em> or <em class="emphasis">perldb.ini</em> file (depending on youroperating system), whichcontains initialization code.  This init file holds Perl code, notdebugger commands, and is processed before the <tt class="literal">PERLDB_OPTS</tt>environment variable is looked at.  For instance, you could makealiases by adding entries to the <tt class="literal">%DB::alias</tt> hash this way:<blockquote><pre class="programlisting">$alias{len}  = 's/^len(.*)/p length($1)/';$alias{stop} = 's/^stop (at|in)/b/';$alias{ps}   = 's/^ps\b/p scalar /';$alias{quit} = 's/^quit(\s*)/exit/';$alias{help} = 's/^help\s*$/|h/';</pre></blockquote>You can change options from within your init file using functioncalls into the debugger's internal API:<blockquote><pre class="programlisting">parse_options("NonStop=1 LineInfo=db.out AutoTrace=1 frame=2");</pre></blockquote>If your init file defines the subroutine <tt class="literal">afterinit</tt>, that function iscalled after debugger initialization ends.  The init file may belocated in the current directory or in the home directory.  Becausethis file contains arbitrary Perl commands, for security reasons, itmust be owned by the superuser or the current user, and writable by noone but its owner.</p><p>If you want to modify the debugger, copy <em class="emphasis">perl5db.pl</em> from thePerl library to another name and hack it to your heart's content.You'll then want to set your <tt class="literal">PERL5DB</tt> environment variable to saysomething like this:<blockquote><pre class="programlisting">BEGIN { require "myperl5db.pl" }</pre></blockquote><a name="INDEX-3593"></a><a name="INDEX-3594"></a><a name="INDEX-3595"></a>As a last resort, you could also use <tt class="literal">PERL5DB</tt> to customize thedebugger by directly setting internal variables or calling internaldebugger functions.  Be aware, though, that any variables andfunctions not documented either here or else in the online<em class="emphasis">perldebug</em>, <em class="emphasis">perldebguts</em>, or <em class="emphasis">DB</em> manpages are consideredto be for internal use only and are subject to change withoutnotice.</p><a name="ch20-sect-do"></a><h3 class="sect2">20.3.3. Debugger Options</h3><p><a name="INDEX-3596"></a><a name="INDEX-3597"></a>The debugger has numerous options that you can set with the <tt class="literal">O</tt>command, either interactively or from the environment or from aninit file.</p><dl><dt><b><tt class="literal">recallCommand</tt>, <tt class="literal">ShellBang</tt></b></dt><dd><p><a name="INDEX-3598"></a><a name="INDEX-3599"></a><a name="INDEX-3600"></a>The characters used to recall a command or spawn a shell.  By default,both are set to <tt class="literal">!</tt>.</p></dd><dt><b><tt class="literal">pager</tt></b></dt><dd><p><a name="INDEX-3601"></a>Program to use for output of pager-piped commands (those beginningwith a <tt class="literal">|</tt> character.)  By default, <tt class="literal">$ENV{PAGER}</tt> will be used.Because the debugger uses your current terminal characteristicsfor bold and underlining, if the chosen pager does not passescape sequences through unchanged, the output of some debuggercommands will not be readable when sent through the pager.</p></dd><dt><b><tt class="literal">tkRunning</tt></b></dt><dd><p><a name="INDEX-3602"></a>Run under the <tt class="literal">Tk</tt> module while prompting (with <tt class="literal">ReadLine</tt>).</p></dd><dt><b><tt class="literal">signalLevel</tt>, <tt class="literal">warnLevel</tt>, <tt class="literal">dieLevel</tt></b></dt><dd><p><a name="INDEX-3603"></a><a name="INDEX-3604"></a><a name="INDEX-3605"></a>Set the level of verbosity.  By default, the debugger leaves your exceptionsand warnings alone because altering them can break correctly runningprograms.<a name="INDEX-3606"></a></p><p>To disable this default safe mode, set these values to somethinghigher than 0.  At a level of 1, you get backtraces upon receiving anykind of warning (this is often annoying) or exception (this is oftenvaluable).  Unfortunately, the debugger cannot distinguish fatalexceptions from nonfatal ones.  If <tt class="literal">dieLevel</tt> is 1, then yournonfatal exceptions are also traced and unceremoniously altered ifthey came from <tt class="literal">eval</tt>ed strings or from any kind of <tt class="literal">eval</tt> withinmodules you're attempting to load.  If <tt class="literal">dieLevel</tt> is 2, the debuggerdoesn't care where they came from: it usurps your exception handlerand prints out a trace, and then modifies all exceptions with its ownembellishments.  This may perhaps be useful for some tracing purposes,but it tends to hopelessly confuse any program that takes its exceptionhandling seriously.</p><p>The debugger will attempt to print a message when any uncaught <tt class="literal">INT</tt>,<tt class="literal">BUS</tt>, or <tt class="literal">SEGV</tt> signal arrives.  If you're in a slow syscall (like

⌨️ 快捷键说明

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