2013年9月18日 星期三

Eclipse debug Android jni c/c++ of installed app on Ubuntu

////////////////eclipse setting//////////////////
http://www.eclipse.org/downloads/packages/release/Kepler/SR2
Eclipse Standard 4.3.2 -> linux 64bits
install eclipse-standard-kepler-SR2-linux-gtk-x86_64.tar.gz
extract to /opt/eclipse
chmod 755 -R /opt/eclipse

gedit /opt/eclipse.ini
-XX:PermSize=64m
-XX:MaxPermSize=256m
-Xms128m
-Xmx4096m

//android sdk path
http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2
install ndk to /opt/android-ndk-r8e
chmod 755 -R /opt/android-ndk-r8e

http://dl.google.com/android/android-sdk_r22.2.1-linux.tgz
install android sdk to /opt/android-sdk-linux

http://dl-ssl.google.com/android/repository/platform-tools_r18.0.1-linux.zip
install android sdk platform-tools to /opt/android-sdk-linux
chmod 755 -R /opt/android-sdk-linux

//start eclipse
help -> install new software
[work with]: Kepler - http://download.eclipse.org/releases/kepler
install cdt
programming -> c++ development tools
programming -> c++ development tools sdk

http://dl.google.com/android/ADT-22.2.1.zip
help -> install new software
Add... -> Archive... -> ADT-22.2.1.zip

window -> android sdk manager
install only
1.android sdk build-tools 18.1.1
2.android api 4.3 api 18

window -> perferences -> android
sdk location:/opt/android-sdk-linux
ndk location:/opt/android-ndk-r8e

//If you want to use Android 5.1.1(API 22) refer to here
https://fatalfeel.blogspot.tw/2013/09/build-eclipse-debug-environment-for.html

/////////////////////jni setting///////////////
//path
gedit /etc/environment
add
/opt/android-ndk-r8e
reboot

/////ndk modify
gedit /opt/android-ndk-r8e/ndk-gdb

//find
APP_PROCESS=$APP_OUT/app_process
run adb_cmd pull /system/bin/app_process `native_path $APP_PROCESS`
log "Pulled app_process from device/emulator."
//modify to
APP_PROCESS=$APP_OUT/app_process
if [ "$API_LEVEL" -lt "21" ] ; then
    run adb_cmd pull /system/bin/app_process `native_path $APP_PROCESS`
    log "Pulled app_process from device/emulator to $APP_PROCESS"
else
    run adb_cmd pull /system/bin/app_process32 `native_path $APP_PROCESS`
    log "Pulled app_process32 from device/emulator to $APP_PROCESS"
fi
//save to  ndk-gdb

//NKD r10e
gedit /opt/android-ndk-r10e/ndk-gdb
#adb_var_shell BCFILES run-as $PACKAGE_NAME /system/bin/sh -c "ls lib/*.bc"
to
adb_var_shell BCFILES run-as $PACKAGE_NAME /system/bin/sh -c '"ls lib/*.bc"'
//save to ndk-gdb

cp /opt/android-ndk-xxx/ndk-gdb /opt/android-ndk-xxx/ndk-gdb-eclipse
gedit /opt/android-ndk-xxx/ndk-gdb-eclipse
//remove
$GDBCLIENT -x `native_path $GDBSETUP`
//save to ndk-gdb-eclipse

gedit ~/jni/Android.mk
//add after LOCAL_MODULE
LOCAL_STRIP_MODULE := false

//build c++ debug
convert c/c++
right click file > new > other
convert c/c++
makefile project = android gcc

properties > c/c++ build
uncheck [use defaultbuild command]
[build command]: ndk-build NDK_DEBUG=1 V=1

//generate process
Debug As -> Android Application
install to target and run it once

open new Termial
cd /root/nativeeglexample
ndk-gdb --start
then press q, press y
generate 2 files
/root/nativeeglexample/obj/local/armeabi-v7a/app_process
/root/nativeeglexample/obj/local/armeabi-v7a/gdb.setup

gedit /root/nativeeglexample/obj/local/armeabi-v7a/gdb.setup
//remove line
target remote :5039
//save as gdb_eclipse.setup

//Debugger menu popup for gdbserver
Debug As->Debug configurations, double click [C/C++ Application]
click into bottom line -Select other...-
enable [Use configuration specific settings]
select [Standard Create Process Launcher]
(Linux => [Legacy Create Process Launcher])

(1)[Main] > [C/C++ Application:] obj/local/armeabi-v7a/app_process
(2)[Debugger:] GdbServer
(3)[Stop on starup at:] Java_com_example_NativeEglExample_nativeOnStart
(4)[GDB debugger:] /opt/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb
(5)[GDB command file:] /root/nativeeglexample/obj/local/armeabi-v7a/gdb-eclipse.setup
(6)[Verbose console mode] enable it. For watching running text
(7)[Connection] > [Type:] TCP
(8)[Host name or Ip address:] localhost
(9)[Port number:] 5039

//breakpoint
breakpoint at super.onCreate(savedInstanceState);
Debug As -> Android Application
when stop at super.onCreate(savedInstanceState);

open new Termial
cd /root/nativeeglexample
ndk-gdb-eclipse

Debug As -> c/c++ Application

retun to super.onCreate(savedInstanceState);
continue it~~~done

If add new break point, drag  /root/nativeeglexample/xxxxxx.cpp to eclipse
set breakpoint, done

demo photo:
https://picasaweb.google.com/106185541018774360364/IMx6#6234033020574002994

沒有留言:

張貼留言