Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
@ 2015-08-03 18:49 Pedro Alves
  2015-08-03 18:54 ` Doug Evans
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-08-03 18:49 UTC (permalink / raw)
  To: gdb-patches

Implicit void * -> function pointer conversion doesn't work in C++, so
in C++, we need to cast the result of dlsym.  This adds a few typedefs
and macros that make this easy.  GDBserver's version already had the
CHK macro, so I added it to GDB too.

Tested on x86_64 Fedora 20.

gdb/gdbserver/ChangeLog:
2015-08-03  Pedro Alves  <palves@redhat.com>

	* thread-db.c (td_ta_new_ftype, td_ta_map_lwp2thr_ftype)
	(td_ta_thr_iter_ftype, td_ta_event_addr_ftype)
	(td_ta_set_event_ftype, td_ta_clear_event_ftype)
	(td_ta_event_getmsg_ftype, td_thr_validate_ftype)
	(td_thr_get_info_ftype, td_thr_event_enable_ftype)
	(td_thr_tls_get_addr_ftype, td_thr_tlsbase_ftype)
	(td_symbol_list_ftype, td_ta_delete_ftype): New typedefs.
	(struct thread_db): Use them.
	(try_thread_db_load_1): Define local TDB_DLSYM macro and use it in
	CHK calls.
	(disable_thread_event_reporting): Cast result of dlsym to
	destination function pointer type.
	(thread_db_mourn): Use td_ta_delete_ftype.

gdb/ChangeLog:
2015-08-03  Pedro Alves  <palves@redhat.com>

	* linux-thread-db.c (td_init_ftype, td_ta_new_ftype)
	(td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
	(td_ta_event_addr_ftype, td_ta_set_event_ftype)
	(td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
	(td_thr_validate_ftype, td_thr_get_info_ftype)
	(td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
	(td_thr_tlsbase_ftype): New typedefs.
	(struct thread_db_info): Use them.
	(try_thread_db_load_1): Define TDB_VERBOSE_DLSYM, TDB_DLSYM , CHK
	local macros and use them instead of verbose_dlsym and dlsym
	calls.
---
 gdb/gdbserver/thread-db.c | 103 +++++++++++++++++++++--------------
 gdb/linux-thread-db.c     | 135 +++++++++++++++++++++++++++-------------------
 2 files changed, 143 insertions(+), 95 deletions(-)

diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index 4288fdb..8ab7277 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -37,6 +37,39 @@ static int thread_db_use_events;
 #include <limits.h>
 #include <ctype.h>
 
+typedef td_err_e (td_ta_new_ftype) (struct ps_prochandle * ps,
+				    td_thragent_t **ta);
+typedef td_err_e (td_ta_map_lwp2thr_ftype) (const td_thragent_t *ta,
+					    lwpid_t lwpid, td_thrhandle_t *th);
+typedef td_err_e (td_ta_thr_iter_ftype) (const td_thragent_t *ta,
+					 td_thr_iter_f *callback, void *cbdata_p,
+					 td_thr_state_e state, int ti_pri,
+					 sigset_t *ti_sigmask_p,
+					 unsigned int ti_user_flags);
+typedef td_err_e (td_ta_event_addr_ftype) (const td_thragent_t *ta,
+					   td_event_e event, td_notify_t *ptr);
+typedef td_err_e (td_ta_set_event_ftype) (const td_thragent_t *ta,
+					  td_thr_events_t *event);
+typedef td_err_e (td_ta_clear_event_ftype) (const td_thragent_t *ta,
+					    td_thr_events_t *event);
+typedef td_err_e (td_ta_event_getmsg_ftype) (const td_thragent_t *ta,
+					     td_event_msg_t *msg);
+
+typedef td_err_e (td_thr_validate_ftype) (const td_thrhandle_t *th);
+typedef td_err_e (td_thr_get_info_ftype) (const td_thrhandle_t *th,
+					  td_thrinfo_t *infop);
+typedef td_err_e (td_thr_event_enable_ftype) (const td_thrhandle_t *th,
+					      int event);
+
+typedef td_err_e (td_thr_tls_get_addr_ftype) (const td_thrhandle_t *th,
+					      psaddr_t map_address,
+					      size_t offset, psaddr_t *address);
+typedef td_err_e (td_thr_tlsbase_ftype) (const td_thrhandle_t *th,
+					 unsigned long int modid,
+					 psaddr_t *base);
+typedef const char ** (td_symbol_list_ftype) (void);
+typedef td_err_e (td_ta_delete_ftype) (td_thragent_t *);
+
 struct thread_db
 {
   /* Structure that identifies the child process for the
@@ -67,30 +100,17 @@ struct thread_db
   struct breakpoint *td_create_bp;
 
   /* Addresses of libthread_db functions.  */
-  td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
-  td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
-				    td_event_msg_t *msg);
-  td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
-				 td_thr_events_t *event);
-  td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
-				  td_event_e event, td_notify_t *ptr);
-  td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid,
-				   td_thrhandle_t *th);
-  td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
-				 td_thrinfo_t *infop);
-  td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event);
-  td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
-				td_thr_iter_f *callback, void *cbdata_p,
-				td_thr_state_e state, int ti_pri,
-				sigset_t *ti_sigmask_p,
-				unsigned int ti_user_flags);
-  td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
-				     psaddr_t map_address,
-				     size_t offset, psaddr_t *address);
-  td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
-				unsigned long int modid,
-				psaddr_t *base);
-  const char ** (*td_symbol_list_p) (void);
+  td_ta_new_ftype *td_ta_new_p;
+  td_ta_event_getmsg_ftype * td_ta_event_getmsg_p;
+  td_ta_set_event_ftype *td_ta_set_event_p;
+  td_ta_event_addr_ftype *td_ta_event_addr_p;
+  td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p;
+  td_thr_get_info_ftype *td_thr_get_info_p;
+  td_thr_event_enable_ftype *td_thr_event_enable_p;
+  td_ta_thr_iter_ftype *td_ta_thr_iter_p;
+  td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p;
+  td_thr_tlsbase_ftype *td_thr_tlsbase_p;
+  td_symbol_list_ftype *td_symbol_list_p;
 };
 
 static char *libthread_db_search_path;
@@ -645,7 +665,10 @@ try_thread_db_load_1 (void *handle)
     }								\
   while (0)
 
-  CHK (1, tdb->td_ta_new_p = dlsym (handle, "td_ta_new"));
+#define TDB_DLSYM(tdb, func) \
+  tdb->func ## _p = (func ## _ftype *) dlsym (tdb->handle, #func)
+
+  CHK (1, TDB_DLSYM (tdb, td_ta_new));
 
   /* Attempt to open a connection to the thread library.  */
   err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
@@ -658,23 +681,23 @@ try_thread_db_load_1 (void *handle)
       return 0;
     }
 
-  CHK (1, tdb->td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
-  CHK (1, tdb->td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
-  CHK (1, tdb->td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
-  CHK (1, tdb->td_symbol_list_p = dlsym (handle, "td_symbol_list"));
+  CHK (1, TDB_DLSYM (tdb, td_ta_map_lwp2thr));
+  CHK (1, TDB_DLSYM (tdb, td_thr_get_info));
+  CHK (1, TDB_DLSYM (tdb, td_ta_thr_iter));
+  CHK (1, TDB_DLSYM (tdb, td_symbol_list));
 
   /* This is required only when thread_db_use_events is on.  */
-  CHK (thread_db_use_events,
-       tdb->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
+  CHK (thread_db_use_events, TDB_DLSYM (tdb, td_thr_event_enable));
 
   /* These are not essential.  */
-  CHK (0, tdb->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
-  CHK (0, tdb->td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
-  CHK (0, tdb->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
-  CHK (0, tdb->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
-  CHK (0, tdb->td_thr_tlsbase_p = dlsym (handle, "td_thr_tlsbase"));
+  CHK (0, TDB_DLSYM (tdb, td_ta_event_addr));
+  CHK (0, TDB_DLSYM (tdb, td_ta_set_event));
+  CHK (0, TDB_DLSYM (tdb, td_ta_event_getmsg));
+  CHK (0, TDB_DLSYM (tdb, td_thr_tls_get_addr));
+  CHK (0, TDB_DLSYM (tdb, td_thr_tlsbase));
 
 #undef CHK
+#undef TDB_DLSYM
 
   return 1;
 }
@@ -914,7 +937,9 @@ disable_thread_event_reporting (struct process_info *proc)
 				       td_thr_events_t *event);
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
-      td_ta_clear_event_p = dlsym (thread_db->handle, "td_ta_clear_event");
+      td_ta_clear_event_p
+	= (td_ta_clear_event_ftype *) dlsym (thread_db->handle,
+					     "td_ta_clear_event");
 #else
       td_ta_clear_event_p = &td_ta_clear_event;
 #endif
@@ -974,10 +999,10 @@ thread_db_mourn (struct process_info *proc)
   struct thread_db *thread_db = proc->priv->thread_db;
   if (thread_db)
     {
-      td_err_e (*td_ta_delete_p) (td_thragent_t *);
+      td_ta_delete_ftype *td_ta_delete_p;
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
-      td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
+      td_ta_delete_p = (td_ta_delete_ftype *) dlsym (thread_db->handle, "td_ta_delete");
 #else
       td_ta_delete_p = &td_ta_delete;
 #endif
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 26350bb..a076b5e 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -133,6 +133,41 @@ static int thread_signals;
 static sigset_t thread_stop_set;
 static sigset_t thread_print_set;
 
+/* Types of the libthread_db functions.  */
+
+typedef td_err_e (td_init_ftype) (void);
+
+typedef td_err_e (td_ta_new_ftype) (struct ps_prochandle * ps,
+				    td_thragent_t **ta);
+typedef td_err_e (td_ta_map_lwp2thr_ftype) (const td_thragent_t *ta,
+					    lwpid_t lwpid, td_thrhandle_t *th);
+typedef td_err_e (td_ta_thr_iter_ftype) (const td_thragent_t *ta,
+					 td_thr_iter_f *callback, void *cbdata_p,
+					 td_thr_state_e state, int ti_pri,
+					 sigset_t *ti_sigmask_p,
+					 unsigned int ti_user_flags);
+typedef td_err_e (td_ta_event_addr_ftype) (const td_thragent_t *ta,
+					   td_event_e event, td_notify_t *ptr);
+typedef td_err_e (td_ta_set_event_ftype) (const td_thragent_t *ta,
+					  td_thr_events_t *event);
+typedef td_err_e (td_ta_clear_event_ftype) (const td_thragent_t *ta,
+					    td_thr_events_t *event);
+typedef td_err_e (td_ta_event_getmsg_ftype) (const td_thragent_t *ta,
+					     td_event_msg_t *msg);
+
+typedef td_err_e (td_thr_validate_ftype) (const td_thrhandle_t *th);
+typedef td_err_e (td_thr_get_info_ftype) (const td_thrhandle_t *th,
+					  td_thrinfo_t *infop);
+typedef td_err_e (td_thr_event_enable_ftype) (const td_thrhandle_t *th,
+					      int event);
+
+typedef td_err_e (td_thr_tls_get_addr_ftype) (const td_thrhandle_t *th,
+					      psaddr_t map_address,
+					      size_t offset, psaddr_t *address);
+typedef td_err_e (td_thr_tlsbase_ftype) (const td_thrhandle_t *th,
+					 unsigned long int modid,
+					 psaddr_t *base);
+
 struct thread_db_info
 {
   struct thread_db_info *next;
@@ -174,37 +209,19 @@ struct thread_db_info
 
   /* Pointers to the libthread_db functions.  */
 
-  td_err_e (*td_init_p) (void);
-
-  td_err_e (*td_ta_new_p) (struct ps_prochandle * ps,
-				td_thragent_t **ta);
-  td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta,
-				   lwpid_t lwpid, td_thrhandle_t *th);
-  td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
-				td_thr_iter_f *callback, void *cbdata_p,
-				td_thr_state_e state, int ti_pri,
-				sigset_t *ti_sigmask_p,
-				unsigned int ti_user_flags);
-  td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
-				  td_event_e event, td_notify_t *ptr);
-  td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
-				 td_thr_events_t *event);
-  td_err_e (*td_ta_clear_event_p) (const td_thragent_t *ta,
-				   td_thr_events_t *event);
-  td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
-				    td_event_msg_t *msg);
-
-  td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
-				 td_thrinfo_t *infop);
-  td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th,
-				     int event);
-
-  td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
-				     psaddr_t map_address,
-				     size_t offset, psaddr_t *address);
-  td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
-				unsigned long int modid,
-				psaddr_t *base);
+  td_init_ftype *td_init_p;
+  td_ta_new_ftype *td_ta_new_p;
+  td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p;
+  td_ta_thr_iter_ftype *td_ta_thr_iter_p;
+  td_ta_event_addr_ftype *td_ta_event_addr_p;
+  td_ta_set_event_ftype *td_ta_set_event_p;
+  td_ta_clear_event_ftype *td_ta_clear_event_p;
+  td_ta_event_getmsg_ftype * td_ta_event_getmsg_p;
+  td_thr_validate_ftype *td_thr_validate_p;
+  td_thr_get_info_ftype *td_thr_get_info_p;
+  td_thr_event_enable_ftype *td_thr_event_enable_p;
+  td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p;
+  td_thr_tlsbase_ftype *td_thr_tlsbase_p;
 };
 
 /* List of known processes using thread_db, and the required
@@ -677,9 +694,20 @@ try_thread_db_load_1 (struct thread_db_info *info)
   /* Initialize pointers to the dynamic library functions we will use.
      Essential functions first.  */
 
-  info->td_init_p = verbose_dlsym (info->handle, "td_init");
-  if (info->td_init_p == NULL)
-    return 0;
+#define TDB_VERBOSE_DLSYM(info, func)			\
+  info->func ## _p = (func ## _ftype *) verbose_dlsym (info->handle, #func)
+
+#define TDB_DLSYM(info, func)			\
+  info->func ## _p = (func ## _ftype *) dlsym (info->handle, #func)
+
+#define CHK(a)								\
+  do									\
+    {									\
+      if ((a) == NULL)							\
+	return 0;							\
+  } while (0)
+
+  CHK (TDB_VERBOSE_DLSYM (info, td_init));
 
   err = info->td_init_p ();
   if (err != TD_OK)
@@ -689,9 +717,7 @@ try_thread_db_load_1 (struct thread_db_info *info)
       return 0;
     }
 
-  info->td_ta_new_p = verbose_dlsym (info->handle, "td_ta_new");
-  if (info->td_ta_new_p == NULL)
-    return 0;
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_new));
 
   /* Initialize the structure that identifies the child process.  */
   info->proc_handle.ptid = inferior_ptid;
@@ -720,27 +746,24 @@ try_thread_db_load_1 (struct thread_db_info *info)
       return 0;
     }
 
-  info->td_ta_map_lwp2thr_p = verbose_dlsym (info->handle,
-					     "td_ta_map_lwp2thr");
-  if (info->td_ta_map_lwp2thr_p == NULL)
-    return 0;
-
-  info->td_ta_thr_iter_p = verbose_dlsym (info->handle, "td_ta_thr_iter");
-  if (info->td_ta_thr_iter_p == NULL)
-    return 0;
-
-  info->td_thr_get_info_p = verbose_dlsym (info->handle, "td_thr_get_info");
-  if (info->td_thr_get_info_p == NULL)
-    return 0;
+  /* These are essential.  */
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_map_lwp2thr));
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
+  CHK (TDB_VERBOSE_DLSYM (info, td_thr_validate));
+  CHK (TDB_VERBOSE_DLSYM (info, td_thr_get_info));
 
   /* These are not essential.  */
-  info->td_ta_event_addr_p = dlsym (info->handle, "td_ta_event_addr");
-  info->td_ta_set_event_p = dlsym (info->handle, "td_ta_set_event");
-  info->td_ta_clear_event_p = dlsym (info->handle, "td_ta_clear_event");
-  info->td_ta_event_getmsg_p = dlsym (info->handle, "td_ta_event_getmsg");
-  info->td_thr_event_enable_p = dlsym (info->handle, "td_thr_event_enable");
-  info->td_thr_tls_get_addr_p = dlsym (info->handle, "td_thr_tls_get_addr");
-  info->td_thr_tlsbase_p = dlsym (info->handle, "td_thr_tlsbase");
+  TDB_DLSYM (info, td_ta_event_addr);
+  TDB_DLSYM (info, td_ta_set_event);
+  TDB_DLSYM (info, td_ta_clear_event);
+  TDB_DLSYM (info, td_ta_event_getmsg);
+  TDB_DLSYM (info, td_thr_event_enable);
+  TDB_DLSYM (info, td_thr_tls_get_addr);
+  TDB_DLSYM (info, td_thr_tlsbase);
+
+#undef TDB_VERBOSE_DLSYM
+#undef TDB_DLSYM
+#undef CHK
 
   /* It's best to avoid td_ta_thr_iter if possible.  That walks data
      structures in the inferior's address space that may be corrupted,
-- 
1.9.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-03 18:49 [PATCH] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c Pedro Alves
@ 2015-08-03 18:54 ` Doug Evans
  2015-08-03 19:28   ` [PATCH v2] " Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Doug Evans @ 2015-08-03 18:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Mon, Aug 3, 2015 at 11:49 AM, Pedro Alves <palves@redhat.com> wrote:
> Implicit void * -> function pointer conversion doesn't work in C++, so
> in C++, we need to cast the result of dlsym.  This adds a few typedefs
> and macros that make this easy.  GDBserver's version already had the
> CHK macro, so I added it to GDB too.
>
> Tested on x86_64 Fedora 20.
>
> gdb/gdbserver/ChangeLog:
> 2015-08-03  Pedro Alves  <palves@redhat.com>
>
>         * thread-db.c (td_ta_new_ftype, td_ta_map_lwp2thr_ftype)
>         (td_ta_thr_iter_ftype, td_ta_event_addr_ftype)
>         (td_ta_set_event_ftype, td_ta_clear_event_ftype)
>         (td_ta_event_getmsg_ftype, td_thr_validate_ftype)
>         (td_thr_get_info_ftype, td_thr_event_enable_ftype)
>         (td_thr_tls_get_addr_ftype, td_thr_tlsbase_ftype)
>         (td_symbol_list_ftype, td_ta_delete_ftype): New typedefs.
>         (struct thread_db): Use them.
>         (try_thread_db_load_1): Define local TDB_DLSYM macro and use it in
>         CHK calls.
>         (disable_thread_event_reporting): Cast result of dlsym to
>         destination function pointer type.
>         (thread_db_mourn): Use td_ta_delete_ftype.
>
> gdb/ChangeLog:
> 2015-08-03  Pedro Alves  <palves@redhat.com>
>
>         * linux-thread-db.c (td_init_ftype, td_ta_new_ftype)
>         (td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
>         (td_ta_event_addr_ftype, td_ta_set_event_ftype)
>         (td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
>         (td_thr_validate_ftype, td_thr_get_info_ftype)
>         (td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
>         (td_thr_tlsbase_ftype): New typedefs.
>         (struct thread_db_info): Use them.
>         (try_thread_db_load_1): Define TDB_VERBOSE_DLSYM, TDB_DLSYM , CHK
>         local macros and use them instead of verbose_dlsym and dlsym
>         calls.

Hi.

Nit: Can we put all the typedefs in a common header?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-03 18:54 ` Doug Evans
@ 2015-08-03 19:28   ` Pedro Alves
  2015-08-03 19:35     ` Doug Evans
  2015-08-05 13:34     ` Ulrich Weigand
  0 siblings, 2 replies; 9+ messages in thread
From: Pedro Alves @ 2015-08-03 19:28 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On 08/03/2015 07:54 PM, Doug Evans wrote:

> Nit: Can we put all the typedefs in a common header?

Good idea.  How about this?

From 387898b86474ca9647ca8a498a68d521033555e1 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 3 Aug 2015 20:23:59 +0100
Subject: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and
 gdb/gdbserver/thread-db.c

Implicit void * -> function pointer conversion doesn't work in C++, so
in C++, we need to cast the result of dlsym.  This adds a few typedefs
and macros that make this easy.  GDBserver's version already had the
CHK macro, so I added it to GDB too.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/gdbserver/ChangeLog:
2015-08-03  Pedro Alves  <palves@redhat.com>

	* thread-db.c (struct thread_db): Use new typedefs.
	(try_thread_db_load_1): Define local TDB_DLSYM macro and use it in
	CHK calls.
	(disable_thread_event_reporting): Cast result of dlsym to
	destination function pointer type.
	(thread_db_mourn): Use td_ta_delete_ftype.

gdb/ChangeLog:
2015-08-03  Pedro Alves  <palves@redhat.com>

	* nat/gdb_thread_db.h (td_init_ftype, td_ta_new_ftype)
	(td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
	(td_ta_event_addr_ftype, td_ta_set_event_ftype)
	(td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
	(td_thr_validate_ftype, td_thr_get_info_ftype)
	(td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
	(td_thr_tlsbase_ftype, td_symbol_list_ftype, td_ta_delete_ftype):
	New typedefs.
	* linux-thread-db.c (struct thread_db_info): Use new typedefs.
	(try_thread_db_load_1): Define TDB_VERBOSE_DLSYM, TDB_DLSYM , CHK
	local macros and use them instead of verbose_dlsym and dlsym
	calls.
---
 gdb/gdbserver/thread-db.c |  70 ++++++++++++++------------------
 gdb/linux-thread-db.c     | 100 ++++++++++++++++++++--------------------------
 gdb/nat/gdb_thread_db.h   |  38 ++++++++++++++++++
 3 files changed, 113 insertions(+), 95 deletions(-)

diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index 4288fdb..3da636e 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -67,30 +67,17 @@ struct thread_db
   struct breakpoint *td_create_bp;
 
   /* Addresses of libthread_db functions.  */
-  td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
-  td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
-				    td_event_msg_t *msg);
-  td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
-				 td_thr_events_t *event);
-  td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
-				  td_event_e event, td_notify_t *ptr);
-  td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid,
-				   td_thrhandle_t *th);
-  td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
-				 td_thrinfo_t *infop);
-  td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event);
-  td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
-				td_thr_iter_f *callback, void *cbdata_p,
-				td_thr_state_e state, int ti_pri,
-				sigset_t *ti_sigmask_p,
-				unsigned int ti_user_flags);
-  td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
-				     psaddr_t map_address,
-				     size_t offset, psaddr_t *address);
-  td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
-				unsigned long int modid,
-				psaddr_t *base);
-  const char ** (*td_symbol_list_p) (void);
+  td_ta_new_ftype *td_ta_new_p;
+  td_ta_event_getmsg_ftype * td_ta_event_getmsg_p;
+  td_ta_set_event_ftype *td_ta_set_event_p;
+  td_ta_event_addr_ftype *td_ta_event_addr_p;
+  td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p;
+  td_thr_get_info_ftype *td_thr_get_info_p;
+  td_thr_event_enable_ftype *td_thr_event_enable_p;
+  td_ta_thr_iter_ftype *td_ta_thr_iter_p;
+  td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p;
+  td_thr_tlsbase_ftype *td_thr_tlsbase_p;
+  td_symbol_list_ftype *td_symbol_list_p;
 };
 
 static char *libthread_db_search_path;
@@ -645,7 +632,10 @@ try_thread_db_load_1 (void *handle)
     }								\
   while (0)
 
-  CHK (1, tdb->td_ta_new_p = dlsym (handle, "td_ta_new"));
+#define TDB_DLSYM(tdb, func) \
+  tdb->func ## _p = (func ## _ftype *) dlsym (tdb->handle, #func)
+
+  CHK (1, TDB_DLSYM (tdb, td_ta_new));
 
   /* Attempt to open a connection to the thread library.  */
   err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
@@ -658,23 +648,23 @@ try_thread_db_load_1 (void *handle)
       return 0;
     }
 
-  CHK (1, tdb->td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
-  CHK (1, tdb->td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
-  CHK (1, tdb->td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
-  CHK (1, tdb->td_symbol_list_p = dlsym (handle, "td_symbol_list"));
+  CHK (1, TDB_DLSYM (tdb, td_ta_map_lwp2thr));
+  CHK (1, TDB_DLSYM (tdb, td_thr_get_info));
+  CHK (1, TDB_DLSYM (tdb, td_ta_thr_iter));
+  CHK (1, TDB_DLSYM (tdb, td_symbol_list));
 
   /* This is required only when thread_db_use_events is on.  */
-  CHK (thread_db_use_events,
-       tdb->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
+  CHK (thread_db_use_events, TDB_DLSYM (tdb, td_thr_event_enable));
 
   /* These are not essential.  */
-  CHK (0, tdb->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
-  CHK (0, tdb->td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
-  CHK (0, tdb->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
-  CHK (0, tdb->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
-  CHK (0, tdb->td_thr_tlsbase_p = dlsym (handle, "td_thr_tlsbase"));
+  CHK (0, TDB_DLSYM (tdb, td_ta_event_addr));
+  CHK (0, TDB_DLSYM (tdb, td_ta_set_event));
+  CHK (0, TDB_DLSYM (tdb, td_ta_event_getmsg));
+  CHK (0, TDB_DLSYM (tdb, td_thr_tls_get_addr));
+  CHK (0, TDB_DLSYM (tdb, td_thr_tlsbase));
 
 #undef CHK
+#undef TDB_DLSYM
 
   return 1;
 }
@@ -914,7 +904,9 @@ disable_thread_event_reporting (struct process_info *proc)
 				       td_thr_events_t *event);
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
-      td_ta_clear_event_p = dlsym (thread_db->handle, "td_ta_clear_event");
+      td_ta_clear_event_p
+	= (td_ta_clear_event_ftype *) dlsym (thread_db->handle,
+					     "td_ta_clear_event");
 #else
       td_ta_clear_event_p = &td_ta_clear_event;
 #endif
@@ -974,10 +966,10 @@ thread_db_mourn (struct process_info *proc)
   struct thread_db *thread_db = proc->priv->thread_db;
   if (thread_db)
     {
-      td_err_e (*td_ta_delete_p) (td_thragent_t *);
+      td_ta_delete_ftype *td_ta_delete_p;
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
-      td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
+      td_ta_delete_p = (td_ta_delete_ftype *) dlsym (thread_db->handle, "td_ta_delete");
 #else
       td_ta_delete_p = &td_ta_delete;
 #endif
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 26350bb..84599d3 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -174,37 +174,19 @@ struct thread_db_info
 
   /* Pointers to the libthread_db functions.  */
 
-  td_err_e (*td_init_p) (void);
-
-  td_err_e (*td_ta_new_p) (struct ps_prochandle * ps,
-				td_thragent_t **ta);
-  td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta,
-				   lwpid_t lwpid, td_thrhandle_t *th);
-  td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
-				td_thr_iter_f *callback, void *cbdata_p,
-				td_thr_state_e state, int ti_pri,
-				sigset_t *ti_sigmask_p,
-				unsigned int ti_user_flags);
-  td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
-				  td_event_e event, td_notify_t *ptr);
-  td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
-				 td_thr_events_t *event);
-  td_err_e (*td_ta_clear_event_p) (const td_thragent_t *ta,
-				   td_thr_events_t *event);
-  td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
-				    td_event_msg_t *msg);
-
-  td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
-				 td_thrinfo_t *infop);
-  td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th,
-				     int event);
-
-  td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
-				     psaddr_t map_address,
-				     size_t offset, psaddr_t *address);
-  td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
-				unsigned long int modid,
-				psaddr_t *base);
+  td_init_ftype *td_init_p;
+  td_ta_new_ftype *td_ta_new_p;
+  td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p;
+  td_ta_thr_iter_ftype *td_ta_thr_iter_p;
+  td_ta_event_addr_ftype *td_ta_event_addr_p;
+  td_ta_set_event_ftype *td_ta_set_event_p;
+  td_ta_clear_event_ftype *td_ta_clear_event_p;
+  td_ta_event_getmsg_ftype * td_ta_event_getmsg_p;
+  td_thr_validate_ftype *td_thr_validate_p;
+  td_thr_get_info_ftype *td_thr_get_info_p;
+  td_thr_event_enable_ftype *td_thr_event_enable_p;
+  td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p;
+  td_thr_tlsbase_ftype *td_thr_tlsbase_p;
 };
 
 /* List of known processes using thread_db, and the required
@@ -677,9 +659,20 @@ try_thread_db_load_1 (struct thread_db_info *info)
   /* Initialize pointers to the dynamic library functions we will use.
      Essential functions first.  */
 
-  info->td_init_p = verbose_dlsym (info->handle, "td_init");
-  if (info->td_init_p == NULL)
-    return 0;
+#define TDB_VERBOSE_DLSYM(info, func)			\
+  info->func ## _p = (func ## _ftype *) verbose_dlsym (info->handle, #func)
+
+#define TDB_DLSYM(info, func)			\
+  info->func ## _p = (func ## _ftype *) dlsym (info->handle, #func)
+
+#define CHK(a)								\
+  do									\
+    {									\
+      if ((a) == NULL)							\
+	return 0;							\
+  } while (0)
+
+  CHK (TDB_VERBOSE_DLSYM (info, td_init));
 
   err = info->td_init_p ();
   if (err != TD_OK)
@@ -689,9 +682,7 @@ try_thread_db_load_1 (struct thread_db_info *info)
       return 0;
     }
 
-  info->td_ta_new_p = verbose_dlsym (info->handle, "td_ta_new");
-  if (info->td_ta_new_p == NULL)
-    return 0;
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_new));
 
   /* Initialize the structure that identifies the child process.  */
   info->proc_handle.ptid = inferior_ptid;
@@ -720,27 +711,24 @@ try_thread_db_load_1 (struct thread_db_info *info)
       return 0;
     }
 
-  info->td_ta_map_lwp2thr_p = verbose_dlsym (info->handle,
-					     "td_ta_map_lwp2thr");
-  if (info->td_ta_map_lwp2thr_p == NULL)
-    return 0;
-
-  info->td_ta_thr_iter_p = verbose_dlsym (info->handle, "td_ta_thr_iter");
-  if (info->td_ta_thr_iter_p == NULL)
-    return 0;
-
-  info->td_thr_get_info_p = verbose_dlsym (info->handle, "td_thr_get_info");
-  if (info->td_thr_get_info_p == NULL)
-    return 0;
+  /* These are essential.  */
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_map_lwp2thr));
+  CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
+  CHK (TDB_VERBOSE_DLSYM (info, td_thr_validate));
+  CHK (TDB_VERBOSE_DLSYM (info, td_thr_get_info));
 
   /* These are not essential.  */
-  info->td_ta_event_addr_p = dlsym (info->handle, "td_ta_event_addr");
-  info->td_ta_set_event_p = dlsym (info->handle, "td_ta_set_event");
-  info->td_ta_clear_event_p = dlsym (info->handle, "td_ta_clear_event");
-  info->td_ta_event_getmsg_p = dlsym (info->handle, "td_ta_event_getmsg");
-  info->td_thr_event_enable_p = dlsym (info->handle, "td_thr_event_enable");
-  info->td_thr_tls_get_addr_p = dlsym (info->handle, "td_thr_tls_get_addr");
-  info->td_thr_tlsbase_p = dlsym (info->handle, "td_thr_tlsbase");
+  TDB_DLSYM (info, td_ta_event_addr);
+  TDB_DLSYM (info, td_ta_set_event);
+  TDB_DLSYM (info, td_ta_clear_event);
+  TDB_DLSYM (info, td_ta_event_getmsg);
+  TDB_DLSYM (info, td_thr_event_enable);
+  TDB_DLSYM (info, td_thr_tls_get_addr);
+  TDB_DLSYM (info, td_thr_tlsbase);
+
+#undef TDB_VERBOSE_DLSYM
+#undef TDB_DLSYM
+#undef CHK
 
   /* It's best to avoid td_ta_thr_iter if possible.  That walks data
      structures in the inferior's address space that may be corrupted,
diff --git a/gdb/nat/gdb_thread_db.h b/gdb/nat/gdb_thread_db.h
index a1d9473..2938eaf 100644
--- a/gdb/nat/gdb_thread_db.h
+++ b/gdb/nat/gdb_thread_db.h
@@ -14,3 +14,41 @@
    libthread_db associated with whatever libpthread the app is using.  */
 #define LIBTHREAD_DB_SEARCH_PATH "$sdir:$pdir"
 #endif
+
+/* Types of the libthread_db functions.  */
+
+typedef td_err_e (td_init_ftype) (void);
+
+typedef td_err_e (td_ta_new_ftype) (struct ps_prochandle * ps,
+				    td_thragent_t **ta);
+typedef td_err_e (td_ta_map_lwp2thr_ftype) (const td_thragent_t *ta,
+					    lwpid_t lwpid, td_thrhandle_t *th);
+typedef td_err_e (td_ta_thr_iter_ftype) (const td_thragent_t *ta,
+					 td_thr_iter_f *callback, void *cbdata_p,
+					 td_thr_state_e state, int ti_pri,
+					 sigset_t *ti_sigmask_p,
+					 unsigned int ti_user_flags);
+typedef td_err_e (td_ta_event_addr_ftype) (const td_thragent_t *ta,
+					   td_event_e event, td_notify_t *ptr);
+typedef td_err_e (td_ta_set_event_ftype) (const td_thragent_t *ta,
+					  td_thr_events_t *event);
+typedef td_err_e (td_ta_clear_event_ftype) (const td_thragent_t *ta,
+					    td_thr_events_t *event);
+typedef td_err_e (td_ta_event_getmsg_ftype) (const td_thragent_t *ta,
+					     td_event_msg_t *msg);
+
+typedef td_err_e (td_thr_validate_ftype) (const td_thrhandle_t *th);
+typedef td_err_e (td_thr_get_info_ftype) (const td_thrhandle_t *th,
+					  td_thrinfo_t *infop);
+typedef td_err_e (td_thr_event_enable_ftype) (const td_thrhandle_t *th,
+					      int event);
+
+typedef td_err_e (td_thr_tls_get_addr_ftype) (const td_thrhandle_t *th,
+					      psaddr_t map_address,
+					      size_t offset, psaddr_t *address);
+typedef td_err_e (td_thr_tlsbase_ftype) (const td_thrhandle_t *th,
+					 unsigned long int modid,
+					 psaddr_t *base);
+
+typedef const char ** (td_symbol_list_ftype) (void);
+typedef td_err_e (td_ta_delete_ftype) (td_thragent_t *);
-- 
1.9.3



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-03 19:28   ` [PATCH v2] " Pedro Alves
@ 2015-08-03 19:35     ` Doug Evans
  2015-08-04  8:47       ` Pedro Alves
  2015-08-05 13:34     ` Ulrich Weigand
  1 sibling, 1 reply; 9+ messages in thread
From: Doug Evans @ 2015-08-03 19:35 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Mon, Aug 3, 2015 at 12:28 PM, Pedro Alves <palves@redhat.com> wrote:
> On 08/03/2015 07:54 PM, Doug Evans wrote:
>
>> Nit: Can we put all the typedefs in a common header?
>
> Good idea.  How about this?
>
> From 387898b86474ca9647ca8a498a68d521033555e1 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 3 Aug 2015 20:23:59 +0100
> Subject: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and
>  gdb/gdbserver/thread-db.c
>
> Implicit void * -> function pointer conversion doesn't work in C++, so
> in C++, we need to cast the result of dlsym.  This adds a few typedefs
> and macros that make this easy.  GDBserver's version already had the
> CHK macro, so I added it to GDB too.
>
> Tested on x86_64 Fedora 20, native and gdbserver.
>
> gdb/gdbserver/ChangeLog:
> 2015-08-03  Pedro Alves  <palves@redhat.com>
>
>         * thread-db.c (struct thread_db): Use new typedefs.
>         (try_thread_db_load_1): Define local TDB_DLSYM macro and use it in
>         CHK calls.
>         (disable_thread_event_reporting): Cast result of dlsym to
>         destination function pointer type.
>         (thread_db_mourn): Use td_ta_delete_ftype.
>
> gdb/ChangeLog:
> 2015-08-03  Pedro Alves  <palves@redhat.com>
>
>         * nat/gdb_thread_db.h (td_init_ftype, td_ta_new_ftype)
>         (td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
>         (td_ta_event_addr_ftype, td_ta_set_event_ftype)
>         (td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
>         (td_thr_validate_ftype, td_thr_get_info_ftype)
>         (td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
>         (td_thr_tlsbase_ftype, td_symbol_list_ftype, td_ta_delete_ftype):
>         New typedefs.
>         * linux-thread-db.c (struct thread_db_info): Use new typedefs.
>         (try_thread_db_load_1): Define TDB_VERBOSE_DLSYM, TDB_DLSYM , CHK
>         local macros and use them instead of verbose_dlsym and dlsym
>         calls.

"works for me"
[FAOD, I have no other comments on the patch.]


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-03 19:35     ` Doug Evans
@ 2015-08-04  8:47       ` Pedro Alves
  0 siblings, 0 replies; 9+ messages in thread
From: Pedro Alves @ 2015-08-04  8:47 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On 08/03/2015 08:35 PM, Doug Evans wrote:

> "works for me"
> [FAOD, I have no other comments on the patch.]

Thanks, I pushed it.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-03 19:28   ` [PATCH v2] " Pedro Alves
  2015-08-03 19:35     ` Doug Evans
@ 2015-08-05 13:34     ` Ulrich Weigand
  2015-08-05 13:51       ` Pedro Alves
  1 sibling, 1 reply; 9+ messages in thread
From: Ulrich Weigand @ 2015-08-05 13:34 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Doug Evans, gdb-patches

Pedro Alves wrote:

> gdb/ChangeLog:
> 2015-08-03  Pedro Alves  <palves@redhat.com>
> 
> 	* nat/gdb_thread_db.h (td_init_ftype, td_ta_new_ftype)
> 	(td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
> 	(td_ta_event_addr_ftype, td_ta_set_event_ftype)
> 	(td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
> 	(td_thr_validate_ftype, td_thr_get_info_ftype)
> 	(td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
> 	(td_thr_tlsbase_ftype, td_symbol_list_ftype, td_ta_delete_ftype):
> 	New typedefs.

This breaks the build for me with:

In file included from /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/thread-db.c:31:                         
/home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:20: error: redefinition of typedef ‘td_init_ftype’                                                                                                                                            
/home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:20: error: previous declaration of ‘td_init_ftype’ was here                                                                                                                                   
/home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:23: error: redefinition of typedef ‘td_ta_new_ftype’                                                                                                                                          
/home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:23: error: previous declaration of ‘td_ta_new_ftype’ was here                                                                                                                                 
[... etc for each of the typedefs ...]

It seems this is caused by the nat/gdb_thread_db.h header file
being included twice into gdbserver/thread-db.c:

1) via line 23:
#include "linux-low.h"
(which includes "nat/gdb_thread_db.h" at line 20)

2) directly in line 30:
#include "nat/gdb_thread_db.h"

and the file not being guarded against double inclusion.

(I'm not 100% sure whether an identical second typedef is supposed
to be valid C or not, but at least my GCC 4.1 host compiler rejects
it in this case.)

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-05 13:34     ` Ulrich Weigand
@ 2015-08-05 13:51       ` Pedro Alves
  2015-08-05 14:35         ` Ulrich Weigand
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-08-05 13:51 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Doug Evans, gdb-patches

