How to debug android c programs by gdbserver on G1

by David Turner » Tue, 24 Feb 2009 16:57:55 GMT


Sponsored Links
 You can use "adb forward tcp:1234 tcp:1234" to forward the local port on
your development machine to the local port 1234 on the device/emulator.
After that, you can do "target remote localhost:1234" in gdb to connect to
your target through gdbserver.





--~--~---------~--~----~------------~-------~--~----~

-~----------~----~----~----~------~----~------~--~---



Other Threads

1. ndk5 exception crash with third-party library

Hi everyone, that's my first post, please be nice :)
My problem is as follows:

I have 2 library, namely lib1 and lib2 compiled with standalone
toolchain.
Both libs need to use stl and exception.
I am using ndkr5, and i have problem with exception !

According to the doc in ndk (document android-ndk-r5b/docs/CPLUSPLUS-
SUPPORT.html), it is mentioned that :
"
WARNING: IMPORTANT CAVEAT

     AT THE MOMENT, OUR STLPORT IMPLEMENTATION DOES NOT SUPPORT
EXCEPTIONS
     AND RTTI. PLEASE BE SURE TO NOT USE -fexceptions OR -frtti IN ALL
     MODULES THAT USE IT.

     IF YOU NEED THESE, PLEASE USE "gnustl_static".
"

so in my Application.mk, I have added:
APP_STL  := gnustl_static

==================== my test with one single lib (promising)
=================================
I tested as follows:
1) Test 1 :
if i use try/catch within jni, it works with gnustl_static, but it
works as well for stlport_static. i assume it works for stlport_shared
as well
example:
try {
throw 1
} catch (in e) {
LOHI("catch int %d", e); // OK
}

2) Test 2 :
if i use try/catch within my external lib, say in lib1, then it works
with gnustl_static, but it works as well for stlport_static. i assume
it works for stlport_shared as well.
example:
try {
throw 1
} catch (in e) {
LOHI("catch int %d", e); // OK
}

3) Test 3:
if i throw the exception from the external lib and try to catch it
withing the jni code, then the app crashes if i use gnustl_static.
example:
lib.c
void func()
{
throw 1;
}
and in jni:
try{
func(); // CRASH
} catch (int e) {
LOHI("catch int %d", e);
}

I have figured that if i use stlport_static instead of gnustl_static,
then it works! This is contradictory to what documentation says ... ??
Can someone share their experience ?

Anyway, my first tests finished, I have tried with 2 libs instead of a
single one... and the problems started.

=========================== end my test with one single lib
================================


=================my external libs compiled with standalone toolchain
===========================
my 2 external libs are as follows:
lib1 has just one file lib1.c containing one function:
void lib1_func1(int *i)
{
throw 11;
}
According to doc android-ndk-r5b/docs/STANDALONE-TOOLCHAIN.html, it is
mentioned that:
"
The toolchain binaries *do* support C++ exceptions and RTTI by
default.
They are enabled by default, so use -fno-exceptions and -fno-rtti if
you
want to disable them when building sources with them (e.g. to generate
smaller machine code).

NOTE: You will need to explicitely link with libsupc++ if you use
these
      features. To do this, use -lsupc++ when linking binaries, as in:

    arm-linux-androideabi-g++ .... -lsupc++

"

so i compile and link against lsupc++ as:
arm-linux-androideabi-g++ -mthumb -O2 -g -Wall -fpic -c lib1.c -o
lib1.o
arm-linux-androideabi-g++ -shared -Wl,-soname,liblib1.so  lib1.o -lsupc
++ -o liblib1.so

lib2 has just one file lib2.c containing one function:
void lib2_func1(int *i)
{
throw 21;
}
i compile it as (linking against libsupc++):
arm-linux-androideabi-g++ -mthumb -O2 -g -Wall -fpic -c lib2.c -o
lib2.o
arm-linux-androideabi-g++ -shared -Wl,-soname,liblib2.so  lib2.o -lsupc
++ -o liblib2.so

=================== end external lib
===================================================

===================== Android.mk
====================================================
in my Android.mk
LOCAL_SHARED_LIBRARIES  := lib1 lib2
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := lib1
LOCAL_SRC_FILES := liblib1.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := lib2
LOCAL_SRC_FILES := liblib2.so
include $(PREBUILT_SHARED_LIBRARY)
====================== end Android.mk
===============================================

====================== Application.mk
================================================
in my Application.mk
# comment: I've tried with gnu_static and stlport_shared, no luck...
APP_STL         := stlport_static
APP_CPPFLAGS    += -fexceptions -frtti
======================== end Application.mk
===========================================

======================== jni call
====================================================
// this function is called from Java
void native_func()
{
int a = 0;
try {
        lib1_func1(&a);
}
catch (int e) {
        LOGI("catch lib1_func1 %d", e);
}
try {
        lib2_func1(&a);
}
catch (int e) {
        LOGI("catch lib2_func1 %d", e);
}
}
======================== end jni call
=================================================

======================== Java loading
================================================
 static {
        System.loadLibrary("lib1");
        System.loadLibrary("lib2");
        System.loadLibrary("myjni"); // jni
        }
========================= end Java loading
============================================

======================= logcat output
================================================
the libs are loaded succssfully, application runs. Then i launch the
call to native function.
the app crashes when calling lib2_func1 as follows:

