Wednesday, January 18, 2012

using gdbserver on android emulator

1. Make your library debugable (add -g options in makefile)
modify your Android.mk add below command "LOCAL_CPPFLAGS += -g" for C++ files and "LOCAL_CFLAGS += -G" FOR C files.
rebuild your library and system image(if necessary)

2. in your local system redirect the debug port
$ telnet localhost 5554
redir add tcp:1234:1234
exit

3.you can start emulator by below command with debug port redirected.
./emulator -avd avdname -qemu -redir udp:1234::1234

4. push gdbserver to emulator
adb push ./out/target/product/generic/obj/EXECUTABLES/gdbserver_intermediates/gdbserver /system/bin/

5. run # gdbserver :1234 --attach your-desired-pid or gdbserver :1234 desired_process

6. run ./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb ./out/target/product/generic/symbols/system/bin/app_process

7. in gdb-terminal
gdb>set solib-search-path out/target/product/generic/symbols/system/lib
In case there are multiple library paths to be searched, use ':' to concatenate the paths
gdb>target remote localhost:1234

8. Now you can see the Errors .... Happy remote Debugging!!!!

Common Error:

Malformed packet(b) (missing colon): re:0;
Packet: 'T050b:00000000;0d:c03ecebe;0f:b0070040;thread:4ab;core:0;'

This means the gdbserver and gdb in localhost are not compatible!!

4 comments:

AgNO3 said...

I am facing this commom error. Can neone help me to resolve it?

Shivram RV said...

hey,
AgNO3, if u are still facing the same error, pls share the details of ur gdb version

Unknown said...

I'm seeing that:
Malformed packet(b) (missing colon): re:0;

error, my Minix Neo X5 has a gdbserver that is configured:

This gdbserver was configured as "arm-elf-linux"

Where as the (Google) ARM NDK package I'm using provides a: arm-none-linux-gnueabi-gdb.exe configured as:

This GDB was configured as "--host=i686-mingw32 --target=arm-none-linux-gnueabi"

(I'm trying to compile and debug C (not C++, not particularly Android programs from a windows machine to the ARM in the Minxi Neo X5. gdb and gdbserver seem to be configured for arm and linux but that seem to not be enough. Any idea where to get a gdb (that I can use in Eclipse) that would work with that Arm system?

Unknown said...

Found a gdbserver/gdb pair that works on Minix Neo X5 (debugging from windows)

http://gnutoolchains.com/android/
http://gnutoolchains.com/android/7.4.1/arm-linux-android-gdb+gdbserver.zip