Suspend and Resume Threads
After debugging begins, the developer can suspend the executing thread in order to view information about the thread's stack frame, as follows.
(1) Select the thread in the Debug view.
(2) on the toolbar of the debug view, click on the "Suspend" button, the thread will be suspended, the debug view displays the call stack of the current thread (as shown), and the editor in the Debug view will highlight the code corresponding to that stack frame, which is where the program runs when the thread is suspended.
When a thread hangs, the stack frame at the top of the thread is automatically selected (that is, the recently called method), and the variable view shows the variable in the stack frame and its value, and the complex variable can be expanded to see the values of its members. Developers can also select a method call in the call stack frame of the debug view, and the variable information for that method will be displayed in the variable view.
When a thread hangs, the value of the variable is displayed when you move the mouse over a variable in the Java editor.
A thread can either be suspended or resumed execution.
(1) Select the thread or its stack frame in the Debug view.
(2) In the Debug View toolbar, click the "Continue" button (or press F8), the thread resumes execution.
Stepping through the program
After the thread is suspended, you can use step-by-line execution of the program. If a breakpoint is encountered during this process, it is suspended at the breakpoint and the stepping is terminated.
There are several things to do when stepping into a program.
(1) "Single Step Skip". F6.
(2) "Single Step Into". F5.
(3) "Step Into selected content". In the Java editor, overwrite the cursor with the name of the method you want to enter, press CTRL+F5, and the program runs until the selected method is called.
(4) "Single Step Filter". Avoid interruptions during the debugging process. This interruption is caused by the use of stepping into the calling method code without source code. When an interrupt occurs, a window pops up asking for the location of the source code. This happens when you use a codebase that contains only class files. The debugger does not step into any packages and classes that are set in the filter.
To set the step filter, click the menu Window->preferences->java->debug->step Filtering, as shown in. You can add classes, packages, and filters to the right window window, and you can also enable or disable filters.
(5) If you have entered a method call and have seen the desired result, and want to return from the method as soon as possible, you can use step back (F7).
(6) Once a thread is suspended, you can let it resume execution until a line is reached, allowing the program to run to a row without having to set breakpoints. Select the line that you want to run to, and then use the shortcut key ctrl+r.
Calculation and display of expressions
When the JVM suspends a thread (because it encounters a breakpoint or stepping), it can evaluate the expression in the context of the stack frame. By default, the expression view is located in the upper-right corner of the debug view, which shares a pane with views such as breakpoints, variable views, and so on. The expression view is used as follows.
(1) Select the stack frame in which to evaluate. For variables and expression views, value is determined by the context of the variable.
(2) Click on the blank area to display the results.
View and modify the value of a variable
For simple variables, simply move the mouse over the variable name in the Java editor.
If you want to see the value of a complex variable, you can use the variable view. The variable view displays all variables in the current scope (that is, the context of the stack frame).
The variable view can also be used to modify the value of a variable, either by clicking the value directly or by right-clicking on the row on which the variable is located, and selecting "Change Value ..." In the popup menu.
Breakpoint
You can add a line breakpoint to the program's executable code (that is, code that is not commented out), and the thread is suspended until the line of code with the breakpoint is executed, the debugger automatically selects the suspended thread, and the information in the thread stack is displayed in the Debug view. In the editing of the debug view, the line that sets the breakpoint is highlighted.
1. Method breakpoints
In a Java program, it applies to class files (that is,. class files). The steps to add a method breakpoint are as follows.
(1) In outline view, open a class and select a method that you want to add a method breakpoint to.
(2) Right click and select "Toggle Method breakpoint" in the pop-up menu.
(3) After adding a breakpoint, if the source file of this class exists, the breakpoint of the selected method will be displayed in the tag bar of the file editor.
(4) When the method is entered, the thread is suspended until any code that invokes the method executes.
2. Conditional breakpoints
You can set a condition for a breakpoint so that the breakpoint hangs when it encounters the following conditions.
(1) When the condition is established.
(2) In the event of a change in condition.
To set a condition for a breakpoint, proceed as follows:
(1) Locate the breakpoint that you want to set conditions for.
(2) Right click on the breakpoint and select "Breakpoint Properties ..." In the popup menu to pop up the window as shown.
(3) After selecting "Conditional" in the Properties menu, enter the conditional expression in the text area.
(4) If you want each condition to be true, the breakpoint will cause the thread to hang, then choose Suspend when ' true ', or select another item if you want the thread to hang when the result of the condition is changed.
(5) Click "OK" to complete the conditional breakpoint settings.
As you can see, there is also a "Hit count" option. This option applies To line breakpoints, exception breakpoints, checkpoints, and method breakpoints. Hit count starts working after the breakpoint has hit count enabled. When a thread runs through the breakpoint N times (that is, the number of times it is set), the thread is suspended. However, this "hit count" can only be used once, unless it is enabled again or changes the number of hits.
Exception Breakpoint
By using an exception breakpoint, you can suspend the thread when an exception is thrown, suspend the thread where the exception is caught, suspend it where it is not caught, and suspend execution where the exception is caught and not caught. To set a Java exception breakpoint, follow these steps:
(1) In the breakpoint view or the "Run" menu of the Workbench, select "Add Java Exception Breakpoint". All available exceptions are listed in the window that appears, as shown in.
(2) Enter or select an exception from the list that you want to catch. At the bottom of the window, select where you want to suspend the thread.
Common debugging methods