I/jni_callback.cpp( 1631): catch lib1_func1 11
I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** ***
*** *** *
**
I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic:2.3/
GRH55/79397:eng/t
est-keys'
I/DEBUG   (   31): pid: 1631, tid: 1631  >>> com.me.test <<<
I/DEBUG   (   31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault
addr deadbaa
d
I/DEBUG   (   31):  r0 deadbaad  r1 80000000  r2 00000027  r3 00000000
I/DEBUG   (   31):  r4 00000080  r5 afd46668  r6 8380d710  r7 000e6e98
I/DEBUG   (   31):  r8 be8a309c  r9 83906730  10 be8a3038  fp be8a2ffc
I/DEBUG   (   31):  ip ffffffff  sp be8a2fa0  lr afd19375  pc
afd15ef0  cpsr 000
00030
I/DEBUG   (   31):          #00  pc 00015ef0  /system/lib/libc.so
I/DEBUG   (   31):          #01  lr afd19375  /system/lib/libc.so
I/DEBUG   (   31):
I/DEBUG   (   31): code around pc:
I/DEBUG   (   31): afd15ed0 68241c23 d1fb2c00 68dae027 d0042a00
I/DEBUG   (   31): afd15ee0 20014d18 6028447d 48174790 24802227
I/DEBUG   (   31): afd15ef0 f7f57002 2106eb56 ec92f7f6 0563aa01
I/DEBUG   (   31): afd15f00 60932100 91016051 1c112006 e818f7f6
I/DEBUG   (   31): afd15f10 2200a905 f7f62002 f7f5e824 2106eb42
I/DEBUG   (   31):
I/DEBUG   (   31): code around lr:
I/DEBUG   (   31): afd19354 b0834a0d 589c447b 26009001 686768a5
I/DEBUG   (   31): afd19364 220ce008 2b005eab 1c28d003 47889901
I/DEBUG   (   31): afd19374 35544306 d5f43f01 2c006824 b003d1ee
I/DEBUG   (   31): afd19384 bdf01c30 000281a8 ffffff88 1c0fb5f0
I/DEBUG   (   31): afd19394 43551c3d a904b087 1c16ac01 604d9004
I/DEBUG   (   31):
I/DEBUG   (   31): stack:
I/DEBUG   (   31):     be8a2f60  00000015
I/DEBUG   (   31):     be8a2f64  afd18407  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f68  afd4270c  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f6c  afd426b8  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f70  00000000
I/DEBUG   (   31):     be8a2f74  afd19375  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f78  0000002b
I/DEBUG   (   31):     be8a2f7c  afd183d9  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f80  001c0ce0  [heap]
I/DEBUG   (   31):     be8a2f84  00000000
I/DEBUG   (   31):     be8a2f88  afd46668
I/DEBUG   (   31):     be8a2f8c  8380d710  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2f90  000e6e98  [heap]
I/DEBUG   (   31):     be8a2f94  afd18677  /system/lib/libc.so
I/DEBUG   (   31):     be8a2f98  df002777
I/DEBUG   (   31):     be8a2f9c  e3a070ad
I/DEBUG   (   31): #00 be8a2fa0  be8a309c
I/DEBUG   (   31):     be8a2fa4  83906730  /data/data/com.me.test/lib/
li
bcg-jni.so
I/DEBUG   (   31):     be8a2fa8  be8a3038
I/DEBUG   (   31):     be8a2fac  be8a2ffc
I/DEBUG   (   31):     be8a2fb0  001c0ce0  [heap]
I/DEBUG   (   31):     be8a2fb4  fffffbdf
I/DEBUG   (   31):     be8a2fb8  8380fcbc  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fbc  8380fcbc  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fc0  afd426b8  /system/lib/libc.so
I/DEBUG   (   31):     be8a2fc4  8380765c  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fc8  8380fcbc  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fcc  8380765c  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fd0  838074e8  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fd4  00000000
I/DEBUG   (   31):     be8a2fd8  8380fdc8  /data/data/com.me.test/lib/
li
blib2.so
I/DEBUG   (   31):     be8a2fdc  001c0ce0  [heap]
I/DEBUG   (   31):     be8a2fe0  00000043
I/DEBUG   (   31):     be8a2fe4  838074e8  /data/data/com.me.test/lib/
li
blib2.so
D/Zygote  (   33): Process 1631 terminated by signal (11)

============================ end logcat output
=======================================


If i swap lib1 and lib2 in my Android.mk to:
LOCAL_SHARED_LIBRARIES  := lib2 lib1 (in previous Android.mk, it was
lib1 lib2)
i call this scenario 2.

in scenario 2, the app crashes on the call to lib1_func1 ! Before, the
call to lib1_func1 worked.
In scenario 2, if i change the c++ native code in jni by calling
lib2_func1 first and and then lib1_func1, then call to lib2_func1
succeeds but call to lib1_func1 crashes... !

update of jni code:
try {
lib2_func1(&a);
}
catch (int e) {
LOGI("catch lib2_func1 %d", e);
}
try {
lib1_func1(&a); // crashes here
}
catch (int e) {
LOGI("catch lib1_func1 %d", e);
}

It seems the order of libs matter ??


Anyone could help me out ??

Thanks a lot to all of u.
Cheers.

-- 

2. urgent help

hiiiii
Is there are anyone who worked on SIP server.
I want to get registered with server and make call.

-- 

3. What kind of debug output statement is valid in getaddrinfo.c?

4. Problem when coming back to activity after changing font in Galaxy S

5. Syntax error: Unterminated quoted string

6. Java Guru needed -- compiler bug?

7. Specific drawable not working?????