diff options
Diffstat (limited to 'files/zh-cn/using_breakpoints_in_venkman/index.html')
-rw-r--r-- | files/zh-cn/using_breakpoints_in_venkman/index.html | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/files/zh-cn/using_breakpoints_in_venkman/index.html b/files/zh-cn/using_breakpoints_in_venkman/index.html deleted file mode 100644 index ddf030f18b..0000000000 --- a/files/zh-cn/using_breakpoints_in_venkman/index.html +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: 在Venkman中使用断点 -slug: Using_Breakpoints_in_Venkman -tags: - - Tools - - Venkman -translation_of: Archive/Mozilla/Venkman/Using_breakpoints ---- -<p>这篇文章包含在以<a href="cn/Venkman%e5%85%a5%e9%97%a8">Venkman入门</a>开篇的一系列关于Venkman的文档中。</p> -<p>调试任何一种编程语言的一个基本任务是设置“断点”。断点表示了代码的执行在什么位置暂停。当你在像Venkman这类调试程序中设置断点时,你可以暂停程序的执行,来检查变量,对象和其它的运行参数。</p> -<p>这篇文章描述了在JavaScript中的断点,和如何在Venkman中设置和使用断点。</p> -<h3 id=".E5.9F.BA.E6.9C.AC.E7.9A.84.E6.96.AD.E7.82.B9" name=".E5.9F.BA.E6.9C.AC.E7.9A.84.E6.96.AD.E7.82.B9">基本的断点</h3> -<p>“Stop”按钮和<code>debugger</code>命令是JavaScript调试器中很关键的要素,但是当你深入调试极其复杂的代码时,你会发现使用基本的工具已经无能为力,这时你需要断点来帮忙了。</p> -<h4 id=".E6.96.AD.E7.82.B9.E7.9A.84.E7.B1.BB.E5.9E.8B" name=".E6.96.AD.E7.82.B9.E7.9A.84.E7.B1.BB.E5.9E.8B">断点的类型</h4> -<p>Venkman有两种类型的断点。第一种,也是最常见的,叫做“硬断点”。A hard breakpoint represents an actual trap instruction included in the pseudocode of a compiled function. Hard breakpoints can only exist in the context of a function currently "live" in the browser. Hard breakpoints are the ones that actually stop program execution.</p> -<p>第二种类型的断点,“将来断点”,represents a promise from Venkman to set a hard breakpoint as soon as it is possible. Future breakpoints are used when you want to stop in a script that has not yet been compiled. The most common use of future breakpoints is to stop in a "top level" script (script that executes outside of any function), or script that executes during the onLoad event of a page. When a script is loaded that matches the URL of a future breakpoint, and has executable code at the specified line, Venkman will automatically set a future breakpoint.</p> -<p>除了下面提到的这个差别以外,断点工作在Venkman和工作在其它调试器中的情况是很相似的。你在源代码视图左边框看到的点显示了哪一行包含了可执行的代码,同时也表明了那一行可以设置硬断点。</p> -<p><img align="none" alt="“Figure 1” Venkman“源代码”视图中标明的可执行代码"></p> -<h4 id=".E8.AE.BE.E7.BD.AE.E6.96.AD.E7.82.B9" name=".E8.AE.BE.E7.BD.AE.E6.96.AD.E7.82.B9">设置断点</h4> -<p>在源代码视图中点击一个圆点,就会在这一行设置一个断点。Venkman会在这行代码执行前停止代码的运行。当一个断点被设置后,这一行左侧的边沿就会变成字母"B",如Figure 2。如果你在设置完断点后再次执行代码,Venkman会在第81行停止运行。</p> -<p><img align="none" alt="“Figure 2” 设置断点"></p> -<p>Venkman会在“已加载脚本”视图中显示一个或更多已经设置好的断点,一个红色的圆点会出现在已设置有断点的文件旁,后面还会显示断点所在的函数的行号。</p> -<p><img align="none" alt="“Figure 3” 在“已加载脚本”视图中的带有断点的文件"></p> -<h4 id=".E4.BD.BF.E7.94.A8.E6.96.AD.E7.82.B9.E8.BF.9B.E8.A1.8C.E8.B0.83.E8.AF.95" name=".E4.BD.BF.E7.94.A8.E6.96.AD.E7.82.B9.E8.BF.9B.E8.A1.8C.E8.B0.83.E8.AF.95">使用断点进行调试</h4> -<p>当你设置一个断点后,你就给了Venkman(或是任何你使用的调试器)显示执行环境信息的机会。 调试脚本或程序,最重要的表现是,它可以检查函数返回值,错误,计数器,变量作用范围,这些改变了脚本执行的路线。</p> -<p>在Figure 1中的<code>onFlipX</code>函数,例如,使用变量<code>newSign</code>来指明用什么图片表示fish。当你在第81行设置一个断点,你可以激活浏览器窗口的页面,Venkman停止代码的执行,当他加入了<code>onFlipX</code>函数。停在那里,Venkman在本地变量视图中显示了变量<code>newSign</code>的值"1"。</p> -<p><img align="none" alt="“Figure 4” 在断点处的本地变量"></p> -<p>使用断点和交互视图,你可以改变Venkman显示的变量值(仅仅是在调试环境的上下文中),还可以观察这些改变怎样影响代码的执行。</p> -<p><img align="none" alt="“Figure 5” 在断点处与脚本结合"></p> -<p>如果你想获得更多关于“调试动作”的信息,请浏览Venkman入门的<a href="cn/Venkman_Introduction#Debugging_Basics">调试基础</a>章节。</p> -<h4 id=".E6.B8.85.E9.99.A4.E6.96.AD.E7.82.B9" name=".E6.B8.85.E9.99.A4.E6.96.AD.E7.82.B9">清除断点</h4> -<p>点击两次边框来清除断点。第一次单击会清除硬断点,只保留一个用字母“F”表示的将来断点。第二次单击将会清除将来断点。</p> -<p><img align="none" alt="“Figure 6” 将来断点"></p> -<h3 id=".E9.AB.98.E7.BA.A7.E6.96.AD.E7.82.B9" name=".E9.AB.98.E7.BA.A7.E6.96.AD.E7.82.B9">高级断点</h3> -<p>Venkman允许你将一个断点和一段脚本关联在一起:当遇到断点时,这个脚本就会被执行。这个针对关联脚本的高级特性和其他一些选项,你可以在将来断点属性对话框中找到他们,你只需要右键单击一个断点,选择“属性”。</p> -<p><img align="none" alt="“Figure 7” 将来断点属性对话框"></p> -<p>一旦你创建了一个与断点相关联的脚本,你就可以从将来断点属性对话框中选择一些不同的选项,这些选项决定了Venkman如何处理关联脚本的输出。下面是经常用到的选项:</p> -<ul> - <li>“Continue regardless of result” 使Venkman在运行完断点脚本后继续执行正常的脚本。这对于试验不工作的额外脚本非常有用。</li> - <li>“Stop regardless of result” 使Venkman在运行完断点脚本后停止执行正常的脚本,这允许你检查程序的状态。</li> - <li>“Stop if result is true” 非常有效的将它当作一个条件断点。如果断点脚本返回true值(它并不必须是一个严格的布尔值<code>true</code>,比如非<code>null</code>、非空字符串、非零、非<code>undefined</code>、非<code>false</code>都是可以接受的),脚本执行会继续下去。如果返回false值,Venkman会在断点处停止脚本的执行。</li> - <li>“Early return from caller with result” will cause the function that the breakpoint is set in to return the value of the breakpoint script as its result, immediatley after the breakpoint script completes.</li> - <li>The “Pass exceptions to caller” checkbox allows you to pass exceptions thrown by the breakpoint script directly to the caller. Normally, if the breakpoint script generates an exception, Venkman assumes you made a mistake and stops execution after displaying the exception. If you would like to see what your code does when exceptions are thrown at it, check "Pass exceptions to caller", and thrown an exception from the breakpoint script.</li> - <li>The “Log result” checkbox tells Venkman you want the result of the script to show up in the Interactive Session View. When used with the “Continue regardless of result” option, the breakpoint can be used as a simple log message.</li> - <li>The number of times the breakpoint has been hit is passed in as a parameter to the breakpoint script. To reset the count, enter a 0 in the "Trigger count" field.</li> -</ul> -<h4 id=".E5.85.B3.E9.94.AE.E6.80.A7.E6.B3.A8.E9.87.8A" name=".E5.85.B3.E9.94.AE.E6.80.A7.E6.B3.A8.E9.87.8A">关键性注释</h4> -<p>You can also embed scripted breakpoints directly into the souce code you are debugging by using a Venkman facility called - <i> - meta comments</i> - . Meta comments are specially formatted comments that pull in the script named after the comment and specify how to treat the output of that script. The following meta comment types are available:</p> -<ul> - <li>The <code>//@JSD_LOG</code> comment will insert a breakpoint which is set to execute the script that follows without stopping. The result of the evaluation will be logged to the Interactive Session.</li> - <li>The <code>//@JSD_BREAK</code> comment will insert a breakpoint which is set to execute the script that follows and stop if the result is true.</li> - <li>The <code>//@JSD_EVAL</code> command will insert a breakpoint which is set to execute the script that follows without stopping and without logging the result.</li> - <li>These meta comments can be used to insert debug-only code in your scripts with zero impact on production code.</li> -</ul> -<p>To enable meta comments in a script, select "Scan for Meta Comments" from the context menu of the file in the Loaded Scripts view.</p> -<p>When you add a meta comment, a normal breakpoint is created. You can change or delete this breakpoint just as you would a breakpoint created by hand.</p> -<h3 id="Resources" name="Resources">Resources</h3> -<ul> - <li><a href="cn/Venkman_Introduction">Venkman Introduction</a>—previous article on Venkman.</li> - <li><a href="cn/Venkman">Venkman's home page on Devmo</a>.</li> -</ul> -<div class="originaldocinfo"> - <h3 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h3> - <ul> - <li>Authors: Robert Ginda, Ian Oeschger</li> - <li>Published 02 May 2003</li> - </ul> -</div> -<hr> -<p>--<a>AndyYard</a> 01:46 2007年11月15日 (PST)</p> |