yann@96
|
1 |
Status: submitted similar patch 2004-12-08
|
yann@96
|
2 |
|
yann@96
|
3 |
This patch cleans up the initialization of thread_db. It works for static
|
yann@96
|
4 |
binaries now. The vsyscall patches hide this problem, since new static
|
yann@96
|
5 |
binaries will load the vsyscall DSO and then trigger thread_db; but
|
yann@96
|
6 |
this is still a good cleanup.
|
yann@96
|
7 |
|
yann@96
|
8 |
Index: gdb-6.3/gdb/thread-db.c
|
yann@96
|
9 |
===================================================================
|
yann@96
|
10 |
--- gdb-6.3.orig/gdb/thread-db.c 2004-10-08 16:29:56.000000000 -0400
|
yann@96
|
11 |
+++ gdb-6.3/gdb/thread-db.c 2004-11-10 00:19:30.626530413 -0500
|
yann@96
|
12 |
@@ -34,6 +34,7 @@
|
yann@96
|
13 |
#include "target.h"
|
yann@96
|
14 |
#include "regcache.h"
|
yann@96
|
15 |
#include "solib-svr4.h"
|
yann@96
|
16 |
+#include "observer.h"
|
yann@96
|
17 |
|
yann@96
|
18 |
#ifdef HAVE_GNU_LIBC_VERSION_H
|
yann@96
|
19 |
#include <gnu/libc-version.h>
|
yann@96
|
20 |
@@ -627,59 +628,49 @@ check_thread_signals (void)
|
yann@96
|
21 |
#endif
|
yann@96
|
22 |
}
|
yann@96
|
23 |
|
yann@96
|
24 |
+/* Check whether thread_db is usable. This function is called when
|
yann@96
|
25 |
+ an inferior is created (or otherwise acquired, e.g. attached to)
|
yann@96
|
26 |
+ and when new shared libraries are loaded into a running process. */
|
yann@96
|
27 |
+
|
yann@96
|
28 |
static void
|
yann@96
|
29 |
-thread_db_new_objfile (struct objfile *objfile)
|
yann@96
|
30 |
+check_for_thread_db (void)
|
yann@96
|
31 |
{
|
yann@96
|
32 |
td_err_e err;
|
yann@96
|
33 |
+ static int already_loaded;
|
yann@96
|
34 |
|
yann@96
|
35 |
/* First time through, report that libthread_db was successfuly
|
yann@96
|
36 |
loaded. Can't print this in in thread_db_load as, at that stage,
|
yann@96
|
37 |
- the interpreter and it's console haven't started. The real
|
yann@96
|
38 |
- problem here is that libthread_db is loaded too early - it should
|
yann@96
|
39 |
- only be loaded when there is a program to debug. */
|
yann@96
|
40 |
- {
|
yann@96
|
41 |
- static int dejavu;
|
yann@96
|
42 |
- if (!dejavu)
|
yann@96
|
43 |
- {
|
yann@96
|
44 |
- Dl_info info;
|
yann@96
|
45 |
- const char *library = NULL;
|
yann@96
|
46 |
- /* Try dladdr. */
|
yann@96
|
47 |
- if (dladdr ((*td_ta_new_p), &info) != 0)
|
yann@96
|
48 |
- library = info.dli_fname;
|
yann@96
|
49 |
- /* Try dlinfo? */
|
yann@96
|
50 |
- if (library == NULL)
|
yann@96
|
51 |
- /* Paranoid - don't let a NULL path slip through. */
|
yann@96
|
52 |
- library = LIBTHREAD_DB_SO;
|
yann@96
|
53 |
- printf_unfiltered ("Using host libthread_db library \"%s\".\n",
|
yann@96
|
54 |
- library);
|
yann@96
|
55 |
- dejavu = 1;
|
yann@96
|
56 |
- }
|
yann@96
|
57 |
- }
|
yann@96
|
58 |
+ the interpreter and it's console haven't started. */
|
yann@96
|
59 |
|
yann@96
|
60 |
- /* Don't attempt to use thread_db on targets which can not run
|
yann@96
|
61 |
- (core files). */
|
yann@96
|
62 |
- if (objfile == NULL || !target_has_execution)
|
yann@96
|
63 |
+ if (!already_loaded)
|
yann@96
|
64 |
{
|
yann@96
|
65 |
- /* All symbols have been discarded. If the thread_db target is
|
yann@96
|
66 |
- active, deactivate it now. */
|
yann@96
|
67 |
- if (using_thread_db)
|
yann@96
|
68 |
- {
|
yann@96
|
69 |
- gdb_assert (proc_handle.pid == 0);
|
yann@96
|
70 |
- unpush_target (&thread_db_ops);
|
yann@96
|
71 |
- using_thread_db = 0;
|
yann@96
|
72 |
- }
|
yann@96
|
73 |
+ Dl_info info;
|
yann@96
|
74 |
+ const char *library = NULL;
|
yann@96
|
75 |
+ if (dladdr ((*td_ta_new_p), &info) != 0)
|
yann@96
|
76 |
+ library = info.dli_fname;
|
yann@96
|
77 |
+
|
yann@96
|
78 |
+ /* Try dlinfo? */
|
yann@96
|
79 |
|
yann@96
|
80 |
- goto quit;
|
yann@96
|
81 |
+ if (library == NULL)
|
yann@96
|
82 |
+ /* Paranoid - don't let a NULL path slip through. */
|
yann@96
|
83 |
+ library = LIBTHREAD_DB_SO;
|
yann@96
|
84 |
+
|
yann@96
|
85 |
+ printf_unfiltered ("Using host libthread_db library \"%s\".\n",
|
yann@96
|
86 |
+ library);
|
yann@96
|
87 |
+ already_loaded = 1;
|
yann@96
|
88 |
}
|
yann@96
|
89 |
|
yann@96
|
90 |
if (using_thread_db)
|
yann@96
|
91 |
/* Nothing to do. The thread library was already detected and the
|
yann@96
|
92 |
target vector was already activated. */
|
yann@96
|
93 |
- goto quit;
|
yann@96
|
94 |
+ return;
|
yann@96
|
95 |
+
|
yann@96
|
96 |
+ /* Don't attempt to use thread_db on targets which can not run
|
yann@96
|
97 |
+ (executables not running yet, core files) for now. */
|
yann@96
|
98 |
+ if (!target_has_execution)
|
yann@96
|
99 |
+ return;
|
yann@96
|
100 |
|
yann@96
|
101 |
- /* Initialize the structure that identifies the child process. Note
|
yann@96
|
102 |
- that at this point there is no guarantee that we actually have a
|
yann@96
|
103 |
- child process. */
|
yann@96
|
104 |
+ /* Initialize the structure that identifies the child process. */
|
yann@96
|
105 |
proc_handle.pid = GET_PID (inferior_ptid);
|
yann@96
|
106 |
|
yann@96
|
107 |
/* Now attempt to open a connection to the thread library. */
|
yann@96
|
108 |
@@ -706,12 +697,24 @@ thread_db_new_objfile (struct objfile *o
|
yann@96
|
109 |
thread_db_err_str (err));
|
yann@96
|
110 |
break;
|
yann@96
|
111 |
}
|
yann@96
|
112 |
+}
|
yann@96
|
113 |
+
|
yann@96
|
114 |
+static void
|
yann@96
|
115 |
+thread_db_new_objfile (struct objfile *objfile)
|
yann@96
|
116 |
+{
|
yann@96
|
117 |
+ if (objfile != NULL)
|
yann@96
|
118 |
+ check_for_thread_db ();
|
yann@96
|
119 |
|
yann@96
|
120 |
-quit:
|
yann@96
|
121 |
if (target_new_objfile_chain)
|
yann@96
|
122 |
target_new_objfile_chain (objfile);
|
yann@96
|
123 |
}
|
yann@96
|
124 |
|
yann@96
|
125 |
+static void
|
yann@96
|
126 |
+check_for_thread_db_observer (struct target_ops *target, int from_tty)
|
yann@96
|
127 |
+{
|
yann@96
|
128 |
+ check_for_thread_db ();
|
yann@96
|
129 |
+}
|
yann@96
|
130 |
+
|
yann@96
|
131 |
/* Attach to a new thread. This function is called when we receive a
|
yann@96
|
132 |
TD_CREATE event or when we iterate over all threads and find one
|
yann@96
|
133 |
that wasn't already in our list. */
|
yann@96
|
134 |
@@ -1366,5 +1369,8 @@ _initialize_thread_db (void)
|
yann@96
|
135 |
/* Add ourselves to objfile event chain. */
|
yann@96
|
136 |
target_new_objfile_chain = deprecated_target_new_objfile_hook;
|
yann@96
|
137 |
deprecated_target_new_objfile_hook = thread_db_new_objfile;
|
yann@96
|
138 |
+
|
yann@96
|
139 |
+ /* Register ourselves for the new inferior observer. */
|
yann@96
|
140 |
+ observer_attach_inferior_created (check_for_thread_db_observer);
|
yann@96
|
141 |
}
|
yann@96
|
142 |
}
|
yann@96
|
143 |
Index: gdb-6.3/gdb/Makefile.in
|
yann@96
|
144 |
===================================================================
|
yann@96
|
145 |
--- gdb-6.3.orig/gdb/Makefile.in 2004-11-09 23:04:57.000000000 -0500
|
yann@96
|
146 |
+++ gdb-6.3/gdb/Makefile.in 2004-11-10 00:19:26.440347022 -0500
|
yann@96
|
147 |
@@ -2626,7 +2626,8 @@ thread.o: thread.c $(defs_h) $(symtab_h)
|
yann@96
|
148 |
$(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) $(ui_out_h)
|
yann@96
|
149 |
thread-db.o: thread-db.c $(defs_h) $(gdb_assert_h) $(gdb_proc_service_h) \
|
yann@96
|
150 |
$(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) $(inferior_h) \
|
yann@96
|
151 |
- $(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h)
|
yann@96
|
152 |
+ $(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) $(solib_svr4_h) \
|
yann@96
|
153 |
+ $(observer_h)
|
yann@96
|
154 |
top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \
|
yann@96
|
155 |
$(cli_script_h) $(cli_setshow_h) $(cli_decode_h) $(symtab_h) \
|
yann@96
|
156 |
$(inferior_h) $(target_h) $(breakpoint_h) $(gdbtypes_h) \
|