native gdb for Android

Barry Song 21cnbao at gmail.com
Sat Feb 4 02:07:55 UTC 2012


Ulrich,
thanks a lot!

2012/2/4 Ulrich Weigand <Ulrich.Weigand at de.ibm.com>:
> Barry Song <21cnbao at gmail.com> wrote.
>> 2012/2/3 Ulrich Weigand <Ulrich.Weigand at de.ibm.com>:
>> > However, from looking at the gdbserver sources provided with Android,
>> > it seems there are some differences; in particular, there's this patch:
>> >
>> > +/* Android doesn't have libthread_db.so.1, just libthread_db.so.  */
>> > +#ifdef __ANDROID__
>> > +#define LIBTHREAD_DB_SO "libthread_db.so"
>> > +#endif
>> > +
>> >
>> > If libthread_db is named differently, this would explain why GDB is
>> > unable to find and use it.
>>
>> there are two ways to handle this issue:
>> 1. ln -s /system/lib/libthread_db.so /system/lib/libthread_db.so.1
>
> That would seem a good thing in any case.  (Is there any reason for
> Android to use nonstandard shared library naming conventions?)
>
>> this "fixed" Assertion `_rtld_global_ro._dl_pagesize != 0' , but it
>> still can't find multi-threads for android processes:
>> (gdb) info threads
>>   Id   Target Id         Frame
>> * 1    process 645 "system_server" __ioctl ()
>>     at bionic/libc/arch-arm/syscalls/__ioctl.S:15
>>
>> (gdb) info threads
>>   Id   Target Id         Frame
>> * 1    process 938 "mediaserver" __ioctl ()
>>     at bionic/libc/arch-arm/syscalls/__ioctl.S:15
>
> I had a quick look at the AOSP sources, and found that there actually
> is an implementation of libthread_db that is supposed to work with
> bionic.  Well, there seem to be multiple versions:
>
> ./bionic/libthread_db
> ./ndk/sources/android/libthread_db/gdb-6.6
> ./ndk/sources/android/libthread_db/gdb-7.1.x
>
> I'm not sure why there needs to be a different version for each
> GDB(server) release ...   Maybe there's something in there that
> also needs changing when it's being used by GDB directly instead
> of by gdbserver.
>
> I'll probably not be able to help you very much here; I'd suggest
> you 1) make sure your GDB actually uses the correct version of
> libthread_db (in particular, not one from glibc, but this one that
> handles bionic) and 2) if it still doesn't work, you'll have to
> debug what's going wrong.

for 1, i think gdb has loaded /system/lib/libthread_db.so of android
according to log info after patching gdb:
--- a/gdb/gdb_thread_db.h
+++ b/gdb/gdb_thread_db.h
@@ -2,7 +2,7 @@
 #include <thread_db.h>

 #ifndef LIBTHREAD_DB_SO
-#define LIBTHREAD_DB_SO "libthread_db.so.1"
+#define LIBTHREAD_DB_SO "libthread_db.so"
 #endif

for 2, the answer is it doesn't work yet.  i reported this issue at:
https://bugs.launchpad.net/gdb-linaro/+bug/926472
as Thiago pointed out. Thanks, Thiago!

>
> Note that from a quick look at the above libthread_db sources,
> those actually do not look into bionic data structures at all,
> but rather just traverse /proc to get a thread list.  While this
> is somewhat odd (if you want to do that, you could just do it in
> gdb/server itself -- the only reason why libthread_db is a separate
> project is its close integration with the thread library), it ought
> to make it easier to understand what's going on / wrong.
>
>
> Mit freundlichen Gruessen / Best Regards
>
> Ulrich Weigand
>
-barry



More information about the linaro-toolchain mailing list