Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Failed to attach to the remote VM" connecting jdb to the android emulator on Windows

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.

like image 692
Tim Barrass Avatar asked Nov 18 '10 22:11

Tim Barrass


2 Answers

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.

like image 137
Tim Barrass Avatar answered Sep 20 '22 13:09

Tim Barrass


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.

like image 31
Zack Morris Avatar answered Sep 18 '22 13:09

Zack Morris