WebStorm 2019.3 Help

Stepping through the program

Stepping is the process of controlling step-by-step execution of the program.

WebStorm provides a set of stepping actions, which are used depending on your strategy (for example, whether you need to go directly to the next line or enter the methods invoked on your way there).

The stepping buttons are located on the Debug tool window toolbar.

Stepping buttons in the Debug tool window

Step over

Steps over the current line of code and takes you to the next line even if the highlighted line has method calls in it. The implementation of the methods is skipped, and you move straight to the next line of the caller method.

  • Click the Step over button Step Over button or press F8.

In the example, line 5 is about to be executed. If you step over, the debugger will move straight to line 6 without jumping into the doCount() method.

Stepping over a method call

If there are breakpoints inside the skipped methods, the debugger will stop at them. If needed to skip any breakpoints on the way, use Force step over.

Step over took us to the next line of code

Step into

Steps into the method to show what happens inside it. Use this option when you are not sure the method is returning a correct result.

  • Click the Step into button Step Into button or press F7.

In the example, line 5 is about to be executed. If you step into, the debugger will jump into the implementation of the count(int to) method allowing you to examine in detail how its result is produced.

Stepping in a method

If there are several method calls on the line, WebStorm asks you which method to enter. This feature is called Smart step into.

Inside the method

You can configure Smart Step Into to be automatically used every time when there are multiple method calls on the line. Alternatively, it can be invoked only when you expressly do so. To configure this feature, go to Settings/Preferences | Build, Execution, Deployment | Debugger | Stepping and set the Always do smart step into option as required.

Some methods (for example methods of standard Java classes like System) are skipped by Step into as you normally don't need to debug them. This list can be fine-tuned on the Build, Execution, Deployment | Debugger | Stepping page of the Settings/Preferences dialog (Ctrl+Alt+S).

Smart step into

Smart step into is helpful when there are several method calls on a line, and you want to be specific about which method to enter. This feature allows you to select the method call you are interested in.

  1. From the main menu, select Run | Smart Step Into or press Shift+F7.

  2. Click the method or select it using the arrow keys and press Enter/F7.

    Smart Step into lets you decide which method to enter

You can configure Smart step into to be used instead of the regular Step into every time there are multiple method calls on the line. This is done in Settings/Preferences | Build, Execution, Deployment | Debugger | Stepping .

Step out

Steps out of the current method and takes you to the caller method.

  • Click the Step out button Step Out button or press Shift+F8.

In the example, stepping out skips all iterations of the loop and takes you straight to the main method (the caller).

Step out continues the execution until the method is complete

Run to cursor

Continues the execution until the position of the caret is reached.

  1. Place the caret at the line where you want the program to pause.

  2. Click the Run to cursor button Run to Cursor button or press Alt+F9.

Also, you can Run to Cursor with a single click. For this, click the line number in the gutter.

You can configure whether you want Run to Cursor to work on clicking a line number in Settings/Preferences | Build, Execution, Deployment | Debugger.

In the example, Run to cursor will continue the execution and stop at line 7 as if there were a breakpoint. If there are breakpoints in the count method, the program will be suspended there.

Caret is in the piece of code where we want to go

If needed to skip any breakpoints on the way, use Force run to cursor.

Force step into

Steps in the method even if this method is skipped by the regular Step Into.

  • Click the Force step into button Force Step Into icon or press Shift+Alt+F7.

In the example, the execution is suspended right before a line which is about to call System.out.println().

Force step into disregards the list of ignored classes

With Force Step Into, we jump right into the implementation of the System.out.println() method, while the regular Step Into would take us to line 20.

Inside println()

Force run to cursor

Continues the execution until the position of the caret is reached. All breakpoints on the way are ignored.

  1. Place the caret at the line where you want the program to pause.

  2. From the main menu, select Run | Force Run to Cursor or press Ctrl+Alt+F9.

In the example, Force run to cursor will continue the execution and stop at line 7 as if there were a breakpoint. The breakpoint inside count will not have any effect.

Caret is in the piece of code where we want to go

Force step over

Steps over the current line of code and takes you to the next line even if the highlighted line has method calls in it. If there are breakpoints in the called methods, they are ignored.

  • From the main menu, select Run | Force Step Over or press Shift+Alt+F8.

In the example, stepping over takes you to the print statement on line 6 even though there is a breakpoint in the count method, which would otherwise suspend the application in all iterations of the loop.

The breakpoint in the called method is going to be ignored

Drop frame

Allows you to undo the last frame and restore the previous frame in the stack. This can be useful, for example, if you've mistakenly stepped too far, or want to re-enter a function where you missed a critical spot.

Note that this option only affects local variables and does not restore the overall program state in that it does not revert values for static and instance variables. This may result in an altered program flow.

  • Click the Drop Frame button Drop Frame button.

In the example, dropping the frame returns you to the caller method as if count has never been executed.

Drop frame undoes the current frame as if the method has not been executed

There are no static or instance variables, which were affected, however the console output stays.

0 1 2

Improve stepping speed

Debugger features consume resources and may impact stepping performance. If the performance is not satisfactory, follow the recommendations provided in this chapter to optimize it.

  • Use the Overhead feature to identify the cause(s) of performance degradation.

  • Disable or minimize the use of the following features if they are not required for your project:

    • Method breakpoints and field watchpoints
    • The Show method return values option

    • The Alternate view for Collections classes option ( Settings/Preferences | Build, Execution, Deployment | Debugger | Data Views | Java )

    • 'toString' object view ( Settings/Preferences | Build, Execution, Deployment | Debugger | Data Views | Java )

  • Simplify the conditions for breakpoints and watchpoints, especially frequently hit ones.

  • During the debugging session, switch to a view with fewer elements.

When a breakpoint is reached the Debug tool window becomes active and enables you to get control over the program's execution. For this purpose, you can use the Run menu commands, or the icons on the stepping toolbar of in the Debug tool window.

Each stepping action advances the execution point to the next execution location, depending on the action you choose.

Stepping through the program

  • Use the buttons in the stepping toolbar of the Debug tool window.

  • On the main Run menu, or on the editor's context menu, choose one of the stepping commands

  • Use the keyboard shortcuts.

Choosing a method to step into (Smart Step Into)

When you reach a line with calls of several methods, you can choose a method you want to step into.

  1. Click The Smart step into button on the stepping toolbar, or press Shift+F7, or select Run | Smart Step Into from the main menu.

  2. In the editor, select the method to step into using the right and left arrow keys.

    To exit the Smart Step Into mode, click Escape.

Suppressing stepping into

You can create a list of scripts that you want the debugger skip while stepping through the program.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click Debugger under Build, Execution, Deployment, and then click Stepping. The Debugger. Stepping page opens.

  2. To skip all library scripts, select the Do not step into library scripts checkbox.

  3. To suppress stepping into some specific scripts, select the Do not step into scripts checkbox and create a list of such scripts using the toolbar buttons.

Tips and tricks

  • The Force Step Into command the Force Step Into button enables you to step into a method of a class not to be stepped into.
    The classes, stepping into which is suppressed, are specified on the Debugger. Stepping page of the Settings/Preferences dialog.

  • The Force Step Over command the Force Step Over button enables you to jump over the method call ignoring the breakpoints on the way.

  • The Force Run to Cursor command the Run to Cursor button enables you to jump to the cursor position ignoring existing breakpoints on the way.

Last modified: 24 November 2019