[RFA] Fix gdbserver build failure on arm-android.

Message ID 1431100919-8245-1-git-send-email-brobecker@adacore.com
State New, archived
Headers

Commit Message

Joel Brobecker May 8, 2015, 4:01 p.m. UTC
  Hello,

The following patch...

| proc-service, extern "C"
|
| libthread_db.so calls symbols in the client (GDB), through the
| proc-service interface.  These routines must have extern "C" linkage
| so their symbol names are not mangled when GDB is built as a C++
| program.  On the GDBserver side, we were missing fallback declarations for
| all these symbols.
|
| gdb/ChangeLog:
|
|     * gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.
|
| gdb/gdbserver/ChangeLog:
| 2015-02-27  Pedro Alves  <palves@redhat.com>
|
|     * gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.
|     [!HAVE_PROC_SERVICE_H] (struct ps_prochandle): Forward declare.
|     [!HAVE_PROC_SERVICE_H] (ps_pdread, ps_pdwrite, ps_ptread)
|     ps_ptwrite, ps_lgetregs, ps_lsetregs, ps_lgetfpregs)
|     (ps_lsetfpregs, ps_getpid)
|     (ps_get_thread_area, ps_pglobal_lookup, ps_pstop, ps_pcontinue)
|     (ps_lstop, ps_lcontinue, ps_lgetxregsize, ps_lgetxregs)
|     (ps_lsetxregs, ps_plog): Declare.

... added a number of declarations which do not compile when cross-
compiling GDBserver on arm-android. The problem comes from type
prfpregset_t not being declared:

    /[...]/gdbserver/gdb_proc_service.h:98:47:
    error: unknown type name 'prfpregset_t'

After searching through the includes of the install we have,
I could not find that type being declared anywhere. So I did
the same as for prgregset_t, and created the typedef if the
type isn't declared.

gdb/gdbserver/ChangeLog:

        * configure.ac: Add prfpregset_t BFD_HAVE_SYS_PROCFS_TYPE check.
        * configure, config.in: Regenerate.
        * gdb_proc_service.h [HAVE_PRFPREGSET_T] (prfpregset_t):
        Declare typedef.

OK to commit?

Thanks,
  

Comments

Pedro Alves May 14, 2015, 10:32 a.m. UTC | #1
On 05/08/2015 05:01 PM, Joel Brobecker wrote:
> Hello,
> 
> The following patch...
> 
> | proc-service, extern "C"
> |
> | libthread_db.so calls symbols in the client (GDB), through the
> | proc-service interface.  These routines must have extern "C" linkage
> | so their symbol names are not mangled when GDB is built as a C++
> | program.  On the GDBserver side, we were missing fallback declarations for
> | all these symbols.
> |
> | gdb/ChangeLog:
> |
> |     * gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.
> |
> | gdb/gdbserver/ChangeLog:
> | 2015-02-27  Pedro Alves  <palves@redhat.com>
> |
> |     * gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.
> |     [!HAVE_PROC_SERVICE_H] (struct ps_prochandle): Forward declare.
> |     [!HAVE_PROC_SERVICE_H] (ps_pdread, ps_pdwrite, ps_ptread)
> |     ps_ptwrite, ps_lgetregs, ps_lsetregs, ps_lgetfpregs)
> |     (ps_lsetfpregs, ps_getpid)
> |     (ps_get_thread_area, ps_pglobal_lookup, ps_pstop, ps_pcontinue)
> |     (ps_lstop, ps_lcontinue, ps_lgetxregsize, ps_lgetxregs)
> |     (ps_lsetxregs, ps_plog): Declare.
> 
> ... added a number of declarations which do not compile when cross-
> compiling GDBserver on arm-android. The problem comes from type
> prfpregset_t not being declared:
> 
>     /[...]/gdbserver/gdb_proc_service.h:98:47:
>     error: unknown type name 'prfpregset_t'
> 
> After searching through the includes of the install we have,
> I could not find that type being declared anywhere. So I did
> the same as for prgregset_t, and created the typedef if the
> type isn't declared.
> 
> gdb/gdbserver/ChangeLog:
> 
>         * configure.ac: Add prfpregset_t BFD_HAVE_SYS_PROCFS_TYPE check.
>         * configure, config.in: Regenerate.
>         * gdb_proc_service.h [HAVE_PRFPREGSET_T] (prfpregset_t):
>         Declare typedef.
> 
> OK to commit?

OK.

BTW, do you also trip on this one? :

 https://sourceware.org/ml/gdb/2015-04/msg00025.html

Thanks,
Pedro Alves
  
Joel Brobecker May 14, 2015, 2:17 p.m. UTC | #2
> > gdb/gdbserver/ChangeLog:
> > 
> >         * configure.ac: Add prfpregset_t BFD_HAVE_SYS_PROCFS_TYPE check.
> >         * configure, config.in: Regenerate.
> >         * gdb_proc_service.h [HAVE_PRFPREGSET_T] (prfpregset_t):
> >         Declare typedef.
> > 
> > OK to commit?
> 
> OK.

