Revision | c2c2a31fdb228d41ce3db62b268efea04bd39c18 (tree) |
---|---|
Time | 2015-12-11 00:46:29 |
Author | Antoine Tremblay <antoine.tremblay@eric...> |
Commiter | Antoine Tremblay |
Remove support for thread events without PTRACE_EVENT_CLONE in GDB
Before, on systems that did not support PTRACE_EVENT_CLONE, both GDB and
GDBServer coordinated with libthread_db.so to insert breakpoints at magic
locations in libpthread.so, in order to break at thread creation and
thread death.
Support for thread events was removed from GDBServer as patch:
https://sourceware.org/ml/gdb-patches/2015-11/msg00466.html
This patch removes support for thread events in GDB.
No regressions found on Ubuntu 14.04 x86_64.
gdb/ChangeLog:
* breakpoint.c (remove_thread_event_breakpoints): Remove.
* breakpoint.h (remove_thread_event_breakpoints): Remove
declaration.
* linux-nat.c (in_pid_list_p): Remove.
(lin_lwp_attach_lwp): Remove.
* linux-nat.h (lin_lwp_attach_lwp): Remove declaration.
* linux-thread-db.c (thread_db_use_events): Remove.
(struct thread_db_info) <td_create_bp_addr>: Remove.
<td_death_bp_addr>: Likewise.
<td_ta_event_addr_p>: Likewise.
<td_ta_set_event_p>: Likewise.
<td_ta_clear_event_p>: Likewise.
<td_ta_event_getmsg_p>: Likewise.
<td_thr_event_enable_p>: Likewise.
(attach_thread): Likewise.
(detach_thread): Likewise.
(have_threads_callback): Likewise.
(have_threads): Likewise.
(enable_thread_event): Likewise.
(enable_thread_event_reporting): Likewise.
(try_thread_db_load_1): Remove td_ta_event_addr, td_ta_set_event,
td_ta_clear_event, td_ta_event_getmsg, td_thr_event_enable
initializations.
(try_thread_db_load_1): Remove enable_thread_event_reporting call.
(disable_thread_event_reporting): Remove.
(record_thread): Adapt to thread_db_use_event removal.
(detach_thread): Remove.
(thread_db_detach): Adapt to thread_db_use_event removal.
(check_event): Remove.
(thread_db_wait): Adapt to thread events support removal.
(thread_db_mourn_inferior): Likewise.
(find_new_threads_callback): Likewise.
(find_new_threads_once): Likewise.
(thread_db_update_thread_list): Likewise.
@@ -1,3 +1,40 @@ | ||
1 | +2015-12-10 Antoine Tremblay <antoine.tremblay@ericsson.com> | |
2 | + | |
3 | + * breakpoint.c (remove_thread_event_breakpoints): Remove. | |
4 | + * breakpoint.h (remove_thread_event_breakpoints): Remove | |
5 | + declaration. | |
6 | + * linux-nat.c (in_pid_list_p): Remove. | |
7 | + (lin_lwp_attach_lwp): Remove. | |
8 | + * linux-nat.h (lin_lwp_attach_lwp): Remove declaration. | |
9 | + * linux-thread-db.c (thread_db_use_events): Remove. | |
10 | + (struct thread_db_info) <td_create_bp_addr>: Remove. | |
11 | + <td_death_bp_addr>: Likewise. | |
12 | + <td_ta_event_addr_p>: Likewise. | |
13 | + <td_ta_set_event_p>: Likewise. | |
14 | + <td_ta_clear_event_p>: Likewise. | |
15 | + <td_ta_event_getmsg_p>: Likewise. | |
16 | + <td_thr_event_enable_p>: Likewise. | |
17 | + (attach_thread): Likewise. | |
18 | + (detach_thread): Likewise. | |
19 | + (have_threads_callback): Likewise. | |
20 | + (have_threads): Likewise. | |
21 | + (enable_thread_event): Likewise. | |
22 | + (enable_thread_event_reporting): Likewise. | |
23 | + (try_thread_db_load_1): Remove td_ta_event_addr, td_ta_set_event, | |
24 | + td_ta_clear_event, td_ta_event_getmsg, td_thr_event_enable | |
25 | + initializations. | |
26 | + (try_thread_db_load_1): Remove enable_thread_event_reporting call. | |
27 | + (disable_thread_event_reporting): Remove. | |
28 | + (record_thread): Adapt to thread_db_use_event removal. | |
29 | + (detach_thread): Remove. | |
30 | + (thread_db_detach): Adapt to thread_db_use_event removal. | |
31 | + (check_event): Remove. | |
32 | + (thread_db_wait): Adapt to thread events support removal. | |
33 | + (thread_db_mourn_inferior): Likewise. | |
34 | + (find_new_threads_callback): Likewise. | |
35 | + (find_new_threads_once): Likewise. | |
36 | + (thread_db_update_thread_list): Likewise. | |
37 | + | |
1 | 38 | 2015-12-10 Andrew Burgess <andrew.burgess@embecosm.com> |
2 | 39 | |
3 | 40 | * dwarf2read.c (dwarf2_ranges_read): Unify and fix base address |
@@ -7765,17 +7765,6 @@ create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | ||
7765 | 7765 | return b; |
7766 | 7766 | } |
7767 | 7767 | |
7768 | -void | |
7769 | -remove_thread_event_breakpoints (void) | |
7770 | -{ | |
7771 | - struct breakpoint *b, *b_tmp; | |
7772 | - | |
7773 | - ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7774 | - if (b->type == bp_thread_event | |
7775 | - && b->loc->pspace == current_program_space) | |
7776 | - delete_breakpoint (b); | |
7777 | -} | |
7778 | - | |
7779 | 7768 | struct lang_and_radix |
7780 | 7769 | { |
7781 | 7770 | enum language lang; |
@@ -1498,8 +1498,6 @@ extern void remove_solib_event_breakpoints (void); | ||
1498 | 1498 | delete at next stop disposition. */ |
1499 | 1499 | extern void remove_solib_event_breakpoints_at_next_stop (void); |
1500 | 1500 | |
1501 | -extern void remove_thread_event_breakpoints (void); | |
1502 | - | |
1503 | 1501 | extern void disable_breakpoints_in_shlibs (void); |
1504 | 1502 | |
1505 | 1503 | /* This function returns TRUE if ep is a catchpoint. */ |
@@ -345,17 +345,6 @@ add_to_pid_list (struct simple_pid_list **listp, int pid, int status) | ||
345 | 345 | } |
346 | 346 | |
347 | 347 | static int |
348 | -in_pid_list_p (struct simple_pid_list *list, int pid) | |
349 | -{ | |
350 | - struct simple_pid_list *p; | |
351 | - | |
352 | - for (p = list; p != NULL; p = p->next) | |
353 | - if (p->pid == pid) | |
354 | - return 1; | |
355 | - return 0; | |
356 | -} | |
357 | - | |
358 | -static int | |
359 | 348 | pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp) |
360 | 349 | { |
361 | 350 | struct simple_pid_list **p; |
@@ -1044,139 +1033,6 @@ linux_nat_post_attach_wait (ptid_t ptid, int first, int *cloned, | ||
1044 | 1033 | return status; |
1045 | 1034 | } |
1046 | 1035 | |
1047 | -/* Attach to the LWP specified by PID. Return 0 if successful, -1 if | |
1048 | - the new LWP could not be attached, or 1 if we're already auto | |
1049 | - attached to this thread, but haven't processed the | |
1050 | - PTRACE_EVENT_CLONE event of its parent thread, so we just ignore | |
1051 | - its existance, without considering it an error. */ | |
1052 | - | |
1053 | -int | |
1054 | -lin_lwp_attach_lwp (ptid_t ptid) | |
1055 | -{ | |
1056 | - struct lwp_info *lp; | |
1057 | - int lwpid; | |
1058 | - | |
1059 | - gdb_assert (ptid_lwp_p (ptid)); | |
1060 | - | |
1061 | - lp = find_lwp_pid (ptid); | |
1062 | - lwpid = ptid_get_lwp (ptid); | |
1063 | - | |
1064 | - /* We assume that we're already attached to any LWP that is already | |
1065 | - in our list of LWPs. If we're not seeing exit events from threads | |
1066 | - and we've had PID wraparound since we last tried to stop all threads, | |
1067 | - this assumption might be wrong; fortunately, this is very unlikely | |
1068 | - to happen. */ | |
1069 | - if (lp == NULL) | |
1070 | - { | |
1071 | - int status, cloned = 0, signalled = 0; | |
1072 | - | |
1073 | - if (ptrace (PTRACE_ATTACH, lwpid, 0, 0) < 0) | |
1074 | - { | |
1075 | - if (linux_supports_tracefork ()) | |
1076 | - { | |
1077 | - /* If we haven't stopped all threads when we get here, | |
1078 | - we may have seen a thread listed in thread_db's list, | |
1079 | - but not processed the PTRACE_EVENT_CLONE yet. If | |
1080 | - that's the case, ignore this new thread, and let | |
1081 | - normal event handling discover it later. */ | |
1082 | - if (in_pid_list_p (stopped_pids, lwpid)) | |
1083 | - { | |
1084 | - /* We've already seen this thread stop, but we | |
1085 | - haven't seen the PTRACE_EVENT_CLONE extended | |
1086 | - event yet. */ | |
1087 | - if (debug_linux_nat) | |
1088 | - fprintf_unfiltered (gdb_stdlog, | |
1089 | - "LLAL: attach failed, but already seen " | |
1090 | - "this thread %s stop\n", | |
1091 | - target_pid_to_str (ptid)); | |
1092 | - return 1; | |
1093 | - } | |
1094 | - else | |
1095 | - { | |
1096 | - int new_pid; | |
1097 | - int status; | |
1098 | - | |
1099 | - if (debug_linux_nat) | |
1100 | - fprintf_unfiltered (gdb_stdlog, | |
1101 | - "LLAL: attach failed, and haven't seen " | |
1102 | - "this thread %s stop yet\n", | |
1103 | - target_pid_to_str (ptid)); | |
1104 | - | |
1105 | - /* We may or may not be attached to the LWP already. | |
1106 | - Try waitpid on it. If that errors, we're not | |
1107 | - attached to the LWP yet. Otherwise, we're | |
1108 | - already attached. */ | |
1109 | - gdb_assert (lwpid > 0); | |
1110 | - new_pid = my_waitpid (lwpid, &status, WNOHANG); | |
1111 | - if (new_pid == -1 && errno == ECHILD) | |
1112 | - new_pid = my_waitpid (lwpid, &status, __WCLONE | WNOHANG); | |
1113 | - if (new_pid != -1) | |
1114 | - { | |
1115 | - if (new_pid == 0) | |
1116 | - { | |
1117 | - /* The child hasn't stopped for its initial | |
1118 | - SIGSTOP stop yet. */ | |
1119 | - if (debug_linux_nat) | |
1120 | - fprintf_unfiltered (gdb_stdlog, | |
1121 | - "LLAL: child hasn't " | |
1122 | - "stopped yet\n"); | |
1123 | - } | |
1124 | - else if (WIFSTOPPED (status)) | |
1125 | - { | |
1126 | - if (debug_linux_nat) | |
1127 | - fprintf_unfiltered (gdb_stdlog, | |
1128 | - "LLAL: adding to stopped_pids\n"); | |
1129 | - add_to_pid_list (&stopped_pids, lwpid, status); | |
1130 | - } | |
1131 | - return 1; | |
1132 | - } | |
1133 | - } | |
1134 | - } | |
1135 | - | |
1136 | - /* If we fail to attach to the thread, issue a warning, | |
1137 | - but continue. One way this can happen is if thread | |
1138 | - creation is interrupted; as of Linux kernel 2.6.19, a | |
1139 | - bug may place threads in the thread list and then fail | |
1140 | - to create them. */ | |
1141 | - warning (_("Can't attach %s: %s"), target_pid_to_str (ptid), | |
1142 | - safe_strerror (errno)); | |
1143 | - return -1; | |
1144 | - } | |
1145 | - | |
1146 | - if (debug_linux_nat) | |
1147 | - fprintf_unfiltered (gdb_stdlog, | |
1148 | - "LLAL: PTRACE_ATTACH %s, 0, 0 (OK)\n", | |
1149 | - target_pid_to_str (ptid)); | |
1150 | - | |
1151 | - status = linux_nat_post_attach_wait (ptid, 0, &cloned, &signalled); | |
1152 | - if (!WIFSTOPPED (status)) | |
1153 | - return 1; | |
1154 | - | |
1155 | - lp = add_lwp (ptid); | |
1156 | - lp->stopped = 1; | |
1157 | - lp->last_resume_kind = resume_stop; | |
1158 | - lp->cloned = cloned; | |
1159 | - lp->signalled = signalled; | |
1160 | - if (WSTOPSIG (status) != SIGSTOP) | |
1161 | - { | |
1162 | - lp->resumed = 1; | |
1163 | - lp->status = status; | |
1164 | - } | |
1165 | - | |
1166 | - target_post_attach (ptid_get_lwp (lp->ptid)); | |
1167 | - | |
1168 | - if (debug_linux_nat) | |
1169 | - { | |
1170 | - fprintf_unfiltered (gdb_stdlog, | |
1171 | - "LLAL: waitpid %s received %s\n", | |
1172 | - target_pid_to_str (ptid), | |
1173 | - status_to_str (status)); | |
1174 | - } | |
1175 | - } | |
1176 | - | |
1177 | - return 0; | |
1178 | -} | |
1179 | - | |
1180 | 1036 | static void |
1181 | 1037 | linux_nat_create_inferior (struct target_ops *ops, |
1182 | 1038 | char *exec_file, char *allargs, char **env, |
@@ -141,8 +141,6 @@ extern void lin_thread_get_thread_signals (sigset_t *mask); | ||
141 | 141 | void linux_proc_pending_signals (int pid, sigset_t *pending, |
142 | 142 | sigset_t *blocked, sigset_t *ignored); |
143 | 143 | |
144 | -extern int lin_lwp_attach_lwp (ptid_t ptid); | |
145 | - | |
146 | 144 | /* For linux_stop_lwp see nat/linux-nat.h. */ |
147 | 145 | |
148 | 146 | /* Stop all LWPs, synchronously. (Any events that trigger while LWPs |
@@ -78,16 +78,6 @@ static char *libthread_db_search_path; | ||
78 | 78 | by the "set auto-load libthread-db" command. */ |
79 | 79 | static int auto_load_thread_db = 1; |
80 | 80 | |
81 | -/* Returns true if we need to use thread_db thread create/death event | |
82 | - breakpoints to learn about threads. */ | |
83 | - | |
84 | -static int | |
85 | -thread_db_use_events (void) | |
86 | -{ | |
87 | - /* Not necessary if the kernel supports clone events. */ | |
88 | - return !linux_supports_traceclone (); | |
89 | -} | |
90 | - | |
91 | 81 | /* "show" command for the auto_load_thread_db configuration variable. */ |
92 | 82 | |
93 | 83 | static void |
@@ -161,30 +151,14 @@ struct thread_db_info | ||
161 | 151 | be able to ignore such stale entries. */ |
162 | 152 | int need_stale_parent_threads_check; |
163 | 153 | |
164 | - /* Location of the thread creation event breakpoint. The code at | |
165 | - this location in the child process will be called by the pthread | |
166 | - library whenever a new thread is created. By setting a special | |
167 | - breakpoint at this location, GDB can detect when a new thread is | |
168 | - created. We obtain this location via the td_ta_event_addr | |
169 | - call. */ | |
170 | - CORE_ADDR td_create_bp_addr; | |
171 | - | |
172 | - /* Location of the thread death event breakpoint. */ | |
173 | - CORE_ADDR td_death_bp_addr; | |
174 | - | |
175 | 154 | /* Pointers to the libthread_db functions. */ |
176 | 155 | |
177 | 156 | td_init_ftype *td_init_p; |
178 | 157 | td_ta_new_ftype *td_ta_new_p; |
179 | 158 | td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p; |
180 | 159 | td_ta_thr_iter_ftype *td_ta_thr_iter_p; |
181 | - td_ta_event_addr_ftype *td_ta_event_addr_p; | |
182 | - td_ta_set_event_ftype *td_ta_set_event_p; | |
183 | - td_ta_clear_event_ftype *td_ta_clear_event_p; | |
184 | - td_ta_event_getmsg_ftype * td_ta_event_getmsg_p; | |
185 | 160 | td_thr_validate_ftype *td_thr_validate_p; |
186 | 161 | td_thr_get_info_ftype *td_thr_get_info_p; |
187 | - td_thr_event_enable_ftype *td_thr_event_enable_p; | |
188 | 162 | td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p; |
189 | 163 | td_thr_tlsbase_ftype *td_thr_tlsbase_p; |
190 | 164 | }; |
@@ -273,12 +247,6 @@ delete_thread_db_info (int pid) | ||
273 | 247 | xfree (info); |
274 | 248 | } |
275 | 249 | |
276 | -/* Prototypes for local functions. */ | |
277 | -static int attach_thread (ptid_t ptid, const td_thrhandle_t *th_p, | |
278 | - const td_thrinfo_t *ti_p); | |
279 | -static void detach_thread (ptid_t ptid); | |
280 | - | |
281 | - | |
282 | 250 | /* Use "struct private_thread_info" to cache thread state. This is |
283 | 251 | a substantial optimization. */ |
284 | 252 |
@@ -359,30 +327,7 @@ thread_db_err_str (td_err_e err) | ||
359 | 327 | return buf; |
360 | 328 | } |
361 | 329 | } |
362 | - | |
363 | -/* Return 1 if any threads have been registered. There may be none if | |
364 | - the threading library is not fully initialized yet. */ | |
365 | - | |
366 | -static int | |
367 | -have_threads_callback (struct thread_info *thread, void *args) | |
368 | -{ | |
369 | - int pid = * (int *) args; | |
370 | - | |
371 | - if (ptid_get_pid (thread->ptid) != pid) | |
372 | - return 0; | |
373 | - | |
374 | - return thread->priv != NULL; | |
375 | -} | |
376 | - | |
377 | -static int | |
378 | -have_threads (ptid_t ptid) | |
379 | -{ | |
380 | - int pid = ptid_get_pid (ptid); | |
381 | - | |
382 | - return iterate_over_threads (have_threads_callback, &pid) != NULL; | |
383 | -} | |
384 | 330 | |
385 | - | |
386 | 331 | /* Fetch the user-level thread id of PTID. */ |
387 | 332 | |
388 | 333 | static struct thread_info * |
@@ -455,37 +400,6 @@ verbose_dlsym (void *handle, const char *name) | ||
455 | 400 | return sym; |
456 | 401 | } |
457 | 402 | |
458 | -static td_err_e | |
459 | -enable_thread_event (td_event_e event, CORE_ADDR *bp) | |
460 | -{ | |
461 | - td_notify_t notify; | |
462 | - td_err_e err; | |
463 | - struct thread_db_info *info; | |
464 | - | |
465 | - info = get_thread_db_info (ptid_get_pid (inferior_ptid)); | |
466 | - | |
467 | - /* Access an lwp we know is stopped. */ | |
468 | - info->proc_handle.ptid = inferior_ptid; | |
469 | - | |
470 | - /* Get the breakpoint address for thread EVENT. */ | |
471 | - err = info->td_ta_event_addr_p (info->thread_agent, event, ¬ify); | |
472 | - if (err != TD_OK) | |
473 | - return err; | |
474 | - | |
475 | - /* Set up the breakpoint. */ | |
476 | - gdb_assert (exec_bfd); | |
477 | - (*bp) = (gdbarch_convert_from_func_ptr_addr | |
478 | - (target_gdbarch (), | |
479 | - /* Do proper sign extension for the target. */ | |
480 | - (bfd_get_sign_extend_vma (exec_bfd) > 0 | |
481 | - ? (CORE_ADDR) (intptr_t) notify.u.bptaddr | |
482 | - : (CORE_ADDR) (uintptr_t) notify.u.bptaddr), | |
483 | - ¤t_target)); | |
484 | - create_thread_event_breakpoint (target_gdbarch (), *bp); | |
485 | - | |
486 | - return TD_OK; | |
487 | -} | |
488 | - | |
489 | 403 | /* Verify inferior's '\0'-terminated symbol VER_SYMBOL starts with "%d.%d" and |
490 | 404 | return 1 if this version is lower (and not equal) to |
491 | 405 | VER_MAJOR_MIN.VER_MINOR_MIN. Return 0 in all other cases. */ |
@@ -517,68 +431,6 @@ inferior_has_bug (const char *ver_symbol, int ver_major_min, int ver_minor_min) | ||
517 | 431 | return retval; |
518 | 432 | } |
519 | 433 | |
520 | -static void | |
521 | -enable_thread_event_reporting (void) | |
522 | -{ | |
523 | - td_thr_events_t events; | |
524 | - td_err_e err; | |
525 | - struct thread_db_info *info; | |
526 | - | |
527 | - info = get_thread_db_info (ptid_get_pid (inferior_ptid)); | |
528 | - | |
529 | - /* We cannot use the thread event reporting facility if these | |
530 | - functions aren't available. */ | |
531 | - if (info->td_ta_event_addr_p == NULL | |
532 | - || info->td_ta_set_event_p == NULL | |
533 | - || info->td_ta_event_getmsg_p == NULL | |
534 | - || info->td_thr_event_enable_p == NULL) | |
535 | - return; | |
536 | - | |
537 | - /* Set the process wide mask saying which events we're interested in. */ | |
538 | - td_event_emptyset (&events); | |
539 | - td_event_addset (&events, TD_CREATE); | |
540 | - | |
541 | - /* There is a bug fixed between linuxthreads 2.1.3 and 2.2 by | |
542 | - commit 2e4581e4fba917f1779cd0a010a45698586c190a | |
543 | - * manager.c (pthread_exited): Correctly report event as TD_REAP | |
544 | - instead of TD_DEATH. Fix comments. | |
545 | - where event reporting facility is broken for TD_DEATH events, | |
546 | - so don't enable it if we have glibc but a lower version. */ | |
547 | - if (!inferior_has_bug ("__linuxthreads_version", 2, 2)) | |
548 | - td_event_addset (&events, TD_DEATH); | |
549 | - | |
550 | - err = info->td_ta_set_event_p (info->thread_agent, &events); | |
551 | - if (err != TD_OK) | |
552 | - { | |
553 | - warning (_("Unable to set global thread event mask: %s"), | |
554 | - thread_db_err_str (err)); | |
555 | - return; | |
556 | - } | |
557 | - | |
558 | - /* Delete previous thread event breakpoints, if any. */ | |
559 | - remove_thread_event_breakpoints (); | |
560 | - info->td_create_bp_addr = 0; | |
561 | - info->td_death_bp_addr = 0; | |
562 | - | |
563 | - /* Set up the thread creation event. */ | |
564 | - err = enable_thread_event (TD_CREATE, &info->td_create_bp_addr); | |
565 | - if (err != TD_OK) | |
566 | - { | |
567 | - warning (_("Unable to get location for thread creation breakpoint: %s"), | |
568 | - thread_db_err_str (err)); | |
569 | - return; | |
570 | - } | |
571 | - | |
572 | - /* Set up the thread death event. */ | |
573 | - err = enable_thread_event (TD_DEATH, &info->td_death_bp_addr); | |
574 | - if (err != TD_OK) | |
575 | - { | |
576 | - warning (_("Unable to get location for thread death breakpoint: %s"), | |
577 | - thread_db_err_str (err)); | |
578 | - return; | |
579 | - } | |
580 | -} | |
581 | - | |
582 | 434 | /* Similar as thread_db_find_new_threads_1, but try to silently ignore errors |
583 | 435 | if appropriate. |
584 | 436 |
@@ -716,11 +568,6 @@ try_thread_db_load_1 (struct thread_db_info *info) | ||
716 | 568 | CHK (TDB_VERBOSE_DLSYM (info, td_thr_get_info)); |
717 | 569 | |
718 | 570 | /* These are not essential. */ |
719 | - TDB_DLSYM (info, td_ta_event_addr); | |
720 | - TDB_DLSYM (info, td_ta_set_event); | |
721 | - TDB_DLSYM (info, td_ta_clear_event); | |
722 | - TDB_DLSYM (info, td_ta_event_getmsg); | |
723 | - TDB_DLSYM (info, td_thr_event_enable); | |
724 | 571 | TDB_DLSYM (info, td_thr_tls_get_addr); |
725 | 572 | TDB_DLSYM (info, td_thr_tlsbase); |
726 | 573 |
@@ -784,10 +631,6 @@ try_thread_db_load_1 (struct thread_db_info *info) | ||
784 | 631 | if (thread_db_list->next == NULL) |
785 | 632 | push_target (&thread_db_ops); |
786 | 633 | |
787 | - /* Enable event reporting, but not when debugging a core file. */ | |
788 | - if (target_has_execution && thread_db_use_events ()) | |
789 | - enable_thread_event_reporting (); | |
790 | - | |
791 | 634 | return 1; |
792 | 635 | } |
793 | 636 |
@@ -1096,23 +939,6 @@ thread_db_load (void) | ||
1096 | 939 | } |
1097 | 940 | |
1098 | 941 | static void |
1099 | -disable_thread_event_reporting (struct thread_db_info *info) | |
1100 | -{ | |
1101 | - if (info->td_ta_clear_event_p != NULL) | |
1102 | - { | |
1103 | - td_thr_events_t events; | |
1104 | - | |
1105 | - /* Set the process wide mask saying we aren't interested in any | |
1106 | - events anymore. */ | |
1107 | - td_event_fillset (&events); | |
1108 | - info->td_ta_clear_event_p (info->thread_agent, &events); | |
1109 | - } | |
1110 | - | |
1111 | - info->td_create_bp_addr = 0; | |
1112 | - info->td_death_bp_addr = 0; | |
1113 | -} | |
1114 | - | |
1115 | -static void | |
1116 | 942 | check_thread_signals (void) |
1117 | 943 | { |
1118 | 944 | if (!thread_signals) |
@@ -1219,75 +1045,6 @@ update_thread_state (struct private_thread_info *priv, | ||
1219 | 1045 | || ti_p->ti_state == TD_THR_ZOMBIE); |
1220 | 1046 | } |
1221 | 1047 | |
1222 | -/* Attach to a new thread. This function is called when we receive a | |
1223 | - TD_CREATE event or when we iterate over all threads and find one | |
1224 | - that wasn't already in our list. Returns true on success. */ | |
1225 | - | |
1226 | -static int | |
1227 | -attach_thread (ptid_t ptid, const td_thrhandle_t *th_p, | |
1228 | - const td_thrinfo_t *ti_p) | |
1229 | -{ | |
1230 | - struct thread_info *tp; | |
1231 | - struct thread_db_info *info; | |
1232 | - | |
1233 | - /* If we're being called after a TD_CREATE event, we may already | |
1234 | - know about this thread. There are two ways this can happen. We | |
1235 | - may have iterated over all threads between the thread creation | |
1236 | - and the TD_CREATE event, for instance when the user has issued | |
1237 | - the `info threads' command before the SIGTRAP for hitting the | |
1238 | - thread creation breakpoint was reported. Alternatively, the | |
1239 | - thread may have exited and a new one been created with the same | |
1240 | - thread ID. In the first case we don't need to do anything; in | |
1241 | - the second case we should discard information about the dead | |
1242 | - thread and attach to the new one. */ | |
1243 | - tp = find_thread_ptid (ptid); | |
1244 | - if (tp != NULL) | |
1245 | - { | |
1246 | - /* If tp->priv is NULL, then GDB is already attached to this | |
1247 | - thread, but we do not know anything about it. We can learn | |
1248 | - about it here. This can only happen if we have some other | |
1249 | - way besides libthread_db to notice new threads (i.e. | |
1250 | - PTRACE_EVENT_CLONE); assume the same mechanism notices thread | |
1251 | - exit, so this can not be a stale thread recreated with the | |
1252 | - same ID. */ | |
1253 | - if (tp->priv != NULL) | |
1254 | - { | |
1255 | - if (!tp->priv->dying) | |
1256 | - return 0; | |
1257 | - | |
1258 | - delete_thread (ptid); | |
1259 | - tp = NULL; | |
1260 | - } | |
1261 | - } | |
1262 | - | |
1263 | - /* Under GNU/Linux, we have to attach to each and every thread. */ | |
1264 | - if (target_has_execution | |
1265 | - && tp == NULL) | |
1266 | - { | |
1267 | - int res; | |
1268 | - | |
1269 | - res = lin_lwp_attach_lwp (ptid_build (ptid_get_pid (ptid), | |
1270 | - ti_p->ti_lid, 0)); | |
1271 | - if (res < 0) | |
1272 | - { | |
1273 | - /* Error, stop iterating. */ | |
1274 | - return 0; | |
1275 | - } | |
1276 | - else if (res > 0) | |
1277 | - { | |
1278 | - /* Pretend this thread doesn't exist yet, and keep | |
1279 | - iterating. */ | |
1280 | - return 1; | |
1281 | - } | |
1282 | - | |
1283 | - /* Otherwise, we sucessfully attached to the thread. */ | |
1284 | - } | |
1285 | - | |
1286 | - info = get_thread_db_info (ptid_get_pid (ptid)); | |
1287 | - record_thread (info, tp, ptid, th_p, ti_p); | |
1288 | - return 1; | |
1289 | -} | |
1290 | - | |
1291 | 1048 | /* Record a new thread in GDB's thread list. Creates the thread's |
1292 | 1049 | private info. If TP is NULL or TP is marked as having exited, |
1293 | 1050 | creates a new thread. Otherwise, uses TP. */ |
@@ -1323,16 +1080,6 @@ record_thread (struct thread_db_info *info, | ||
1323 | 1080 | else |
1324 | 1081 | tp->priv = priv; |
1325 | 1082 | |
1326 | - /* Enable thread event reporting for this thread, except when | |
1327 | - debugging a core file. */ | |
1328 | - if (target_has_execution && thread_db_use_events () && new_thread) | |
1329 | - { | |
1330 | - err = info->td_thr_event_enable_p (th_p, 1); | |
1331 | - if (err != TD_OK) | |
1332 | - error (_("Cannot enable thread event reporting for %s: %s"), | |
1333 | - target_pid_to_str (ptid), thread_db_err_str (err)); | |
1334 | - } | |
1335 | - | |
1336 | 1083 | if (target_has_execution) |
1337 | 1084 | check_thread_signals (); |
1338 | 1085 |
@@ -1340,24 +1087,6 @@ record_thread (struct thread_db_info *info, | ||
1340 | 1087 | } |
1341 | 1088 | |
1342 | 1089 | static void |
1343 | -detach_thread (ptid_t ptid) | |
1344 | -{ | |
1345 | - struct thread_info *thread_info; | |
1346 | - | |
1347 | - /* Don't delete the thread now, because it still reports as active | |
1348 | - until it has executed a few instructions after the event | |
1349 | - breakpoint - if we deleted it now, "info threads" would cause us | |
1350 | - to re-attach to it. Just mark it as having had a TD_DEATH | |
1351 | - event. This means that we won't delete it from our thread list | |
1352 | - until we notice that it's dead (via prune_threads), or until | |
1353 | - something re-uses its thread ID. We'll report the thread exit | |
1354 | - when the underlying LWP dies. */ | |
1355 | - thread_info = find_thread_ptid (ptid); | |
1356 | - gdb_assert (thread_info != NULL && thread_info->priv != NULL); | |
1357 | - thread_info->priv->dying = 1; | |
1358 | -} | |
1359 | - | |
1360 | -static void | |
1361 | 1090 | thread_db_detach (struct target_ops *ops, const char *args, int from_tty) |
1362 | 1091 | { |
1363 | 1092 | struct target_ops *target_beneath = find_target_beneath (ops); |
@@ -1366,21 +1095,7 @@ thread_db_detach (struct target_ops *ops, const char *args, int from_tty) | ||
1366 | 1095 | info = get_thread_db_info (ptid_get_pid (inferior_ptid)); |
1367 | 1096 | |
1368 | 1097 | if (info) |
1369 | - { | |
1370 | - if (target_has_execution && thread_db_use_events ()) | |
1371 | - { | |
1372 | - disable_thread_event_reporting (info); | |
1373 | - | |
1374 | - /* Delete the old thread event breakpoints. Note that | |
1375 | - unlike when mourning, we can remove them here because | |
1376 | - there's still a live inferior to poke at. In any case, | |
1377 | - GDB will not try to insert anything in the inferior when | |
1378 | - removing a breakpoint. */ | |
1379 | - remove_thread_event_breakpoints (); | |
1380 | - } | |
1381 | - | |
1382 | - delete_thread_db_info (ptid_get_pid (inferior_ptid)); | |
1383 | - } | |
1098 | + delete_thread_db_info (ptid_get_pid (inferior_ptid)); | |
1384 | 1099 | |
1385 | 1100 | target_beneath->to_detach (target_beneath, args, from_tty); |
1386 | 1101 |
@@ -1392,101 +1107,6 @@ thread_db_detach (struct target_ops *ops, const char *args, int from_tty) | ||
1392 | 1107 | unpush_target (&thread_db_ops); |
1393 | 1108 | } |
1394 | 1109 | |
1395 | -/* Check if PID is currently stopped at the location of a thread event | |
1396 | - breakpoint location. If it is, read the event message and act upon | |
1397 | - the event. */ | |
1398 | - | |
1399 | -static void | |
1400 | -check_event (ptid_t ptid) | |
1401 | -{ | |
1402 | - struct regcache *regcache = get_thread_regcache (ptid); | |
1403 | - struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1404 | - td_event_msg_t msg; | |
1405 | - td_thrinfo_t ti; | |
1406 | - td_err_e err; | |
1407 | - CORE_ADDR stop_pc; | |
1408 | - int loop = 0; | |
1409 | - struct thread_db_info *info; | |
1410 | - | |
1411 | - info = get_thread_db_info (ptid_get_pid (ptid)); | |
1412 | - | |
1413 | - /* Bail out early if we're not at a thread event breakpoint. */ | |
1414 | - stop_pc = regcache_read_pc (regcache); | |
1415 | - if (!target_supports_stopped_by_sw_breakpoint ()) | |
1416 | - stop_pc -= gdbarch_decr_pc_after_break (gdbarch); | |
1417 | - | |
1418 | - if (stop_pc != info->td_create_bp_addr | |
1419 | - && stop_pc != info->td_death_bp_addr) | |
1420 | - return; | |
1421 | - | |
1422 | - /* Access an lwp we know is stopped. */ | |
1423 | - info->proc_handle.ptid = ptid; | |
1424 | - | |
1425 | - /* If we have only looked at the first thread before libpthread was | |
1426 | - initialized, we may not know its thread ID yet. Make sure we do | |
1427 | - before we add another thread to the list. */ | |
1428 | - if (!have_threads (ptid)) | |
1429 | - thread_db_find_new_threads_1 (ptid); | |
1430 | - | |
1431 | - /* If we are at a create breakpoint, we do not know what new lwp | |
1432 | - was created and cannot specifically locate the event message for it. | |
1433 | - We have to call td_ta_event_getmsg() to get | |
1434 | - the latest message. Since we have no way of correlating whether | |
1435 | - the event message we get back corresponds to our breakpoint, we must | |
1436 | - loop and read all event messages, processing them appropriately. | |
1437 | - This guarantees we will process the correct message before continuing | |
1438 | - from the breakpoint. | |
1439 | - | |
1440 | - Currently, death events are not enabled. If they are enabled, | |
1441 | - the death event can use the td_thr_event_getmsg() interface to | |
1442 | - get the message specifically for that lwp and avoid looping | |
1443 | - below. */ | |
1444 | - | |
1445 | - loop = 1; | |
1446 | - | |
1447 | - do | |
1448 | - { | |
1449 | - err = info->td_ta_event_getmsg_p (info->thread_agent, &msg); | |
1450 | - if (err != TD_OK) | |
1451 | - { | |
1452 | - if (err == TD_NOMSG) | |
1453 | - return; | |
1454 | - | |
1455 | - error (_("Cannot get thread event message: %s"), | |
1456 | - thread_db_err_str (err)); | |
1457 | - } | |
1458 | - | |
1459 | - err = info->td_thr_get_info_p (msg.th_p, &ti); | |
1460 | - if (err != TD_OK) | |
1461 | - error (_("Cannot get thread info: %s"), thread_db_err_str (err)); | |
1462 | - | |
1463 | - ptid = ptid_build (ptid_get_pid (ptid), ti.ti_lid, 0); | |
1464 | - | |
1465 | - switch (msg.event) | |
1466 | - { | |
1467 | - case TD_CREATE: | |
1468 | - /* Call attach_thread whether or not we already know about a | |
1469 | - thread with this thread ID. */ | |
1470 | - attach_thread (ptid, msg.th_p, &ti); | |
1471 | - | |
1472 | - break; | |
1473 | - | |
1474 | - case TD_DEATH: | |
1475 | - | |
1476 | - if (!in_thread_list (ptid)) | |
1477 | - error (_("Spurious thread death event.")); | |
1478 | - | |
1479 | - detach_thread (ptid); | |
1480 | - | |
1481 | - break; | |
1482 | - | |
1483 | - default: | |
1484 | - error (_("Spurious thread event.")); | |
1485 | - } | |
1486 | - } | |
1487 | - while (loop); | |
1488 | -} | |
1489 | - | |
1490 | 1110 | static ptid_t |
1491 | 1111 | thread_db_wait (struct target_ops *ops, |
1492 | 1112 | ptid_t ptid, struct target_waitstatus *ourstatus, |
@@ -1518,17 +1138,9 @@ thread_db_wait (struct target_ops *ops, | ||
1518 | 1138 | if (!thread_db_list) |
1519 | 1139 | unpush_target (&thread_db_ops); |
1520 | 1140 | |
1521 | - /* Thread event breakpoints are deleted by | |
1522 | - update_breakpoints_after_exec. */ | |
1523 | - | |
1524 | 1141 | return ptid; |
1525 | 1142 | } |
1526 | 1143 | |
1527 | - if (ourstatus->kind == TARGET_WAITKIND_STOPPED | |
1528 | - && ourstatus->value.sig == GDB_SIGNAL_TRAP) | |
1529 | - /* Check for a thread event. */ | |
1530 | - check_event (ptid); | |
1531 | - | |
1532 | 1144 | /* Fill in the thread's user-level thread id and status. */ |
1533 | 1145 | thread_from_lwp (ptid); |
1534 | 1146 |
@@ -1544,10 +1156,6 @@ thread_db_mourn_inferior (struct target_ops *ops) | ||
1544 | 1156 | |
1545 | 1157 | target_beneath->to_mourn_inferior (target_beneath); |
1546 | 1158 | |
1547 | - /* Delete the old thread event breakpoints. Do this after mourning | |
1548 | - the inferior, so that we don't try to uninsert them. */ | |
1549 | - remove_thread_event_breakpoints (); | |
1550 | - | |
1551 | 1159 | /* Detach thread_db target ops. */ |
1552 | 1160 | if (!thread_db_list) |
1553 | 1161 | unpush_target (ops); |
@@ -1595,21 +1203,12 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data) | ||
1595 | 1203 | /* A thread ID of zero means that this is the main thread, but |
1596 | 1204 | glibc has not yet initialized thread-local storage and the |
1597 | 1205 | pthread library. We do not know what the thread's TID will |
1598 | - be yet. Just enable event reporting and otherwise ignore | |
1599 | - it. */ | |
1206 | + be yet. */ | |
1600 | 1207 | |
1601 | 1208 | /* In that case, we're not stopped in a fork syscall and don't |
1602 | 1209 | need this glibc bug workaround. */ |
1603 | 1210 | info->need_stale_parent_threads_check = 0; |
1604 | 1211 | |
1605 | - if (target_has_execution && thread_db_use_events ()) | |
1606 | - { | |
1607 | - err = info->td_thr_event_enable_p (th_p, 1); | |
1608 | - if (err != TD_OK) | |
1609 | - error (_("Cannot enable thread event reporting for LWP %d: %s"), | |
1610 | - (int) ti.ti_lid, thread_db_err_str (err)); | |
1611 | - } | |
1612 | - | |
1613 | 1212 | return 0; |
1614 | 1213 | } |
1615 | 1214 |
@@ -1627,24 +1226,7 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data) | ||
1627 | 1226 | ptid = ptid_build (info->pid, ti.ti_lid, 0); |
1628 | 1227 | tp = find_thread_ptid (ptid); |
1629 | 1228 | if (tp == NULL || tp->priv == NULL) |
1630 | - { | |
1631 | - if (attach_thread (ptid, th_p, &ti)) | |
1632 | - cb_data->new_threads += 1; | |
1633 | - else | |
1634 | - /* Problem attaching this thread; perhaps it exited before we | |
1635 | - could attach it? | |
1636 | - This could mean that the thread list inside glibc itself is in | |
1637 | - inconsistent state, and libthread_db could go on looping forever | |
1638 | - (observed with glibc-2.3.6). To prevent that, terminate | |
1639 | - iteration: thread_db_find_new_threads_2 will retry. */ | |
1640 | - return 1; | |
1641 | - } | |
1642 | - else if (target_has_execution && !thread_db_use_events ()) | |
1643 | - { | |
1644 | - /* Need to update this if not using the libthread_db events | |
1645 | - (particularly, the TD_DEATH event). */ | |
1646 | - update_thread_state (tp->priv, &ti); | |
1647 | - } | |
1229 | + thread_from_lwp (ptid); | |
1648 | 1230 | |
1649 | 1231 | return 0; |
1650 | 1232 | } |
@@ -1663,7 +1245,7 @@ find_new_threads_once (struct thread_db_info *info, int iteration, | ||
1663 | 1245 | data.new_threads = 0; |
1664 | 1246 | |
1665 | 1247 | /* See comment in thread_db_update_thread_list. */ |
1666 | - gdb_assert (!target_has_execution || thread_db_use_events ()); | |
1248 | + gdb_assert (!target_has_execution); | |
1667 | 1249 | |
1668 | 1250 | TRY |
1669 | 1251 | { |
@@ -1789,12 +1371,11 @@ thread_db_update_thread_list (struct target_ops *ops) | ||
1789 | 1371 | it. In the latter case, it's possible that a thread exits just |
1790 | 1372 | at the exact time that causes GDB to get stuck in an infinite |
1791 | 1373 | loop. To avoid pausing all threads whenever the core wants to |
1792 | - refresh the thread list, if the kernel supports clone events | |
1793 | - (meaning we're always already attached to all LWPs), we use | |
1794 | - thread_from_lwp immediately when we see an LWP stop. That uses | |
1795 | - thread_db entry points that do not walk libpthread's thread list, | |
1796 | - so should be safe, as well as more efficient. */ | |
1797 | - if (target_has_execution && !thread_db_use_events ()) | |
1374 | + refresh the thread list, use thread_from_lwp immediately when we | |
1375 | + see an LWP stop. That uses thread_db entry points that do not | |
1376 | + walk libpthread's thread list, so should be safe, as well as | |
1377 | + more efficient. */ | |
1378 | + if (target_has_execution) | |
1798 | 1379 | ops->beneath->to_update_thread_list (ops->beneath); |
1799 | 1380 | else |
1800 | 1381 | thread_db_update_thread_list_td_ta_thr_iter (ops); |