Debugger
-
Launching the Debugger
Once you have set up your project's launch configuration, you can run it in debug mode by pressing Shift + F9
In the debugger window, you can see a stack of function calls and a list of threads, with their states, variables, and state viewports. When you select a function call context, you can view the values of the variables corresponding to the selected context.
-
Useful Debugger Keyboard Shortcuts
- Set/remove breakpoint - Ctrl + F8 (Cmd + F8 for Mac)
- Resume program execution - F9
- Go to next instruction - F8
- Go inside function - F7
- Pause execution - Ctrl + F2 (Cmd + F2)
- Switch between viewing a list of breakpoints and detailed information about the selected point - Shift + Ctrl + F8 (Shift + Ctrl + F8)
- Start debugging the code from the point where the cursor is located - Shift + Ctrl + F9 (if it is inside the main() method )
-
Smart transition inside
Sometimes, during step-by-step debugging, you need to go inside a certain method, but not the first one that will be called. In this case, you can press Shift + F7 (Cmd + F7 for Mac) to select the method you need from the list provided. This can save you a lot of time.
-
Remove function call context
If you need to "go back in time" while debugging, you can do so by removing the function call context. This will help a lot if you mistakenly went too deep. This way you won't roll back the global execution state of the program, but at a minimum you will go back up the stack of function calls.
-
Go to cursor
Sometimes you need to resume program execution and stop at some other line of code without creating a breakpoint. It's easy - just press Alt + F9 .
-
Flag element
If you want to easily see an element while debugging, you can add a color mark to it by pressing F11 or selecting the appropriate option from the Variables and Watches tab menu .
When the item appears in the list, you will see its label.
-
Evaluate Expression
In debug mode, you can evaluate any expression using a very powerful tool called Alt + F8 .
This tool provides code completion like an editor, so entering any expression will be very simple.
If you have any elements with labels, code completion will show you these labels so you can easily find the elements you need and calculate their values.
-
Breakpoint status and settings
If you want to change some breakpoint settings, you can press Shift + Ctrl + F8 (Shift + Cmd + F8 for Mac) . In the pop-up window, you can enter the parameters you need.
If you have an element with a label, you can also use that label in expressions.
To get a list of all the breakpoints in your project (with advanced settings), press Shift + Ctrl + F8 (Shift + Cmd + F8 for Mac) again .
-
Variable breakpoints
In addition to conditional breakpoints, you can also use variable breakpoints. Such points are triggered when a variable is read or written. In order to create such a breakpoint, click on the panel to the left of the edited text, opposite the variable you need, while holding Alt .
-
Event breakpoints
Another useful feature is to evaluate a specific expression in the line of code you need without interrupting execution. To do this, you need to click on the panel to the left of the edited code opposite the desired line, while holding Shift .
-
Temporary breakpoints
To create a breakpoint that will only work once, click on the panel to the left of the code while holding Shift + Alt .
-
Disable breakpoints
It is also very useful to know that any breakpoint can be quickly disabled by clicking on the panel to the left of the code while holding Alt .
-
Uploading changes and quick replacement
Sometimes you need to make small changes to your code without interrupting the debugging process. Because the Java Virtual Machine supports HotSwap, the development environment in debug mode prompts you to reload modified classes when you compile them.
Do not forget that the HotSwap functionality in the Java machine has a number of limitations and does not allow reloading static fields and methods.
-
Remote Debugging
The last thing you really need to know about in IntelliJ IDEA is remote debugging. Remote debugging - connecting a debugger to a Java machine that is already running on your computer or on another computer via a network port. This way you can connect the debugger to an application server running on the server.
To create a configuration for remote launch, go to Edit configurations and click “add remote launch configuration” (Remote). Make sure you have specified the correct computer name and port before running this configuration.
-
Settings
If you want to change the default debugger settings, click Settings → Debugger .
GO TO FULL VERSION