emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.29k stars 180 forks source link

[Java] Debugging session not working since Java 11 #273

Open mpsq opened 4 years ago

mpsq commented 4 years ago

I am trying to have the debugger working with my Java project.

The app relies on 1 external argument to be set in order to run, therefore I created my own launch debugging template with:

(dap-register-debug-template "Debug"
                             (list :type "java"
                                   :request "launch"
                                   :args "-d /var/lib/stuff"
                                   :mainClass "io.questdb/io.questdb.ServerMain"))

But when I try to run the template, I get the error:

Warning (emacs): Initialize request failed: Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.

With the stack trace:

com.microsoft.java.debug.core.DebugException: Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.
    at com.microsoft.java.debug.core.adapter.AdapterUtils.createCompletionException(AdapterUtils.java:259)
    at com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handleLaunchCommand(LaunchRequestHandler.java:88)
    at com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handle(LaunchRequestHandler.java:80)
    at com.microsoft.java.debug.core.adapter.DebugAdapter.lambda$dispatchRequest$0(DebugAdapter.java:87)
    at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1106)
    at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2235)
    at com.microsoft.java.debug.core.adapter.DebugAdapter.dispatchRequest(DebugAdapter.java:86)
    at com.microsoft.java.debug.core.adapter.ProtocolServer.dispatchRequest(ProtocolServer.java:118)
    at com.microsoft.java.debug.core.protocol.AbstractProtocolServer.lambda$new$0(AbstractProtocolServer.java:78)
    at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:60)
    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)
    at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
    at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
    at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

I spent quite a long time debugging this + I tried to set modulePaths and/or classPaths but nothing seems to be fixing it. It is worth noticing that everything was working fine with Java 8, but after migrating to Java 11 the module io.questdb seems to be an issue.

Notes:

Based on this I am not sure what is wrong, is seems to me that dap-java.el is not necessarily producing the correct command in the context of Java 11 with modules? Or maybe there is a bug in java-debug and the module is not identified properly?

Thanks for your help

yyoncho commented 4 years ago

Have you tried like this:

:args ["-d" "/var/lib/stuff"]

mpsq commented 4 years ago

Yes, I tried with only :type "java" :args ["-d" "/var/lib/stuff"] and I get the same issue.

yyoncho commented 4 years ago

ok, can you set dap-print-io to t and provide the logs from Messages buffer.

mpsq commented 4 years ago

I get the following:

Sending: 
{
  "command": "initialize",
  "arguments": {
    "clientID": "vscode",
    "clientName": "Visual Studio Code",
    "adapterID": "java",
    "pathFormat": "path",
    "linesStartAt1": true,
    "columnsStartAt1": true,
    "supportsVariableType": true,
    "supportsVariablePaging": true,
    "supportsRunInTerminalRequest": true,
    "locale": "en-us"
  },
  "type": "request",
  "seq": 1
}
Received:
{
  "type": "response",
  "seq": 1,
  "body": {
    "supportsDataBreakpoints": true,
    "exceptionBreakpointFilters": [
      {
        "filter": "uncaught",
        "label": "Uncaught Exceptions"
      },
      {
        "filter": "caught",
        "label": "Caught Exceptions"
      }
    ],
    "supportsExceptionInfoRequest": true,
    "supportsLogPoints": true,
    "supportsDelayedStackTraceLoading": null,
    "supportTerminateDebuggee": true,
    "supportsRestartRequest": null,
    "supportsSetVariable": true,
    "supportsRestartFrame": true,
    "supportsCompletionsRequest": true,
    "supportsEvaluateForHovers": true,
    "supportsConditionalBreakpoints": true,
    "supportsHitConditionalBreakpoints": true,
    "supportsConfigurationDoneRequest": true
  },
  "command": "initialize",
  "request_seq": 1,
  "success": true
}
Sending: 
{
  "command": "launch",
  "arguments": {
    "type": "java",
    "args": "-d /home/mpsq/.questdb",
    "mainClass": "io.questdb/io.questdb.ServerMain",
    "projectName": "core",
    "cwd": "/home/mpsq/quest/questdb/",
    "stopOnEntry": false,
    "host": "localhost",
    "console": "internalConsole",
    "request": "launch",
    "modulePaths": [],
    "name": "ServerMain (core)",
    "debugServer": 45923,
    "__sessionId": "1589268537.356324"
  },
  "type": "request",
  "seq": 2
}
Received:
{
  "type": "response",
  "seq": 2,
  "body": {
    "error": {
      "format": "Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.",
      "id": 1004
    }
  },
  "command": "launch",
  "request_seq": 2,
  "message": "Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.",
  "success": null
}
Debug session process exited with status: deleted
mpsq commented 4 years ago

