本文介绍了为Android构建gdb和gdbserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用64位Linux,需要为我的aarch64 Android手机构建 gdbserver .NDK中已预构建了 gdbserver ,但它在NDK中使用了python包,不使用我的系统python,我无法安装其他python插件.

I'm working on 64 bit linux, need to build gdbserver for my aarch64 Android phone.There is prebuilt gdbserver in NDK, but it uses the python in NDK package, not using my system python, I can't install other python plugins.

如何找到./configure所需的--target--host参数?我尝试了--help和google之类的"build gdbserver aarch64"或"gdbserver configure android",但没有找到关于aarch64 Android的任何答案.

How to find which --target and --host parameter is required for ./configure? I tried the --help, and google like "build gdbserver aarch64" or "gdbserver configure android", but did't find any answer for aarch64 Android.

对于 gdb ,我可以使用./configure --enable-targets=all,但是对于gdbserver呢?所有可用参数都有列表"吗?

For gdb I can use ./configure --enable-targets=all, but what for gdbserver? Is there any "List" for all the available parameters?

这是我尝试构建 gdbserver

  1. 下载了 gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux 软件包,解压缩并将其添加到PATH,添加环境变量CC=arm-none-eabi-gccCXX=arm-none-eabi-g++,使可执行文件可用在PATH中
  2. 我尝试了所有这些方法:
  1. downloaded the gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux package, decompress and add it to PATH, add environment variable CC=arm-none-eabi-gcc, CXX=arm-none-eabi-g++, make the executable available in PATH
  2. I tried all of these:
    ../configure
    ../configure --host=aarch64-linux             --target=aarch64-linux-androideabi
    ../configure --host=aarch64-linux-androideabi --target=aarch64-linux
    ../configure --host=aarch64-linux-androideabi --target=aarch64-linux-androideabi
  1. make,结果为:
    ...
    make[3]: Nothing to be done for 'all'.
    make[3]: Leaving directory '/opt/gdb-9.1/gdb/gdbserver/build/build-libiberty-gdbserver/testsuite'
    make[2]: Leaving directory '/opt/gdb-9.1/gdb/gdbserver/build/build-libiberty-gdbserver'
    make[1]: Leaving directory '/opt/gdb-9.1/gdb/gdbserver/build'
    make: *** No rule to make target '../alloc.c'.  Stop.
also tried:
    make CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++
    or CC=aarch64-linux-android28-clang CXX=aarch64-linux-android28-clang++
But same result.

推荐答案

从其他地方获取答案,以防有人想要这样做.

Got answer from somewhere else, put here in case who wants do the same.

  1. 下载gdb源代码:
   wget ftp://sourceware.org/pub/gdb/releases/gdb-9.1.tar.gz
  1. 提取文件:
 tar xzvf gdb-9.1.tar.gz
  1. 移至源文件夹
 cd gdb-9.1
  1. 编辑文件gdb/gdbserver/linux-low.c:

  • 4.1.新增两行:第107行和第122行的内容如下
  • #define HAVE_ELF32_AUXV_T  //  Line 107 (Added)
    #ifndef HAVE_ELF32_AUXV_T
    
    #define HAVE_ELF64_AUXV_T // Line 122 (Added)
    #ifndef HAVE_ELF64_AUXV_T
    

    此修改对于构建Android是必需的,因为Android系统库已经定义了struct Elf32_auxv_t和Elf64_auxv_t.(请参阅此以获取详细信息: https://github.com/android/ndk/issues/1008 )

    This modification is neccessary to build Android, since Android system libraries already define struct Elf32_auxv_t and Elf64_auxv_t .(Please see this for detail: https://github.com/android/ndk/issues/1008)

    • 4.2.修改功能linux_request_interrupt:
    static void
    linux_request_interrupt (void)
     {
       /* .... */
    -  kill (-signal_pid, SIGINT); // replace this line with next 3 lines
    +  int r = kill (-signal_pid, SIGINT);
    +  if (r != 0)
    +      kill (signal_pid, SIGINT);
     }
    

    这修复了错误"gdbserver无法处理Ctrl+C",详细信息位于: https://sourceware.org/bugzilla/show_bug.cgi?id=18772

    This fixes bug "gdbserver not handling Ctrl+C", detail at: https://sourceware.org/bugzilla/show_bug.cgi?id=18772

    1. 为Linux构建gdb:
    sudo apt-get install build-essential \
      gcc g++ make autogen m4 \
      bison gettext libpython-dev
    
    mkdir build-linux
    
    cd build-linux/
    
    ../configure --enable-targets=all --with-python=/usr/bin/python
    
    make -j4
    
    sudo make install
    
    1. 为Android构建gdbserver:

    • 6.1.下载android-sdk
    • cd ~
      
      mkdir android
      
      cd android
      
      wget https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
      
      unzip commandlinetools-linux-6200805_latest.zip
      
      export PATH=$PATH:~/android/tools/bin
      

      • 6.2.安装Ndk
      • sdkmanager --install "ndk;21.0.6113669" --sdk_root=.
        

        • 6.3.为NDK创建独立的工具链
        • cd ~/android/ndk/21.0.6113669/
          
          ./build/tools/make-standalone-toolchain.sh \
          --toolchain=aarch64-linux-android-4.9 \
          --install-dir=~/android/ndk_21
          

          这一步在以下位置创建独立的工具链:〜/android/ndk_21

          This step create the standalone toolchain at: ~/android/ndk_21

          • 6.4.为Android配置和构建gdbserver
          cd ~/gdb-9.1
          
          mkdir build-android
          
          cd build-android
          
          export PATH=$PATH:~/android/ndk_21/bin
          
          CC=aarch64-linux-android-gcc ../configure \
              --target=aarch64-linux-android \
              --host=aarch64-linux-android \
               LDFLAGS="-static-libstdc++"
          
          make -j4
          

          如果遇到与"source-highlight"有关的错误,请将--disable-source-highlight添加到configure标志.

          If get error related to "source-highlight", add --disable-source-highlight to the configure flag.

          构建完成后, gdbserver 位于:gdb/gdbserver/gdbserver

          After build finishes, gdbserver is located at: gdb/gdbserver/gdbserver

          这篇关于为Android构建gdb和gdbserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 12:16