Compile Android gdbserver by yourself (solve the problem of segmentation fault when running gdbserver)

Source: Internet
Author: User

I. Introduction

Segmentation fault occurs when you use Android pre-installed gdbserver to debug the dynamic library. You have to use the existing compilation chain to re-compile a gdbserver. Thanks to Android
-How-to rebuild gdbserver this article, refer to this article my solution process is as follows.

Here we should emphasize one point:The following is the target path of sysroot during sysroot compilation and the sysroot path specified during gdbserver compilation. You must use the [absolute path].. During the compilation process, I wasted a lot of energy because I didn't use absolute paths.


2. Development Environment

Ubuntu 11.04

Compiled source code for Android 2.3


Iii. Solution Process

1. Because the Android 2.3 source code already exists, it is easy to download and compile the source code.

# Set the android source code directory as an environment variable: $ android_src

Simba @ simba-Vostro-3400 :~ $ Export android_src =/home/Simba/NEPTUNE/android_2.3


2. Download the gdb source code and install patches.

Simba @ simba-Vostro-3400 :~ $ Mkdir gdb_build

Simba @ simba-Vostro-3400 :~ /NEPTUNE/gdb_src $ git clone https://android.googlesource.com/toolchain/gdb.git

# Wait until the download is complete, and then...

# Save the following as a. Patch File

 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;


# Patching

Simba @ simba-Vostro-3400 :~ /Gdb_build $ cd gdb/

Simba @ simba-Vostro-3400 :~ /Gdb_build/GDB $ patch-P1 <./gdb_patch.patch


3. Download build source code

Simba @ simba-Vostro-3400 :~ /Gdb_build $ git clone https://android.googlesource.com/toolchain/build.git

# Wait until the download is complete, and then...

# Compile 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

# Note that the target sysroot directory must be used.Absolute pathOtherwise, sysroot cannot be normally generated, and an error will be reported when gdbserver is compiled later.


4. Modify the compilation script

# Backing up and modifying 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


# The following red text is added to comment out some code.

<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 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: cocould not compile libthread_db.c! "
Exit 1
Fi
Fi
Not_needed


# Back up and modify the 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

Set
Get_toolchain_install ()
{
Echo "$1/toolchains/$ toolchain/prebuilt/$ host_tag"
}
 
To:
 
Get_toolchain_install ()
{
Echo "$1/prebuilt/$ host_tag/toolchain/$ toolchain"
}

5. Compile 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
# Be sure to use Absolute pathSpecify the sysroot directory

6. the target file is located in ~ /Gdb_build/install directory

7. ReferencesAndroid-how-to rebuild gdbserver
Compile Android toolchainandroid build gdbserver in cygwin again
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.