目前Android2.2 和android2.3上的prebuilt gdbserver一執行就會報錯segmentfault,prebuilt的gdbserver是靜態編譯的,這樣做是為了讓gdb能跨android的各個版本使用,但這個做法並沒有考慮到kernel和libc的多樣性。所以就出現了segment fault。
從android issue上看到這樣的解決辦法,具體做法就從git上下載gdb的代碼然後重新編譯
注:凡是路徑最好是使用絕對路徑 避免configure的時候會出問題
#[ENVIRONMENT]
export NDK=~/android/android-ndk-r5b &&
export SDK=~/android/android-sdk-linux_x86 &&
export PATH=~/bin:${PATH}:$NDK:$SDK/tools:$SDK/platform-tools &&
export ANDROID_SRC=~/myandroid
#[I ASSUME YOU HAVE THE SDK & NDK ALREADY]
如果已經有 gingerbread的代碼就不需下載了,直接下載gdb 代碼
#[OBTAIN GINGERBREAD AOSP IF YOU HAVEN'T ALREADY]
mkdir -p ~/bin &&
mkdir -p $ ANDROID_SRC &&
cd $ ANDROID_SRC &&
curl http://android.git.kernel.org/repo > ~/bin/repo &&
chmod a+x ~/bin/repo &&
repo init -u git://android.git.kernel.org/platform/manifest.git -b gingerbread &&
repo sync
#[CONFIGURE ENV FOR ANDROID_SRC (REQUIRED)]
cd $ ANDROID_SRC &&
. build/envsetup.sh &&
lunch full-eng
#[BUILD AOSP IF YOU HAVEN'T ALREADY]
time make -j4
# substitute appropriate '-j#' for your CPU.
#[OBTAIN AND PATCH GDB SOURCES]
mkdir -p ~/src/gdb_build &&
pushd ~/src/gdb_build &&
在我下載的時候android.git.kernel.org聽說被黑了或者關閉了,所以用了一個第三方的git git://android.git.linaro.org/
git clone git://android.git.kernel.org/toolchain/gdb.git &&
git clone git://android.git.kernel.org/toolchain/build.git &&
cd gdb &&
patch -p1
popd
#[INITIALIZE SYSROOT]
pushd ~/src/gdb_build && ./build/build-sysroot.sh $ANDROID_SRC/out/target/product/generic ~/src/gdb_build/sysroot && popd
#[USE ANDROID_SRC PREBUILT TOOLCHAIN, NOT NDK'S TOOLCHAIN]
cd $ ANDROID_SRC &&
rm -Rf $ANDROID_SRC/toolchains/arm-eabi-4.4.3/prebuilt &&
mkdir -p $ANDROID_SRC/toolchains/arm-eabi-4.4.3/prebuilt &&
pushd $ANDROID_SRC/toolchains/arm-eabi-4.4.3/prebuilt &&
ln -s $ANDROID_SRC/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3 linux-x86 &&
popd
#[BUILD GDBSERVER 6.6]
$ANDROID_SRC/ndk/build/tools/build-gdbserver.sh \
~/src/gdb_build $ ANDROID_SRC \
arm-eabi-4.4.3 --verbose \
--build-out=$ANDROID_SRC/src/gdb_build/install \
--gdb-version=6.6 --sysroot=$ANDROID_SRC/src/gdb_build/sysroot
#[COPY NEW GDBSERVER OVER NDK'S BROKEN GDBSERVER]
mv $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver.orig && cp ~/src/gdb_build/install/gdbserver $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver