doug
doug

Reputation: 231

How do you step through a program in Eclipse?

I want to follow a Java program so that I can understand how everything works together. I could do it with Visual Studio so I am hoping that Eclipse may also have a feature to step through that I have not been able to find.

Upvotes: 6

Views: 41266

Answers (5)

Jack Ba
Jack Ba

Reputation: 1

All the answers here are not really "cut and dry". To make this debug feature available in the eclipse workspace, first, you need to set the breakpoint properties of Line Breakpoint. Check the box: "Trigger Point" to allow the trigger to initiate at the line that you want it to begin to break during debug mode. Otherwise, you can F11, F5, or F6 all day long, and nothing will allow you to step into your code.

Upvotes: 0

Sankar Ganesh PMP
Sankar Ganesh PMP

Reputation: 12027

Refer step1, step2, step3,step4 images respectively.

alt text

alt text

alt text

alt text

Upvotes: 3

salexander
salexander

Reputation: 954

First you must set a break point in your code. The easiest way to do this is to open up the source file where you want to stop your program, find the line of code where you want to set your break point, and right-click the left-hand margin and select 'Toggle Breakpoint.' Once you've done this, launch your program within Eclipse using the Debug mode. To do this, go to Run>Debug Configurations and set up the configuration to run your program. Alternatively, you can open up the source file that is the entry point to your program (it should include your 'public static void main(String args[])' method), and right-click within the editor and go to Debug As>Java Application. Once the program launches and the code in which your break point is reached, Eclipse will open up the debug perspective. This will show where you are within your program and any variables that you have set. You can step through your program using the buttons in the 'Debug View'. You can also use the menu items within the Run menu to step through the program.

Upvotes: 2

Bozho
Bozho

Reputation: 597224

  1. Put a breakpoint at a given line (double click before the line, or right-click > toggle breakpoint)

  2. Run the program in debug mode. That is - Debug As > Java program

  3. Whenever the breakpoint is reached, the Debug perspective opens, and you can step through.

Upvotes: 6

Erkan Haspulat
Erkan Haspulat

Reputation: 12562

Simply put, you can run your code in Debug Mode by pressing only F11 or clicking that little bug on the top of the screen. Use F5 to trace into, F6 to step over, CTRL-SHIFT-B to set/remove breakpoints.

Upvotes: 3

Related Questions