Android下用gdb遠端偵錯辦法

來源:互聯網
上載者:User

   Host: ubuntu

  Target: Android ICS

  1. 將gdbserver和gdbclient分別放入target和host。兩者都可在android原始碼的prebuilt目錄下找到。

  2. 在Target上啟動gdbserver,在adb shell中執行

  $ /path/to/gdbserver :1111--attach PID

  其中PID為想要debug程式的進程號,可以通過ps得到。1111為連接埠號碼,可以自訂。

  3. 在Host上啟動gdbclient,首先將target上的庫pull到host上(如/home/jzj/debug/gdb)

  $cd /home/jzj/debug/gdb

  $adb pull /system/lib

  $adb pull /system/bin/app_process

  然後寫啟動指令碼init.gdb(這裡假設程式要用到的庫放在/home/jzj/debug/gdb/下,android的symbol放在/home/jzj/debug/ics/symbols/system/lib/下,android的源碼放在/home/jzj/workspace/ics下)

  file /home/jzj/debug/gdb/app_process

  set solib-absolute-prefix /home/jzj/debug/ics/symbols/

  set solib-search-path /home/jzj/debug/ics/symbols/system/lib/:/home/jzj/debug/gdb

  dir /home/jzj/workspace/ics

  shell adb forward tcp:1111 tcp:1111

  target remote :1111

  最後執行

  $ gdb -x init.gdb

  就可以啟動gdb了。一切正常的話這時候就可以用gdb的準系統,如設斷點或者查看記憶體了。這時有些so庫的符號表可能還沒載入,可以執行

  (gdb) shared

  載入這些符號表。

  最後附個關於gdb設定指令碼中兩個變數的官方解釋,一般solib-absolute-prefix先於solib-search-path尋找。

  solib-absolute-prefix :

  If this variable is set, path will be used as a prefix for any absolute shared library paths; many runtime loaders store the absolute paths to the shared library in the target program's memory. If you use `solib-absolute-prefix' to find shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a `/usr/lib' hierarchy under path. You can set the default value of `solib-absolute-prefix' by using the configure-time `--with-sysroot' option.

  solib-search-path :

  If this variable is set, path is a colon-separated list of directories to search for shared libraries. `solib-search-path' is used after `solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. If you want to use `solib-search-path' instead of `solib-absolute-prefix', be sure to set `solib-absolute-prefix' to a nonexistant directory to prevent GDB from finding your host's libraries.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.