On 08/05/2015 02:34 PM, Ulrich Weigand wrote:
> Pedro Alves wrote:
> 
>> gdb/ChangeLog:
>> 2015-08-03  Pedro Alves  <palves@redhat.com>
>>
>> 	* nat/gdb_thread_db.h (td_init_ftype, td_ta_new_ftype)
>> 	(td_ta_map_lwp2thr_ftype, td_ta_thr_iter_ftype)
>> 	(td_ta_event_addr_ftype, td_ta_set_event_ftype)
>> 	(td_ta_clear_event_ftype, td_ta_event_getmsg_ftype)
>> 	(td_thr_validate_ftype, td_thr_get_info_ftype)
>> 	(td_thr_event_enable_ftype, td_thr_tls_get_addr_ftype)
>> 	(td_thr_tlsbase_ftype, td_symbol_list_ftype, td_ta_delete_ftype):
>> 	New typedefs.
> 
> This breaks the build for me with:
> 
> In file included from /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/thread-db.c:31:                         
> /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:20: error: redefinition of typedef ‘td_init_ftype’                                                                                                                                            
> /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:20: error: previous declaration of ‘td_init_ftype’ was here                                                                                                                                   
> /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:23: error: redefinition of typedef ‘td_ta_new_ftype’                                                                                                                                          
> /home/uweigand/dailybuild/spu-tc-2015-08-04/binutils-gdb-head/binutils-gdb/gdb/gdbserver/../nat/gdb_thread_db.h:23: error: previous declaration of ‘td_ta_new_ftype’ was here                                                                                                                                 
> [... etc for each of the typedefs ...]
> 
> It seems this is caused by the nat/gdb_thread_db.h header file
> being included twice into gdbserver/thread-db.c:
> 
> 1) via line 23:
> #include "linux-low.h"
> (which includes "nat/gdb_thread_db.h" at line 20)
> 
> 2) directly in line 30:
> #include "nat/gdb_thread_db.h"
> 
> and the file not being guarded against double inclusion.

