http://groups.google.com/group/android-ndk/browse_thread/thread/50362904ae0574cf/fe9703f5cc08714e

调试jni apk

http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/

android 上ndk-build 编译可执行程序方法

http://vilimpoc.org/blog/2010/09/26/straightforward-android-native-executables/

1.

After doing much, much research and headaches, I believe I got

debugging to work FINALLY. I want to thank everyone here for there
responses. For those that want to try this, this is what I did:

note: The way I'm debugging here is on a simple mixed java/native c++
app (app that uses jni) using gdb. Most guides regarding this topic
of debugging native code involved a independent standalone c/c++
executable (runs from android shell), this is not the case here. This
is debugging on a java app that makes calls to code in c/c++.

setup: To do this you need an os that can get and build the android os
source, so linux or mac. For windows you can use a virtual machine of
linux (thats what I did vm linux mint)

the app: SimpleJNI (this sample app is part of android os source
located in development/sample/SimpleJNI), it demonstrates the concept

1. First get the Android OS source following the instructions here
http://source.android.com/downloadyou need to get it and make it.
2. Next follow the instructions herehttp://source.android.com/using-eclipse
to setup the eclipse and add the SimpleJNI app to the build path (most
important part to note here is adding the app to build path)
3. Now you need edit the app's Android.mk to add debugging symbols for
gdb. Go to SimpleJNI/jni folder in Android.mk and look for this line
"LOCAL_CFLAGS +=" change it to read "LOCAL_CFLAGS += -g"
4. cd /path/to/android/root and do "make SimpleJNI" to make the app.
5. Back in the Using Eclipse link follow these instructions from the
debugging with eclipse:

cd /path/to/android/root
. build/envsetup.sh
lunch 1 # to build the emulator
make # if you didn't already do this
emulator # you should see a GUI picture of a phone

Note: if your terminal can't seem to recognize the commands make sure
you are in the android root, and rerun ". build/ensetup.sh" and "lunch
1" commands

6. Next you need to install the app, from another terminal use this:
adb install -r ./out/target/product/generic/system/app/SimpleJNI.apk

7. You also need to push gdbserver in the emulator too, this will go
in /data/local directory
adb push ./out/target/product/generic/obj/EXECUTABLES/
gdbserver_intermediates/gdbserver /data/local

8. run the app SimpleJNI in the emulator, so it's running.

9. Follow the instructions herehttp://pdk.android.com/online-pdk/guide/debugging_gdb.html,
use the method of attaching to pid instead of executable

10. To see it work set a breakpoint i.e. b native.cpp:26, now since
there is no main() you can't just use <gdb> run, so what I found that
works is click "back" on the emulator and go back to android
homescreen. Then click open SimpleJNI again and gdb should break at
the breakpoint in this case line 26 in gdb.

11. In the emulator there should be no result displayed except for the
title SimpleJNI if you breaked at line 26

12. In the gdb window type "continue" or "c" and the app should resume
displaying some operation.

Thats it. I hope this was helpful because I felt there wasn't any
clear steps on how to debug w/ gdb/gdbserver on a java/jni app
scenario. I do think this method is very cumbersome and hopefully the
ndk later on will provide a better solution for debuging native code.





2. 一步一步

It is basically that

Then I am doing basically what you said and it is working. But I'll
write here the steps I am following:

cd AOS_ROOT
source build/envsetup.sh
lunch 1
emulator <--- it is important to run this emu instead of the one
included with the SDK

Recompile .so with NDK
cd to NDK_ROOT
make APP=<app_name>
Generate pkg (there are a lot of ways to do this, I am doing it with
eclipse (clean and build))
cp NDK_ROOT/out/apps/<app_name>/<app_name>.so AOS_ROOT/out/target/
product/generic/symbols/system/lib/<app_name>.so

cd to AOS_ROOT
adb install -r NDK_ROOT/apps/<app_name>/bin/<app_name>.apk
execute the installed application in the emulator
adb forward tcp:1234: tcp:1234
adb shell ps
adb shell gdbserver :1234 --attach pid <--- the pid displayed with ps

Open another terminal and cd to AOS_ROOT
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb out/
target/product/generic/symbols/system/bin/app_process
----INSIDE GDB ----
set solib-absolute-prefix out/target/product/generic/symbols
set solib-search-path out/target/product/generic/symbols/system/lib/
target remote :1234

Then a list of lines saying the symbols have been loaded appear and
you can insert breakpoints and debug as usual. I have changed the
behaviour of my app so that it stays doing nothing until I press down
in the keyboard, then the lib is loaded and executed, that way I have
time to attach the debugger.



更多相关文章

  1. Android实际开发bug大总结
  2. android 监听方法
  3. Android之TabHost的几种使用方法
  4. ubuntu 编译 ffmpeg For Android
  5. android之组件4
  6. android sdk 自带的非空非空串判断方法
  7. android中的handler的使用方法
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. 鼠标悬停伪类的理解
  2. 使用伸缩盒标签制作一个首页的二级分类
  3. 1236546545
  4. 万能码齐绽放(安全扫码专业委员会)
  5. Linux服务器遇到攻击怎么办?用这些方法封
  6. ThinkPHP技术交流微信群
  7. TP6&&API接口开发实战uniapp -免费领取
  8. 物理机、虚拟机、云主机、物理服务器、裸
  9. 阿里云Anolis OS 8.4
  10. 可爱的食物怎么画?食物的画法详解!