目前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 > ~/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