连接到Android设备时shmemBase_attach失败 [英] shmemBase_attach failed when connecting to Android device

查看:50
本文介绍了连接到Android设备时shmemBase_attach失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将计算机上的jdb连接到我的Android设备上的某个进程(实际上是任何进程),但这根本不起作用.

I'm trying to hook up jdb on my computer to a process (any process really) on my Android device, but it doesn't work at all.

因此,我使用的命令直接来自Google ADB文档.首先我要做

So the commands I used are straight off the Google ADB Documentation. First I do

adb forward tcp:3456 jdwp:pid

然后,我尝试使用jdb尝试进行连接

Then after that I try to use jdb to try to hook up

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.

我有更多潜在客户,但距离实际解决方案还差得远.

I have more leads, but I'm nowhere close to an actual solution.

由于某些原因,JDB -attach默认使用共享内存方法进行调试,尽管所有文档都坚持将hostname:port指定为-attach参数将迫使其使用套接字进行远程调试.要强制执行此操作,请使用ykw的答案提供的命令,但是由于某些连接错误,它显然还是失败了.

JDB -attach for some reason defaults to debugging using the shared memory method despite all documentation insisting that specifying hostname:port as the -attach parameters will force it to use sockets for remote debugging. To force it, you use the command provided by ykw's answer, but it fails anyway ostensibly due to some connection error.

经过进一步研究,似乎JDB和ADB在某些未知资源上相互冲突,从而导致各种套接字连接错误.我当前的解决方法是完全关闭ADB并运行JDB,然后在处理完JDB之后,使ADB重新联机.绝对不能接受,我希望这可以帮助具有更深入知识的人找出问题所在!

After further investigation it appears that JDB and ADB conflict with each other on some unknown resource causing the various socket connection errors. My current workaround is to shut down ADB completely and run JDB, then when I'm done with the JDB, I get the ADB back online. Not acceptable by any means and I'm hoping this helps someone with a more in-depth knowledge pinpoint what's wrong!

推荐答案

尝试退出Android Studio.

即使您的项目未运行,它的ADB仍在运行.这是一个示例,其中我退出Android Studio,运行ADB,在设备中启动我的应用程序,然后再次运行ADB以查看新的进程ID,转发端口并最终连接JDB:

Its ADB is running even when your project is not. Here is an example where I quit Android Studio, ran ADB, launched my app within the device, then ran ADB again to see the new process id, forwarded the port and finally attached JDB:

$ adb -d jdwp
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
28462
^C
$ 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 ...
> 

您还可以在Android Studio中打开和关闭ADB:

You can also turn ADB on and off within Android Studio:

Android Studio->工具-> Android->启用ADB集成

禁用ADB集成后,您可以照常从控制台运行ADB.您还可以使用以下方法控制和后台运行ADB守护程序:

When ADB integration is disabled, you can run ADB from the console as usual. You can also control and background ADB daemons with:

adb kill-server
adb start-server

我在此上浪费了几个小时,因此它确实需要更好的文档.我也想知道如何同时运行Android Studio调试器和JDB,以便在逐步调试器时可以分析所有方法调用(因为内置的Android Studio监视器跟踪不会显示连续的方法调用带有参数):

I wasted a couple of hours on this, so it really needs better documentation. Also I would like to know how to run both the Android Studio debugger and JDB at the same time so that I can profile all method calls while stepping through the debugger (because the built-in Android Studio monitor tracing doesn't show consecutive method calls with arguments):

http://mybrainoncode.com/blog/2013/11/03/debugging-android-with-jdb/

https://teaspoon-consulting.com/articles/tracing-java-method-calls.html

这篇关于连接到Android设备时shmemBase_attach失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