溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

自己動手編譯android gdbserver 最新版

發(fā)布時間:2020-08-02 13:55:04 來源:網(wǎng)絡(luò) 閱讀:4700 作者:sunzeduo 欄目:移動開發(fā)

前面轉(zhuǎn)載了一篇 如何編譯android gdbserver的博文

原文地址如下:

http://sunzeduo.blog.51cto.com/2758509/1381519


本身這篇文章沒有什么問題,按部就班的操作可以生成 gdbserver,但是存在的問題如下:


1  本文編寫時間比較早,實用的arm交叉編譯版本以及gdb版本都比較老了,arm交叉編譯版本是arm-eabi-4.4.3  gdb使用的版本是 7.1.x 。


2 從文章來看是使用下載后android源碼中的ndk來編譯的,這個可以通過其修改了 $MYDROID/ndk/build/tools/prebuilt-common.sh 這個腳本可以看出來,對于沒有下載android源碼的童鞋造成障礙。


3  文中的

git clone git://android.git.kernel.org/toolchain/gdb.git
git clone git://android.git.kernel.org/toolchain/build.git


這兩個地址早已經(jīng)無法下載了,又對想自己動手編譯android gdbserver的童鞋造成障礙。


4 在中文搜索引擎里面搜索  android gdb調(diào)試等,絕大多數(shù)均出自      

Android - How-to Rebuild gdbserver  這篇文章的翻譯,同樣會存在上面的三個問題。


基于以上的問題,筆者自己動手重新簡化思路,編譯了android gdbserver,降低編譯門檻,供更多的童鞋來了解這方面的知識。


一  需要的前置條件

1 下載 Android NDK
直接從 http://developer.android.com/tools/sdk/ndk/index.html
這個地址下載即可,下載下來就是一個壓縮包,方便使用。
2 下載 gdb源碼
https://github.com/crystax/android-toolchain-gdb
這個下載地址即可


二 添加了兩個腳本 (腳本可以從附件下載)

   添加目錄 你下載解壓縮的目錄下的 build/tools  這個目錄下

build-gdbserver_7.3.x.sh
prebuilt-common_7.3.x.sh


三 對應(yīng)規(guī)則

root@ubuntu:~/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin# ./arm-linux-androideabi-gdb
GNU gdb (GDB) 7.3.1-gg2
root@ubuntu:~/android/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin# ./arm-linux-androideabi-gdb
GNU gdb (GDB) 7.3.1-gg2
arm-linux-androideabi-4.6  GNU gdb (GDB) 7.3.1-gg2
arm-linux-androideabi-4.8  GNU gdb (GDB) 7.3.1-gg2


網(wǎng)上流傳的大部分博文,都是gdb 7.1.x的 對應(yīng)的是 arm交叉編譯的 4.4.3


四 編譯命令

/root/android/android-ndk-r9c/build/tools/build-gdbserver_7.3.x.sh
/Disk/CyanogenMod/androidgdb/gdb_build/
/root/android/android-ndk-r9c/
arm-linux-androideabi-4.6
--verbose
--build-out=/Disk/CyanogenMod/androidgdb/gdb_build/install
--gdb-version=7.3.x
--sysroot=/root/android/android-ndk-r9c/platforms/android-19/arch-arm


命令解釋

 1 /root/android/android-ndk-r9c/build/tools/build-gdbserver_7.3.x.sh

  復(fù)制過去的腳本

2 /Disk/CyanogenMod/androidgdb/gdb_build/ 下載的gdb的路徑

要以下圖的形式組織gdb的目錄,否則腳本執(zhí)行的時候會報錯

自己動手編譯android gdbserver 最新版


3 /root/android/android-ndk-r9c/  

 下載的ndk解壓縮的路徑


4 arm-linux-androideabi-4.6 使用ndk中帶的arm-linux交叉編譯工具,詳見ndk根目錄下的toolchains目錄


5 --verbose  


6 --build-out=/Disk/CyanogenMod/androidgdb/gdb_build/install

 gdbserver生成的目錄,如果編譯成功了,則在這個目錄下生成gdbserver


7 --gdb-version=7.3.x

   要編譯的gdb版本,對應(yīng)你下載的gdb源碼包,參考上面的圖


8 --sysroot=/root/android/android-ndk-r9c/platforms/android-19/arch-arm

   在編譯gdbserver的時候需要用的頭文件和庫文件


五 編譯錯誤修改

筆者在編譯 gdb 7.3.x的時候出現(xiàn)了編譯錯誤,主要是關(guān)于elf頭文件的問題。

在linux_low.c 中

#ifndef ELFMAG0
/* Don't include <linux/elf.h> here.  If it got included by gdb_proc_service.h
   then ELFMAG0 will have been defined.  If it didn't get included by
   gdb_proc_service.h then including it will likely introduce a duplicate
   definition of elf_fpregset_t.  */
#include <elf.h>
#endif


的后面添加下面的代碼

typedef struct {
  uint32_t a_type;
  union {
    uint32_t a_val;
  } a_un;
} Elf32_auxv_t;
typedef struct {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



注意,這個僅僅是7.3.x編譯的時候出錯的修改方法,當(dāng)7.1.x或者其他版本的時候可能也會報錯,需要找到相應(yīng)的錯誤修改即可



六 編譯成功

自己動手編譯android gdbserver 最新版


自己動手編譯android gdbserver 最新版


七  手機(jī)測試

將編譯好的gdbserver 上傳到手機(jī)中,賦予可執(zhí)行的權(quán)限,然后運(yùn)行測試,效果如下圖


自己動手編譯android gdbserver 最新版


八 附件說明

1 build-gdbserver_7.3.x.sh   和 prebuilt-common_7.3.x.sh需要拷貝到 /root/android/android-ndk-r9c/build/tools/ 這個目錄下


2 linux_low.c 需要拷貝到  /Disk/CyanogenMod/androidgdb/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver 這個目錄下




附件:http://down.51cto.com/data/2364200
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI