Build gdbserver for x86 Android
http://blog.csdn.net/yuleslie/article/details/7226767
http://omappedia.org/wiki/Android_-_How-to_Rebuild_gdbserver
The reference links are for ARM target and old Andriod version, when I tried to build gdbserver for x86 target with Android JB 4.2.2_r1, I got some differences:
Environment
Ubuntu 12.04
gdb-7.3.x
Android JB 4.2.2_r1
It seems the modification(Makefile.in and linux-arm-lower.c) in gdb server is not required for me.
Modification of build scripts
diff --git a/build/tools/build-gdbserver.sh b/build/tools/build-gdbserver.sh
index 2b6c1aa..b1ff8a5 100755
--- a/build/tools/build-gdbserver.sh
+++ b/build/tools/build-gdbserver.sh
@@ -143,30 +143,6 @@ BUILD_SYSROOT="$BUILD_OUT/sysroot"
run mkdir -p "$BUILD_SYSROOT"
run cp -RHL "$SYSROOT"/* "$BUILD_SYSROOT"
-# 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.o -c $LIBTHREAD_DB_DIR/libthread_db.c
- run $TOOLCHAIN_PREFIX-ar -r $BUILD_SYSROOT/usr/lib/libthread_db.a $BUILD_SYSROOT/usr/lib/libthread_db.o
- if [ $? != 0 ] ; then
- dump "ERROR: Could not compile libthread_db.c!"
- exit 1
- fi
-fi
-
log "Using build sysroot: $BUILD_SYSROOT"
# configure the gdbserver build now
diff --git a/build/tools/prebuilt-common.sh b/build/tools/prebuilt-common.sh
index 9a13d29..9b111a6 100644
--- a/build/tools/prebuilt-common.sh
+++ b/build/tools/prebuilt-common.sh
@@ -1127,7 +1127,7 @@ get_toolchain_install ()
get_toolchain_install_subdir ()
{
local SYSTEM=${2:-$(get_prebuilt_host_tag)}
- echo "toolchains/$1/prebuilt/$SYSTEM"
+ echo "prebuilts/gcc/$SYSTEM/x86/i686-linux-android-4.6"
}
# Return the relative install prefix for prebuilt host
Compiling errors and solutions
conflicting types
error
/home/peter/workspace/android_4.2.2_r1/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/i686-linux-android-gcc --sysroot=/home/peter/workspace/gdb_build/install/sysroot -o memmem.o -c -O2 -nostdlib -D__ANDROID__ -DANDROID -DSTDC_HEADERS -I/home/peter/workspace/android_4.2.2_r1/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/lib/gcc/i686-linux-android//include -I/home/peter/workspace/gdb_build/install/sysroot/usr/include -I. -I/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver -I/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../common -I/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../regformats -I/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../../include -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-char-subscripts /home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../gnulib/memmem.c
In file included from /home/peter/workspace/gdb_build/install/sysroot/usr/include/sys/_types.h:40:0,
from /home/peter/workspace/gdb_build/install/sysroot/usr/include/stdint.h:32,
from /home/peter/workspace/android_4.2.2_r1/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/../lib/gcc/i686-linux-android/4.6/include/stdint.h:3,
from /home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../gnulib/str-two-way.h:45,
from /home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../gnulib/memmem.c:34:
/home/peter/workspace/gdb_build/install/sysroot/usr/include/machine/_types.h:44:24: error: conflicting types for 'size_t'
/home/peter/workspace/android_4.2.2_r1/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/../lib/gcc/i686-linux-android/4.6/include/stddef.h:212:23: note: previous declaration of 'size_t' was here
/home/peter/workspace/gdb_build/install/sysroot/usr/include/machine/_types.h:46:24: error: conflicting types for 'ptrdiff_t'
/home/peter/workspace/android_4.2.2_r1/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6/bin/../lib/gcc/i686-linux-android/4.6/include/stddef.h:150:26: note: previous declaration of 'ptrdiff_t' was here
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/../gnulib/memmem.c:40:1: error: conflicting types for 'memmem'
/home/peter/workspace/gdb_build/install/sysroot/usr/include/string.h:44:15: note: previous declaration of 'memmem' was here
solution
sysroot/usr/include/machine/_types.h:
#if 0//!defined(__ARM_EABI__)
/* the kernel defines size_t as unsigned int, but g++ wants it to be unsigned long */
#define _SIZE_T
#define _SSIZE_T
#define _PTRDIFF_T
typedef unsigned long size_t;
typedef long ssize_t;
typedef long ptrdiff_t;
#endif
no such instruction
error
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/gdbreplay.c: Assembler messages:
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/gdbreplay.c:232: Error: no such instruction: `rev16 %ax,%ax'
make: *** [gdbreplay.o] Error 1
make: *** Waiting for unfinished jobs....
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/remote-utils.c: Assembler messages:
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/remote-utils.c:410: Error: no such instruction: `rev16 %ax,%ax'
/home/peter/workspace/gdb_build/gdb/gdb-7.3.x/gdb/gdbserver/remote-utils.c:426: Error: no such instruction: `rev16 %si,%si'
solution
copy following files from host /usr/include/bits
sysroot/usr/include/bits/
├── byteswap.h
└── wordsize.h
--- /usr/include/bits/byteswap.h 2013-09-30 23:03:21.000000000 +0800
+++ sysroot/usr/include/bits/byteswap.h 2014-01-05 14:07:28.222628058 +0800
@@ -19,7 +19,7 @@
02111-1307 USA. */
#if !defined _BYTESWAP_H && !defined _NETINET_IN_H && !defined _ENDIAN_H
-# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
+//# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
#endif
#ifndef _BITS_BYTESWAP_H
@@ -134,4 +134,9 @@
# endif
#endif
+# define ntohl(x) __bswap_32 (x)
+# define ntohs(x) __bswap_16 (x)
+# define htonl(x) __bswap_32 (x)
+# define htons(x) __bswap_16 (x)
+
#endif /* _BITS_BYTESWAP_H */
gdb-7.3.x/gdb/gdbserver/remote-utils.c
gdb-7.3.x/gdb/gdbserver/gdbreplay.c
#ifdef HAVE_NETINET_IN_H
+#include <bits/byteswap.h>
#include <netinet/in.h>
#endif
'EAX' undeclared here (not in a function)
copy reg.h from /usr/include/sys/reg.h
--- a/gdb-7.3.x/gdb/gdbserver/linux-x86-low.c
+++ b/gdb-7.3.x/gdb/gdbserver/linux-x86-low.c
@@ -57,7 +57,7 @@ static const char *xmltarget_amd64_linux_no_xml = "@<target>\
</target>";
#endif
-#ifdef HAVE_SYS_REG_H
+#if 1 //def HAVE_SYS_REG_H
#include <sys/reg.h>
#endif
#ifdef HAVE_SYS_PROCFS_H
相關文章
- 使用gdb和gdbserver除錯Android C/C++程式Server除錯AndroidC++
- build libusb for AndroidUIAndroid
- 理解 Android Build 系統AndroidUI
- Android x86 設定豎屏Android
- Qt for android編譯大坑之adb: failed to stat build-test-andoid5_12_8/android-build//build/QTAndroid編譯AIUI
- Android X86 4.4 體驗組圖Android
- x86版Android 4.4正式釋出Android
- com.android.tools.build:gradle:2.0.0-alpha3 build errorsAndroidUIGradleError
- 【Android Build】高效批量打渠道包AndroidUI
- gdbserver 移植與多執行緒除錯Server執行緒除錯
- Android Build系統要點總結AndroidUI
- 關於Android ant build的學習AndroidUI
- gdbserver連線Ubuntu除錯程式(使用串列埠)ServerUbuntu除錯串列埠
- Android解決Couldnotfindcom.android.tools.build:gradleAndroidUIGradle
- 實現交叉編譯gdb和gdbserver(gdb-7.6)編譯Server
- Android開發:build.gradle 配置指南AndroidUIGradle
- Android學習之Build.xml檔案AndroidUIXML
- 用Android SDK Build Tools手動構建APKAndroidUIAPK
- 解決Android打包com.android.build.api.transform.TransformException的問題AndroidUIAPIORMException
- vscode+gdbserver遠端除錯ARM環境搭建VSCodeServer除錯
- Android Studio 編輯Build.gradle時很卡AndroidUIGradle
- Android Gradle 技巧之一: Build Variant 相關AndroidGradleUI
- com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:AndroidUIAPIORMExceptionIDE
- Android學習筆記之build.gradle檔案Android筆記UIGradle
- Gradle for Android系列之二 build.gradle檔案GradleAndroidUI
- Error:Could not find com.android.tools.build:gradle:2.2.2.ErrorAndroidUIGradle
- Android原始碼編譯jar包BUILD_JAVA_LIBRARY 與BUILD_STATIC_JAVA_LIBRARY的區別(一)Android原始碼編譯JARUIJava
- Build CookbookUI
- NDK buildUI
- Android Studio 已有專案新增NDK支援(mac/ndk-build)AndroidMacUI
- 深入淺出Android Gradle構建系統(三:build task)AndroidGradleUI
- 深入淺出Android Gradle構建系統(五:build type)AndroidGradleUI
- Gradle for Android 第二篇( Build.gradle入門 )GradleAndroidUI
- 深入淺出Android Gradle構建系統(3):build taskAndroidGradleUI
- Where the top of the stack is on x86
- virtualization tech of x86 platformPlatform
- 如何在Android studio中更新sdk版本和build-tools版本AndroidUI
- 報錯com.android.build.api.transform.TransformException: java.util.zip.ZipException:AndroidUIAPIORMExceptionJava