“无法连接到远程虚拟机”将 jdb 连接到 Windows 上的 android 模拟器

发布于 2024-10-03 15:02:15 字数 983 浏览 5 评论 0原文

我一直在尝试将 jdb 连接到 android 模拟器一段时间,并且反复遇到:

jdb -sourcepath ./src -attach localhost:8700

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:90)
        at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:98)
        at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:45)
        at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:358)
        at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:168)
        at com.sun.tools.example.debug.tty.Env.init(Env.java:64)
        at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1010)

Fatal error:
Unable to attach to target VM.

不太好。解决这个问题的最佳方法是什么?我在 Windows 7 64 位上运行。

I’ve been trying to connect jdb to the android emulator for a little while, and have been met repeatedly with:

jdb -sourcepath ./src -attach localhost:8700

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:90)
        at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:98)
        at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:45)
        at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:358)
        at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:168)
        at com.sun.tools.example.debug.tty.Env.init(Env.java:64)
        at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1010)

Fatal error:
Unable to attach to target VM.

Not so great. What's the best way of getting round this? I'm running on Windows 7 64bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一萌ing 2024-10-10 15:02:15

目前这对我有用——创建一个套接字而不是共享内存连接。

>jdb –sourcepath .\src -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8700

事先你需要做一些设置——例如,看看这套 有关设置非 Eclipse 调试器的有用详细信息。它包含一个设置初始断点的好技巧——在主目录中创建或编辑 jdb.ini 文件,其内容如下:

stop at com.mine.of.package.some.AClassIn:14

它们将被加载并延迟到连接为止。

编辑:忘记引用Herong Yang的页面

Currently this is working for me -- making a socket rather than a shared memory connection.

>jdb –sourcepath .\src -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8700

Beforehand you need to do some setup -- for example, see this set of useful details on setting up a non-eclipse debugger. It includes a good tip for setting your initial breakpoint -- create or edit a jdb.ini file in your home directory, with content like:

stop at com.mine.of.package.some.AClassIn:14

and they'll get loaded and deferred until connection.

edit: forgot to reference Herong Yang's page.

云柯 2024-10-10 15:02:15

尝试退出 Android Studio。

由于 ADB 守护进程已经在运行,我在 Mac 上也遇到了类似的问题。退出任何正在运行的守护进程后,您应该会看到类似于以下内容的输出:

$ adb -d jdwp
28462
1939
^C
$ adb -d forward tcp:7777 jdwp:1939
$ jdb -attach localhost:7777 -sourcepath ./src
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> 

有关更多信息,请参阅我对类似问题的其他回答详细信息以及如何启动/停止守护进程。

Try quitting Android Studio.

I had a similar problem on the Mac due to the ADB daemon already running. Once you quit any running daemons, you should see output similar to the following:

$ adb -d jdwp
28462
1939
^C
$ adb -d forward tcp:7777 jdwp:1939
$ jdb -attach localhost:7777 -sourcepath ./src
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> 

See my other answer to a similar question for more details and how to start/stop the daemon.

_蜘蛛 2024-10-10 15:02:15

答案#1:将 localhost 映射到您的主机文件中,正如我之前链接到的。只是为了确定。

答案#2:如果您使用共享内存,位大小很容易成为问题。确保您在各处使用相同的字宽。

Answer #1: Map localhost in your hosts file, as I linked to earlier. Just to be sure.

Answer #2: If you're using shared memory, bit-size could easily become an issue. Make sure you're using the same word width everywhere.

攀登最高峰 2024-10-10 15:02:15

要调试应用程序,请按照以下步骤操作:

在设备上打开应用程序。

使用 jdwp 查找 PID(确保清单中的“android:debuggable”设置为 true):

adb jdwp

使用以下参数启动 JVM:

java -agentlib:jdwp=transport=dt_shmem,server=y,address=<port> <class>

此命令的预期输出:

Listening for transport dt_shmem at address: <port>

使用 jdb 附加应用程序:

jdb -attach <port>

如果 jdb 成功附加,我们将看到jdb cli。

例子:

> adb jdwp
  12300
> java -agentlib:jdwp=transport=dt_shmem,server=y,address=8700 com.app.app
  Listening for transport dt_shmem at address: 8700
> jdb -attach 8700
  main[1]

In order to debug application follow this steps:

Open the application on the device.

Find the PID with jdwp (make sure that 'android:debuggable' is set to true in the manifest):

adb jdwp

Start JVM with the following parameters:

java -agentlib:jdwp=transport=dt_shmem,server=y,address=<port> <class>

Expected output for this command:

Listening for transport dt_shmem at address: <port>

Use jdb to attach the application:

jdb -attach <port>

If jdb successful attached we will see the jdb cli.

Example:

> adb jdwp
  12300
> java -agentlib:jdwp=transport=dt_shmem,server=y,address=8700 com.app.app
  Listening for transport dt_shmem at address: 8700
> jdb -attach 8700
  main[1]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文