问题
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.
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.
For gdb I can use ./configure --enable-targets=all
, but what for gdbserver
? Is there any "List" for all the available parameters?
Here's how I tried to build gdbserver
- 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 - 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
- make, which results in:
...
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.
回答1:
Got answer from somewhere else, put here in case who wants do the same.
- Download gdb source code:
wget ftp://sourceware.org/pub/gdb/releases/gdb-9.1.tar.gz
- Extract file:
tar xzvf gdb-9.1.tar.gz
- Move into source folder
cd gdb-9.1
Edit file gdb/gdbserver/linux-low.c:
- 4.1. Add two lines : Line 107 & Line 122 with the content below
#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
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. Modify function
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);
}
This fixes bug "gdbserver not handling Ctrl+C
", detail at: https://sourceware.org/bugzilla/show_bug.cgi?id=18772
- Build gdb for linux:
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
Build gdbserver for android:
- 6.1. Download 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. Install Ndk
sdkmanager --install "ndk;21.0.6113669" --sdk_root=~/android/
- 6.3. Create standalone toolchain for NDK
cd ~/android/ndk/21.0.6113669/
./build/tools/make-standalone-toolchain.sh \
--toolchain=aarch64-linux-android-4.9 \
--install-dir=~/android/ndk_21
This step create the standalone toolchain at: ~/android/ndk_21
- 6.4. Configure and build gdbserver for android
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
If get error related to "source-highlight", add --disable-source-highlight
compile flag.
After build finishes, gdbserver is located at: gdb/gdbserver/gdbserver
回答2:
The easiest way to get this is through the NDK that comes with the Android SDK, e.g., with Android Studio. Got to the NDK in the Android SDK and navigate to ndk-bundle/prebuilt/android-arm64/gdbserver/gdbserver
; that will give you a prebuilt gdbserver executable for aarch64 (arm64). You'll find other prebuilt gdbserver executables in ndk-bundle/prebuilt also, besides for aarch64.
来源:https://stackoverflow.com/questions/60973768/build-gdb-and-gdbserver-for-android