Hi Ulrich,

2012/2/3 Ulrich Weigand <ulrich.weig...@de.ibm.com>:
> Barry Song <21cn...@gmail.com> wrote:
>
>> So my questions are:
>>
>> 1.   Should I compile the native gdb using android toolchain and android
>> bionic/libthread libraries?
>> 2.   Why can’t the current gdb capture multithreads for android
>> processes? This question is actually about the theory for gdb to know
>> multi-threads. In my opinion, both gnu and android use clone() to fork
>> threads and threads in one process have same tgid in kernel and all
>> threads return same getpid() value. Why not gdb just travel process
>> lists to find multi-threads?
>
> I'm not sure what exactly is going on on Android with bionic.  However,
> GDB currently does require support from the thread library in order to
> debug multi-threaded applications.  This is needed e.g. to properly
> handle thread-local storage variables.  GDB will also use this support
> to detect threads of a running process it is attaching to.
>
> (It is true that GDB *could* e.g. look at /proc to find threads, instead
> of inspecting thread library data structures.  However, since the link
> to those data structures is required anyway, e.g. for TLS, this has not
> been implemented so far ...)
>
> When using glibc's libpthread, the support routines gdb uses to inspect
> target thread library datastructures are provided in libthread_db.so.1
> (which comes with glibc, and is linked into gdb).  I do not know the
> details on whether/how bionic provides a corresponding service.
>
> 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
2. patching gdb
i did have changed linaro-gdb 11.10 release by:

diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index ca0bc30..486faf6 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -98,8 +98,8 @@ static const char arm_linux_thumb2_le_breakpoint[] =
{ 0xf0, 0xf7, 0x00, 0xa0 };
    buffer.  This is also true for the SoftFPA model.  However, for the FPA
    model the PC is at offset 21 in the buffer.  */
 #define ARM_LINUX_JB_ELEMENT_SIZE      INT_REGISTER_SIZE
-#define ARM_LINUX_JB_PC_FPA            21
-#define ARM_LINUX_JB_PC_EABI           9
+#define ARM_LINUX_JB_PC_FPA            24/*21*/
+#define ARM_LINUX_JB_PC_EABI           24/*9*/

 /*
    Dynamic Linking on ARM GNU/Linux
diff --git a/gdb/gdb_thread_db.h b/gdb/gdb_thread_db.h
index 957ed2c..51ed4fa 100644
--- 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

 #ifndef LIBTHREAD_DB_SEARCH_PATH

But both 1 and 2 can't simply fix the problem. if we compile gdb
statically by "make LDFLAGS=-static", it will finally come into a
crash:
# gdb attach 643
GNU gdb (Linaro GDB) 7.3-2011.10
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 "arm-none-linux-gnueabi".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
attach: No such file or directory.
Attaching to process 643
Reading symbols from /system/bin/app_process...done.
BFD: /system/bin/linker: warning: sh_link not set for section `.ARM.exidx'

warning: Could not load shared library symbols for 6 libraries, e.g.
gralloc.default.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Reading symbols from /system/bin/linker...(no debugging symbols found)...done.
Loaded symbols for /system/bin/linker
Reading symbols from /system/lib/libc.so...done.
Loaded symbols for /system/lib/libc.so
Reading symbols from /system/lib/libstdc++.so...(no debugging symbols
found)...done.
Loaded symbols for /system/lib/libstdc++.so
Reading symbols from /system/lib/libm.so...(no debugging symbols found)...done.
Loaded symbols for /system/lib/libm.so
...
__ioctl () at bionic/libc/arch-arm/syscalls/__ioctl.S:15
15      bionic/libc/arch-arm/syscalls/__ioctl.S: No such file or directory.
        in bionic/libc/arch-arm/syscalls/__ioctl.S
gdb: ../sysdeps/unix/sysv/linux/getpagesize.c:32: __getpagesize:
Assertion `_rtld_global_ro._dl_pagesize != 0' failed.
Aborted
#

then i simply hardcoded __getpagesize() to return 4096 and avoid the assert:

001d9b70 <__getpagesize>:
  1d9b70:       f44f 5080       mov.w   r0, #4096       ; 0x1000
  1d9b74:       4770            bx      lr
  1d9b76:       bf00            nop

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

>
>
> Mit freundlichen Gruessen / Best Regards
>
> Ulrich Weigand
>
> --
>  Dr. Ulrich Weigand | Phone: +49-7031/16-3727
>  STSM, GNU compiler and toolchain for Linux on System z and Cell/B.E.
>  IBM Deutschland Research & Development GmbH
>  Vorsitzende des Aufsichtsrats: Martina Koederitz | Geschäftsführung: Dirk
> Wittkopp
>  Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht
> Stuttgart, HRB 243294

-barry

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to