Patchwork [12/36] proc-service, extern "C"

login
register
mail settings
Submitter Pedro Alves
Date Feb. 9, 2015, 11:20 p.m.
Message ID <1423524046-20605-13-git-send-email-palves@redhat.com>
Download mbox | patch
Permalink /patch/4987/
State New
Headers show

Comments

Pedro Alves - Feb. 9, 2015, 11:20 p.m.
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:
2015-02-09  Pedro Alves  <palves@redhat.com>

	* gdb_proc_service.h: Wrap with EXTERN_C_PUSH/EXTERN_C_POP.

gdb/gdbserver/ChangeLog:
2015-02-09  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.
---
 gdb/gdb_proc_service.h           | 11 ++++++
 gdb/gdbserver/gdb_proc_service.h | 79 ++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/proc-service.c     |  4 +-
 3 files changed, 92 insertions(+), 2 deletions(-)

Patch

diff --git a/gdb/gdb_proc_service.h b/gdb/gdb_proc_service.h
index 2c633b3..e736991 100644
--- a/gdb/gdb_proc_service.h
+++ b/gdb/gdb_proc_service.h
@@ -22,8 +22,15 @@ 
 #include <sys/types.h>
 
 #ifdef HAVE_PROC_SERVICE_H
+
+/* glibc's proc_service.h doesn't wrap itself with extern "C".  Need
+   to do it ourselves.  */
+EXTERN_C_PUSH
+
 #include <proc_service.h>
 
+EXTERN_C_POP
+
 #else /* HAVE_PROC_SERVICE_H */
 
 /* The following fallback definitions have been imported and adjusted
@@ -55,6 +62,8 @@ 
 
 #include "gregset.h"
 
+EXTERN_C_PUSH
+
 /* Functions in this interface return one of these status codes.  */
 typedef enum
 {
@@ -150,6 +159,8 @@  extern ps_err_e ps_lsetxregs (struct ps_prochandle *ph, lwpid_t lwpid,
 /* Log a message (sends to gdb_stderr).  */
 extern void ps_plog (const char *fmt, ...);
 
+EXTERN_C_POP
+
 #endif /* HAVE_PROC_SERVICE_H */
 
 /* Fix-up some broken systems.  */
diff --git a/gdb/gdbserver/gdb_proc_service.h b/gdb/gdbserver/gdb_proc_service.h
index 1f3e277..2dcfa5b 100644
--- a/gdb/gdbserver/gdb_proc_service.h
+++ b/gdb/gdbserver/gdb_proc_service.h
@@ -22,7 +22,15 @@ 
 #include <sys/types.h>
 
 #ifdef HAVE_PROC_SERVICE_H
+
+/* glibc's proc_service.h doesn't wrap itself with extern "C".  Need
+   to do it ourselves.  */
+EXTERN_C_PUSH
+
 #include <proc_service.h>
+
+EXTERN_C_POP
+
 #else
 
 #ifdef HAVE_SYS_PROCFS_H
@@ -38,6 +46,8 @@ 
 # endif
 #endif
 
+EXTERN_C_PUSH
+
 typedef enum
 {
   PS_OK,			/* Success.  */
@@ -61,6 +71,75 @@  typedef void *psaddr_t;
 typedef elf_gregset_t prgregset_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;
+
+
+/* Read or write process memory at the given address.  */
+extern ps_err_e ps_pdread (struct ps_prochandle *,
+			   psaddr_t, void *, size_t);
+extern ps_err_e ps_pdwrite (struct ps_prochandle *,
+			    psaddr_t, const void *, size_t);
+extern ps_err_e ps_ptread (struct ps_prochandle *,
+			   psaddr_t, void *, size_t);
+extern ps_err_e ps_ptwrite (struct ps_prochandle *,
+			    psaddr_t, const void *, size_t);
+
+
+/* Get and set the given LWP's general or FPU register set.  */
+extern ps_err_e ps_lgetregs (struct ps_prochandle *,
+			     lwpid_t, prgregset_t);
+extern ps_err_e ps_lsetregs (struct ps_prochandle *,
+			     lwpid_t, const prgregset_t);
+extern ps_err_e ps_lgetfpregs (struct ps_prochandle *,
+			       lwpid_t, prfpregset_t *);
+extern ps_err_e ps_lsetfpregs (struct ps_prochandle *,
+			       lwpid_t, const prfpregset_t *);
+
+/* Return the PID of the process.  */
+extern pid_t ps_getpid (struct ps_prochandle *);
+
+/* Fetch the special per-thread address associated with the given LWP.
+   This call is only used on a few platforms (most use a normal register).
+   The meaning of the `int' parameter is machine-dependent.  */
+extern ps_err_e ps_get_thread_area (const struct ps_prochandle *,
+				    lwpid_t, int, psaddr_t *);
+
+
+/* Look up the named symbol in the named DSO in the symbol tables
+   associated with the process being debugged, filling in *SYM_ADDR
+   with the corresponding run-time address.  */
+extern ps_err_e ps_pglobal_lookup (struct ps_prochandle *,
+				   const char *object_name,
+				   const char *sym_name,
+				   psaddr_t *sym_addr);
+
+
+/* Stop or continue the entire process.  */
+extern ps_err_e ps_pstop (struct ps_prochandle *);
+extern ps_err_e ps_pcontinue (struct ps_prochandle *);
+
+/* Stop or continue the given LWP alone.  */
+extern ps_err_e ps_lstop (struct ps_prochandle *, lwpid_t);
+extern ps_err_e ps_lcontinue (struct ps_prochandle *, lwpid_t);
+
+/* The following are only defined in/called by Solaris.  */
+
+/* Get size of extra register set.  */
+extern ps_err_e ps_lgetxregsize (struct ps_prochandle *ph,
+				 lwpid_t lwpid, int *xregsize);
+/* Get extra register set.  */
+extern ps_err_e ps_lgetxregs (struct ps_prochandle *ph, lwpid_t lwpid,
+			      caddr_t xregset);
+extern ps_err_e ps_lsetxregs (struct ps_prochandle *ph, lwpid_t lwpid,
+			      caddr_t xregset);
+
+/* Log a message (sends to gdb_stderr).  */
+extern void ps_plog (const char *fmt, ...);
+
+EXTERN_C_POP
+
 #endif /* HAVE_PROC_SERVICE_H */
 
 /* Structure that identifies the target process.  */
diff --git a/gdb/gdbserver/proc-service.c b/gdb/gdbserver/proc-service.c
index b181ae5..f36e3fb 100644
--- a/gdb/gdbserver/proc-service.c
+++ b/gdb/gdbserver/proc-service.c
@@ -135,7 +135,7 @@  ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
    process PH and store them in FPREGSET.  */
 
 ps_err_e
-ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset)
+ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
 {
   /* Unneeded.  */
   return PS_ERR;
@@ -145,7 +145,7 @@  ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset)
    process PH from FPREGSET.  */
 
 ps_err_e
-ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset)
+ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
 {
   /* Unneeded.  */
   return PS_ERR;