JavaRush /Java Blog /Random EN /IntelliJ IDEA User Guide. Debugger
theGrass
Level 24
Саратов

IntelliJ IDEA User Guide. Debugger

Published in the Random EN group
IntelliJ IDEA User Guide.  Debugger - 1

Debugger

  1. Launching the Debugger

    Once you have set up your project's launch configuration, you can run it in debug mode by pressing Shift + F9

    IntelliJ IDEA User Guide.  Debugger - 2

    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.

  2. 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 )
  3. 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.

    IntelliJ IDEA User Guide.  Debugger - 3
  4. 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.

    IntelliJ IDEA User Guide.  Debugger - 4
  5. 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 .

    IntelliJ IDEA User Guide.  Debugger - 5
  6. 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 .

    IntelliJ IDEA User Guide.  Debugger - 6

    When the item appears in the list, you will see its label.

    IntelliJ IDEA User Guide.  Debugger - 7
  7. Evaluate Expression

    In debug mode, you can evaluate any expression using a very powerful tool called Alt + F8 .

    IntelliJ IDEA User Guide.  Debugger - 8

    This tool provides code completion like an editor, so entering any expression will be very simple.

    IntelliJ IDEA User Guide.  Debugger - 9

    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.

    IntelliJ IDEA User Guide.  Debugger - 10
  8. 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.

    IntelliJ IDEA User Guide.  Debugger - 11

    If you have an element with a label, you can also use that label in expressions.

    IntelliJ IDEA User Guide.  Debugger - 12

    To get a list of all the breakpoints in your project (with advanced settings), press Shift + Ctrl + F8 (Shift + Cmd + F8 for Mac) again .

  9. 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 .

    IntelliJ IDEA User Guide.  Debugger - 13
  10. 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 .

    IntelliJ IDEA User Guide.  Debugger - 14
  11. 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 .

    IntelliJ IDEA User Guide.  Debugger - 15
  12. 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 .

    IntelliJ IDEA User Guide.  Debugger - 16
  13. 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.

    IntelliJ IDEA User Guide.  Debugger - 17

    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.

  14. 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.

    IntelliJ IDEA User Guide.  Debugger - 18
  15. Settings

    If you want to change the default debugger settings, click Settings → Debugger .

    IntelliJ IDEA User Guide.  Debugger - 19
Original article
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION