You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将jdb连接到jhsdb debugd调试服务器进程?

如何将jdb连接到jhsdb启动的调试服务器?

当尝试调试未通过-agentlib:jdwp=transport=dt_socket,...启动的Java进程时,我使用以下命令启动了调试服务器:

jhsdb debugd --pid <jvm_pid>

需要将jdb进程连接到该调试服务器。

通过jdb -listconnectors | Select-String 'Connector'列出的可用连接器如下:

Connector: com.sun.jdi.ProcessAttach  Transport: local
  Connector: com.sun.jdi.RawCommandLineLaunch  Transport: dt_shmem
  Connector: com.sun.jdi.SocketAttach  Transport: dt_socket
  Connector: com.sun.jdi.SocketListen  Transport: dt_socket
  Connector: com.sun.jdi.CommandLineLaunch  Transport: dt_shmem
  Connector: com.sun.jdi.SharedMemoryAttach  Transport: dt_shmem
  Connector: com.sun.jdi.SharedMemoryListen  Transport: dt_shmem

已尝试的连接方式及问题

  1. SocketAttach连接失败
    执行命令:
jdb -connect com.sun.jdi.SocketAttach:port=<port>

报错信息:

java.io.IOException: handshake failed - connection prematurally closed
        at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:139)
        at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:273)
        at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
        at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:563)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:369)
        at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
        at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1176)

尝试了jhsdb监听的所有端口,均失败。

  1. ProcessAttach连接目标JVM进程
    执行命令:
jdb -connect com.sun.jdi.ProcessAttach:pid=<jvm_pid>

命令无限挂起,无任何输出。

  1. ProcessAttach连接jhsdb进程
    执行命令:
jdb -connect com.sun.jdi.ProcessAttach:pid=<jhsdb_pid>

报错信息:

java.io.IOException: Not a debuggee, or not listening for debugger to attach
        at jdk.jdi/com.sun.tools.jdi.ProcessAttachingConnector.attach(ProcessAttachingConnector.java:114)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:563)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:369)
        at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
        at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1176)

Fatal error:
Unable to attach to target VM.

环境:Windows 11 x86_64,Oracle JDK 21。


正确的连接方法

在Windows系统上,jhsdb debugd默认使用**共享内存(dt_shmem)**作为传输方式,而非Socket,因此需要使用SharedMemoryAttach连接器进行连接:

方法1:使用自动生成的共享内存名称

  1. 启动jhsdb debugd后,控制台会输出类似Debugger listening on shmem://<debug_name>的信息,记录下<debug_name>;
  2. 执行以下命令连接:
jdb -connect com.sun.jdi.SharedMemoryAttach:name=<debug_name>

方法2:手动指定共享内存名称

启动jhsdb时手动设置服务器名称,避免自动生成的随机名称:

jhsdb debugd --pid <jvm_pid> --servername my_debug_server

然后执行连接命令:

jdb -connect com.sun.jdi.SharedMemoryAttach:name=my_debug_server

内容的提问来源于stack exchange,提问作者czerny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 15:14:52