一、引言
使用Android 預裝 gdbserver 調試 動態庫時出現,Segmentation fault錯誤。不得不使用現有編譯鏈重新編譯一份gdbserver。我的解決過程如下。
這裡要強調一點:下面編譯sysroot時sysroot的目標路徑,和編譯gdbserver時指定的sysroot路徑,一定要是用[絕對路徑]。我編譯過程中,曾因未使用絕對路徑浪費不少精力。
二、開發環境
Ubuntu 11.04
編譯通過的Android 2.3 源碼
三、解決過程
1、因已經有了Android 2.3源碼,省去下載源碼並編譯的漫長過程。
#設置Android源碼目錄為環境變量:$ANDROID_SRC
simba@simba-Vostro-3400:~$ export ANDROID_SRC=/home/simba/neptune/android_2.3
2、下載gdb源碼,並打補丁
simba@simba-Vostro-3400:~$ mkdir gdb_build
simba@simba-Vostro-3400:~/neptune/gdb_src$ git clone https://android.googlesource.com/toolchain/gdb.git
#坐等下載完畢,然後...
#將以下保存成.patch文件
[plain]
- <span > diff --git a/gdb-7.1.x/gdb/gdbserver/Makefile.in b/gdb-7.1.x/gdb/gdbserver/Makefile.in
- index 5bf82e2..488bfb6 100644
- --- a/gdb-7.1.x/gdb/gdbserver/Makefile.in
- +++ b/gdb-7.1.x/gdb/gdbserver/Makefile.in
- @@ -176,13 +176,13 @@ clean-info:
-
- gdbserver$(EXEEXT): $(OBS) ${ADD_DEPS} ${CDEPS}
- rm -f gdbserver$(EXEEXT)
- - ${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbserver$(EXEEXT) $(OBS) \
- - $(GDBSERVER_LIBS) $(XM_CLIBS)
- + ${CC-LD} $(INTERNAL_CFLAGS) -o gdbserver$(EXEEXT) $(OBS) \
- + $(GDBSERVER_LIBS) $(XM_CLIBS) $(INTERNAL_LDFLAGS)
-
- gdbreplay$(EXEEXT): $(GDBREPLAY_OBS)
- rm -f gdbreplay$(EXEEXT)
- - ${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
- - $(XM_CLIBS)
- + ${CC-LD} $(INTERNAL_CFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
- + $(XM_CLIBS) $(INTERNAL_LDFLAGS)
-
- # Put the proper machine-specific files first, so M-. on a machine
- # specific routine gets the one for the correct machine.
- diff --git a/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c b/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
- index 54668f8..7a78cce 100644
- --- a/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
- +++ b/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
- @@ -43,10 +43,7 @@ void init_registers_arm_with_neon (void);
- # define PTRACE_SETWMMXREGS 19
- #endif
-
- -#ifndef PTRACE_GETVFPREGS
- -# define PTRACE_GETVFPREGS 27
- # define PTRACE_SETVFPREGS 28
- -#endif
-
- static unsigned long arm_hwcap;</span>
#打補丁
simba@simba-Vostro-3400:~/gdb_build$ cd gdb/
simba@simba-Vostro-3400:~/gdb_build/gdb$ patch -p1 <./gdb_patch.patch
3、下載build源碼
simba@simba-Vostro-3400:~/gdb_build$ git clone https://android.googlesource.com/toolchain/build.git
#坐等下載完畢,然後...
#編譯 sysroot
simba@simba-Vostro-3400:~/neptune/build_src$ cd build/
simba@simba-Vostro-3400:~/gdb_build/build$ ./build-sysroot.sh $ANDROID_SRC/out/target/product/imx51_bbg/
$HOME/gdb_build/sysroot
#注意此處sysroot的目標目錄一定要是用絕對路徑,否則sysroot不能正常生成,之後編譯gdbserver時會報錯。