我正在尝试将计算机上的 jdb 连接到 Android 设备上的进程(实际上是任何进程),但它根本不起作用。
所以我使用的命令直接来自 Google ADB 文档。首先我这样做
adb forward tcp:3456 jdwp:pid
然后我尝试使用jdb来尝试连接
jdb -attach emulatorIP:3456
但我收到以下错误:
java.io.IOException: shmemBase_attach failed: The system cannot find the file specified
at com.sun.tools.jdi.SharedMemoryTransportService.attach0(Native Method)
at com.sun.tools.jdi.SharedMemoryTransportService.attach(SharedMemoryTransportService.java:108)
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:63)
at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
Fatal error:
Unable to attach to target VM.
编辑:我有更多线索,但距离实际解决方案还差得很远。
出于某种原因,JDB -attach 默认使用共享内存方法进行调试,尽管所有文档都坚持指定主机名:端口作为 -attach 参数将强制它使用套接字进行远程调试。要强制执行此操作,您可以使用 ykw 的答案提供的命令,但表面上由于某些连接错误,它仍然失败。
经过进一步调查,发现 JDB 和 ADB 在某些未知资源上相互冲突,导致各种套接字连接错误。我当前的解决方法是完全关闭 ADB 并运行 JDB,然后当我完成 JDB 后,我让 ADB 重新上线。无论如何都是 Not Acceptable ,我希望这可以帮助有更深入知识的人找出问题所在!
最佳答案
您可以尝试输入以下命令:
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=3456
理论上,您应该得到以下输出:
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
但是,我得到了以下信息:
java.io.IOException: handshake failed - connection prematurally closed
at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136)
at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232)
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90)
at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
有谁知道为什么会这样吗?
好的...以上问题已经解决。这是由于 adb 调用之间的冲突造成的。在任何时间点都应该只运行 1 个 adb 实例。当 jdb 尝试连接而 adb 已在您的程序中运行时,就会发生这种情况。 jdb 在此状态下将永远无法成功附加。
TLDR 版本只需键入此答案顶部的命令,您就会得到预期的输出。
关于android - 连接 Android 设备时 shmemBase_attach 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37670487/