2009-10-29 Paul Pluzhnikov <ppluzhnikov@google.com>
authorPaul Pluzhnikov <ppluzhnikov@google.com>
Thu, 29 Oct 2009 17:43:44 +0000 (17:43 +0000)
committerPaul Pluzhnikov <ppluzhnikov@google.com>
Thu, 29 Oct 2009 17:43:44 +0000 (17:43 +0000)
* configure.ac: New --with-libthread-db option.
* thread-db.c: Allow direct dependence on libthread_db.
(thread_db_free): Adjust.
* config.in: Regenerate.
* configure: Likewise.

gdb/gdbserver/ChangeLog
gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/thread-db.c

index 77a5d1902830cdc9b7a67f508e3a0b538f8cc492..fceb900c4f79e8d6a497344415ad1b0d9764fea7 100644 (file)
@@ -1,3 +1,11 @@
+2009-10-29  Paul Pluzhnikov  <ppluzhnikov@google.com>
+
+       * configure.ac: New --with-libthread-db option.
+       * thread-db.c: Allow direct dependence on libthread_db.
+       (thread_db_free): Adjust.
+       * config.in: Regenerate.
+       * configure: Likewise.
+       
 2009-10-28  Paul Pluzhnikov  <ppluzhnikov@google.com>
 
        PR gdb/10757
index 7eb11b9941ab572f1bf3d5a6a9cd51a40e4de148..7c8996631f6b94744a19396c52cad4c2368c9015 100644 (file)
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define if we should use libthread_db directly. */
+#undef USE_LIBTHREAD_DB_DIRECTLY
+
 /* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
index b88ed5b605deabe1a02eff5c2cf9bc29131eec22..687105a5c85e1253881f3adf73bfcdb58584dc29 100755 (executable)
@@ -668,6 +668,7 @@ ac_user_opts='
 enable_option_checking
 with_pkgversion
 with_bugurl
+with_libthread_db
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1297,6 +1298,8 @@ Optional Packages:
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-pkgversion=PKG   Use PKG in the version string in place of "GDB"
   --with-bugurl=URL       Direct users to URL to report a bug
+  --with-libthread-db=PATH
+                          use given libthread_db directly
 
 Some influential environment variables:
   CC          C compiler command
@@ -4268,6 +4271,18 @@ $as_echo "#define HAVE_TD_VERSION 1" >>confdefs.h
   fi
 fi
 
+
+# Check whether --with-libthread-db was given.
+if test "${with_libthread_db+set}" = set; then :
+  withval=$with_libthread_db; srv_libthread_db_path="${withval}"
+
+$as_echo "#define USE_LIBTHREAD_DB_DIRECTLY 1" >>confdefs.h
+
+  srv_libs="$srv_libthread_db_path"
+
+fi
+
+
 if test "$srv_xmlfiles" != ""; then
   srv_xmlbuiltin="xml-builtin.o"
 
index a631c7eb0fa396e1d7a548c0914e83d07b2539f2..2f2b2a3ff4b2d6020ad0fab087239fc61cf56727 100644 (file)
@@ -158,6 +158,13 @@ if test "$srv_linux_thread_db" = "yes"; then
   fi
 fi
 
+AC_ARG_WITH(libthread-db,
+AS_HELP_STRING([--with-libthread-db=PATH], [use given libthread_db directly]),
+[srv_libthread_db_path="${withval}"
+  AC_DEFINE(USE_LIBTHREAD_DB_DIRECTLY, 1, [Define if we should use libthread_db directly.])
+  srv_libs="$srv_libthread_db_path"
+])
+
 if test "$srv_xmlfiles" != ""; then
   srv_xmlbuiltin="xml-builtin.o"
   AC_DEFINE(USE_XML, 1, [Define if an XML target description is available.])
index 0fb8647feb6ae841c2b808476462ffb548827d9b..06dfe3510a97a22c067e67c9c3f28f8954449201 100644 (file)
@@ -30,7 +30,10 @@ static int thread_db_use_events;
 #include "gdb_proc_service.h"
 #include "../gdb_thread_db.h"
 
+#ifndef USE_LIBTHREAD_DB_DIRECTLY
 #include <dlfcn.h>
+#endif
+
 #include <stdint.h>
 #include <limits.h>
 #include <ctype.h>
@@ -44,8 +47,10 @@ struct thread_db
   /* Connection to the libthread_db library.  */
   td_thragent_t *thread_agent;
 
+#ifndef USE_LIBTHREAD_DB_DIRECTLY
   /* Handle of the libthread_db from dlopen.  */
   void *handle;
+#endif
 
   /* Addresses of libthread_db functions.  */
   td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
@@ -484,6 +489,51 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
     return err;
 }
 
+#ifdef USE_LIBTHREAD_DB_DIRECTLY
+
+static int
+thread_db_load_search (void)
+{
+  td_err_e err;
+  struct thread_db tdb;
+  struct process_info *proc = current_process ();
+
+  if (proc->private->thread_db != NULL)
+    fatal ("unexpected: proc->private->thread_db != NULL");
+
+  tdb.td_ta_new_p = &td_ta_new;
+
+  /* Attempt to open a connection to the thread library.  */
+  err = tdb.td_ta_new_p (&tdb.proc_handle, &tdb.thread_agent);
+  if (err != TD_OK)
+    {
+      if (debug_threads)
+       fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
+      return 0;
+    }
+
+  tdb.td_ta_map_lwp2thr_p = &td_ta_map_lwp2thr;
+  tdb.td_thr_get_info_p = &td_thr_get_info;
+  tdb.td_ta_thr_iter_p = &td_ta_thr_iter;
+  tdb.td_symbol_list_p = &td_symbol_list;
+
+  /* This is required only when thread_db_use_events is on.  */
+  tdb.td_thr_event_enable_p = &td_thr_event_enable;
+
+  /* These are not essential.  */
+  tdb.td_ta_event_addr_p = &td_ta_event_addr;
+  tdb.td_ta_set_event_p = &td_ta_set_event;
+  tdb.td_ta_event_getmsg_p = &td_ta_event_getmsg;
+  tdb.td_thr_tls_get_addr_p = &td_thr_tls_get_addr;
+
+  proc->private->thread_db = xmalloc (sizeof (tdb));
+  memcpy (proc->private->thread_db, &tdb, sizeof (tdb));
+
+  return 1;
+}
+
+#else
+
 static int
 try_thread_db_load_1 (void *handle)
 {
@@ -662,6 +712,8 @@ thread_db_load_search (void)
   return rc;
 }
 
+#endif  /* USE_LIBTHREAD_DB_DIRECTLY */
+
 int
 thread_db_init (int use_events)
 {
@@ -705,6 +757,7 @@ thread_db_free (struct process_info *proc)
   struct thread_db *thread_db = proc->private->thread_db;
   if (thread_db)
     {
+#ifndef USE_LIBTHREAD_DB_DIRECTLY
       td_err_e (*td_ta_delete_p) (td_thragent_t *);
 
       td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
@@ -712,6 +765,10 @@ thread_db_free (struct process_info *proc)
        (*td_ta_delete_p) (thread_db->thread_agent);
 
       dlclose (thread_db->handle);
+#else
+      td_ta_delete (thread_db->thread_agent);
+#endif  /* USE_LIBTHREAD_DB_DIRECTLY  */
+
       free (thread_db);
       proc->private->thread_db = NULL;
     }