3

A nice thing that you can do in Visual Studio is to start your program and stop it to debug in the very first line, just by pressing F10 for line by line debugging. This is extremely useful when writing sample code or trying something new.

Is there a way to do this in Eclipse for a Java program? You can't start with line by line because that option is not enabled until you actually start debugging.

I know I could set a breakpoint at the very first line, but then I would have to remove it to actually debug something else.

bounty: for exact answers to the question (if it is even possible) and not a workaround.

1
  • @SJuan76 the Step over, into, etc. are still disabled if you don't actually start debugging Commented Nov 15, 2013 at 22:02

2 Answers 2

9

The debug configuration for each program has ab option/checkbox “stop in main”. This will do what you describe.

http://help.eclipse.org/indigo/topic/org.eclipse.jdt.doc.user/tasks/tasks-java-local-configuration.htm

Sign up to request clarification or add additional context in comments.

3 Comments

+1 indeed. Now that we have two debug configurations (with and without stopping at the main), is there a way to start one of them without going to the menu with the mouse? I mean, a key config or something
F11 starts the last used configuration, but I don’t know whether there’s a key shortcut for switching between them.
last used config is ok I guess, didn't know either that it runs the last one. I'll leave it open for a while just in case someone knows how to do exactly what I ask; if not I'll set this as the correct answer.
4
+50

The "stop in main" mentioned by Holger is to be declared in a launched configuration:

http://help.eclipse.org/indigo/topic/org.eclipse.jdt.doc.user/tips/images/org.eclipse.jdt.debug.ui/stop_in_main.png

The problem is to call that specific configuration from a keyboard shortcut, especially when this isn't always the last one you just launched
(if it were, you could use the shortcut "Run last launched" Ctrl+F11).

You can assign a shortcut to open the "run configurations" window, but then you need to select the right configuration to launch.

Or you can assign a true shortcut to a specific launch configuration, which is closer to what you are after, but that need an additional plugin ("Practically Macro")

2 Comments

Thanks for the answer, but that seems like too much for such a simple thing! I wonder why they don't make it as simple as "start debugging with step into".
@JuliánUrbano I agree, but it works: you can assign through that macro a keyboard shortcut for that specifc action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.