patches/gdb/6.3/620-debian_static-thread-db.patch
changeset 330 447b203edc2e
parent 329 419d959441ed
child 331 0c05f9ea3254
     1.1 --- a/patches/gdb/6.3/620-debian_static-thread-db.patch	Tue Aug 14 19:32:22 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,156 +0,0 @@
     1.4 -Status: submitted similar patch 2004-12-08
     1.5 -
     1.6 -This patch cleans up the initialization of thread_db.  It works for static
     1.7 -binaries now.  The vsyscall patches hide this problem, since new static
     1.8 -binaries will load the vsyscall DSO and then trigger thread_db; but
     1.9 -this is still a good cleanup.
    1.10 -
    1.11 -Index: gdb-6.3/gdb/thread-db.c
    1.12 -===================================================================
    1.13 ---- gdb-6.3.orig/gdb/thread-db.c	2004-10-08 16:29:56.000000000 -0400
    1.14 -+++ gdb-6.3/gdb/thread-db.c	2004-11-10 00:19:30.626530413 -0500
    1.15 -@@ -34,6 +34,7 @@
    1.16 - #include "target.h"
    1.17 - #include "regcache.h"
    1.18 - #include "solib-svr4.h"
    1.19 -+#include "observer.h"
    1.20 - 
    1.21 - #ifdef HAVE_GNU_LIBC_VERSION_H
    1.22 - #include <gnu/libc-version.h>
    1.23 -@@ -627,59 +628,49 @@ check_thread_signals (void)
    1.24 - #endif
    1.25 - }
    1.26 - 
    1.27 -+/* Check whether thread_db is usable.  This function is called when
    1.28 -+   an inferior is created (or otherwise acquired, e.g. attached to)
    1.29 -+   and when new shared libraries are loaded into a running process.  */
    1.30 -+
    1.31 - static void
    1.32 --thread_db_new_objfile (struct objfile *objfile)
    1.33 -+check_for_thread_db (void)
    1.34 - {
    1.35 -   td_err_e err;
    1.36 -+  static int already_loaded;
    1.37 - 
    1.38 -   /* First time through, report that libthread_db was successfuly
    1.39 -      loaded.  Can't print this in in thread_db_load as, at that stage,
    1.40 --     the interpreter and it's console haven't started.  The real
    1.41 --     problem here is that libthread_db is loaded too early - it should
    1.42 --     only be loaded when there is a program to debug.  */
    1.43 --  {
    1.44 --    static int dejavu;
    1.45 --    if (!dejavu)
    1.46 --      {
    1.47 --	Dl_info info;
    1.48 --	const char *library = NULL;
    1.49 --	/* Try dladdr.  */
    1.50 --	if (dladdr ((*td_ta_new_p), &info) != 0)
    1.51 --	  library = info.dli_fname;
    1.52 --	/* Try dlinfo?  */
    1.53 --	if (library == NULL)
    1.54 --	  /* Paranoid - don't let a NULL path slip through.  */
    1.55 --	  library = LIBTHREAD_DB_SO;
    1.56 --	printf_unfiltered ("Using host libthread_db library \"%s\".\n",
    1.57 --			   library);
    1.58 --	dejavu = 1;
    1.59 --      }
    1.60 --  }
    1.61 -+     the interpreter and it's console haven't started.  */
    1.62 - 
    1.63 --  /* Don't attempt to use thread_db on targets which can not run
    1.64 --     (core files).  */
    1.65 --  if (objfile == NULL || !target_has_execution)
    1.66 -+  if (!already_loaded)
    1.67 -     {
    1.68 --      /* All symbols have been discarded.  If the thread_db target is
    1.69 --         active, deactivate it now.  */
    1.70 --      if (using_thread_db)
    1.71 --	{
    1.72 --	  gdb_assert (proc_handle.pid == 0);
    1.73 --	  unpush_target (&thread_db_ops);
    1.74 --	  using_thread_db = 0;
    1.75 --	}
    1.76 -+      Dl_info info;
    1.77 -+      const char *library = NULL;
    1.78 -+      if (dladdr ((*td_ta_new_p), &info) != 0)
    1.79 -+	library = info.dli_fname;
    1.80 -+
    1.81 -+      /* Try dlinfo?  */
    1.82 - 
    1.83 --      goto quit;
    1.84 -+      if (library == NULL)
    1.85 -+	/* Paranoid - don't let a NULL path slip through.  */
    1.86 -+	library = LIBTHREAD_DB_SO;
    1.87 -+
    1.88 -+      printf_unfiltered ("Using host libthread_db library \"%s\".\n",
    1.89 -+			 library);
    1.90 -+      already_loaded = 1;
    1.91 -     }
    1.92 - 
    1.93 -   if (using_thread_db)
    1.94 -     /* Nothing to do.  The thread library was already detected and the
    1.95 -        target vector was already activated.  */
    1.96 --    goto quit;
    1.97 -+    return;
    1.98 -+
    1.99 -+  /* Don't attempt to use thread_db on targets which can not run
   1.100 -+     (executables not running yet, core files) for now.  */
   1.101 -+  if (!target_has_execution)
   1.102 -+    return;
   1.103 - 
   1.104 --  /* Initialize the structure that identifies the child process.  Note
   1.105 --     that at this point there is no guarantee that we actually have a
   1.106 --     child process.  */
   1.107 -+  /* Initialize the structure that identifies the child process.  */
   1.108 -   proc_handle.pid = GET_PID (inferior_ptid);
   1.109 - 
   1.110 -   /* Now attempt to open a connection to the thread library.  */
   1.111 -@@ -706,12 +697,24 @@ thread_db_new_objfile (struct objfile *o
   1.112 - 	       thread_db_err_str (err));
   1.113 -       break;
   1.114 -     }
   1.115 -+}
   1.116 -+
   1.117 -+static void
   1.118 -+thread_db_new_objfile (struct objfile *objfile)
   1.119 -+{
   1.120 -+  if (objfile != NULL)
   1.121 -+    check_for_thread_db ();
   1.122 - 
   1.123 --quit:
   1.124 -   if (target_new_objfile_chain)
   1.125 -     target_new_objfile_chain (objfile);
   1.126 - }
   1.127 - 
   1.128 -+static void
   1.129 -+check_for_thread_db_observer (struct target_ops *target, int from_tty)
   1.130 -+{
   1.131 -+  check_for_thread_db ();
   1.132 -+}
   1.133 -+
   1.134 - /* Attach to a new thread.  This function is called when we receive a
   1.135 -    TD_CREATE event or when we iterate over all threads and find one
   1.136 -    that wasn't already in our list.  */
   1.137 -@@ -1366,5 +1369,8 @@ _initialize_thread_db (void)
   1.138 -       /* Add ourselves to objfile event chain.  */
   1.139 -       target_new_objfile_chain = deprecated_target_new_objfile_hook;
   1.140 -       deprecated_target_new_objfile_hook = thread_db_new_objfile;
   1.141 -+
   1.142 -+      /* Register ourselves for the new inferior observer.  */
   1.143 -+      observer_attach_inferior_created (check_for_thread_db_observer);
   1.144 -     }
   1.145 - }
   1.146 -Index: gdb-6.3/gdb/Makefile.in
   1.147 -===================================================================
   1.148 ---- gdb-6.3.orig/gdb/Makefile.in	2004-11-09 23:04:57.000000000 -0500
   1.149 -+++ gdb-6.3/gdb/Makefile.in	2004-11-10 00:19:26.440347022 -0500
   1.150 -@@ -2626,7 +2626,8 @@ thread.o: thread.c $(defs_h) $(symtab_h)
   1.151 - 	$(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) $(ui_out_h)
   1.152 - thread-db.o: thread-db.c $(defs_h) $(gdb_assert_h) $(gdb_proc_service_h) \
   1.153 - 	$(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) $(inferior_h) \
   1.154 --	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h)
   1.155 -+	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) \
   1.156 -+	$(observer_h)
   1.157 - top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \
   1.158 - 	$(cli_script_h) $(cli_setshow_h) $(cli_decode_h) $(symtab_h) \
   1.159 - 	$(inferior_h) $(target_h) $(breakpoint_h) $(gdbtypes_h) \