Yeah, I think we should just add the guards.

Are you already taking care of that, or would you like me to?

> 
> (I'm not 100% sure whether an identical second typedef is supposed
> to be valid C or not, but at least my GCC 4.1 host compiler rejects
> it in this case.)

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-05 13:51       ` Pedro Alves
@ 2015-08-05 14:35         ` Ulrich Weigand
  2015-08-05 14:36           ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Ulrich Weigand @ 2015-08-05 14:35 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Doug Evans, gdb-patches

Pedro Alves wrote:
> On 08/05/2015 02:34 PM, Ulrich Weigand wrote:
> > It seems this is caused by the nat/gdb_thread_db.h header file
> > being included twice into gdbserver/thread-db.c:
> > 
> > 1) via line 23:
> > #include "linux-low.h"
> > (which includes "nat/gdb_thread_db.h" at line 20)
> > 
> > 2) directly in line 30:
> > #include "nat/gdb_thread_db.h"
> > 
> > and the file not being guarded against double inclusion.
> 
> Yeah, I think we should just add the guards.
> 
> Are you already taking care of that, or would you like me to?

I've now checked in the patch below.  (Also adding the missing
copyright header while I was at it.)

Tested on i686-linux.

Bye,
Ulrich

ChangeLog:

	* nat/gdb_thread_db.h: Add copyright header.
	Protect against multiple inclusion.

