fwcd / kotlin-debug-adapter

Kotlin/JVM debugging for any editor/IDE using the Debug Adapter Protocol
MIT License
110 stars 19 forks source link

* Fix Spring Boot project debugging bugs. #40

Closed MrRogerHuang closed 3 years ago

MrRogerHuang commented 3 years ago

When I debug a Spring Boot program by attaching, I find a breakpoint works only once. If I run "continue," the breakpoint will not be hit again.

I refer to the code to fix this bug: https://github.com/microsoft/java-debug/blob/27e3c455f8627ac895d49a5633409689e7fff6b4/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSession.java#L64 I guess kotlin-debug-adapter misses a line to resume VM? I am not sure. Nevertheless, changes of my commit does fix this problem in my manual test. 🙂

Steps to reproduce the bug:

  1. Run
    git clone https://github.com/MrRogerHuang/SpringBootExample
    cd SpringBootExample
    ./gradlew bootRun --debug-jvm
    code .
  2. Open src/main/kotlin/com/example/demo/DemoApplication.kt.
  3. Set a breakpoint to this line: https://github.com/MrRogerHuang/SpringBootExample/blob/e92ad942ddaf656c81d02ebd1026ab10d75693e5/src/main/kotlin/com/example/demo/DemoApplication.kt#L13
  4. Run Kotlin Attach 4.1 (update) Detach the debugger and wait Spring Boot example run to a message line like: 2020-06-29 13:57:01.030 INFO 42742 --- [ restartedMain] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 651.506 seconds (JVM running for 657.988) 4.2 (update) Run Kotlin Attach again.
  5. Open the URL by your browser: http://localhost:8080/hello You will find VS Code correctly hit the breakpoint.
  6. Press Continue
  7. Reload http://localhost:8080/hello again. You will find VS Code can't hit the breakpoint anymore ☹️
MrRogerHuang commented 3 years ago

Steps to reproduce the bug:

  1. Run
git clone https://github.com/MrRogerHuang/SpringBootExample
cd SpringBootExample
./gradlew bootRun --debug-jvm
code .
  1. Open src/main/kotlin/com/example/demo/DemoApplication.kt.
  2. Set a breakpoint to this line: https://github.com/MrRogerHuang/SpringBootExample/blob/e92ad942ddaf656c81d02ebd1026ab10d75693e5/src/main/kotlin/com/example/demo/DemoApplication.kt#L13
  3. Run Kotlin Attach
  4. Open the URL by your browser: http://localhost:8080/hello You will find VS Code correctly hit the breakpoint.
  5. Press Continue
  6. Reload http://localhost:8080/hello again. You will find VS Code can't hit the breakpoint anymore ☹️

Sorry, there is still another bug in kotlin-debug-adapter I don't fix, so that this bug can't be correctly reproduced using steps above. One workaround requires the two additional steps: Step 4.1 Detach the debugger and wait Spring Boot example run to a message line like: 2020-06-29 13:57:01.030 INFO 42742 --- [ restartedMain] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 651.506 seconds (JVM running for 657.988) Step 4.2 Run Kotlin Attach again.

MrRogerHuang commented 3 years ago

This commit 58d817d fixes parts of the following problem.

Sorry, there is still another bug in kotlin-debug-adapter I don't fix, so that this bug can't be correctly reproduced using steps above. One workaround requires the two additional steps: Step 4.1 Detach the debugger and wait Spring Boot example run to a message line like: 2020-06-29 13:57:01.030 INFO 42742 --- [ restartedMain] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 651.506 seconds (JVM running for 657.988) Step 4.2 Run Kotlin Attach again.

However, there is still a bug such that we have to run steps 4.1 and 4.2 to reproduce the first bug in this issue.

MrRogerHuang commented 3 years ago

The commit 4268081 fixes the threads update bug that kotlin-debug-adapter responds outdated threads after a stop event to vscode-kotlin extension, so that vscode can't correctly hit a break point. Then, user can't run continue function through vscode. It results in a deadlock between vscode and the debuggee program.

Now, the Spring Boot example works well with this version of kotlin-debug-adapter 🙂

MrRogerHuang commented 3 years ago

Sorry, commits 80ccf0e and 3cf2029 results in gradlew check deadlock. However, they are not related to Spring Boot project debugging bugs . I make a force push to the commit 4268081 and please merge it. Thanks.

MrRogerHuang commented 3 years ago

I fix a minor bug in commit 76fade5. Please merge it. Thanks.