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.

Julián Urbano
  • 8,378
  • 1
  • 30
  • 52

2 Answers2

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

Holger
  • 285,553
  • 42
  • 434
  • 765
  • +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 – Julián Urbano Nov 15 '13 at 22:52
  • `F11` starts the last used configuration, but I don’t know whether there’s a key shortcut for switching between them. – Holger Nov 15 '13 at 23:11
  • 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. – Julián Urbano Nov 15 '13 at 23:13
4

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")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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án Urbano Nov 19 '13 at 13:59
  • @JuliánUrbano I agree, but it works: you can assign through that macro a keyboard shortcut for that specifc action. – VonC Nov 19 '13 at 15:26