Cannot attach GDB - Connection refused

606 views
Skip to first unread message

Ranjit

unread,
May 25, 2010, 10:22:48 PM5/25/10
to android-ndk
I am tyring to debug some JNI code running in the Android emulator.
Both the emulator and the host controlling the emulator are running on
the same Windows computer.

I did the following but I get a connection refused when I try to
attach gdb.

C:\android-sdk-windows\tools>adb shell
# gdbserver :12345 --attach 1478
gdbserver :12345 --attach 1478
Attached; pid = 1478
Listening on port 12345

$ /cygdrive/c/android-sdk-windows/android-ndk-r4/build/prebuilt/
windows/arm-eabi-4.2.1/bin/arm-eabi-gdb.exe
This GDB was configured as "--host=i686-pc-cygwin --target=arm-elf-
linux".
(gdb) target remote localhost:1234
localhost:1234: Connection refused.

What am I doing wrong?

Also, can someone explain the need for port forwarding if both the
debugger and the debuggee are running on the same computer?

Thanks,
Ranjit

Angus Lees

unread,
May 26, 2010, 3:01:57 AM5/26/10
to andro...@googlegroups.com
On Wed, May 26, 2010 at 12:22, Ranjit <ranji...@gmail.com> wrote:
> What am I doing wrong?

You use port 12345 in your gdbserver command and port 1234 in your gdb
target, which is fine but - you also need to use adb to forward the
host port to a port on the emulator (adb forward tcp:1234 tcp:12345 in
your example)

> Also, can someone explain the need for port forwarding if both the
> debugger and the debuggee are running on the same computer?

As far as gdb (and most of your system) is concerned, they are not
running on the same computer - it is almost impossible for a process
on your local machine to directly access a specific process inside the
Android emulator.
The emulator is a virtual machine and "adb" is effectively providing a
network connection between the real machine and the Android "machine".

- Gus

Ranjit

unread,
May 26, 2010, 6:48:05 PM5/26/10
to android-ndk
Thank you. Port forwarding did solve the issue and I can attach gdb to
the gdbserver.

On May 26, 12:01 am, Angus Lees <al...@google.com> wrote:

Reply all
Reply to author
Forward
0 new messages