2009年8月9日 星期日

How to use gdb and gdbserver to debug native applications on the Android platform

1.Disable sleep to prevent screen from going black while in the process of debugging.
Settings →Screen sleep timeout →Never

2.build codes:

source build/envsetup.sh
choosecombo 1 1 qsd8250_surf eng

mmm hello showcommands

or

cd ./hello
mm
mm showcommands


we can find that the not-stripped hello is out/target/product/qsd8250_surf/obj/EXECUTABLES/hello_intermediates/LINKED/hello and use the gcc flag "-g" to compile codes.


3.For target:

emulator @qustion
adb shell mkdir /data/debug
adb push ./out/target/product/qsd8250_surf/system/bin/hello /data/debug #在taget端hello可以是被strip的
adb shell gdbserver :5039 /data/debug/hello

4.For host:

adb forward tcp:5039 tcp:5039
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb ./out/target/product/qsd8250_surf/obj/EXECUTABLES/hello_intermediates/LINKED/hello
gdb>set solib-absolute-prefix ./out/target/product/qsd8250_surf/symbols
gdb>set solib-search-path ./out/target/product/qsd8250_surf/system/lib/
gdb>file ./out/target/product/qsd8250_surf/obj/EXECUTABLES/hello_intermediates/LINKED/hello #load the symbols of hello
gdb>target remote 127.0.0.1:5039
gdb>sharedlibrary
gdb>b jeff_func
gdb>c

reference:
"MSM7xxx/QSD8xxx Android™ Debug Guide" 80-VM989-1 B
http://groups.google.com/group/android-framework/browse_thread/thread/f3a9fbdef44c1366?fwc=1
http://checko.blogspot.com/2006/05/use-gdbserver-and-gdb-remote-debugging.html

hello.c:

#include

char * jeff_func(){

printf("enter func...ddddd\n");
return "Jeff";
}

int main(){

printf("Hello the world!!\n");

printf("Hello %s!!\n",jeff_func());

return 0;
}

Android.mk:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= hello.c

LOCAL_C_INCLUDES += frameworks/base/include system/core/include

LOCAL_MODULE:= hello

include $(BUILD_EXECUTABLE)

1 則留言:

Trilim 提到...

Lenovo Rocket? WNC?