vscode-java-debug
vscode-java-debug copied to clipboard
Breakpoint on outer loop won't stop when using Resume (F5) after breaking once
When you put a breakpoint on a outer while loop in a method, the debugger break only once instead of for each loop executed. Also, a loop in a if won't work correctly. But if you have an inner loop (loop in a loop), the breakpoint work as expected, so the debugger break after each execution of the inner loop.
Environment
- Operating System: Windows 10
- JDK version: 17.0.8
- Visual Studio Code version: 1.83.1
- Java extension version: 1.24.0
- Java Debugger extension version: 0.55.0
Steps To Reproduce
Using this code: package sandbox;
public class At09Ex05 { public static void main(String[] args) { int nb1, nb2, som1, som2;
som1 = nb1 = 17;
som2 = nb2 = 7;
while (som1 != som2) {
while (som1 < som2) {
som1 += nb1;
}
while (som2 < som1) {
som2 += nb2;
}
}
System.out.println("Le PPCM de " + nb1 + " et " + nb2 + " est " + som1);
}
}
- Place a breakpoint on line : while (som1 != som2) {
- Run the debugger and the program stop at the breakpoint
- Use Resume (F5)
Current Result
The program run until the end when using F5 on the outer loop
Expected Result
Since the loop should execute a few times, Resume (F5) should stop again at the breakpoint after executing the loop.
Additional Informations
If you do the same test with a brepoint on the while (som1 < som2) { , the behaviour is correct. If you change while (som1 != som2) { for if (som1 != som2) { then the two inner loops have the problem.
@LeducNic I cannot reproduce it. See the screenshot below:
https://github.com/microsoft/vscode-java-debug/assets/14052197/e4d4139d-f996-47df-b32a-c7b2551c7f45
Do you use Oracle JDK or OpenJDK?
Hello,
I installed Oracle JDK 17.0.9 on a clean Windows 10 VM with VSCode 1.84.2 (user) and Java Extension Pack. I created a new text file named At09Ex05.java in my home directory and copied the main() as above. I don't use any project manager (like Maven) for my Java code. With only one breackpoint the code doesn't stop after reaching the breackpoint once. After that, I have put three breakpoints and you can see that only the last two breakpoints are working correctly. Can you give me more infos about your configuration?
Thank you very much for your help Nicolas
https://github.com/microsoft/vscode-java-debug/assets/13322252/6d67e0b5-9714-4769-b7d8-3ac183646117
I don't use any project manager (like Maven) for my Java code.
@LeducNic thanks for the information. The screenshot I shared is based on a gradle project, which delegates the build to the javac and the outer loop breakpoint works well.
And then I tried it with a no buildtool folder again, I can reproduce it. The no buildtool project will use the built-in compiler (ECJ) in Java language server to compile java files. Looks like the ECJ result is somehow different with javac. Anyway, I see the final running result is not affected, just the outer loop breakpoint is somehow broken in the ECJ case.
Thanks. Do you know if it is possible to use javac to compile the source when running/debugging with no build tools?
Thanks. Do you know if it is possible to use javac to compile the source when running/debugging with no build tools?
This requires a change in the infrastructure to use Javac instead of ECJ, which is a big decision that we need to evaluate more. At the moment we need to investigate this issue further to see if it's a common or corner case.
After some experimentation, I have found that the java assembly code generated for the loops by ECJ and javac are different. The ECJ code won't debug correctly with jdb, but the javac code work fine. Also, even the Eclipse debugger don't work correctly with the loops because the first press on continue won't do anything but after that Eclipse stop after each loop correctly. So maybe ECJ needs to generate code like javac for the loops?