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.
第二种类型的断点，“将来断点”，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.
当你设置一个断点后，you give Venkman （或是任何你使用的调试器） the opportunity to display information about the execution environment. One of the most important aspects of debugging a script or software program is the ability to examine variables—function return values, errors, counters, variable scopes—as they change over the course of the script execution.
newSign来指明用什么图片表示fish。当你在第81行设置一个断点，you can start animation on the web page in the browser window and see Venkman stop execution as it enters the
onFlipX function. Stopped there, Venkman displays the value of the
newSign variable as "1" in the Local Variables View.
Using breakpoints and the Interactive View, you can change the values of the variables that Venkman displays (only in the context of the debugging environment itself) and see how these changes affect the execution of the code.
For more information about the sorts of actions you can take in Venkman when you're at a breakpoint, see the Debugging Basics section of the introductory Venkman article.
Venkman allows you to associate a breakpoint with a script that will be executed in the scope of the function when that breakpoint is hit. This advanced feature and other options you can see for the associated script are available from the Future Breakpoint Properties dialog, which you can access by right-clicking a breakpoint and selecting Properties.
Once you've created a script that will be executed when the associated breakpoint is hit, you can select a number of different options from the Future Breakpoint Properties dialog that determine how Venkman will deal with the output of the associated script. The following options are available:
- Continue regardless of result causes Venkman to continue normal execution after running the breakpoint script. This can be useful to try out additional code, on the fly.
- Stop regardless of result causes Venkman to stop execution after executing the breakpoint script, allowing you to inspect program state.
- Stop if result is true effectively makes this a conditional breakpoint. If the breakpoint script returns a true value (it doesn't have to strictly be a boolean
true, any non-
null, non-empty string, non-zero, non-
undefined, and non-
falsevalue will do), execution will continue normally. If, on the other hand, the script returns a false value, Venkman will stop execution at that point.
- 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.
- 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.
- 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.
- 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.
You can also embed scripted breakpoints directly into the souce code you are debugging by using a Venkman facility called meta comments. 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:
//@JSD_LOGcomment 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.
//@JSD_BREAKcomment will insert a breakpoint which is set to execute the script that follows and stop if the result is true.
//@JSD_EVALcommand will insert a breakpoint which is set to execute the script that follows without stopping and without logging the result.
- These meta comments can be used to insert debug-only code in your scripts with zero impact on production code.
To enable meta comments in a script, select "Scan for Meta Comments" from the context menu of the file in the Loaded Scripts view.
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.
Original Document Information
- Authors: Robert Ginda, Ian Oeschger
- Published 02 May 2003
--AndyYard 01:46 2007年11月15日 (PST)