0

I've been trying to run jdb to try and get it attached to a process on my android device.

The commands I've tried are as follows:

adb forward tcp:12345 jdwp:4127

jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=12345

We can assume that process with pid 4127 is still alive.

However, after the 2 commands are entered, I received the error message as follows:

java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:130)
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)

I've noticed a strange behaviour that this output only occurs when 1 of my applications is running. Could this be due to a clash of threads or processes or ports while the program is running?

I can get the following output most of the time when I that particular application is closed:

Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> Input stream closed.

I've also tried running the command prompt in Administrator mode with the following steps:

netsh advfirewall set global StatefulFTP disable
adb forward tcp:12345 jdwp:4127
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=12345

The output is as follows:

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)

Fatal error:
Unable to attach to target VM.
ykw
  • 91
  • 3
  • 9

2 Answers2

1

Try quitting Android Studio.

The problem is that Android Studio keeps its ADB running, which conflicts with yours. See my answer to your similar question for more details.

Zack Morris
  • 4,727
  • 2
  • 55
  • 83
0

The problem lies with my program starting an instance of android debug bridge. When my program tries to run jdb, a race condition for ADB occurs. Since my program already creates an instance of ADB before it runs jdb, jdb will never be able to attach successfully. Even running jdb through command prompt gives the same result. Closing my program destroys the instance of ADB and that is why I can run jdb through command prompt after my program closes.

I hope my answer will provide some clues as to why such a phenomenon happens.

ykw
  • 91
  • 3
  • 9