When I do the same in VSCode I get:


!ENTRY java-debug 1 0 2020-05-12 08:54:19.283
!MESSAGE 
[request]
{
    "command": "launch",
    "arguments": {
        "type": "java",
        "name": "Debug (Launch)-ServerMain<core>",
        "request": "launch",
        "mainClass": "io.questdb/io.questdb.ServerMain",
        "args": "-d /home/mpsq/.questdb",
        "projectName": "core",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "modulePaths": [
            "/home/meril/quest/questdb/core/target/classes",
            "/home/meril/.m2/repository/org/jetbrains/annotations/17.0.0/annotations-17.0.0.jar"
        ],
        "classPaths": [],
        "javaExec": "/usr/lib/jvm/java-11-openjdk/bin/java",
        "cwd": "/home/mpsq/quest/questdb",
        "shortenCommandLine": "argfile",
        "debugServer": 42101,
        "__sessionId": "527d3501-e08e-436f-af1b-93672daf5515"
    },
    "type": "request",
    "seq": 2
}

!ENTRY java-debug 1 0 2020-05-12 08:54:19.284
!MESSAGE Trying to launch Java Program with options:
main-class: io.questdb/io.questdb.ServerMain
args: -d /home/mpsq/.questdb
module-path: 
class-path: 
vmArgs: -Dfile.encoding=UTF-8 @/tmp/cp_5e9x0velhy4p83z3u6z8odyn2.argfile

!ENTRY java-debug 1 0 2020-05-12 08:54:19.284
!MESSAGE 
[[REQUEST]]
Content-Length: 445
{
    "command": "runInTerminal",
    "arguments": {
        "kind": "integrated",
        "title": "Java Debug Console",
        "cwd": "/home/meril/quest/questdb",
        "args": [
            "/usr/lib/jvm/java-11-openjdk/bin/java",
            "-agentlib:jdwp\u003dtransport\u003ddt_socket,server\u003dn,suspend\u003dy,address\u003dlocalhost:37509",
            "-Dfile.encoding\u003dUTF-8",
            "@/tmp/cp_5e9x0velhy4p83z3u6z8odyn2.argfile",
            "-m",
            "io.questdb/io.questdb.ServerMain",
            "-d",
            "/home/mpsq/.questdb"
        ]
    },
    "seq": 2,
    "type": "request"
}

!ENTRY java-debug 1 0 2020-05-12 08:54:19.323
!MESSAGE 
[response]
{
    "type": "response",
    "seq": 3,
    "command": "runInTerminal",
    "request_seq": 2,
    "success": true,
    "body": {
        "shellProcessId": 7895
    }
}
mpsq commented 4 years ago

If I set the modulePaths manually:

:modulePaths [
  "/home/mpsq/quest/questdb/core/target/classes"
  "/home/mpsq/.m2/repository/org/jetbrains/annotations/17.0.0/annotations-17.0.0.jar"
]

It actually works. I suspect there is an issue with the way we retrieve the modulePaths automatically when not set.

yyoncho commented 4 years ago

this part is not there i think, I will fix the template later today and ask you to test.

serezlan commented 3 years ago

Hello, I think I also hit the same wall. I still had to update modulePaths manually to get it to work. Any update on this issue?

Thanks

mpsq commented 3 years ago

This issue is actually fixed for me, since Ivan's update it works nicely on my side.

serezlan commented 3 years ago

I've just update my lsp and dap and still got the same result. Am I missing something here?

  1. Create simple maven command line project
  2. Set to target java 1.9
  3. Add module-info.java in src/main/java
  4. At this point, everything is compiled just fine.
  5. Run dap-debug and select "Java Run Configuration"
  6. Received error "Missing module path"

And here is log from dap:

Sending: { "command": "launch", "arguments": { "name": "Java Run Configuration<3>", "type": "java", "request": "launch", "args": "", "cwd": "/tmp/delta/mazda/", "stopOnEntry": false, "host": "localhost", "modulePaths": [], "classPaths": [], "projectName": "mazda", "mainClass": "com.serezlan.mazda/com.serezlan.mazda.App", "console": "internalConsole", "debugServer": 45255, "__sessionId": "1616041551.2389154" }, "type": "request", "seq": 2 } Received: { "success": null, "message": "Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.", "request_seq": 2, "command": "launch", "body": { "error": { "id": 1004, "format": "Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration." } },

As additional info: