Debugging
General debugging steps
- To debug CoffeeScript, TypeScript, and Dart code, you need to generate a source map for it. This will set the correspondence between lines in your original code and in the generated JavaScript code. If no source map is generated, your breakpoints will not be recognized and processed correctly.
- Define a run/debug configuration for the application to be debugged.
- Create breakpoints in the source code.
- Launch a debugging session.
- Pause or resume the debugging session as required.
- During the debugger session, step through the breakpoints, evaluate expressions, change values on-the-fly examine suspended program, and set watches.
After you've started a debug session, the icon that marks the Debug tool window toggles to to indicate that the debug process is active.
Debug
After you have configured a run configuration for your project, you can launch it in debug mode by pressing Shift+F9.
In the Debug tool window you can see the list of frames and threads with their states, variables and watches. When you select a frame, you see the variables corresponding to the selected frame.
Useful debugger shortcuts
- Toggle breakpoint: Ctrl+F8
- Resume program: F9
- Step over: F8
- Step into: F7
- Stop: Ctrl+F2
- View breakpoint details/all breakpoints: Ctrl+Shift+F8
- Debug code at caret Shift+F9 (e.g if you stay within the main method), or Shift+Alt+F9
Breakpoints
Breakpoint details and condition
If you want to change details of a breakpoint, press Ctrl+Shift+F8. Here you can specify the breakpoint conditions.
If you have any instance marked with a label, you can use it in the condition expression as well:
To see all breakpoints in the project (with more advanced settings), press the same shortcut Ctrl+Shift+F8 again.
Action breakpoints
Another action might be useful if you want to evaluate something at a particular line of code without actually making a stop. You can do that by using the Action breakpoint. To create one, just click on the gutter while holding Shift.
Temporary breakpoints
To create a breakpoint that stops only once, click the left gutter while holding Shift+Alt.
Refer to the section Breakpoint types for details.
Disable breakpoints
It's also useful to know that any breakpoint can be quickly disabled by clicking on the gutter while holding Alt.
Refer to the section Enabling, Disabling and Removing Breakpoints for details.
Debugger session
Smart step into
Sometimes it happens that you stay at a line and want to step into a particular method but not the first one that will be invoked. In this case use Smart step into by pressing Shift+F7 to choose a particular method. This is a great time-saver.
Refer to the section Choosing a Method to Step Into for details.
Drop frame
In case you want to “go back in time” while debugging you can do it via Drop Frame action. This is a great help if you mistakenly stepped too far. This will not revert the global state of your application but at least will get you back by stack of frames.
The icon is described in the Debug tool window reference.
Run to cursor
Sometimes you need to resume the program and stop at another line of code, without adding another breakpoint. Easy: just press Alt+F9.
The icon is described in the toolbar reference of the Debug tool window.
Mark instance
If you want a particular instance to be always recognized while debugging, you can mark it with a colored label via F11 or the context menu in the Variables and Watches tabs.
The next time this instance appears in Watches, Variables or Evaluate expression, you will see the label:
Evaluate expression
While in debug mode, you can evaluate any expression by pressing Alt+F8.
This tool provides code completion just as in the editor so it’s very easy to enter any expression:
If you have any instances marked with labels, code completion will offer you its names so you can evaluate them:
Refer to the section Evaluating Expressions for details.
Settings
If you want to change the default debugger settings, choose Debugger in PyCharm Settings/Preferences.