Android上GDB的使用

來源:互聯網
上載者:User
轉自:blog.163.com/bjtornado@yeah/blog/static/69510484201081181657449/

1) 編譯包含Debug 資訊
設定如下環境變數:
TARGET_BUILD_TYPE=debug
TARGET_STRIP_MODULE=false (發現即使設定編譯為Debug模式, 最後產生的檔案系統中的程式和庫還是會被strip. 設定此選項可以避免被strip)不過還要需要修改一下build/core/combo/linux-arm.mk, 否者即使設定TARGET_STRIP_MODULE=false也無效
修改
113:  TARGET_STRIP_MODULE:=true

ifeq ( $(strip $(TARGET_STRIP_MODULE)),,)
TARGET_STRIP_MODULE := true
endif

然後 make

2) 在板子上啟動gdb server
gdb-server IP-address:Port 可執行程式
或者
gdb-server IP-address:Port --attach 程式的PID
(Note: IP-Address是目標板自己的IP地址, 此選項可以省略)

3) 在主機端

(前提: 進入 android 目錄, 執行過 source build/envsetup.sh)

#gdbclient 在板子上執行的程式名稱
(預設已經設定好如下資訊, 無需自己設定
set solib-absolute-prefix /absolute-source-path/out/debug/target/product/product-name/symbols
set solib-search-path /absolute-source-path/out/debug/target/product/product-name/symbols/system/lib)
(gdb) target remote 板子的ip-address:port

(gdb) b main
(gdb) c
程式會停在main函數

補充:
如果板子上找不到gdb-server, 可以到如下地址下載已經做好的: http://ortegaalfredo.googlepages.com/android
gdb在android開發中的使用相信很多開發人員都很想掌握,今天我們就用gdb在Android Emulator中進行調試,讓大家學習gdb調試。在Android手機開發平台的emulator裡,有兩種方式可以做Gdb調試:直接使用GdbServer或利用Gdb調試進行調試。
  1、利用Gdb Server進行調試:
  A、從下面的連結中下載針對Android的Gdb Server   http://www.billrocks.org/android_libs/bin/
  B、把下載的Gdb Server安裝到你的emulator 中
  1)、 啟動emulator
  2)、下載Gdb Server到你的emulator
  開啟一個終端,運行:
    $ adb shell
    #cd data
    #mkdir bin
  在另外一個終端裡運行:
    $ adb push gdbserver /data/bin
  這樣通過Android自己的adb,把gdbserver 下載到emulator 中了。
  C、運行gdbserver :
     # /data/bin/gdbserver 10.0.2.2:1234 [args...]
  D、回到另一終端,映射連接埠:
       $telnet localhost 5554
      telnet到emulator 中,運行下面的命令:
       redir add tcp:1234:1234
  E、在第三個終端中運行 gdb:
       $gdb test
       test 是你要調試的程式,然後在gdb命令列運行:
       (gdb) target remote localhost:1234
       然後你就可以像以前用gdb那樣進行程式調試了。
  2、直接用本地Gdb進行調試
  A、從下面的連結中下載Android調試包,它是用Android的toolchain編譯好的二進位檔案:
      http://ortegaalfredo.googlepages.com/android-debug.tbz
  B、解壓調試包,然後把gdb下載到你的emulator 中,當然如果你有真的手機,也可以這樣調試:
   $adb push gdb /data/bin
  C、利用adb串連到emulator
   $adb shell
  運行gdb,會出現下面的資訊:
   # /data/bin/gdb
dlopen failed on 'libthread_db.so.1' - libthread_db.so.1: cannot open shared object file: No such file or directory
GDB will not be able to debug pthreads.
GNU gdb 6.7
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=arm-none-linux-gnueabi --target=".
(gdb)
  D、    然後你就可以像以前用gdb那樣對程式進行調試了。

相關文章

聯繫我們

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