2013年9月20日 星期五

Android + Eclipse debug shared library & daemon service

To prepare Eclipse:
http://fatalfeel.blogspot.tw/2013/09/eclipse-setting-for-ubuntu-imx6-android.html

//////////////////////////////////////////////
////////Debug surfaceflinger////////
//////////////////////////////////////////////
1.
gedit /mnt/projects/marsh_mnt/myandroid/frameworks/native/services/surfaceflinger/Android.mk
add
LOCAL_CFLAGS += -O0 -g
LOCAL_CPPFLAGS += -O0 -g
LOCAL_STRIP_MODULE := false

//then build and burn to target

2.
gedit /mnt/projects/marsh_mnt/myandroid/frameworks/native/services/surfaceflinger/gdb-android.cmds
add
set solib-absolute-prefix /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols
set solib-search-path /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/lib:/mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/bin

3. Run eclipse
File -> New -> Makefile Project with Existing Code -> Android GCC
project name: surfaceflinger
Existing Code Location: /mnt/projects/marsh_mnt/myandroid/frameworks/native/services/surfaceflinger

4. In Eclipse right click project
Debug As -> Debug Configurations -> C/C++ Remote Application (double click)

5. in Main tab
Name: surfaceflingerC++
C/C++ Application: /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/bin/surfaceflinger
Project: surfaceflinger
disable auto build

6. in Debugger tab
into Main
GDB debugger: /mnt/projects/marsh_mnt/myandroid/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gdb
GDB command file: /mnt/projects/marsh_mnt/myandroid/frameworks/native/services/surfaceflinger/gdb-android.cmds
enable -> Force thread list update on suspend

into Connection
Type:TCP
Host name or IP address: localhost
port number: 5039

7.in client terminal
adb forward tcp:5039 tcp:5039
* daemon started successfully *

8.in target terminal
su //change to root
ps | grep surfaceflinger
system    223   1     174984 9288  SyS_epoll_ 00000000 S /system/bin/surfaceflinger
gdbserver :5039 --attach 223
or
gdbserver :5039 --attach $(pgrep -f surfaceflinger)

9.
set breakpoint at onDispSyncEvent of SurfaceFlinger.cpp
right click project
Debug As -> Debug Configurations -> surfaceflingerC++
click Debug

//////////////////////////////////////////////
/////Debug libaudioFlinger.so//////
//////////////////////////////////////////////
1.
gedit /mnt/projects/marsh_mnt/myandroid/frameworks/av/services/audioflinger/Android.mk
gedit /mnt/projects/marsh_mnt/myandroid/frameworks/av/media/mediaserver/Android.mk
//Both add
LOCAL_CFLAGS += -O0 -g
LOCAL_CPPFLAGS += -O0 -g
LOCAL_STRIP_MODULE := false

//then build and burn to target

2.
gedit /mnt/projects/marsh_mnt/myandroid/frameworks/av/media/mediaserver/gdb-android.cmds
set solib-absolute-prefix /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols
set solib-search-path /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/lib:/mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/bin

3. Run eclipse
File -> New -> Makefile Project with Existing Code -> Android GCC
project name: mediaserver
Existing Code Location: /mnt/projects/marsh_mnt/myandroid/frameworks/av/media/mediaserver

4.
Audioflinger directory at /mnt/projects/marsh_mnt/myandroid/frameworks/av/services/audioflinger
In file manager, drag Audioflinger directory to Eclipse mediaserver project
then show [File and Folder Operation] box
select Link to files and folders
check Create link locations relative to: PROJECT_LOC

5. In Eclipse right click project
Debug As -> Debug Configurations -> C/C++ Remote Application (double click)

6. in Main tab
Name: mediaserverC++
C/C++ Application: /mnt/projects/marsh_mnt/out/matrix_io/android/target/product/matrix_io/symbols/system/bin/mediaserver
Project: mediaserver
disable auto build

7. in Debugger tab
into Main
GDB debugger: /mnt/projects/marsh_mnt/myandroid/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gdb
GDB command file: /mnt/projects/marsh_mnt/myandroid/frameworks/av/media/mediaserver/gdb-android.cmds
enable -> Force thread list update on suspend

into Connection
Type:TCP
Host name or IP address: localhost
port number: 5039

8.in client terminal
adb forward tcp:5039 tcp:5039
* daemon started successfully *

9.in target terminal
su //change to root
ps | grep mediaserver
system    223   1     174984 9288  SyS_epoll_ 00000000 S /system/bin/mediaserver
gdbserver :5039 --attach 223
or
gdbserver :5039 --attach $(pgrep -f mediaserver)

10.
set breakpoint at AudioFlinger::createTrack of AudioFlinger.cpp
right click project
Debug As -> Debug Configurations -> mediaserverC++
click Debug

Ref:
http://apienthusiast.blogspot.tw/2014/07/debugging-android-native-applications.html


Download:
http://www.mediafire.com/download/r7mbh1hak06607a/Android-App-Debug.zip

沒有留言:

張貼留言