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

來源:互聯網
上載者:User

一、引言

        使用Android 預裝 gdbserver 調試 動態庫時出現,Segmentation fault錯誤。不得不使用現有編譯鏈重新編譯一份gdbserver。多謝Android
- How-to Rebuild 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檔案

 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;


#打補丁

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

#坐等下載完畢,然後...

#編譯 sysrootsimba@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時會報錯。


4.修改編譯指令碼

#備份並修改build-gdbserver.sh

 simba@simba-Vostro-3400:~/gdb_build/build$ cd ..

simba@simba-Vostro-3400:~/gdb_build$ cp $ANDROID_SRC/ndk/build/tools/build-gdbserver.sh $ANDROID_SRC/ndk/build/tools/build-gdbserver.sh_back

simba@simba-Vostro-3400:~/gdb_build$ gedit $ANDROID_SRC/ndk/build/tools/build-gdbserver.sh


#以下紅字部分為新增內容,目的是注釋掉部分代碼

<<NOT_NEEDED
# Remove libthread_db to ensure we use exactly the one we want.
rm -f $BUILD_SYSROOT/usr/lib/libthread_db*
rm -f $BUILD_SYSROOT/usr/include/thread_db.h

if [ "$NOTHREADS" != "yes" ] ; then
    # We're going to rebuild libthread_db.o from its source
    # that is under sources/android/libthread_db and place its header
    # and object file into the build sysroot.
    LIBTHREAD_DB_DIR=$ANDROID_NDK_ROOT/sources/android/libthread_db/gdb-$GDB_VERSION
    if [ ! -d "$LIBTHREAD_DB_DIR" ] ; then
        dump "ERROR: Missing directory: $LIBTHREAD_DB_DIR"
        exit 1
    fi
    # Small trick, to avoid calling ar, we store the single object file
    # with an .a suffix. The linker will handle that seamlessly.
    run cp $LIBTHREAD_DB_DIR/thread_db.h $BUILD_SYSROOT/usr/include/
    run $TOOLCHAIN_PREFIX-gcc --sysroot=$BUILD_SYSROOT -o $BUILD_SYSROOT/usr/lib/libthread_db.a -c $LIBTHREAD_DB_DIR/libthread_db.c
    if [ $? != 0 ] ; then
        dump "ERROR: Could not compile libthread_db.c!"
        exit 1
    fi
fi
NOT_NEEDED


#備份並修改prebuilt-common.sh simba@simba-Vostro-3400:~/gdb_build$ cp $ANDROID_SRC/ndk/build/tools/prebuilt-common.sh $ANDROID_SRC/ndk/build/tools/prebuilt-common.sh_backsimba@simba-Vostro-3400:~/gdb_build$ gedit $ANDROID_SRC/ndk/build/tools/prebuilt-common.sh


 get_toolchain_install ()
 {
     echo "$1/toolchains/$TOOLCHAIN/prebuilt/$HOST_TAG"
 }
 
修改為:
 
 get_toolchain_install ()
 {
     echo "$1/prebuilt/$HOST_TAG/toolchain/$TOOLCHAIN"
 }

5.編譯gdbserversimba@simba-Vostro-3400:~/gdb_build$ $ANDROID_SRC/ndk/build/tools/build-gdbserver.sh $HOME/gdb_build $ANDROID_SRC arm-eabi-4.4.3 --verbose --build-out=$HOME/gdb_build/install --gdb-version=7.1.x --sysroot= $HOME/gdb_build/sysroot
#注意此處一定要是用 絕對路徑指定sysroot的目錄

6.目標檔案位於~/gdb_build/install目錄下

7.參考文章Android - How-to Rebuild gdbserver
再次在 cygwin 下編譯 android toolchainAndroid build gdbserver
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.