summaryrefslogtreecommitdiff
path: root/patches/gdb/6.3/620-debian_static-thread-db.patch
blob: c5ac5a6237eb8a7a2ba1db5940a767a6f3aae5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Status: submitted similar patch 2004-12-08

This patch cleans up the initialization of thread_db.  It works for static
binaries now.  The vsyscall patches hide this problem, since new static
binaries will load the vsyscall DSO and then trigger thread_db; but
this is still a good cleanup.

Index: gdb-6.3/gdb/thread-db.c
===================================================================
--- gdb-6.3.orig/gdb/thread-db.c	2004-10-08 16:29:56.000000000 -0400
+++ gdb-6.3/gdb/thread-db.c	2004-11-10 00:19:30.626530413 -0500
@@ -34,6 +34,7 @@
 #include "target.h"
 #include "regcache.h"
 #include "solib-svr4.h"
+#include "observer.h"
 
 #ifdef HAVE_GNU_LIBC_VERSION_H
 #include <gnu/libc-version.h>
@@ -627,59 +628,49 @@ check_thread_signals (void)
 #endif
 }
 
+/* Check whether thread_db is usable.  This function is called when
+   an inferior is created (or otherwise acquired, e.g. attached to)
+   and when new shared libraries are loaded into a running process.  */
+
 static void
-thread_db_new_objfile (struct objfile *objfile)
+check_for_thread_db (void)
 {
   td_err_e err;
+  static int already_loaded;
 
   /* First time through, report that libthread_db was successfuly
      loaded.  Can't print this in in thread_db_load as, at that stage,
-     the interpreter and it's console haven't started.  The real
-     problem here is that libthread_db is loaded too early - it should
-     only be loaded when there is a program to debug.  */
-  {
-    static int dejavu;
-    if (!dejavu)
-      {
-	Dl_info info;
-	const char *library = NULL;
-	/* Try dladdr.  */
-	if (dladdr ((*td_ta_new_p), &info) != 0)
-	  library = info.dli_fname;
-	/* Try dlinfo?  */
-	if (library == NULL)
-	  /* Paranoid - don't let a NULL path slip through.  */
-	  library = LIBTHREAD_DB_SO;
-	printf_unfiltered ("Using host libthread_db library \"%s\".\n",
-			   library);
-	dejavu = 1;
-      }
-  }
+     the interpreter and it's console haven't started.  */
 
-  /* Don't attempt to use thread_db on targets which can not run
-     (core files).  */
-  if (objfile == NULL || !target_has_execution)
+  if (!already_loaded)
     {
-      /* All symbols have been discarded.  If the thread_db target is
-         active, deactivate it now.  */
-      if (using_thread_db)
-	{
-	  gdb_assert (proc_handle.pid == 0);
-	  unpush_target (&thread_db_ops);
-	  using_thread_db = 0;
-	}
+      Dl_info info;
+      const char *library = NULL;
+      if (dladdr ((*td_ta_new_p), &info) != 0)
+	library = info.dli_fname;
+
+      /* Try dlinfo?  */
 
-      goto quit;
+      if (library == NULL)
+	/* Paranoid - don't let a NULL path slip through.  */
+	library = LIBTHREAD_DB_SO;
+
+      printf_unfiltered ("Using host libthread_db library \"%s\".\n",
+			 library);
+      already_loaded = 1;
     }
 
   if (using_thread_db)
     /* Nothing to do.  The thread library was already detected and the
        target vector was already activated.  */
-    goto quit;
+    return;
+
+  /* Don't attempt to use thread_db on targets which can not run
+     (executables not running yet, core files) for now.  */
+  if (!target_has_execution)
+    return;
 
-  /* Initialize the structure that identifies the child process.  Note
-     that at this point there is no guarantee that we actually have a
-     child process.  */
+  /* Initialize the structure that identifies the child process.  */
   proc_handle.pid = GET_PID (inferior_ptid);
 
   /* Now attempt to open a connection to the thread library.  */
@@ -706,12 +697,24 @@ thread_db_new_objfile (struct objfile *o
 	       thread_db_err_str (err));
       break;
     }
+}
+
+static void
+thread_db_new_objfile (struct objfile *objfile)
+{
+  if (objfile != NULL)
+    check_for_thread_db ();
 
-quit:
   if (target_new_objfile_chain)
     target_new_objfile_chain (objfile);
 }
 
+static void
+check_for_thread_db_observer (struct target_ops *target, int from_tty)
+{
+  check_for_thread_db ();
+}
+
 /* Attach to a new thread.  This function is called when we receive a
    TD_CREATE event or when we iterate over all threads and find one
    that wasn't already in our list.  */
@@ -1366,5 +1369,8 @@ _initialize_thread_db (void)
       /* Add ourselves to objfile event chain.  */
       target_new_objfile_chain = deprecated_target_new_objfile_hook;
       deprecated_target_new_objfile_hook = thread_db_new_objfile;
+
+      /* Register ourselves for the new inferior observer.  */
+      observer_attach_inferior_created (check_for_thread_db_observer);
     }
 }
Index: gdb-6.3/gdb/Makefile.in
===================================================================
--- gdb-6.3.orig/gdb/Makefile.in	2004-11-09 23:04:57.000000000 -0500
+++ gdb-6.3/gdb/Makefile.in	2004-11-10 00:19:26.440347022 -0500
@@ -2626,7 +2626,8 @@ thread.o: thread.c $(defs_h) $(symtab_h)
 	$(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) $(ui_out_h)
 thread-db.o: thread-db.c $(defs_h) $(gdb_assert_h) $(gdb_proc_service_h) \
 	$(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) $(inferior_h) \
-	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h)
+	$(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) \
+	$(observer_h)
 top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \
 	$(cli_script_h) $(cli_setshow_h) $(cli_decode_h) $(symtab_h) \
 	$(inferior_h) $(target_h) $(breakpoint_h) $(gdbtypes_h) \