diff --git a/gdb/nat/gdb_thread_db.h b/gdb/nat/gdb_thread_db.h
index 2938eaf..3be4170 100644
--- a/gdb/nat/gdb_thread_db.h
+++ b/gdb/nat/gdb_thread_db.h
@@ -1,3 +1,23 @@
+/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_THREAD_DB_H
+#define GDB_THREAD_DB_H 1
+
 #ifdef HAVE_THREAD_DB_H
 #include <thread_db.h>
 #else
@@ -52,3 +72,5 @@ typedef td_err_e (td_thr_tlsbase_ftype) (const td_thrhandle_t *th,
 
 typedef const char ** (td_symbol_list_ftype) (void);
 typedef td_err_e (td_ta_delete_ftype) (td_thragent_t *);
+
+#endif /* GDB_THREAD_DB_H */


-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c
  2015-08-05 14:35         ` Ulrich Weigand
@ 2015-08-05 14:36           ` Pedro Alves
  0 siblings, 0 replies; 9+ messages in thread
From: Pedro Alves @ 2015-08-05 14:36 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Doug Evans, gdb-patches

On 08/05/2015 03:35 PM, Ulrich Weigand wrote:

> I've now checked in the patch below.  (Also adding the missing
> copyright header while I was at it.)

Thanks!

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-08-05 14:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-03 18:49 [PATCH] C++: dlsym casts in gdb/linux-thread-db.c and gdb/gdbserver/thread-db.c Pedro Alves
2015-08-03 18:54 ` Doug Evans
2015-08-03 19:28   ` [PATCH v2] " Pedro Alves
2015-08-03 19:35     ` Doug Evans
2015-08-04  8:47       ` Pedro Alves
2015-08-05 13:34     ` Ulrich Weigand
2015-08-05 13:51       ` Pedro Alves
2015-08-05 14:35         ` Ulrich Weigand
2015-08-05 14:36           ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox