2009-10-28 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / thread-db.c
CommitLineData
0d62e5e8 1/* Thread management interface, for the remote server for GDB.
0fb0cc75 2 Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009
9b254dd1 3 Free Software Foundation, Inc.
0d62e5e8
DJ
4
5 Contributed by MontaVista Software.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
0d62e5e8
DJ
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0d62e5e8
DJ
21
22#include "server.h"
23
24#include "linux-low.h"
25
26extern int debug_threads;
27
24a09b5f
DJ
28static int thread_db_use_events;
29
0050a760 30#include "gdb_proc_service.h"
cdbfd419 31#include "../gdb_thread_db.h"
0d62e5e8 32
cdbfd419 33#include <dlfcn.h>
186947f7 34#include <stdint.h>
cdbfd419
PP
35#include <limits.h>
36#include <ctype.h>
37
38struct thread_db
39{
40 /* Structure that identifies the child process for the
41 <proc_service.h> interface. */
42 struct ps_prochandle proc_handle;
43
44 /* Connection to the libthread_db library. */
45 td_thragent_t *thread_agent;
46
47 /* Handle of the libthread_db from dlopen. */
48 void *handle;
49
50 /* Addresses of libthread_db functions. */
51 td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
52 td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
53 td_event_msg_t *msg);
54 td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
55 td_thr_events_t *event);
56 td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
57 td_event_e event, td_notify_t *ptr);
58 td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid,
59 td_thrhandle_t *th);
60 td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
61 td_thrinfo_t *infop);
62 td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event);
63 td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
64 td_thr_iter_f *callback, void *cbdata_p,
65 td_thr_state_e state, int ti_pri,
66 sigset_t *ti_sigmask_p,
67 unsigned int ti_user_flags);
68 td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
69 void *map_address,
70 size_t offset, void **address);
71 const char ** (*td_symbol_list_p) (void);
72};
73
74static char *libthread_db_search_path;
186947f7 75
95954743 76static int find_one_thread (ptid_t);
0d62e5e8
DJ
77static int find_new_threads_callback (const td_thrhandle_t *th_p, void *data);
78
54363045 79static const char *
0d62e5e8
DJ
80thread_db_err_str (td_err_e err)
81{
82 static char buf[64];
83
84 switch (err)
85 {
86 case TD_OK:
87 return "generic 'call succeeded'";
88 case TD_ERR:
89 return "generic error";
90 case TD_NOTHR:
91 return "no thread to satisfy query";
92 case TD_NOSV:
93 return "no sync handle to satisfy query";
94 case TD_NOLWP:
95 return "no LWP to satisfy query";
96 case TD_BADPH:
97 return "invalid process handle";
98 case TD_BADTH:
99 return "invalid thread handle";
100 case TD_BADSH:
101 return "invalid synchronization handle";
102 case TD_BADTA:
103 return "invalid thread agent";
104 case TD_BADKEY:
105 return "invalid key";
106 case TD_NOMSG:
107 return "no event message for getmsg";
108 case TD_NOFPREGS:
109 return "FPU register set not available";
110 case TD_NOLIBTHREAD:
111 return "application not linked with libthread";
112 case TD_NOEVENT:
113 return "requested event is not supported";
114 case TD_NOCAPAB:
115 return "capability not available";
116 case TD_DBERR:
117 return "debugger service failed";
118 case TD_NOAPLIC:
119 return "operation not applicable to";
120 case TD_NOTSD:
121 return "no thread-specific data for this thread";
122 case TD_MALLOC:
123 return "malloc failed";
124 case TD_PARTIALREG:
125 return "only part of register set was written/read";
126 case TD_NOXREGS:
127 return "X register set not available for this thread";
3db0444b
DJ
128#ifdef HAVE_TD_VERSION
129 case TD_VERSION:
130 return "version mismatch between libthread_db and libpthread";
131#endif
0d62e5e8
DJ
132 default:
133 snprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
134 return buf;
135 }
136}
137
138#if 0
139static char *
140thread_db_state_str (td_thr_state_e state)
141{
142 static char buf[64];
143
144 switch (state)
145 {
146 case TD_THR_STOPPED:
147 return "stopped by debugger";
148 case TD_THR_RUN:
149 return "runnable";
150 case TD_THR_ACTIVE:
151 return "active";
152 case TD_THR_ZOMBIE:
153 return "zombie";
154 case TD_THR_SLEEP:
155 return "sleeping";
156 case TD_THR_STOPPED_ASLEEP:
157 return "stopped by debugger AND blocked";
158 default:
159 snprintf (buf, sizeof (buf), "unknown thread_db state %d", state);
160 return buf;
161 }
162}
163#endif
164
b65d95c5 165static int
0d62e5e8
DJ
166thread_db_create_event (CORE_ADDR where)
167{
168 td_event_msg_t msg;
169 td_err_e err;
54a0b537 170 struct lwp_info *lwp;
cdbfd419
PP
171 struct thread_db *thread_db = current_process ()->private->thread_db;
172
173 if (thread_db->td_ta_event_getmsg_p == NULL)
174 fatal ("unexpected thread_db->td_ta_event_getmsg_p == NULL");
0d62e5e8
DJ
175
176 if (debug_threads)
177 fprintf (stderr, "Thread creation event.\n");
178
0d62e5e8
DJ
179 /* FIXME: This assumes we don't get another event.
180 In the LinuxThreads implementation, this is safe,
181 because all events come from the manager thread
182 (except for its own creation, of course). */
cdbfd419 183 err = thread_db->td_ta_event_getmsg_p (thread_db->thread_agent, &msg);
0d62e5e8
DJ
184 if (err != TD_OK)
185 fprintf (stderr, "thread getmsg err: %s\n",
186 thread_db_err_str (err));
187
4105de34
DJ
188 /* If we do not know about the main thread yet, this would be a good time to
189 find it. We need to do this to pick up the main thread before any newly
190 created threads. */
54a0b537
PA
191 lwp = get_thread_lwp (current_inferior);
192 if (lwp->thread_known == 0)
95954743 193 find_one_thread (lwp->head.id);
4105de34 194
0d62e5e8
DJ
195 /* msg.event == TD_EVENT_CREATE */
196
197 find_new_threads_callback (msg.th_p, NULL);
b65d95c5
DJ
198
199 return 0;
0d62e5e8
DJ
200}
201
0d62e5e8
DJ
202static int
203thread_db_enable_reporting ()
204{
205 td_thr_events_t events;
206 td_notify_t notify;
207 td_err_e err;
cdbfd419
PP
208 struct thread_db *thread_db = current_process ()->private->thread_db;
209
210 if (thread_db->td_ta_set_event_p == NULL
211 || thread_db->td_ta_event_addr_p == NULL
212 || thread_db->td_ta_event_getmsg_p == NULL)
213 /* This libthread_db is missing required support. */
214 return 0;
0d62e5e8
DJ
215
216 /* Set the process wide mask saying which events we're interested in. */
217 td_event_emptyset (&events);
218 td_event_addset (&events, TD_CREATE);
219
cdbfd419 220 err = thread_db->td_ta_set_event_p (thread_db->thread_agent, &events);
0d62e5e8
DJ
221 if (err != TD_OK)
222 {
223 warning ("Unable to set global thread event mask: %s",
1b3f6016 224 thread_db_err_str (err));
0d62e5e8
DJ
225 return 0;
226 }
227
228 /* Get address for thread creation breakpoint. */
cdbfd419
PP
229 err = thread_db->td_ta_event_addr_p (thread_db->thread_agent, TD_CREATE,
230 &notify);
0d62e5e8
DJ
231 if (err != TD_OK)
232 {
233 warning ("Unable to get location for thread creation breakpoint: %s",
234 thread_db_err_str (err));
235 return 0;
236 }
237 set_breakpoint_at ((CORE_ADDR) (unsigned long) notify.u.bptaddr,
238 thread_db_create_event);
239
0d62e5e8
DJ
240 return 1;
241}
242
ae13219e 243static int
95954743 244find_one_thread (ptid_t ptid)
0d62e5e8 245{
ae13219e
DJ
246 td_thrhandle_t th;
247 td_thrinfo_t ti;
0d62e5e8
DJ
248 td_err_e err;
249 struct thread_info *inferior;
54a0b537 250 struct lwp_info *lwp;
cdbfd419 251 struct thread_db *thread_db = current_process ()->private->thread_db;
95954743 252 int lwpid = ptid_get_lwp (ptid);
0d62e5e8 253
95954743 254 inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
54a0b537
PA
255 lwp = get_thread_lwp (inferior);
256 if (lwp->thread_known)
ae13219e
DJ
257 return 1;
258
24a09b5f 259 /* Get information about this thread. */
cdbfd419 260 err = thread_db->td_ta_map_lwp2thr_p (thread_db->thread_agent, lwpid, &th);
ae13219e 261 if (err != TD_OK)
24a09b5f
DJ
262 error ("Cannot get thread handle for LWP %d: %s",
263 lwpid, thread_db_err_str (err));
ae13219e 264
cdbfd419 265 err = thread_db->td_thr_get_info_p (&th, &ti);
ae13219e 266 if (err != TD_OK)
24a09b5f
DJ
267 error ("Cannot get thread info for LWP %d: %s",
268 lwpid, thread_db_err_str (err));
ae13219e
DJ
269
270 if (debug_threads)
24a09b5f 271 fprintf (stderr, "Found thread %ld (LWP %d)\n",
ae13219e
DJ
272 ti.ti_tid, ti.ti_lid);
273
95954743 274 if (lwpid != ti.ti_lid)
24a09b5f
DJ
275 {
276 warning ("PID mismatch! Expected %ld, got %ld",
95954743 277 (long) lwpid, (long) ti.ti_lid);
24a09b5f
DJ
278 return 0;
279 }
ae13219e 280
24a09b5f 281 if (thread_db_use_events)
0d62e5e8 282 {
cdbfd419 283 err = thread_db->td_thr_event_enable_p (&th, 1);
ae13219e
DJ
284 if (err != TD_OK)
285 error ("Cannot enable thread event reporting for %d: %s",
286 ti.ti_lid, thread_db_err_str (err));
0d62e5e8 287 }
ae13219e 288
24a09b5f
DJ
289 /* If the new thread ID is zero, a final thread ID will be available
290 later. Do not enable thread debugging yet. */
291 if (ti.ti_tid == 0)
292 return 0;
ae13219e 293
54a0b537
PA
294 lwp->thread_known = 1;
295 lwp->th = th;
ae13219e 296
ae13219e
DJ
297 return 1;
298}
299
300static void
301maybe_attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
302{
303 td_err_e err;
54a0b537 304 struct lwp_info *lwp;
ae13219e 305
95954743
PA
306 lwp = find_lwp_pid (pid_to_ptid (ti_p->ti_lid));
307 if (lwp != NULL)
0d62e5e8
DJ
308 return;
309
310 if (debug_threads)
311 fprintf (stderr, "Attaching to thread %ld (LWP %d)\n",
312 ti_p->ti_tid, ti_p->ti_lid);
24a09b5f 313 linux_attach_lwp (ti_p->ti_lid);
95954743
PA
314 lwp = find_lwp_pid (pid_to_ptid (ti_p->ti_lid));
315 if (lwp == NULL)
0d62e5e8
DJ
316 {
317 warning ("Could not attach to thread %ld (LWP %d)\n",
318 ti_p->ti_tid, ti_p->ti_lid);
319 return;
320 }
321
54a0b537
PA
322 lwp->thread_known = 1;
323 lwp->th = *th_p;
24a09b5f
DJ
324
325 if (thread_db_use_events)
326 {
cdbfd419
PP
327 struct thread_db *thread_db = current_process ()->private->thread_db;
328 err = thread_db->td_thr_event_enable_p (th_p, 1);
24a09b5f
DJ
329 if (err != TD_OK)
330 error ("Cannot enable thread event reporting for %d: %s",
331 ti_p->ti_lid, thread_db_err_str (err));
332 }
0d62e5e8
DJ
333}
334
335static int
336find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
337{
338 td_thrinfo_t ti;
339 td_err_e err;
cdbfd419 340 struct thread_db *thread_db = current_process ()->private->thread_db;
0d62e5e8 341
cdbfd419 342 err = thread_db->td_thr_get_info_p (th_p, &ti);
0d62e5e8
DJ
343 if (err != TD_OK)
344 error ("Cannot get thread info: %s", thread_db_err_str (err));
345
346 /* Check for zombies. */
347 if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
348 return 0;
349
350 maybe_attach_thread (th_p, &ti);
351
352 return 0;
353}
354
355static void
356thread_db_find_new_threads (void)
357{
358 td_err_e err;
95954743 359 ptid_t ptid = ((struct inferior_list_entry *) current_inferior)->id;
cdbfd419 360 struct thread_db *thread_db = current_process ()->private->thread_db;
0d62e5e8 361
ae13219e
DJ
362 /* This function is only called when we first initialize thread_db.
363 First locate the initial thread. If it is not ready for
364 debugging yet, then stop. */
95954743 365 if (find_one_thread (ptid) == 0)
ae13219e
DJ
366 return;
367
0d62e5e8 368 /* Iterate over all user-space threads to discover new threads. */
cdbfd419
PP
369 err = thread_db->td_ta_thr_iter_p (thread_db->thread_agent,
370 find_new_threads_callback, NULL,
371 TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY,
372 TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
0d62e5e8
DJ
373 if (err != TD_OK)
374 error ("Cannot find new threads: %s", thread_db_err_str (err));
375}
376
fd500816
DJ
377/* Cache all future symbols that thread_db might request. We can not
378 request symbols at arbitrary states in the remote protocol, only
379 when the client tells us that new symbols are available. So when
380 we load the thread library, make sure to check the entire list. */
381
382static void
383thread_db_look_up_symbols (void)
384{
cdbfd419
PP
385 struct thread_db *thread_db = current_process ()->private->thread_db;
386 const char **sym_list;
fd500816
DJ
387 CORE_ADDR unused;
388
cdbfd419 389 for (sym_list = thread_db->td_symbol_list_p (); *sym_list; sym_list++)
fd500816
DJ
390 look_up_one_symbol (*sym_list, &unused);
391}
392
dae5f5cf
DJ
393int
394thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
395 CORE_ADDR load_module, CORE_ADDR *address)
396{
dae5f5cf
DJ
397 psaddr_t addr;
398 td_err_e err;
54a0b537 399 struct lwp_info *lwp;
95954743 400 struct thread_info *saved_inferior;
cdbfd419
PP
401 struct process_info *proc;
402 struct thread_db *thread_db;
403
404 proc = get_thread_process (thread);
405 thread_db = proc->private->thread_db;
dae5f5cf 406
7fe519cb 407 /* If the thread layer is not (yet) initialized, fail. */
cdbfd419 408 if (!proc->all_symbols_looked_up)
7fe519cb
UW
409 return TD_ERR;
410
cdbfd419
PP
411 if (thread_db->td_thr_tls_get_addr_p == NULL)
412 return -1;
413
54a0b537
PA
414 lwp = get_thread_lwp (thread);
415 if (!lwp->thread_known)
95954743 416 find_one_thread (lwp->head.id);
54a0b537 417 if (!lwp->thread_known)
dae5f5cf
DJ
418 return TD_NOTHR;
419
95954743
PA
420 saved_inferior = current_inferior;
421 current_inferior = thread;
186947f7
DJ
422 /* Note the cast through uintptr_t: this interface only works if
423 a target address fits in a psaddr_t, which is a host pointer.
424 So a 32-bit debugger can not access 64-bit TLS through this. */
cdbfd419
PP
425 err = thread_db->td_thr_tls_get_addr_p (&lwp->th,
426 (psaddr_t) (uintptr_t) load_module,
427 offset, &addr);
95954743 428 current_inferior = saved_inferior;
dae5f5cf
DJ
429 if (err == TD_OK)
430 {
186947f7 431 *address = (CORE_ADDR) (uintptr_t) addr;
dae5f5cf
DJ
432 return 0;
433 }
434 else
435 return err;
cdbfd419
PP
436}
437
438static int
439try_thread_db_load_1 (void *handle)
440{
441 td_err_e err;
442 struct thread_db tdb;
443 struct process_info *proc = current_process ();
444
445 if (proc->private->thread_db != NULL)
446 fatal ("unexpected: proc->private->thread_db != NULL");
447
448 tdb.handle = handle;
449
450 /* Initialize pointers to the dynamic library functions we will use.
451 Essential functions first. */
452
453#define CHK(required, a) \
454 do \
455 { \
456 if ((a) == NULL) \
457 { \
458 if (debug_threads) \
459 fprintf (stderr, "dlsym: %s\n", dlerror ()); \
460 if (required) \
461 return 0; \
462 } \
463 } \
464 while (0)
465
466 CHK (1, tdb.td_ta_new_p = dlsym (handle, "td_ta_new"));
467
468 /* Attempt to open a connection to the thread library. */
469 err = tdb.td_ta_new_p (&tdb.proc_handle, &tdb.thread_agent);
470 if (err != TD_OK)
471 {
472 if (debug_threads)
473 fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
474 return 0;
475 }
476
477 CHK (1, tdb.td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
478 CHK (1, tdb.td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
479 CHK (1, tdb.td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
480 CHK (1, tdb.td_symbol_list_p = dlsym (handle, "td_symbol_list"));
481
482 /* This is required only when thread_db_use_events is on. */
483 CHK (thread_db_use_events,
484 tdb.td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
485
486 /* These are not essential. */
487 CHK (0, tdb.td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
488 CHK (0, tdb.td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
489 CHK (0, tdb.td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
490 CHK (0, tdb.td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
491
492#undef CHK
493
494 proc->private->thread_db = xmalloc (sizeof (tdb));
495 memcpy (proc->private->thread_db, &tdb, sizeof (tdb));
496
497 return 1;
498}
499
500/* Lookup a library in which given symbol resides.
501 Note: this is looking in the GDBSERVER process, not in the inferior.
502 Returns library name, or NULL. */
503
504static const char *
505dladdr_to_soname (const void *addr)
506{
507 Dl_info info;
508
509 if (dladdr (addr, &info) != 0)
510 return info.dli_fname;
511 return NULL;
512}
513
514static int
515try_thread_db_load (const char *library)
516{
517 void *handle;
518
519 if (debug_threads)
520 fprintf (stderr, "Trying host libthread_db library: %s.\n",
521 library);
522 handle = dlopen (library, RTLD_NOW);
523 if (handle == NULL)
524 {
525 if (debug_threads)
526 fprintf (stderr, "dlopen failed: %s.\n", dlerror ());
527 return 0;
528 }
529
530 if (debug_threads && strchr (library, '/') == NULL)
531 {
532 void *td_init;
533
534 td_init = dlsym (handle, "td_init");
535 if (td_init != NULL)
536 {
537 const char *const libpath = dladdr_to_soname (td_init);
538
539 if (libpath != NULL)
540 fprintf (stderr, "Host %s resolved to: %s.\n",
541 library, libpath);
542 }
543 }
544
545 if (try_thread_db_load_1 (handle))
546 return 1;
547
548 /* This library "refused" to work on current inferior. */
549 dlclose (handle);
550 return 0;
551}
552
553static int
554thread_db_load_search (void)
555{
556 char path[PATH_MAX];
557 const char *search_path;
558 int rc = 0;
559
560 if (libthread_db_search_path == NULL)
561 libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
562
563 search_path = libthread_db_search_path;
564 while (*search_path)
565 {
566 const char *end = strchr (search_path, ':');
567 if (end)
568 {
569 size_t len = end - search_path;
570 if (len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path))
571 {
572 char *cp = xmalloc (len + 1);
573 memcpy (cp, search_path, len);
574 cp[len] = '\0';
575 warning ("libthread_db_search_path component too long, "
576 "ignored: %s.", cp);
577 free (cp);
578 search_path += len + 1;
579 continue;
580 }
581 memcpy (path, search_path, len);
582 path[len] = '\0';
583 search_path += len + 1;
584 }
585 else
586 {
587 size_t len = strlen (search_path);
588
589 if (len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path))
590 {
591 warning ("libthread_db_search_path component too long,"
592 " ignored: %s.", search_path);
593 break;
594 }
595 memcpy (path, search_path, len + 1);
596 search_path += len;
597 }
598 strcat (path, "/");
599 strcat (path, LIBTHREAD_DB_SO);
600 if (debug_threads)
601 fprintf (stderr, "thread_db_load_search trying %s\n", path);
602 if (try_thread_db_load (path))
603 {
604 rc = 1;
605 break;
606 }
607 }
608 if (rc == 0)
609 rc = try_thread_db_load (LIBTHREAD_DB_SO);
610
611 if (debug_threads)
612 fprintf (stderr, "thread_db_load_search returning %d\n", rc);
613 return rc;
dae5f5cf
DJ
614}
615
0d62e5e8 616int
24a09b5f 617thread_db_init (int use_events)
0d62e5e8 618{
95954743 619 struct process_info *proc = current_process ();
0d62e5e8 620
fd500816
DJ
621 /* FIXME drow/2004-10-16: This is the "overall process ID", which
622 GNU/Linux calls tgid, "thread group ID". When we support
623 attaching to threads, the original thread may not be the correct
624 thread. We would have to get the process ID from /proc for NPTL.
625 For LinuxThreads we could do something similar: follow the chain
626 of parent processes until we find the highest one we're attached
627 to, and use its tgid.
628
629 This isn't the only place in gdbserver that assumes that the first
630 process in the list is the thread group leader. */
ea025f5f 631
24a09b5f
DJ
632 thread_db_use_events = use_events;
633
cdbfd419 634 if (thread_db_load_search ())
0d62e5e8 635 {
24a09b5f 636 if (use_events && thread_db_enable_reporting () == 0)
cdbfd419
PP
637 {
638 /* Keep trying; maybe event reporting will work later. */
639 thread_db_free (proc);
640 return 0;
641 }
0d62e5e8 642 thread_db_find_new_threads ();
fd500816 643 thread_db_look_up_symbols ();
95954743 644 proc->all_symbols_looked_up = 1;
0d62e5e8 645 return 1;
cdbfd419 646 }
0d62e5e8 647
cdbfd419
PP
648 return 0;
649}
650
651/* Disconnect from libthread_db and free resources. */
652
653void
654thread_db_free (struct process_info *proc)
655{
656 struct thread_db *thread_db = proc->private->thread_db;
657 if (thread_db)
658 {
659 td_err_e (*td_ta_delete_p) (td_thragent_t *);
660
661 td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
662 if (td_ta_delete_p != NULL)
663 (*td_ta_delete_p) (thread_db->thread_agent);
664
665 dlclose (thread_db->handle);
666 free (thread_db);
667 proc->private->thread_db = NULL;
668 }
669}
670
671/* Handle "set libthread-db-search-path" monitor command and return 1.
672 For any other command, return 0. */
673
674int
675thread_db_handle_monitor_command (char *mon)
676{
677 if (strncmp (mon, "set libthread-db-search-path ", 29) == 0)
678 {
679 const char *cp = mon + 29;
680
681 if (libthread_db_search_path != NULL)
682 free (libthread_db_search_path);
683
684 /* Skip leading space (if any). */
685 while (isspace (*cp))
686 ++cp;
687
688 libthread_db_search_path = xstrdup (cp);
689
690 monitor_output ("libthread-db-search-path set to `");
691 monitor_output (libthread_db_search_path);
692 monitor_output ("'\n");
693 return 1;
0d62e5e8
DJ
694 }
695
cdbfd419 696 /* Tell server.c to perform default processing. */
0d62e5e8
DJ
697 return 0;
698}
This page took 0.659788 seconds and 4 git commands to generate.