Thanks! Pushed to master.

> BTW, do you also trip on this one? :
> 
>  https://sourceware.org/ml/gdb/2015-04/msg00025.html

We don't, at the moment. But we're planning on upgrading to a newer
version in the next few weeks, so we might eventually hit that issue
too. We don't know yet which version we'll target, so I can't say
much more at the moment.
  
Pedro Alves May 15, 2015, 10:56 a.m. UTC | #3
On 05/14/2015 03:17 PM, Joel Brobecker wrote:

>> BTW, do you also trip on this one? :
>>
>>  https://sourceware.org/ml/gdb/2015-04/msg00025.html
> 
> We don't, at the moment. But we're planning on upgrading to a newer
> version in the next few weeks, so we might eventually hit that issue
> too. We don't know yet which version we'll target, so I can't say
> much more at the moment.

OK.  Seems the clash is with the group_from_gid / user_from_uid
BSD functions that do a similar thing from what our
versions do.  E.g.,:

 http://nixdoc.net/man-pages/openbsd/man3/group_from_gid.3.html
 https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/group_from_gid.3.html

"functions first appeared in 4.4BSD".

Though BSD's return a pointer to a statically allocated
buffer, while gdb's take a buffer pointer as argument.

As glibc doesn't support those BSD functions, we don't trip
on that on GNU/Linux.

I think we should just rename our symbols.  E.g.,
 group_from_gid -> gdb_group_from_gid
 user_from_uid -> gdb_user_from_uid

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 3c3bfca..9359ce5 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -164,6 +164,9 @@ 
 /* Define to 1 if you have the `pread64' function. */
 #undef HAVE_PREAD64
 
+/* Define if <sys/procfs.h> has prfpregset_t. */
+#undef HAVE_PRFPREGSET_T
+
 /* Define if <sys/procfs.h> has prgregset_t. */
 #undef HAVE_PRGREGSET_T
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 75860dd..b5a2f85 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -6535,6 +6535,43 @@  $as_echo "#define HAVE_PRGREGSET_T 1" >>confdefs.h
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $bfd_cv_have_sys_procfs_type_prgregset_t" >&5
 $as_echo "$bfd_cv_have_sys_procfs_type_prgregset_t" >&6; }
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for prfpregset_t in sys/procfs.h" >&5
+$as_echo_n "checking for prfpregset_t in sys/procfs.h... " >&6; }
+ if test "${bfd_cv_have_sys_procfs_type_prfpregset_t+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#define _SYSCALL32
+/* Needed for new procfs interface on sparc-solaris.  */
+#define _STRUCTURED_PROC 1
+#include <sys/procfs.h>
+int
+main ()
+{
+prfpregset_t avar
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  bfd_cv_have_sys_procfs_type_prfpregset_t=yes
+else
+  bfd_cv_have_sys_procfs_type_prfpregset_t=no
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+ if test $bfd_cv_have_sys_procfs_type_prfpregset_t = yes; then
+
+$as_echo "#define HAVE_PRFPREGSET_T 1" >>confdefs.h
+
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $bfd_cv_have_sys_procfs_type_prfpregset_t" >&5
+$as_echo "$bfd_cv_have_sys_procfs_type_prfpregset_t" >&6; }
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for elf_fpregset_t in sys/procfs.h" >&5
 $as_echo_n "checking for elf_fpregset_t in sys/procfs.h... " >&6; }
  if test "${bfd_cv_have_sys_procfs_type_elf_fpregset_t+set}" = set; then :
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 34af269..efbb346 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -343,6 +343,7 @@  if test "$ac_cv_header_sys_procfs_h" = yes; then
   BFD_HAVE_SYS_PROCFS_TYPE(lwpid_t)
   BFD_HAVE_SYS_PROCFS_TYPE(psaddr_t)
   BFD_HAVE_SYS_PROCFS_TYPE(prgregset_t)
+  BFD_HAVE_SYS_PROCFS_TYPE(prfpregset_t)
   BFD_HAVE_SYS_PROCFS_TYPE(elf_fpregset_t)
 fi
 
diff --git a/gdb/gdbserver/gdb_proc_service.h b/gdb/gdbserver/gdb_proc_service.h
index 2dcfa5b..cbafbf3 100644
--- a/gdb/gdbserver/gdb_proc_service.h
+++ b/gdb/gdbserver/gdb_proc_service.h
@@ -71,6 +71,10 @@  typedef void *psaddr_t;
 typedef elf_gregset_t prgregset_t;
 #endif
 
+#ifndef HAVE_PRFPREGSET_T
+typedef elf_fpregset_t prfpregset_t;
+#endif
+
 /* This type is opaque in this interface.  It's defined by the user of
    libthread_db.  GDB's version is defined below.  */
 struct ps_prochandle;