Android jdb debug

來源:互聯網
上載者:User

標籤:

在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/

Android jdb debug

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.