[For beginners] How to debug in Eclipse

1.First of all

The IDE (Integrated Development Environment) is Integrated because you can "debug" it on the editor. Being able to debug in the IDE increases productivity. Debugging is [learning. ](Https://qiita.com/YudaiTsukamoto/items/42a8df22ca4c6b327dfd#4-%E5%8B%89%E5%BC%B7%E3%81%AE%E3%81%9F%E3%82%81%E3 % 81% AB% E3% 83% 87% E3% 83% 90% E3% 83% 83% E3% 82% B0% E3% 82% 92% E8% A1% 8C% E3% 81% AA% E3% 81 % 86)

1.1. Subject of this text

--Target environment: Eclipse. I don't care about the version. --Target: Beginners in Eclipse and debugging. --Target language: Java. I don't care about the version.

1.2. What are debugs and debuggers?

"Debugging" is to investigate the cause of a bug and fix it.

The tool used to investigate the cause of a bug in a program is the "debugger".

Debugger --Pause the program at a "breakpoint" --Look at the values of variables at that time, move them line by line, and see how the program works. ――Investigate where the movement will be different from what you expected Use it like this.

1.3. Why is there a debugger?

Because there is a bug. You don't need it if everything works as expected.

When I run the program, the data is different from what I expected, the design is not well considered Bugs occur due to various causes such as coding mistakes. (It may also be used to confirm that it is working as expected.)

2. How to use

2.1. "Breakpoints" and their settings

A "breakpoint" is a line of a program that you want to pause. If you double-click the leftmost side of the program's "Editor" window, it will be set as a breakpoint and a circle will be displayed. BreakPoint.png

--Can only be set on lines that can be stopped. (Does not stop at blank lines, class or method definition lines, etc.) --Multiple lines can be set as breakpoints. --Pause when you come to that line. --It is also possible to set a condition for a breakpoint and pause only when the condition is set.

Set it to "I'm suspicious around here, I want to see the value of this variable, I want to see the behavior around here".

If you want to cancel the breakpoint, double-click ○.

2.2. "Run" / "Debug"

There are two ways to execute a program in the IDE.

--"Run": Do not pause at breakpoints. --"Debug": Pause at a breakpoint.

When you reach a breakpoint in debugging, you pause there, the editor in Eclipse's Debug Perspective opens, and the stopped line is indicated by an arrow. BreakPoint2.png

If you want to set the argument with the main function, you can set it by right-clicking → "Argument" of "run configuration, debug configuration".

2.3. What you can do while debugging is stopped

2.3.1. Confirmation of value

You can check the value below. You can also see the method return value and the class fields.

2.3.2. Inspect: If you want to see it only once

With the field selected, right click-> inspection

2.3.3. Watch: If you want to watch continuously

With the field selected, right click-> monitor

If it's a variable, you can see the value of the variable on the Variable tab.

2.4. Move from pause

When "What happens when the process advances to the next line?" While debugging is paused, operate as follows. (Only frequently used items are listed.)

Using shortcuts such as step-over saves time and effort.

Japanese command English behavior Shortcut
Resume Resume Run until the end of the program. * F8
End Terminate Suspend processing(アプリケーションをEnd)To do. Ctrl+2
Step in Step Into Go to the next line that is paused and pause. When calling a method on the target line, enter the called method and pause at the beginning. F5
Step over Step Over Go to the next line that is paused and pause. If the method is called on the target line, perform those processes and proceed to the next line. * F6
Step return Step Return It performs until the method being executed returns, and pauses when it returns to the calling method. * F7

For shortcuts, be careful not to press the wrong button! "Finally reproduced!" → While tracing, press F7 and F8 by mistake → (゚ Д ゚) (゚ Д ゚) (゚ Д ゚)

Recommended Posts

[For beginners] How to debug in Eclipse
How to debug the generated jar file in Eclipse
How to run JUnit in Eclipse
How to set Lombok in Eclipse
java Eclipse How to debug javaScript
How to include Spring Tool in Eclipse 4.6.3?
[Ruby] How to use slice for beginners
[For beginners] I tried using DBUnit in Eclipse
[JavaFX] How to write Eclipse permissions in build.gradle
How to color code console output in Eclipse
[For beginners] I tried using JUnit 5 in Eclipse
[For beginners] How to implement the delete function
[For super beginners] How to use autofocus: true
How to implement Pagination in GraphQL (for ruby)
How to automatically generate a constructor in Eclipse
[Java] [For beginners] How to insert elements directly in a 2D array
How to implement login request processing (Rails / for beginners)
How to switch Tomcat context.xml with WTP in Eclipse
Java debug execution [for Java beginners]
How to use Z3 library in Scala with Eclipse
[For beginners] How to operate Stream API after Java 8
[For beginners] Minimum sample to display RecyclerView in Java
How to use JDD library in Scala with Eclipse
How to use Eclipse Debug_Shell
How to Git manage Java EE projects in Eclipse
How to use GitHub for super beginners (team development)
[For Ruby beginners] Explain how to freely delete array elements!
How to set character code and line feed code in Eclipse
How to deploy Java application to Alibaba Cloud EDAS in Eclipse
How to install Web application for each language in Nginx
For Java beginners: List, Map, Iterator / Array ... How to convert?
[Rails] How to display error messages for comment function (for beginners)
How to use Lombok in Spring
How to find May'n in XPath
How to hide scrollbars in WebView
How to specify validation for time_field
How to iterate infinitely in Ruby
Rock-paper-scissors game for beginners in Java
[Rails] How to write in Japanese
How to run Ant in Gradle
[For beginners] Run Selenium in Java
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
How to use InjectorHolder in OpenAM
How to use classes in Java?
How to name variables in Java
How to concatenate strings in java
How to install Swiper in Rails
Must-see for beginners! How to manage your Xcode project on Github
I tried setting Java beginners to use shortcut keys in eclipse
[Tips] How to solve problems with XCode and Swift for beginners
[For beginners] Minimum sample to update RecyclerView with DiffUtils in Java
[swift5] How to specify color in hexadecimal
A memorandum on how to use Eclipse
How to implement search functionality in Rails
How to implement date calculation in Java
Multilingual Locale in Java How to use Locale
How to use binding.pry for view files
How to use Apache Derby on Eclipse