1 /* Thread management interface, for the remote server for GDB.
2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "linux-low.h"
25 extern int debug_threads;
27 static int thread_db_use_events;
29 #include "gdb_proc_service.h"
30 #include "nat/gdb_thread_db.h"
33 #ifndef USE_LIBTHREAD_DB_DIRECTLY
43 /* Structure that identifies the child process for the
44 <proc_service.h> interface. */
45 struct ps_prochandle proc_handle;
47 /* Connection to the libthread_db library. */
48 td_thragent_t *thread_agent;
50 /* If this flag has been set, we've already asked GDB for all
51 symbols we might need; assume symbol cache misses are
53 int all_symbols_looked_up;
55 #ifndef USE_LIBTHREAD_DB_DIRECTLY
56 /* Handle of the libthread_db from dlopen. */
60 /* Thread creation event breakpoint. The code at this location in
61 the child process will be called by the pthread library whenever
62 a new thread is created. By setting a special breakpoint at this
63 location, GDB can detect when a new thread is created. We obtain
64 this location via the td_ta_event_addr call. Note that if the
65 running kernel supports tracing clones, then we don't need to use
66 (and in fact don't use) this magic thread event breakpoint to
67 learn about threads. */
68 struct breakpoint *td_create_bp;
70 /* Addresses of libthread_db functions. */
71 td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
72 td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
74 td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
75 td_thr_events_t *event);
76 td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
77 td_event_e event, td_notify_t *ptr);
78 td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid,
80 td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
82 td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event);
83 td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
84 td_thr_iter_f *callback, void *cbdata_p,
85 td_thr_state_e state, int ti_pri,
86 sigset_t *ti_sigmask_p,
87 unsigned int ti_user_flags);
88 td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
90 size_t offset, psaddr_t *address);
91 td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
92 unsigned long int modid,
94 const char ** (*td_symbol_list_p) (void);
97 static char *libthread_db_search_path;
99 static int find_one_thread (ptid_t);
100 static int find_new_threads_callback (const td_thrhandle_t *th_p, void *data);
103 thread_db_err_str (td_err_e err)
110 return "generic 'call succeeded'";
112 return "generic error";
114 return "no thread to satisfy query";
116 return "no sync handle to satisfy query";
118 return "no LWP to satisfy query";
120 return "invalid process handle";
122 return "invalid thread handle";
124 return "invalid synchronization handle";
126 return "invalid thread agent";
128 return "invalid key";
130 return "no event message for getmsg";
132 return "FPU register set not available";
134 return "application not linked with libthread";
136 return "requested event is not supported";
138 return "capability not available";
140 return "debugger service failed";
142 return "operation not applicable to";
144 return "no thread-specific data for this thread";
146 return "malloc failed";
148 return "only part of register set was written/read";
150 return "X register set not available for this thread";
151 #ifdef HAVE_TD_VERSION
153 return "version mismatch between libthread_db and libpthread";
156 xsnprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
163 thread_db_state_str (td_thr_state_e state)
170 return "stopped by debugger";
179 case TD_THR_STOPPED_ASLEEP:
180 return "stopped by debugger AND blocked";
182 xsnprintf (buf, sizeof (buf), "unknown thread_db state %d", state);
189 thread_db_create_event (CORE_ADDR where)
193 struct lwp_info *lwp;
194 struct thread_db *thread_db = current_process ()->private->thread_db;
196 gdb_assert (thread_db->td_ta_event_getmsg_p != NULL);
199 debug_printf ("Thread creation event.\n");
201 /* FIXME: This assumes we don't get another event.
202 In the LinuxThreads implementation, this is safe,
203 because all events come from the manager thread
204 (except for its own creation, of course). */
205 err = thread_db->td_ta_event_getmsg_p (thread_db->thread_agent, &msg);
207 fprintf (stderr, "thread getmsg err: %s\n",
208 thread_db_err_str (err));
210 /* If we do not know about the main thread yet, this would be a good time to
211 find it. We need to do this to pick up the main thread before any newly
213 lwp = get_thread_lwp (current_thread);
214 if (lwp->thread_known == 0)
215 find_one_thread (current_thread->entry.id);
217 /* msg.event == TD_EVENT_CREATE */
219 find_new_threads_callback (msg.th_p, NULL);
225 thread_db_enable_reporting (void)
227 td_thr_events_t events;
230 struct thread_db *thread_db = current_process ()->private->thread_db;
232 if (thread_db->td_ta_set_event_p == NULL
233 || thread_db->td_ta_event_addr_p == NULL
234 || thread_db->td_ta_event_getmsg_p == NULL)
235 /* This libthread_db is missing required support. */
238 /* Set the process wide mask saying which events we're interested in. */
239 td_event_emptyset (&events);
240 td_event_addset (&events, TD_CREATE);
242 err = thread_db->td_ta_set_event_p (thread_db->thread_agent, &events);
245 warning ("Unable to set global thread event mask: %s",
246 thread_db_err_str (err));
250 /* Get address for thread creation breakpoint. */
251 err = thread_db->td_ta_event_addr_p (thread_db->thread_agent, TD_CREATE,
255 warning ("Unable to get location for thread creation breakpoint: %s",
256 thread_db_err_str (err));
259 thread_db->td_create_bp
260 = set_breakpoint_at ((CORE_ADDR) (unsigned long) notify.u.bptaddr,
261 thread_db_create_event);
267 find_one_thread (ptid_t ptid)
272 struct thread_info *inferior;
273 struct lwp_info *lwp;
274 struct thread_db *thread_db = current_process ()->private->thread_db;
275 int lwpid = ptid_get_lwp (ptid);
277 inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
278 lwp = get_thread_lwp (inferior);
279 if (lwp->thread_known)
282 /* Get information about this thread. */
283 err = thread_db->td_ta_map_lwp2thr_p (thread_db->thread_agent, lwpid, &th);
285 error ("Cannot get thread handle for LWP %d: %s",
286 lwpid, thread_db_err_str (err));
288 err = thread_db->td_thr_get_info_p (&th, &ti);
290 error ("Cannot get thread info for LWP %d: %s",
291 lwpid, thread_db_err_str (err));
294 debug_printf ("Found thread %ld (LWP %d)\n",
295 ti.ti_tid, ti.ti_lid);
297 if (lwpid != ti.ti_lid)
299 warning ("PID mismatch! Expected %ld, got %ld",
300 (long) lwpid, (long) ti.ti_lid);
304 if (thread_db_use_events)
306 err = thread_db->td_thr_event_enable_p (&th, 1);
308 error ("Cannot enable thread event reporting for %d: %s",
309 ti.ti_lid, thread_db_err_str (err));
312 /* If the new thread ID is zero, a final thread ID will be available
313 later. Do not enable thread debugging yet. */
317 lwp->thread_known = 1;
323 /* Attach a thread. Return true on success. */
326 attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
328 struct process_info *proc = current_process ();
329 int pid = pid_of (proc);
330 ptid_t ptid = ptid_build (pid, ti_p->ti_lid, 0);
331 struct lwp_info *lwp;
335 debug_printf ("Attaching to thread %ld (LWP %d)\n",
336 ti_p->ti_tid, ti_p->ti_lid);
337 err = linux_attach_lwp (ptid);
340 warning ("Could not attach to thread %ld (LWP %d): %s\n",
341 ti_p->ti_tid, ti_p->ti_lid,
342 linux_ptrace_attach_fail_reason_string (ptid, err));
346 lwp = find_lwp_pid (ptid);
347 gdb_assert (lwp != NULL);
348 lwp->thread_known = 1;
351 if (thread_db_use_events)
354 struct thread_db *thread_db = proc->private->thread_db;
356 err = thread_db->td_thr_event_enable_p (th_p, 1);
358 error ("Cannot enable thread event reporting for %d: %s",
359 ti_p->ti_lid, thread_db_err_str (err));
365 /* Attach thread if we haven't seen it yet.
366 Increment *COUNTER if we have attached a new thread.
367 Return false on failure. */
370 maybe_attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p,
373 struct lwp_info *lwp;
375 lwp = find_lwp_pid (pid_to_ptid (ti_p->ti_lid));
379 if (!attach_thread (th_p, ti_p))
389 find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
393 struct thread_db *thread_db = current_process ()->private->thread_db;
395 err = thread_db->td_thr_get_info_p (th_p, &ti);
397 error ("Cannot get thread info: %s", thread_db_err_str (err));
401 /* A thread with kernel thread ID -1 is either a thread that
402 exited and was joined, or a thread that is being created but
403 hasn't started yet, and that is reusing the tcb/stack of a
404 thread that previously exited and was joined. (glibc marks
405 terminated and joined threads with kernel thread ID -1. See
408 debug_printf ("thread_db: skipping exited and "
409 "joined thread (0x%lx)\n", ti.ti_tid);
413 /* Check for zombies. */
414 if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
417 if (!maybe_attach_thread (th_p, &ti, (int *) data))
419 /* Terminate iteration early: we might be looking at stale data in
420 the inferior. The thread_db_find_new_threads will retry. */
428 thread_db_find_new_threads (void)
431 ptid_t ptid = current_ptid;
432 struct thread_db *thread_db = current_process ()->private->thread_db;
435 /* This function is only called when we first initialize thread_db.
436 First locate the initial thread. If it is not ready for
437 debugging yet, then stop. */
438 if (find_one_thread (ptid) == 0)
441 /* Require 4 successive iterations which do not find any new threads.
442 The 4 is a heuristic: there is an inherent race here, and I have
443 seen that 2 iterations in a row are not always sufficient to
444 "capture" all threads. */
445 for (loop = 0, iteration = 0; loop < 4; ++loop, ++iteration)
447 int new_thread_count = 0;
449 /* Iterate over all user-space threads to discover new threads. */
450 err = thread_db->td_ta_thr_iter_p (thread_db->thread_agent,
451 find_new_threads_callback,
454 TD_THR_LOWEST_PRIORITY,
455 TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
457 debug_printf ("Found %d threads in iteration %d.\n",
458 new_thread_count, iteration);
460 if (new_thread_count != 0)
462 /* Found new threads. Restart iteration from beginning. */
467 error ("Cannot find new threads: %s", thread_db_err_str (err));
470 /* Cache all future symbols that thread_db might request. We can not
471 request symbols at arbitrary states in the remote protocol, only
472 when the client tells us that new symbols are available. So when
473 we load the thread library, make sure to check the entire list. */
476 thread_db_look_up_symbols (void)
478 struct thread_db *thread_db = current_process ()->private->thread_db;
479 const char **sym_list;
482 for (sym_list = thread_db->td_symbol_list_p (); *sym_list; sym_list++)
483 look_up_one_symbol (*sym_list, &unused, 1);
485 /* We're not interested in any other libraries loaded after this
486 point, only in symbols in libpthread.so. */
487 thread_db->all_symbols_looked_up = 1;
491 thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp)
493 struct thread_db *thread_db = current_process ()->private->thread_db;
494 int may_ask_gdb = !thread_db->all_symbols_looked_up;
496 /* If we've passed the call to thread_db_look_up_symbols, then
497 anything not in the cache must not exist; we're not interested
498 in any libraries loaded after that point, only in symbols in
499 libpthread.so. It might not be an appropriate time to look
500 up a symbol, e.g. while we're trying to fetch registers. */
501 return look_up_one_symbol (name, addrp, may_ask_gdb);
505 thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
506 CORE_ADDR load_module, CORE_ADDR *address)
510 struct lwp_info *lwp;
511 struct thread_info *saved_thread;
512 struct process_info *proc;
513 struct thread_db *thread_db;
515 proc = get_thread_process (thread);
516 thread_db = proc->private->thread_db;
518 /* If the thread layer is not (yet) initialized, fail. */
519 if (thread_db == NULL || !thread_db->all_symbols_looked_up)
522 /* If td_thr_tls_get_addr is missing rather do not expect td_thr_tlsbase
524 if (thread_db->td_thr_tls_get_addr_p == NULL
525 || (load_module == 0 && thread_db->td_thr_tlsbase_p == NULL))
528 lwp = get_thread_lwp (thread);
529 if (!lwp->thread_known)
530 find_one_thread (thread->entry.id);
531 if (!lwp->thread_known)
534 saved_thread = current_thread;
535 current_thread = thread;
537 if (load_module != 0)
539 /* Note the cast through uintptr_t: this interface only works if
540 a target address fits in a psaddr_t, which is a host pointer.
541 So a 32-bit debugger can not access 64-bit TLS through this. */
542 err = thread_db->td_thr_tls_get_addr_p (&lwp->th,
543 (psaddr_t) (uintptr_t) load_module,
548 /* This code path handles the case of -static -pthread executables:
549 https://sourceware.org/ml/libc-help/2014-03/msg00024.html
550 For older GNU libc r_debug.r_map is NULL. For GNU libc after
551 PR libc/16831 due to GDB PR threads/16954 LOAD_MODULE is also NULL.
552 The constant number 1 depends on GNU __libc_setup_tls
553 initialization of l_tls_modid to 1. */
554 err = thread_db->td_thr_tlsbase_p (&lwp->th, 1, &addr);
555 addr = (char *) addr + offset;
558 current_thread = saved_thread;
561 *address = (CORE_ADDR) (uintptr_t) addr;
568 #ifdef USE_LIBTHREAD_DB_DIRECTLY
571 thread_db_load_search (void)
574 struct thread_db *tdb;
575 struct process_info *proc = current_process ();
577 gdb_assert (proc->private->thread_db == NULL);
579 tdb = xcalloc (1, sizeof (*tdb));
580 proc->private->thread_db = tdb;
582 tdb->td_ta_new_p = &td_ta_new;
584 /* Attempt to open a connection to the thread library. */
585 err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
589 debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
591 proc->private->thread_db = NULL;
595 tdb->td_ta_map_lwp2thr_p = &td_ta_map_lwp2thr;
596 tdb->td_thr_get_info_p = &td_thr_get_info;
597 tdb->td_ta_thr_iter_p = &td_ta_thr_iter;
598 tdb->td_symbol_list_p = &td_symbol_list;
600 /* This is required only when thread_db_use_events is on. */
601 tdb->td_thr_event_enable_p = &td_thr_event_enable;
603 /* These are not essential. */
604 tdb->td_ta_event_addr_p = &td_ta_event_addr;
605 tdb->td_ta_set_event_p = &td_ta_set_event;
606 tdb->td_ta_event_getmsg_p = &td_ta_event_getmsg;
607 tdb->td_thr_tls_get_addr_p = &td_thr_tls_get_addr;
608 tdb->td_thr_tlsbase_p = &td_thr_tlsbase;
616 try_thread_db_load_1 (void *handle)
619 struct thread_db *tdb;
620 struct process_info *proc = current_process ();
622 gdb_assert (proc->private->thread_db == NULL);
624 tdb = xcalloc (1, sizeof (*tdb));
625 proc->private->thread_db = tdb;
627 tdb->handle = handle;
629 /* Initialize pointers to the dynamic library functions we will use.
630 Essential functions first. */
632 #define CHK(required, a) \
638 debug_printf ("dlsym: %s\n", dlerror ()); \
642 proc->private->thread_db = NULL; \
649 CHK (1, tdb->td_ta_new_p = dlsym (handle, "td_ta_new"));
651 /* Attempt to open a connection to the thread library. */
652 err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
656 debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
658 proc->private->thread_db = NULL;
662 CHK (1, tdb->td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
663 CHK (1, tdb->td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
664 CHK (1, tdb->td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
665 CHK (1, tdb->td_symbol_list_p = dlsym (handle, "td_symbol_list"));
667 /* This is required only when thread_db_use_events is on. */
668 CHK (thread_db_use_events,
669 tdb->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
671 /* These are not essential. */
672 CHK (0, tdb->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
673 CHK (0, tdb->td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
674 CHK (0, tdb->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
675 CHK (0, tdb->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
676 CHK (0, tdb->td_thr_tlsbase_p = dlsym (handle, "td_thr_tlsbase"));
685 /* Lookup a library in which given symbol resides.
686 Note: this is looking in the GDBSERVER process, not in the inferior.
687 Returns library name, or NULL. */
690 dladdr_to_soname (const void *addr)
694 if (dladdr (addr, &info) != 0)
695 return info.dli_fname;
702 try_thread_db_load (const char *library)
707 debug_printf ("Trying host libthread_db library: %s.\n",
709 handle = dlopen (library, RTLD_NOW);
713 debug_printf ("dlopen failed: %s.\n", dlerror ());
718 if (debug_threads && strchr (library, '/') == NULL)
722 td_init = dlsym (handle, "td_init");
725 const char *const libpath = dladdr_to_soname (td_init);
728 fprintf (stderr, "Host %s resolved to: %s.\n",
734 if (try_thread_db_load_1 (handle))
737 /* This library "refused" to work on current inferior. */
742 /* Handle $sdir in libthread-db-search-path.
743 Look for libthread_db in the system dirs, or wherever a plain
744 dlopen(file_without_path) will look.
745 The result is true for success. */
748 try_thread_db_load_from_sdir (void)
750 return try_thread_db_load (LIBTHREAD_DB_SO);
753 /* Try to load libthread_db from directory DIR of length DIR_LEN.
754 The result is true for success. */
757 try_thread_db_load_from_dir (const char *dir, size_t dir_len)
761 if (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path))
763 char *cp = xmalloc (dir_len + 1);
765 memcpy (cp, dir, dir_len);
767 warning (_("libthread-db-search-path component too long,"
768 " ignored: %s."), cp);
773 memcpy (path, dir, dir_len);
775 strcpy (path + dir_len + 1, LIBTHREAD_DB_SO);
776 return try_thread_db_load (path);
779 /* Search libthread_db_search_path for libthread_db which "agrees"
780 to work on current inferior.
781 The result is true for success. */
784 thread_db_load_search (void)
786 VEC (char_ptr) *dir_vec;
790 if (libthread_db_search_path == NULL)
791 libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
793 dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
795 for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
797 const int pdir_len = sizeof ("$pdir") - 1;
800 this_dir_len = strlen (this_dir);
802 if (strncmp (this_dir, "$pdir", pdir_len) == 0
803 && (this_dir[pdir_len] == '\0'
804 || this_dir[pdir_len] == '/'))
806 /* We don't maintain a list of loaded libraries so we don't know
807 where libpthread lives. We *could* fetch the info, but we don't
808 do that yet. Ignore it. */
810 else if (strcmp (this_dir, "$sdir") == 0)
812 if (try_thread_db_load_from_sdir ())
820 if (try_thread_db_load_from_dir (this_dir, this_dir_len))
828 free_char_ptr_vec (dir_vec);
830 debug_printf ("thread_db_load_search returning %d\n", rc);
834 #endif /* USE_LIBTHREAD_DB_DIRECTLY */
837 thread_db_init (int use_events)
839 struct process_info *proc = current_process ();
841 /* FIXME drow/2004-10-16: This is the "overall process ID", which
842 GNU/Linux calls tgid, "thread group ID". When we support
843 attaching to threads, the original thread may not be the correct
844 thread. We would have to get the process ID from /proc for NPTL.
845 For LinuxThreads we could do something similar: follow the chain
846 of parent processes until we find the highest one we're attached
847 to, and use its tgid.
849 This isn't the only place in gdbserver that assumes that the first
850 process in the list is the thread group leader. */
852 thread_db_use_events = use_events;
854 if (thread_db_load_search ())
856 if (use_events && thread_db_enable_reporting () == 0)
858 /* Keep trying; maybe event reporting will work later. */
859 thread_db_mourn (proc);
862 thread_db_find_new_threads ();
863 thread_db_look_up_symbols ();
871 any_thread_of (struct inferior_list_entry *entry, void *args)
875 if (ptid_get_pid (entry->id) == *pid_p)
882 switch_to_process (struct process_info *proc)
884 int pid = pid_of (proc);
887 (struct thread_info *) find_inferior (&all_threads,
888 any_thread_of, &pid);
891 /* Disconnect from libthread_db and free resources. */
894 disable_thread_event_reporting (struct process_info *proc)
896 struct thread_db *thread_db = proc->private->thread_db;
899 td_err_e (*td_ta_clear_event_p) (const td_thragent_t *ta,
900 td_thr_events_t *event);
902 #ifndef USE_LIBTHREAD_DB_DIRECTLY
903 td_ta_clear_event_p = dlsym (thread_db->handle, "td_ta_clear_event");
905 td_ta_clear_event_p = &td_ta_clear_event;
908 if (td_ta_clear_event_p != NULL)
910 struct thread_info *saved_thread = current_thread;
911 td_thr_events_t events;
913 switch_to_process (proc);
915 /* Set the process wide mask saying we aren't interested
916 in any events anymore. */
917 td_event_fillset (&events);
918 (*td_ta_clear_event_p) (thread_db->thread_agent, &events);
920 current_thread = saved_thread;
926 remove_thread_event_breakpoints (struct process_info *proc)
928 struct thread_db *thread_db = proc->private->thread_db;
930 if (thread_db->td_create_bp != NULL)
932 struct thread_info *saved_thread = current_thread;
934 switch_to_process (proc);
936 delete_breakpoint (thread_db->td_create_bp);
937 thread_db->td_create_bp = NULL;
939 current_thread = saved_thread;
944 thread_db_detach (struct process_info *proc)
946 struct thread_db *thread_db = proc->private->thread_db;
950 disable_thread_event_reporting (proc);
951 remove_thread_event_breakpoints (proc);
955 /* Disconnect from libthread_db and free resources. */
958 thread_db_mourn (struct process_info *proc)
960 struct thread_db *thread_db = proc->private->thread_db;
963 td_err_e (*td_ta_delete_p) (td_thragent_t *);
965 #ifndef USE_LIBTHREAD_DB_DIRECTLY
966 td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
968 td_ta_delete_p = &td_ta_delete;
971 if (td_ta_delete_p != NULL)
972 (*td_ta_delete_p) (thread_db->thread_agent);
974 #ifndef USE_LIBTHREAD_DB_DIRECTLY
975 dlclose (thread_db->handle);
976 #endif /* USE_LIBTHREAD_DB_DIRECTLY */
979 proc->private->thread_db = NULL;
983 /* Handle "set libthread-db-search-path" monitor command and return 1.
984 For any other command, return 0. */
987 thread_db_handle_monitor_command (char *mon)
989 const char *cmd = "set libthread-db-search-path";
990 size_t cmd_len = strlen (cmd);
992 if (strncmp (mon, cmd, cmd_len) == 0
993 && (mon[cmd_len] == '\0'
994 || mon[cmd_len] == ' '))
996 const char *cp = mon + cmd_len;
998 if (libthread_db_search_path != NULL)
999 free (libthread_db_search_path);
1001 /* Skip leading space (if any). */
1002 while (isspace (*cp))
1006 cp = LIBTHREAD_DB_SEARCH_PATH;
1007 libthread_db_search_path = xstrdup (cp);
1009 monitor_output ("libthread-db-search-path set to `");
1010 monitor_output (libthread_db_search_path);
1011 monitor_output ("'\n");
1015 /* Tell server.c to perform default processing. */