You may have debug Android in eclipse, Have you ever used jdb tracing Android. Since Dalvikvm support jdwp, we can use jdb to debug the program. there are 2 ways

Android as debug host

Steps

1) update libandroid_runtime


change below

frameworks/base/core/jni/AndroidRuntime.cpp    620     opt.optionString =    621         "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";asopt.optionString = "-agentlib:jdwp=transport=dt_socket,address=8011,server=y,suspend=y";




use "mmm frameworks/base/core/jni" to re-generate system/lib/libandroid_runtime.so, then copy to your runing env (system/lib)

2) change system/root/default.prop on your running env


change "ro.debuggable=0" to "ro.debuggable=1"


if you won not do it, you can specify AndroidManifest.xml

<application android:label="@string/app_name" android:icon="@drawable/plasma" android:debuggable="true">

Or the App can not be debugged


3) start the app


check stop you will see below

I/Zygote  ( 6843/6843): Accepting command socket connectionsI/jdwp    ( 7385/7385): JDWP will wait for debugger on port 8011



4) use jdb to attach the port


jdb -attach localhost:8011

--- you will see ---

Initializing jdb ...>VM Started: "thread=<1> main", dalvik.system.Zygote.nativeForkSystemServer(), line=-1 bci=-1<1> main[1]




5) include source dirs by "use" command, you will see source code


<1> main[1] use /home/user/jb/frameworks/base/core/java:/home/user/jb/frameworks/base/packages/SettingsProvider/src/:/home/user/jb/frameworks/base/services/java


6) set break and trace

Use commands: stop in, cont, list, next, you will able to trace your code<1> main[1] stop in com.android.server.InputMethodManagerService.getEnabledInputMethodSubtypeListDeferring breakpoint com.android.server.InputMethodManagerService.getEnabledInputMethodSubtypeList.<1> main[1] cont> Ignoring cmd 268435570/199/1 from the VMSet deferred breakpoint com.android.server.InputMethodManagerService.getEnabledInputMethodSubtypeListBreakpoint hit: "thread=<12> android.server.ServerThread", com.android.server.InputMethodManagerService.getEnabledInputMethodSubtypeList(), line=845 bci=0845            synchronized (mMethodMap) { <12> android.server.ServerThread[1] list841    842        @Override843        public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,844                boolean allowsImplicitlySelectedSubtypes) {845 =>         synchronized (mMethodMap) {846                return getEnabledInputMethodSubtypeListLocked(imi, allowsImplicitlySelectedSubtypes);847            }848        }849    850        @Override<12> android.server.ServerThread[1] nextStep completed: "thread=<12> android.server.ServerThread", com.android.server.InputMethodManagerService.getEnabledInputMethodSubtypeList(), line=846 bci=3846                return getEnabledInputMethodSubtypeListLocked(imi, allowsImplicitlySelectedSubtypes);<12> android.server.ServerThread[1]


Jdb as debug host

There are shortcomings in "Android as host", because every time the JavaVM starts up, it will move to listen status, So the SystemServer will listen, even we don't want to. so "Jdb as debug host" is a better idea.


1) update libandroid_runtime


change below

frameworks/base/core/jni/AndroidRuntime.cpp    620     opt.optionString =    621         "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";asopt.optionString = "-agentlib:jdwp=transport=dt_socket,address=localhost:8011,server=n,suspend=y";



if you won't run jdb on the same host, change "localhost" to other host/ip

2) change system/root/default.prop on your running env

change "ro.debuggable=0" to "ro.debuggable=1"

3) use jdb to listen the port

jdb -listen 8011

4) Start Android or APPs


when your Dalvik VM start, it will connect 8011

The good advantages of "Jdb as Host" is that when you need to debug, you let jdb listen; if you won't listen, Android will run as normal.

For example, when I want to debug the App, I run "jdb -listen 8011", then I click the App icon on the Launcher and start to debug.

Attention:

The Apps have launch timeout limits or It will be terminated by AM, when you enter jdb console, you need to quickly set breakpoint, and enter "cont" to run


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. androidmanifest.xml的一些高级属性
  2. mainefest中配置组件的android:process属
  3. android vr全景图片初探(仿微博360全景图
  4. AppInterface,一套Android与H5的混合开发
  5. 如何在android设备上insmod自己单独编译
  6. Vue自定义数字键盘组件
  7. Android(安卓)蓝牙学习笔记(一)
  8. Android(安卓)AsyncTask使用以及源码解析
  9. 详解Android(安卓)Activity之间跳转出现
  10. Windows下搭建Android(安卓)2.1开发环境