Debugging your programs

In this section, you will learn how to debug a VJET program.

  1. Please make sure the VJET file MyTest.js is opened in your editor area.
  2. Place your cursor on the vertical ruler along the left edge of the editor area on the following line in the main() method:

    var size = x.length;

    and double-click on the ruler to set a breakpoint.

    MyTest.js editor showing added breakpoint

    The breakpoint icon indicates the status of the breakpoint. The plain blue breakpoint icon indicates that the breakpoint has been set, but not yet installed.
  3. From Script Explorer view, select MyTest.js file, Right click on it.
    From context menu, select Debug As > VJET JS Application.

    Note: the Debug As context menu is also available in other places.

  4. You can also simply hit the debug button Debug button which will launch the currently selected resource or active editor.
  5. The program will run until the breakpoint is reached. When the breakpoint is hit, execution is suspended, and you will reach the Debug perspective.

    Notice that the process is still active (not terminated) in the Debug view. Other threads might still be running.

    Debug perspective

  6. In the editor in the Debug perspective, select x.length from the line above where the breakpoint is set, and from its context menu, select Inspect.

    Test.js editor with selected breakpoint line showing context menu

  7. The expression is evaluated in the context of the current stack frame, and a pop-up appears which displays the results. You can send a result to the Expressions view by pressing the key binding displayed in the pop-up.

    Test.js inspect pop-up with value

  8. Expressions that you evaluate while debugging a program will be listed in this view. To delete an expression after working with it, select the expression and choose Remove from its context menu.
  9. The Variables view (available on a tab along with the Expressions view) displays the values of the variables in the selected stack frame. Expand the x.length tree in the Variables view until you can see elementCount.
  10. The variables (e.g., size) in the Variables view will change when you step through Test in the Debug view.  To step through the code, click the Step Over (Step Over) button.  (Or F6 as a shortcut). Execution will continue at the next line in the same method (or, if you are at the end of a method, it will continue in the method from which the current method was called).

    Variables view

  11. Try some other step buttons (Step Into Step Into, Step Return Step Return)to step through the code.  Note the differences in stepping techniques. Select the Use Step Filters command [ Use Step Filters ] to change whether step filters should be used in the Debug View. Step filters are commonly used to filter out types that you do not wish to see or step through while debugging.
    For example, if you did not want to the see or step through anything from the URI pattern test.Test.*, you would add this to the list of filtered URIs.
    Adding URIs to the list of those to be filtered can be done via the Opens the Step Filtering preference page VJET > Debug > Step Filtering preference page.
  12. You can end a debugging session by allowing the program to run to completion or by terminating it.

Related reference