歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 自己編譯Android gdbserver(解決運行 gdbserver時 Segmentation fault 問題)

自己編譯Android gdbserver(解決運行 gdbserver時 Segmentation fault 問題)

日期:2017/3/1 10:35:19   编辑:Linux編程

一、引言

使用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]
  1. <span > diff --git a/gdb-7.1.x/gdb/gdbserver/Makefile.in b/gdb-7.1.x/gdb/gdbserver/Makefile.in
  2. index 5bf82e2..488bfb6 100644
  3. --- a/gdb-7.1.x/gdb/gdbserver/Makefile.in
  4. +++ b/gdb-7.1.x/gdb/gdbserver/Makefile.in
  5. @@ -176,13 +176,13 @@ clean-info:
  6. gdbserver$(EXEEXT): $(OBS) ${ADD_DEPS} ${CDEPS}
  7. rm -f gdbserver$(EXEEXT)
  8. - ${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbserver$(EXEEXT) $(OBS) \
  9. - $(GDBSERVER_LIBS) $(XM_CLIBS)
  10. + ${CC-LD} $(INTERNAL_CFLAGS) -o gdbserver$(EXEEXT) $(OBS) \
  11. + $(GDBSERVER_LIBS) $(XM_CLIBS) $(INTERNAL_LDFLAGS)
  12. gdbreplay$(EXEEXT): $(GDBREPLAY_OBS)
  13. rm -f gdbreplay$(EXEEXT)
  14. - ${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
  15. - $(XM_CLIBS)
  16. + ${CC-LD} $(INTERNAL_CFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
  17. + $(XM_CLIBS) $(INTERNAL_LDFLAGS)
  18. # Put the proper machine-specific files first, so M-. on a machine
  19. # specific routine gets the one for the correct machine.
  20. diff --git a/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c b/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
  21. index 54668f8..7a78cce 100644
  22. --- a/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
  23. +++ b/gdb-7.1.x/gdb/gdbserver/linux-arm-low.c
  24. @@ -43,10 +43,7 @@ void init_registers_arm_with_neon (void);
  25. # define PTRACE_SETWMMXREGS 19
  26. #endif
  27. -#ifndef PTRACE_GETVFPREGS
  28. -# define PTRACE_GETVFPREGS 27
  29. # define PTRACE_SETVFPREGS 28
  30. -#endif
  31. 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時會報錯。

Copyright © Linux教程網 All Rights Reserved