Reputation: 386
Software: Official TI android release (source code package), Jelly bean 4.2.2 for AM335x, (Yes, arago/rowboat/TI developers add modifications to vanilla aosp but not relevant to my question.)
Hardware: am335xevm_sk (a TI dev booard based on AM335x Cortex A8 SOC)
What I do:
build the system and using sd card to boot the hardware. Everything works properly.
adb pull the init.am335xevm.rc file, comment out the rild service and push it back, reboot the target system. I do this because I want to use cross debugger to remote debug rild.
set up the remote debug: adb forward tcp ports. and launch gdbserver on target system, as:
root@android:/ # gdbserver localhost:2345 system/bin/rild
Process system/bin/rild created; pid = 829
Listening on port 2345
Remote debugging from host 127.0.0.1
remote debug rild, as:
ma@ma-aspire:~/devkit/JB422$ PATH=$PATH:/home/ma/devkit/JB422/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin
ma@ma-aspire:~/devkit/JB422$ arm-linux-androideabi-gdb
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<xxxx://www.gnu.org/software/gdb/bugs/>.
(gdb) file /home/ma/devkit/JB422/out/target/product/am335xevm_sk/symbols/system/bin/rild
Reading symbols from /home/ma/devkit/JB422/out/target/product/am335xevm_sk/symbols/system/bin/rild...done.
(gdb) set sysroot /home/ma/devkit/JB422/out/target/product/am335xevm_sk/symbols
(gdb) target remote localhost:2345
Remote debugging using localhost:2345
__dl__start () at bionic/linker/arch/arm/begin.S:35
35 mov r0, sp
(gdb) n
36 mov r1, #0
(gdb) n
37 bl __linker_init
(gdb) n
Program received signal SIGILL, Illegal instruction.
0x4013a89e in __linker_init (elfdata=0xbee7bae0) at bionic/linker/linker.cpp:2030
2030 extern "C" unsigned __linker_init(unsigned **elfdata) {
(gdb) c
Continuing.
Program terminated with signal SIGILL, Illegal instruction.
The program no longer exists.
(gdb)
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am not very familiar with low-level toolchain problem. I googled the problem and it seems very few people encountered the same problem.
I downloaded the aosp source (Android 4.2.2_r1, JDQ39) and compared the prebuilt toolchain and NDK content, no significant difference was found.
I also tried with the latest NDK (r10b). Use the prebuilt toolchain in the NDK to rebuild the whole target system and do the debug, the results are the same.
I also tried to generate the standalone toolchain with platform set to android-17 and android-18, and repeat the above steps, the results are the same.
I also tried to re-built the NDK toolchain and got no difference.
I also tried the newer version of gdbserver (prebuilts in NDK r10b package), and the problem persists.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
but if I use the NDK toolchain to debug a simple hello-world program (with liblog dynamically linked), as proposed in this page:
www dot srombauts dot fr/2011/03/06/standalone-toolchain/
and do the debug, I can step into main(), but after the program exit, the process on target system got a similar SIGILL termination, instead of a normal exit.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am very confused why this occurs, since many many developers use gdb to debug native code and platform developers at google should also rely on gdb debug heavily. It seems unlikely that the problem arised from a bug in gdb or gdbserver. Perhaps it is related and specific to am335x kernel? Or I missed something important to use gdb? say, target architecture options? Or certain compiler options should be specified for this kind of native debug? I had read quite a few online articles on native remote debug on android carefully and not found anything specifically being pointed out.
I really want to use remote GDB to debug some native program, including ril and some other test cases wrapping HAL libs. Please HELP!
Upvotes: 1
Views: 1382
Reputation: 386
Sorry that this isn't an answer but an supplementary to my previous question.
I digged the problem further.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I put a basic helloworld program inside android source tree:
#include <stdio.h>
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "hello-native", __VA_ARGS__))
void main(void)
{
printf("Hello Native Printf\n");
LOGI("Hello Native LOGI");
}
with Android.mk file as:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-native
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := hello-native.c
LOCAL_SHARED_LIBRARIES := liblog
include $(BUILD_EXECUTABLE)
Then the debug fails with SIGILL as mentioned in the previous post.
But if I use a standard Makefile (as proposed by Karim Yaghmour in his excellent book Embedded Android, page 140):
#Paths and settings
TARGET_PRODUCT = am335xevm_sk
ANDROID_ROOT = /home/ma/devkit/JB422
BIONIC_LIBC = $(ANDROID_ROOT)/bionic/libc
PRODUCT_OUT = $(ANDROID_ROOT)/out/target/product/$(TARGET_PRODUCT)
CROSS_COMPILE = $(ANDROID_ROOT)/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-
# Tool names
AS = $(CROSS_COMPILE)as
AR = $(CROSS_COMPILE)ar
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
LD = $(CROSS_COMPILE)ld
NM = $(CROSS_COMPILE)nm
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)ranlib
READELF = $(CROSS_COMPILE)readelf
SIZE = $(CROSS_COMPILE)size
STRINGS = $(CROSS_COMPILE)strings
STRIP = $(CROSS_COMPILE)strip
export AS AR CC CPP LD NM OBJCOPY OBJDUMP RANLIB READELF \
SIZE STRINGS STRIP
# Build settings
CFLAGS = -O0 -Wall -fno-short-enums -ggdb
HEADER_OPS = -I$(BIONIC_LIBC)/include \
-I$(BIONIC_LIBC)/arch-arm/include \
-I$(BIONIC_LIBC)/kernel/common \
-I$(BIONIC_LIBC)/kernel/arch-arm \
-I$(ANDROID_ROOT)/system/core/include
LDFLAGS = -nostdlib -Wl,-dynamic-linker,/system/bin/linker \
$(PRODUCT_OUT)/obj/lib/crtbegin_dynamic.o \
$(PRODUCT_OUT)/obj/lib/crtend_android.o \
-L$(PRODUCT_OUT)/obj/lib -lc -ldl -llog
# Installation variables
EXEC_NAME = hello-native
INSTALL = install
INSTALL_DIR = $(PRODUCT_OUT)/system/bin
# Files needed for the build
OBJS = hello-native.o
# Make rules
all: hello-native
.c.o:
$(CC) $(CFLAGS) $(HEADER_OPS) -c $<
hello-native: ${OBJS}
$(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS)
install: hello-native
test -d $(INSTALL_DIR) || $(INSTALL) -d -m 755 $(INSTALL_DIR)
$(INSTALL) -m 755 $(EXEC_NAME) $(INSTALL_DIR)
clean:
rm -f *.o $(EXEC_NAME) core
distclean:
rm -f *~
rm -f *.o $(EXEC_NAME) core
Then the program compiles and debug correctly. The only exception is when program exits, if I set sysroot to /out/target/product/am335xevm_sk/symbols, I got and SIGILL, but if I do not set debugger sysroot, the program exits normally.
They works all the same way with different Toolchain and debugger, that from original TI release, that from the original or new version NDK, or that rebuilts from source code in NDK.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Then I tried to compile rild in ARM code, with LOCAL_ARM_MODE set to arm, as:
ifeq ($(TARGET_ARCH),arm)
LOCAL_SHARED_LIBRARIES += libdl
endif # arm
LOCAL_CFLAGS := -DRIL_SHLIB -O0
LOCAL_ARM_MODE := arm
LOCAL_MODULE:= rild
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
Then the program compiles and debug correctly, if I do NOT set sysroot to out/target/product/am335xevm_sk/symbols, otherwise, the debugger can step into linker and crash with SIGILL as previously mentioned.
This at least provide a workaround solution for my need, but I can NOT believe that the Android (ndk) gdb can NOT handle thumb codes? Is there anything I missed for gcc/gdb settings? or some gcc options are modified in Rowboat distro that prevent official gdb tool from working properly?
HELP!
Upvotes: 0