2013年9月21日 星期六

Eclipse debug Android framework and service

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

//////////////////////////////////////////////
////////Debug surfaceflinger////////
//////////////////////////////////////////////
1.
gedit ~/OK8MM-android-source/frameworks/native/services/surfaceflinger/Android.mk
//add
LOCAL_CFLAGS += -O0 -g
LOCAL_CPPFLAGS += -O0 -g
LOCAL_STRIP_MODULE := false

//If use Android.bp then add flags in all Android.bp under surfaceflinger
cflags: [
      "-Wno-unused-parameter"
    "-O0",
    "-g",
],

cppflags: [
      "-Wno-unused-parameter"
    "-O0",
    "-g",
],

strip: {
        none: true,
    },

2. build and burn
//build
cd ~/OK8MM-android-source
source build/envsetup.sh
lunch evk_8mm-userdebug
cd ~/OK8MM-android-source/frameworks/native/services/surfaceflinger
mm

//burn
cd [your project]
source build/envsetup.sh
lunch evk_8mm-userdebug
export ANDROID_PRODUCT_OUT=~/OK8MM-android-source/out/target/product/evk_8mm
adb root
adb disable-verity
adb remount
adb sync system
 
3.
gedit ~/OK8MM-android-source/frameworks/native/services/surfaceflinger/gdb-androidx.cmds
//add
set solib-absolute-prefix ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols
set solib-search-path ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/lib:~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/bin

//If use aarch64 gdb and libs
set directories ~/OK8MM-android-source
set solib-absolute-prefix ~/OK8MM-android-source/out/target/product/evk_8mm/symbols
set solib-search-path ~/OK8MM-android-source/out/target/product/evk_8mm/symbols/system/lib64:~/OK8MM-android-source/out/target/product/evk_8mm/symbols/system/bin

ps: set directories can make aarch64 gdb find absolute path, important!

4. Run eclipse
File -> New -> Makefile Project with Existing Code -> Android GCC
project name: surfaceflinger
Existing Code Location: ~/OK8MM-android-source/frameworks/native/services/surfaceflinger

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

6. in Main tab
Name: surfaceflingerC++
C/C++ Application: ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/bin/surfaceflinger
Project: surfaceflinger
disable auto build

7. in Debugger tab
into Main
GDB debugger: ~/OK8MM-android-source/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gdb
GDB command file: ~/OK8MM-android-source/frameworks/native/services/surfaceflinger/gdb-androidx.cmds
enable -> Force thread list update on suspend

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

//If in aarch64 then use aarch64-linux-android-gdb

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

9.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)
or
gdbserver64 :5039 --attach $(pgrep -f surfaceflinger)

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

//////////////////////////////////////////////
/////Debug libaudioFlinger.so//////
//////////////////////////////////////////////
1.
gedit ~/OK8MM-android-source/frameworks/av/services/audioflinger/Android.mk
gedit ~/OK8MM-android-source/frameworks/av/media/mediaserver/Android.mk
//Both add
LOCAL_CFLAGS += -O0 -g
LOCAL_CPPFLAGS += -O0 -g
LOCAL_STRIP_MODULE := false

//If use Android.bp then add
cflags: [
      "-Wno-unused-parameter"
    "-O0",
    "-g",
],

cppflags: [
      "-Wno-unused-parameter"
    "-O0",
    "-g",
],

strip: {
        none: true,
    },

2. Go to mediaserver and audioflinger directories build and burn
//build
cd ~/OK8MM-android-source
source build/envsetup.sh
lunch evk_8mm-userdebug
cd ~/OK8MM-android-source/frameworks/av/services/audioflinger
mm
cd ~/OK8MM-android-source/frameworks/av/media/mediaserver
mm

//burn
cd [your project]
source build/envsetup.sh
lunch evk_8mm-userdebug
export ANDROID_PRODUCT_OUT=~/OK8MM-android-source/out/target/product/evk_8mm
adb root
adb disable-verity
adb remount
adb sync system

3.
gedit ~/OK8MM-android-source/frameworks/av/media/mediaserver/gdb-android.cmds
set solib-absolute-prefix ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols
set solib-search-path ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/lib:~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/bin

//If use aarch64 gdb and libs
set directories ~/OK8MM-android-source
set solib-absolute-prefix ~/OK8MM-android-source/out/target/product/evk_8mm/symbols
set solib-search-path ~/OK8MM-android-source/out/target/product/evk_8mm/symbols/system/lib64:~/OK8MM-android-source/out/target/product/evk_8mm/symbols/system/bin

ps: set directories can make aarch64 gdb find absolute path, important!

4. Run eclipse
File -> New -> Makefile Project with Existing Code -> Android GCC
project name: mediaserver
Existing Code Location: ~/OK8MM-android-source/frameworks/av/media/mediaserver

5.
Audioflinger directory at ~/OK8MM-android-source/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

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

7. in Main tab
Name: mediaserverC++
C/C++ Application: ~/OK8MM-android-source/out/matrix_io/android/target/product/matrix_io/symbols/system/bin/mediaserver
Project: mediaserver
disable auto build

8. in Debugger tab
into Main
GDB debugger: ~/OK8MM-android-source/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gdb
GDB command file: ~/OK8MM-android-source/frameworks/av/media/mediaserver/gdb-androidx.cmds
enable -> Force thread list update on suspend

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

//If in aarch64 then use aarch64-linux-android-gdb

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

10.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)
or
gdbserver64 :5039 --attach $(pgrep -f mediaserver)

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

Android 9 surfaceflinger patch for debugging:
http://www.mediafire.com/file/k124dslt4zvxcvu/surfaceflinger_resource.tar.gz

Android GDB aarch64 with liblzma build script: Android 9 gdbserver64 need gdb send 64 bits address. gdb maybe need lzma debug format:
http://www.mediafire.com/file/fi4mstilpruspkv/build_aarch64_gdb.sh
http://www.mediafire.com/file/a1xeyw0l3nvhrid/build_aarch64_lzma_gdb.sh

Eclipse Luna SR2 64bits linux ADT + CDT + Openocd on Java8. Extract to /opt/eclipse_luna
http://www.mediafire.com/file/8fb3dsi88j5iru9/eclipse_luna_adt_cdt_openocd.tar.gz

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

沒有留言:

張貼留言