日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

使用 GDB 调试 Android 应用

發(fā)布時間:2024/4/11 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用 GDB 调试 Android 应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

GNU 工程調(diào)試器(GDB)是一個常用的 Unix 調(diào)試器。本文詳述使用 gdb 調(diào)試 Android 應(yīng)用和進(jìn)程的方法。

調(diào)試運(yùn)行中的應(yīng)用或進(jìn)程

gdbclient 是源碼庫中的一個 shell 腳本調(diào)試工具,它位于 android-7.1.1_r22/development/scripts/gdbclient。該腳本將根據(jù) Android 源碼庫的根目錄,設(shè)置端口轉(zhuǎn)發(fā),在設(shè)備上啟動適當(dāng)?shù)?gdbserver,在主機(jī)上啟動適當(dāng)?shù)?gdb,配置 gdb 查找符號,并將 gdb 連接到遠(yuǎn)程的 gdbserver。

在執(zhí)行 gdbclient 首先需要設(shè)置 ANDROID_BUILD_TOP 環(huán)境變量,這個環(huán)境變量可以手動設(shè)置,如:

/media/data/Androids/android-7.1.1_r22$ export ANDROID_BUILD_TOP=/media/data/Androids/android-7.1.1_r22

也可以通過如下命令設(shè)置:

/media/data/Androids/android-7.1.1_r22$ source build/envsetup.sh including device/asus/fugu/vendorsetup.sh including device/generic/mini-emulator-arm64/vendorsetup.sh including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh including device/generic/mini-emulator-mips64/vendorsetup.sh including device/generic/mini-emulator-mips/vendorsetup.sh including device/generic/mini-emulator-x86_64/vendorsetup.sh including device/generic/mini-emulator-x86/vendorsetup.sh including device/google/dragon/vendorsetup.sh including device/google/marlin/vendorsetup.sh including device/htc/flounder/vendorsetup.sh including device/huawei/angler/vendorsetup.sh including device/lge/bullhead/vendorsetup.sh including device/linaro/hikey/vendorsetup.sh including device/moto/shamu/vendorsetup.sh including sdk/bash_completion/adb.bash hanpfei0306@ThundeRobot:/media/data/Androids/android-7.1.1_r22$ lunch 18============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=7.1.1 TARGET_PRODUCT=aosp_sailfish TARGET_BUILD_VARIANT=userdebug TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm64 TARGET_ARCH_VARIANT=armv8-a TARGET_CPU_VARIANT=generic TARGET_2ND_ARCH=arm TARGET_2ND_ARCH_VARIANT=armv7-a-neon TARGET_2ND_CPU_VARIANT=krait HOST_ARCH=x86_64 HOST_2ND_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-4.4.0-89-generic-x86_64-with-Ubuntu-16.04-xenial HOST_CROSS_OS=windows HOST_CROSS_ARCH=x86 HOST_CROSS_2ND_ARCH=x86_64 HOST_BUILD_TYPE=release BUILD_ID=NMF26X OUT_DIR=out ============================================

也就是 Android 源碼庫編譯前配置。

如果沒有設(shè)置 ANDROID_BUILD_TOP 環(huán)境變量的話,在執(zhí)行 gdbclient 時將報(bào)出如下的錯誤:

/media/data/Androids/android-7.1.1_r22$ development/scripts/gdbclient $ANDROID_BUILD_TOP is not set. Source build/envsetup.sh.

有了前面的那些配置,即可使用 gdbclient 調(diào)試 Android 應(yīng)用程序了。要連接一個已經(jīng)在運(yùn)行的應(yīng)用或本地層守護(hù)進(jìn)程,則以 PID 作為參數(shù)執(zhí)行 gdbclient。比如,要調(diào)試 PID 為 1234 的進(jìn)程,則運(yùn)行:

$ gdbclient 1234

它會為我們準(zhǔn)備一切。

調(diào)試本地進(jìn)程啟動

要調(diào)試進(jìn)程的啟動,則使用 gdbserver 或 gdbserver64 (64 位進(jìn)程)。比如:

$ adb shell gdbserver64 :5039 /system/bin/screenrecord

示例輸出如下:

Process /system/bin/screenrecord created; pid = 12571 Listening on port 5039

接著,從 gdbserver 的輸出中得到應(yīng)用程序的 PID,并在另一個終端窗口中使用如下命令:

$ gdbclient 12571

最后,在 gdb 提示符下鍵入 continue。

使用的 gdbserver 與實(shí)際運(yùn)行的應(yīng)用程序格式不匹配時,在執(zhí)行 gdbclient 時將報(bào)出如下的錯誤:

$ gdbclient 12484 including device/asus/fugu/vendorsetup.sh including device/generic/mini-emulator-arm64/vendorsetup.sh including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh including device/generic/mini-emulator-mips64/vendorsetup.sh including device/generic/mini-emulator-mips/vendorsetup.sh including device/generic/mini-emulator-x86_64/vendorsetup.sh including device/generic/mini-emulator-x86/vendorsetup.sh including device/google/dragon/vendorsetup.sh including device/google/marlin/vendorsetup.sh including device/htc/flounder/vendorsetup.sh including device/huawei/angler/vendorsetup.sh including device/lge/bullhead/vendorsetup.sh including device/linaro/hikey/vendorsetup.sh including device/moto/shamu/vendorsetup.sh including sdk/bash_completion/adb.bashIt looks like gdbserver is already attached to 12484 (process is traced), trying to connect to it using local port=5039 GNU gdb (GDB) 7.11 Copyright (C) 2016 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 "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from out/target/product/sailfish/symbols/system/bin/screenrecord...done. warning: Selected architecture aarch64 is not compatible with reported target architecture arm out/target/product/sailfish/gdbclient.cmds:4: Error in sourced command file: Reply contains invalid hex digit 59 (gdb) break main Breakpoint 1 at 0x5820: file frameworks/av/cmds/screenrecord/screenrecord.cpp, line 900. (gdb) r Starting program: /media/data/Androids/android-7.1.1_r22/out/target/product/sailfish/symbols/system/bin/screenrecord /usr/local/google/buildbot/src/android/master-ndk/toolchain/gdb/gdb-7.11/gdb/regcache.c:1056: internal-error: regcache_raw_supply: Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) yThis is a bug, please report it. For instructions, see: <http://www.gnu.org/software/gdb/bugs/>./usr/local/google/buildbot/src/android/master-ndk/toolchain/gdb/gdb-7.11/gdb/regcache.c:1056: internal-error: regcache_raw_supply: Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Create a core file of GDB? (y or n) y /media/data/Androids/android-7.1.1_r22/prebuilts/gdb/linux-x86/bin/gdb: 行 3: 12882 已放棄 (核心已轉(zhuǎn)儲) PYTHONHOME="$GDBDIR/.." "$GDBDIR/gdb-orig" "$@" hanpfei0306@ThundeRobot:/media/data/Androids/android-7.1.1_r22$ /bin/bash: /media/data/Androids/android-7.1.1_r22/out/target/product/sailfish/symbols/system/bin/screenrecord: cannot execute binary file: 可執(zhí)行文件格式錯誤 /bin/bash: /media/data/Androids/android-7.1.1_r22/out/target/product/sailfish/symbols/system/bin/screenrecord: 成功

即我們在 gdb 的提示符下輸入 continue 執(zhí)行應(yīng)用程序之后,報(bào)出了 可執(zhí)行文件格式錯誤。

Done.

總結(jié)

以上是生活随笔為你收集整理的使用 GDB 调试 Android 应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。