Android jdb debug

在ubuntu上android的debug的方式有很多种,可以用eclipse,android studio。但是有的时候,为了方便也可以用命令行去debug。下面列出命令行debug的过程

xxx:~$ cd source/
xxx:~/source$ cd packages/apps/Settings/
xx:~/source/packages/apps/Settings$ adb shell ps | grep com.android.settings
system 3119 202 550436 38152 ffffffff 400dd888 S com.android.settings
xxx:~/source/packages/apps/Settings$ adb forward tcp:7777 jdwp:3119
xxx:~/source/packages/apps/Settings$ ls
AndroidManifest.xml Android.mk CleanSpec.mk MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src tests
xxx:~/source/packages/apps/Settings$ jdb -sourcepath src -attach localhost:7777
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> stop in com.android.settings.Settings.onCreate
Set breakpoint com.android.settings.Settings.onCreate
>
Breakpoint hit: "thread=<1> main", com.android.settings.Settings.onCreate(), line=197 bci=2
197 if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {

<1> main[1] list
193 };
194
195 @Override
196 protected void onCreate(Bundle savedInstanceState) {
197 => if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
198 getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
199 }
200
201 mAuthenticatorHelper = new AuthenticatorHelper();
202 mAuthenticatorHelper.updateAuthDescriptions(this);
<1> main[1] next

.....

<1> main[1] print mInLocalHeaderSwitch
mInLocalHeaderSwitch = true

.....

以上,操作还是蛮简单的。

     附:** JDB命令列表 **

  • connectors — 列出此 VM 中可用的连接器和传输
  • run [class [args]] — 开始执行应用程序的主类
  • threads [threadgroup] — 列出线程
  • thread — 设置默认线程
  • suspend [thread id(s)] — 挂起线程 (默认值: all)
  • resume [thread id(s)] — 恢复线程 (默认值: all)
  • where [ | all] — 转储线程的堆栈
  • wherei [ | all]– 转储线程的堆栈, 以及 pc 信息
  • up [n frames] — 上移线程的堆栈
  • down [n frames] — 下移线程的堆栈
  • kill — 终止具有给定的异常错误对象的线程
  • interrupt — 中断线程
  • print — 输出表达式的值
  • dump — 输出所有对象信息
  • eval — 对表达式求值 (与 print 相同)
  • set = — 向字段/变量/数组元素分配新值
  • locals — 输出当前堆栈帧中的所有本地变量
  • classes — 列出当前已知的类
  • class — 显示已命名类的详细资料
  • methods — 列出类的方法
  • fields — 列出类的字段
  • threadgroups — 列出线程组
  • threadgroup — 设置当前线程组
  • stop in .[(argument_type,...)] — 在方法中设置断点
  • stop at : — 在行中设置断点
  • clear .[(argument_type,...)] — 清除方法中的断点
  • clear : — 清除行中的断点
  • clear — 列出断点
  • catch [uncaught|caught|all] | — 出现指定的异常错误时中断
  • ignore [uncaught|caught|all] | — 对于指定的异常错误, 取消 ‘catch’
  • watch [access|all] . — 监视对字段的访问/修改
  • unwatch [access|all] . — 停止监视对字段的访问/修改
  • trace [go] methods [thread] — 跟踪方法进入和退出。 — 除非指定 ‘go’, 否则挂起所有线程
  • trace [go] method exit | exits [thread] — 跟踪当前方法的退出, 或者所有方法的退出 — 除非指定 ‘go’, 否则挂起所有线程
  • untrace [methods] — 停止跟踪方法进入和/或退出
  • step — 执行当前行
  • step up — 一直执行, 直到当前方法返回到其调用方
  • stepi — 执行当前指令
  • 下一步 — 步进一行 (步过调用)
  • cont — 从断点处继续执行
  • list [line number|method] — 输出源代码
  • use (或 sourcepath) [source file path] — 显示或更改源路径
  • exclude [, ... | "none"] — 对于指定的类, 不报告步骤或方法事件
  • classpath — 从目标 VM 输出类路径信息
  • monitor — 每次程序停止时执行命令
  • monitor — 列出监视器
  • unmonitor <monitor#> — 删除监视器
  • read — 读取并执行命令文件
  • lock — 输出对象的锁信息
  • threadlocks [thread id] — 输出线程的锁信息
  • pop — 通过当前帧出栈, 且包含当前帧
  • reenter — 与 pop 相同, 但重新进入当前帧
  • redefine — 重新定义类的代码
  • disablegc — 禁止对象的垃圾收集
  • enablegc — 允许对象的垃圾收集
  • !! — 重复执行最后一个命令
  • — 将命令重复执行 n 次
  • # <command> — 放弃 (无操作)
  • help (或 ?) — 列出命令
  • version — 输出版本信息
  • exit (或 quit) — 退出调试器
  • : 带有程序包限定符的完整类名
  • : 带有前导或尾随通配符 (‘*’) 的类名
  • : ‘threads’ 命令中报告的线程编号
  • : Java(TM) 编程语言表达式。
  • 支持大多数常见语法。

参考:

http://codeseekah.com/2012/02/16/command-line-android-development-debugging/

http://resources.infosecinstitute.com/android-hacking-security-part-5-debugging-java-applications-using-jdb/

posted @ 2015-05-12 10:46  CodingWarrior  阅读(589)  评论(0编辑  收藏  举报