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"
32 #include "nat/linux-procfs.h"
34 #ifndef USE_LIBTHREAD_DB_DIRECTLY
44 /* Structure that identifies the child process for the
45 <proc_service.h> interface. */
46 struct ps_prochandle proc_handle;
48 /* Connection to the libthread_db library. */
49 td_thragent_t *thread_agent;
51 /* If this flag has been set, we've already asked GDB for all
52 symbols we might need; assume symbol cache misses are
54 int all_symbols_looked_up;
56 #ifndef USE_LIBTHREAD_DB_DIRECTLY
57 /* Handle of the libthread_db from dlopen. */
61 /* Thread creation event breakpoint. The code at this location in
62 the child process will be called by the pthread library whenever
63 a new thread is created. By setting a special breakpoint at this
64 location, GDB can detect when a new thread is created. We obtain
65 this location via the td_ta_event_addr call. Note that if the
66 running kernel supports tracing clones, then we don't need to use
67 (and in fact don't use) this magic thread event breakpoint to
68 learn about threads. */
69 struct breakpoint *td_create_bp;
71 /* Addresses of libthread_db functions. */
72 td_err_e (*td_ta_new_p) (struct ps_prochandle * ps, td_thragent_t **ta);
73 td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,
75 td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,
76 td_thr_events_t *event);
77 td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,
78 td_event_e event, td_notify_t *ptr);
79 td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid,
81 td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,
83 td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event);
84 td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,
85 td_thr_iter_f *callback, void *cbdata_p,
86 td_thr_state_e state, int ti_pri,
87 sigset_t *ti_sigmask_p,
88 unsigned int ti_user_flags);
89 td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,
91 size_t offset, psaddr_t *address);
92 td_err_e (*td_thr_tlsbase_p) (const td_thrhandle_t *th,
93 unsigned long int modid,
95 const char ** (*td_symbol_list_p) (void);
98 static char *libthread_db_search_path;
100 static int find_one_thread (ptid_t);
101 static int find_new_threads_callback (const td_thrhandle_t *th_p, void *data);
104 thread_db_err_str (td_err_e err)
111 return "generic 'call succeeded'";
113 return "generic error";
115 return "no thread to satisfy query";
117 return "no sync handle to satisfy query";
119 return "no LWP to satisfy query";
121 return "invalid process handle";
123 return "invalid thread handle";
125 return "invalid synchronization handle";
127 return "invalid thread agent";
129 return "invalid key";
131 return "no event message for getmsg";
133 return "FPU register set not available";
135 return "application not linked with libthread";
137 return "requested event is not supported";
139 return "capability not available";
141 return "debugger service failed";
143 return "operation not applicable to";
145 return "no thread-specific data for this thread";
147 return "malloc failed";
149 return "only part of register set was written/read";
151 return "X register set not available for this thread";
152 #ifdef HAVE_TD_VERSION
154 return "version mismatch between libthread_db and libpthread";
157 xsnprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
164 thread_db_state_str (td_thr_state_e state)
171 return "stopped by debugger";
180 case TD_THR_STOPPED_ASLEEP:
181 return "stopped by debugger AND blocked";
183 xsnprintf (buf, sizeof (buf), "unknown thread_db state %d", state);
190 thread_db_create_event (CORE_ADDR where)
194 struct lwp_info *lwp;
195 struct thread_db *thread_db = current_process ()->private->thread_db;
197 gdb_assert (thread_db->td_ta_event_getmsg_p != NULL);
200 debug_printf ("Thread creation event.\n");
202 /* FIXME: This assumes we don't get another event.
203 In the LinuxThreads implementation, this is safe,
204 because all events come from the manager thread
205 (except for its own creation, of course). */
206 err = thread_db->td_ta_event_getmsg_p (thread_db->thread_agent, &msg);
208 fprintf (stderr, "thread getmsg err: %s\n",
209 thread_db_err_str (err));
211 /* If we do not know about the main thread yet, this would be a good time to
212 find it. We need to do this to pick up the main thread before any newly
214 lwp = get_thread_lwp (current_thread);
215 if (lwp->thread_known == 0)
216 find_one_thread (current_thread->entry.id);
218 /* msg.event == TD_EVENT_CREATE */
220 find_new_threads_callback (msg.th_p, NULL);
226 thread_db_enable_reporting (void)
228 td_thr_events_t events;
231 struct thread_db *thread_db = current_process ()->private->thread_db;
233 if (thread_db->td_ta_set_event_p == NULL
234 || thread_db->td_ta_event_addr_p == NULL
235 || thread_db->td_ta_event_getmsg_p == NULL)
236 /* This libthread_db is missing required support. */
239 /* Set the process wide mask saying which events we're interested in. */
240 td_event_emptyset (&events);
241 td_event_addset (&events, TD_CREATE);
243 err = thread_db->td_ta_set_event_p (thread_db->thread_agent, &events);
246 warning ("Unable to set global thread event mask: %s",
247 thread_db_err_str (err));
251 /* Get address for thread creation breakpoint. */
252 err = thread_db->td_ta_event_addr_p (thread_db->thread_agent, TD_CREATE,
256 warning ("Unable to get location for thread creation breakpoint: %s",
257 thread_db_err_str (err));
260 thread_db->td_create_bp
261 = set_breakpoint_at ((CORE_ADDR) (unsigned long) notify.u.bptaddr,
262 thread_db_create_event);
268 find_one_thread (ptid_t ptid)
273 struct thread_info *inferior;
274 struct lwp_info *lwp;
275 struct thread_db *thread_db = current_process ()->private->thread_db;
276 int lwpid = ptid_get_lwp (ptid);
278 inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
279 lwp = get_thread_lwp (inferior);
280 if (lwp->thread_known)
283 /* Get information about this thread. */
284 err = thread_db->td_ta_map_lwp2thr_p (thread_db->thread_agent, lwpid, &th);
286 error ("Cannot get thread handle for LWP %d: %s",
287 lwpid, thread_db_err_str (err));
289 err = thread_db->td_thr_get_info_p (&th, &ti);
291 error ("Cannot get thread info for LWP %d: %s",
292 lwpid, thread_db_err_str (err));
295 debug_printf ("Found thread %ld (LWP %d)\n",
296 ti.ti_tid, ti.ti_lid);
298 if (lwpid != ti.ti_lid)
300 warning ("PID mismatch! Expected %ld, got %ld",
301 (long) lwpid, (long) ti.ti_lid);
305 if (thread_db_use_events)
307 err = thread_db->td_thr_event_enable_p (&th, 1);
309 error ("Cannot enable thread event reporting for %d: %s",
310 ti.ti_lid, thread_db_err_str (err));
313 /* If the new thread ID is zero, a final thread ID will be available
314 later. Do not enable thread debugging yet. */
318 lwp->thread_known = 1;
324 /* Attach a thread. Return true on success. */
327 attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
329 struct process_info *proc = current_process ();
330 int pid = pid_of (proc);
331 ptid_t ptid = ptid_build (pid, ti_p->ti_lid, 0);
332 struct lwp_info *lwp;
336 debug_printf ("Attaching to thread %ld (LWP %d)\n",
337 ti_p->ti_tid, ti_p->ti_lid);
338 err = linux_attach_lwp (ptid);
341 warning ("Could not attach to thread %ld (LWP %d): %s\n",
342 ti_p->ti_tid, ti_p->ti_lid,
343 linux_ptrace_attach_fail_reason_string (ptid, err));
347 lwp = find_lwp_pid (ptid);
348 gdb_assert (lwp != NULL);
349 lwp->thread_known = 1;
352 if (thread_db_use_events)
355 struct thread_db *thread_db = proc->private->thread_db;
357 err = thread_db->td_thr_event_enable_p (th_p, 1);
359 error ("Cannot enable thread event reporting for %d: %s",
360 ti_p->ti_lid, thread_db_err_str (err));
366 /* Attach thread if we haven't seen it yet.
367 Increment *COUNTER if we have attached a new thread.
368 Return false on failure. */
371 maybe_attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p,
374 struct lwp_info *lwp;
376 lwp = find_lwp_pid (pid_to_ptid (ti_p->ti_lid));
380 if (!attach_thread (th_p, ti_p))
390 find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
394 struct thread_db *thread_db = current_process ()->private->thread_db;
396 err = thread_db->td_thr_get_info_p (th_p, &ti);
398 error ("Cannot get thread info: %s", thread_db_err_str (err));
402 /* A thread with kernel thread ID -1 is either a thread that
403 exited and was joined, or a thread that is being created but
404 hasn't started yet, and that is reusing the tcb/stack of a
405 thread that previously exited and was joined. (glibc marks
406 terminated and joined threads with kernel thread ID -1. See
409 debug_printf ("thread_db: skipping exited and "
410 "joined thread (0x%lx)\n", ti.ti_tid);
414 /* Check for zombies. */
415 if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
418 if (!maybe_attach_thread (th_p, &ti, (int *) data))
420 /* Terminate iteration early: we might be looking at stale data in
421 the inferior. The thread_db_find_new_threads will retry. */
429 thread_db_find_new_threads (void)
432 ptid_t ptid = current_ptid;
433 struct thread_db *thread_db = current_process ()->private->thread_db;
436 /* This function is only called when we first initialize thread_db.
437 First locate the initial thread. If it is not ready for
438 debugging yet, then stop. */
439 if (find_one_thread (ptid) == 0)
442 /* Require 4 successive iterations which do not find any new threads.
443 The 4 is a heuristic: there is an inherent race here, and I have
444 seen that 2 iterations in a row are not always sufficient to
445 "capture" all threads. */
446 for (loop = 0, iteration = 0; loop < 4; ++loop, ++iteration)
448 int new_thread_count = 0;
450 /* Iterate over all user-space threads to discover new threads. */
451 err = thread_db->td_ta_thr_iter_p (thread_db->thread_agent,
452 find_new_threads_callback,
455 TD_THR_LOWEST_PRIORITY,
456 TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
458 debug_printf ("Found %d threads in iteration %d.\n",
459 new_thread_count, iteration);
461 if (new_thread_count != 0)
463 /* Found new threads. Restart iteration from beginning. */
468 error ("Cannot find new threads: %s", thread_db_err_str (err));
471 /* Cache all future symbols that thread_db might request. We can not
472 request symbols at arbitrary states in the remote protocol, only
473 when the client tells us that new symbols are available. So when
474 we load the thread library, make sure to check the entire list. */
477 thread_db_look_up_symbols (void)
479 struct thread_db *thread_db = current_process ()->private->thread_db;
480 const char **sym_list;
483 for (sym_list = thread_db->td_symbol_list_p (); *sym_list; sym_list++)
484 look_up_one_symbol (*sym_list, &unused, 1);
486 /* We're not interested in any other libraries loaded after this
487 point, only in symbols in libpthread.so. */
488 thread_db->all_symbols_looked_up = 1;
492 thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp)
494 struct thread_db *thread_db = current_process ()->private->thread_db;
495 int may_ask_gdb = !thread_db->all_symbols_looked_up;
497 /* If we've passed the call to thread_db_look_up_symbols, then
498 anything not in the cache must not exist; we're not interested
499 in any libraries loaded after that point, only in symbols in
500 libpthread.so. It might not be an appropriate time to look
501 up a symbol, e.g. while we're trying to fetch registers. */
502 return look_up_one_symbol (name, addrp, may_ask_gdb);
506 thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
507 CORE_ADDR load_module, CORE_ADDR *address)
511 struct lwp_info *lwp;
512 struct thread_info *saved_thread;
513 struct process_info *proc;
514 struct thread_db *thread_db;
516 proc = get_thread_process (thread);
517 thread_db = proc->private->thread_db;
519 /* If the thread layer is not (yet) initialized, fail. */
520 if (thread_db == NULL || !thread_db->all_symbols_looked_up)
523 /* If td_thr_tls_get_addr is missing rather do not expect td_thr_tlsbase
525 if (thread_db->td_thr_tls_get_addr_p == NULL
526 || (load_module == 0 && thread_db->td_thr_tlsbase_p == NULL))
529 lwp = get_thread_lwp (thread);
530 if (!lwp->thread_known)
531 find_one_thread (thread->entry.id);
532 if (!lwp->thread_known)
535 saved_thread = current_thread;
536 current_thread = thread;
538 if (load_module != 0)
540 /* Note the cast through uintptr_t: this interface only works if
541 a target address fits in a psaddr_t, which is a host pointer.
542 So a 32-bit debugger can not access 64-bit TLS through this. */
543 err = thread_db->td_thr_tls_get_addr_p (&lwp->th,
544 (psaddr_t) (uintptr_t) load_module,
549 /* This code path handles the case of -static -pthread executables:
550 https://sourceware.org/ml/libc-help/2014-03/msg00024.html
551 For older GNU libc r_debug.r_map is NULL. For GNU libc after
552 PR libc/16831 due to GDB PR threads/16954 LOAD_MODULE is also NULL.
553 The constant number 1 depends on GNU __libc_setup_tls
554 initialization of l_tls_modid to 1. */
555 err = thread_db->td_thr_tlsbase_p (&lwp->th, 1, &addr);
556 addr = (char *) addr + offset;
559 current_thread = saved_thread;
562 *address = (CORE_ADDR) (uintptr_t) addr;
569 #ifdef USE_LIBTHREAD_DB_DIRECTLY
572 thread_db_load_search (void)
575 struct thread_db *tdb;
576 struct process_info *proc = current_process ();
578 gdb_assert (proc->private->thread_db == NULL);
580 tdb = xcalloc (1, sizeof (*tdb));
581 proc->private->thread_db = tdb;
583 tdb->td_ta_new_p = &td_ta_new;
585 /* Attempt to open a connection to the thread library. */
586 err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
590 debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
592 proc->private->thread_db = NULL;
596 tdb->td_ta_map_lwp2thr_p = &td_ta_map_lwp2thr;
597 tdb->td_thr_get_info_p = &td_thr_get_info;
598 tdb->td_ta_thr_iter_p = &td_ta_thr_iter;
599 tdb->td_symbol_list_p = &td_symbol_list;
601 /* This is required only when thread_db_use_events is on. */
602 tdb->td_thr_event_enable_p = &td_thr_event_enable;
604 /* These are not essential. */
605 tdb->td_ta_event_addr_p = &td_ta_event_addr;
606 tdb->td_ta_set_event_p = &td_ta_set_event;
607 tdb->td_ta_event_getmsg_p = &td_ta_event_getmsg;
608 tdb->td_thr_tls_get_addr_p = &td_thr_tls_get_addr;
609 tdb->td_thr_tlsbase_p = &td_thr_tlsbase;
617 try_thread_db_load_1 (void *handle)
620 struct thread_db *tdb;
621 struct process_info *proc = current_process ();
623 gdb_assert (proc->private->thread_db == NULL);
625 tdb = xcalloc (1, sizeof (*tdb));
626 proc->private->thread_db = tdb;
628 tdb->handle = handle;
630 /* Initialize pointers to the dynamic library functions we will use.
631 Essential functions first. */
633 #define CHK(required, a) \
639 debug_printf ("dlsym: %s\n", dlerror ()); \
643 proc->private->thread_db = NULL; \
650 CHK (1, tdb->td_ta_new_p = dlsym (handle, "td_ta_new"));
652 /* Attempt to open a connection to the thread library. */
653 err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
657 debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
659 proc->private->thread_db = NULL;
663 CHK (1, tdb->td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
664 CHK (1, tdb->td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
665 CHK (1, tdb->td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
666 CHK (1, tdb->td_symbol_list_p = dlsym (handle, "td_symbol_list"));
668 /* This is required only when thread_db_use_events is on. */
669 CHK (thread_db_use_events,
670 tdb->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
672 /* These are not essential. */
673 CHK (0, tdb->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
674 CHK (0, tdb->td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
675 CHK (0, tdb->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
676 CHK (0, tdb->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
677 CHK (0, tdb->td_thr_tlsbase_p = dlsym (handle, "td_thr_tlsbase"));
686 /* Lookup a library in which given symbol resides.
687 Note: this is looking in the GDBSERVER process, not in the inferior.
688 Returns library name, or NULL. */
691 dladdr_to_soname (const void *addr)
695 if (dladdr (addr, &info) != 0)
696 return info.dli_fname;
703 try_thread_db_load (const char *library)
708 debug_printf ("Trying host libthread_db library: %s.\n",
710 handle = dlopen (library, RTLD_NOW);
714 debug_printf ("dlopen failed: %s.\n", dlerror ());
719 if (debug_threads && strchr (library, '/') == NULL)
723 td_init = dlsym (handle, "td_init");
726 const char *const libpath = dladdr_to_soname (td_init);
729 fprintf (stderr, "Host %s resolved to: %s.\n",
735 if (try_thread_db_load_1 (handle))
738 /* This library "refused" to work on current inferior. */
743 /* Handle $sdir in libthread-db-search-path.
744 Look for libthread_db in the system dirs, or wherever a plain
745 dlopen(file_without_path) will look.
746 The result is true for success. */
749 try_thread_db_load_from_sdir (void)
751 return try_thread_db_load (LIBTHREAD_DB_SO);
754 /* Try to load libthread_db from directory DIR of length DIR_LEN.
755 The result is true for success. */
758 try_thread_db_load_from_dir (const char *dir, size_t dir_len)
762 if (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path))
764 char *cp = xmalloc (dir_len + 1);
766 memcpy (cp, dir, dir_len);
768 warning (_("libthread-db-search-path component too long,"
769 " ignored: %s."), cp);
774 memcpy (path, dir, dir_len);
776 strcpy (path + dir_len + 1, LIBTHREAD_DB_SO);
777 return try_thread_db_load (path);
780 /* Search libthread_db_search_path for libthread_db which "agrees"
781 to work on current inferior.
782 The result is true for success. */
785 thread_db_load_search (void)
787 VEC (char_ptr) *dir_vec;
791 if (libthread_db_search_path == NULL)
792 libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
794 dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
796 for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
798 const int pdir_len = sizeof ("$pdir") - 1;
801 this_dir_len = strlen (this_dir);
803 if (strncmp (this_dir, "$pdir", pdir_len) == 0
804 && (this_dir[pdir_len] == '\0'
805 || this_dir[pdir_len] == '/'))
807 /* We don't maintain a list of loaded libraries so we don't know
808 where libpthread lives. We *could* fetch the info, but we don't
809 do that yet. Ignore it. */
811 else if (strcmp (this_dir, "$sdir") == 0)
813 if (try_thread_db_load_from_sdir ())
821 if (try_thread_db_load_from_dir (this_dir, this_dir_len))
829 free_char_ptr_vec (dir_vec);
831 debug_printf ("thread_db_load_search returning %d\n", rc);
835 #endif /* USE_LIBTHREAD_DB_DIRECTLY */
838 thread_db_init (int use_events)
840 struct process_info *proc = current_process ();
842 /* FIXME drow/2004-10-16: This is the "overall process ID", which
843 GNU/Linux calls tgid, "thread group ID". When we support
844 attaching to threads, the original thread may not be the correct
845 thread. We would have to get the process ID from /proc for NPTL.
846 For LinuxThreads we could do something similar: follow the chain
847 of parent processes until we find the highest one we're attached
848 to, and use its tgid.
850 This isn't the only place in gdbserver that assumes that the first
851 process in the list is the thread group leader. */
853 thread_db_use_events = use_events;
855 if (thread_db_load_search ())
857 if (use_events && thread_db_enable_reporting () == 0)
859 /* Keep trying; maybe event reporting will work later. */
860 thread_db_mourn (proc);
864 /* It's best to avoid td_ta_thr_iter if possible. That walks
865 data structures in the inferior's address space that may be
866 corrupted, or, if the target is running, the list may change
867 while we walk it. In the latter case, it's possible that a
868 thread exits just at the exact time that causes GDBserver to
869 get stuck in an infinite loop. If the kernel supports clone
870 events, and /proc/PID/task/ exits, then we already know about
871 all threads in the process. When we need info out of
872 thread_db on a given thread (e.g., for TLS), we'll use
873 find_one_thread then. That uses thread_db entry points that
874 do not walk libpthread's thread list, so should be safe, as
875 well as more efficient. */
877 || !linux_proc_task_list_dir_exists (pid_of (proc)))
878 thread_db_find_new_threads ();
879 thread_db_look_up_symbols ();
887 any_thread_of (struct inferior_list_entry *entry, void *args)
891 if (ptid_get_pid (entry->id) == *pid_p)
898 switch_to_process (struct process_info *proc)
900 int pid = pid_of (proc);
903 (struct thread_info *) find_inferior (&all_threads,
904 any_thread_of, &pid);
907 /* Disconnect from libthread_db and free resources. */
910 disable_thread_event_reporting (struct process_info *proc)
912 struct thread_db *thread_db = proc->private->thread_db;
915 td_err_e (*td_ta_clear_event_p) (const td_thragent_t *ta,
916 td_thr_events_t *event);
918 #ifndef USE_LIBTHREAD_DB_DIRECTLY
919 td_ta_clear_event_p = dlsym (thread_db->handle, "td_ta_clear_event");
921 td_ta_clear_event_p = &td_ta_clear_event;
924 if (td_ta_clear_event_p != NULL)
926 struct thread_info *saved_thread = current_thread;
927 td_thr_events_t events;
929 switch_to_process (proc);
931 /* Set the process wide mask saying we aren't interested
932 in any events anymore. */
933 td_event_fillset (&events);
934 (*td_ta_clear_event_p) (thread_db->thread_agent, &events);
936 current_thread = saved_thread;
942 remove_thread_event_breakpoints (struct process_info *proc)
944 struct thread_db *thread_db = proc->private->thread_db;
946 if (thread_db->td_create_bp != NULL)
948 struct thread_info *saved_thread = current_thread;
950 switch_to_process (proc);
952 delete_breakpoint (thread_db->td_create_bp);
953 thread_db->td_create_bp = NULL;
955 current_thread = saved_thread;
960 thread_db_detach (struct process_info *proc)
962 struct thread_db *thread_db = proc->private->thread_db;
966 disable_thread_event_reporting (proc);
967 remove_thread_event_breakpoints (proc);
971 /* Disconnect from libthread_db and free resources. */
974 thread_db_mourn (struct process_info *proc)
976 struct thread_db *thread_db = proc->private->thread_db;
979 td_err_e (*td_ta_delete_p) (td_thragent_t *);
981 #ifndef USE_LIBTHREAD_DB_DIRECTLY
982 td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
984 td_ta_delete_p = &td_ta_delete;
987 if (td_ta_delete_p != NULL)
988 (*td_ta_delete_p) (thread_db->thread_agent);
990 #ifndef USE_LIBTHREAD_DB_DIRECTLY
991 dlclose (thread_db->handle);
992 #endif /* USE_LIBTHREAD_DB_DIRECTLY */
995 proc->private->thread_db = NULL;
999 /* Handle "set libthread-db-search-path" monitor command and return 1.
1000 For any other command, return 0. */
1003 thread_db_handle_monitor_command (char *mon)
1005 const char *cmd = "set libthread-db-search-path";
1006 size_t cmd_len = strlen (cmd);
1008 if (strncmp (mon, cmd, cmd_len) == 0
1009 && (mon[cmd_len] == '\0'
1010 || mon[cmd_len] == ' '))
1012 const char *cp = mon + cmd_len;
1014 if (libthread_db_search_path != NULL)
1015 free (libthread_db_search_path);
1017 /* Skip leading space (if any). */
1018 while (isspace (*cp))
1022 cp = LIBTHREAD_DB_SEARCH_PATH;
1023 libthread_db_search_path = xstrdup (cp);
1025 monitor_output ("libthread-db-search-path set to `");
1026 monitor_output (libthread_db_search_path);
1027 monitor_output ("'\n");
1031 /* Tell server.c to perform default processing. */