diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4ee17b31e55..fb99d260ff5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2015-01-09 Pedro Alves + + * linux-nat.c (lin_lwp_attach_lwp): Assert that the lwp id we're + about to wait for is > 0. + * linux-thread-db.c (find_new_threads_callback): Ignore thread if + the kernel thread ID is -1. + 2015-01-09 Pedro Alves * linux-nat.c (attach_proc_task_lwp_callback): New function. diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 2ee6a00f83d..d6bafae9b8d 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2015-01-09 Pedro Alves + + * thread-db.c (find_new_threads_callback): Ignore thread if the + kernel thread ID is -1. + 2015-01-09 Pedro Alves * linux-low.c (linux_attach_fail_reason_string): Move to diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c index 4e0d32acfce..b0d1f0d945a 100644 --- a/gdb/gdbserver/thread-db.c +++ b/gdb/gdbserver/thread-db.c @@ -396,6 +396,17 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data) if (err != TD_OK) error ("Cannot get thread info: %s", thread_db_err_str (err)); + if (ti.ti_lid == -1) + { + /* A thread with kernel thread ID -1 is either a thread that + exited and was joined, or a thread that is being created but + hasn't started yet, and that is reusing the tcb/stack of a + thread that previously exited and was joined. (glibc marks + terminated and joined threads with kernel thread ID -1. See + glibc PR17707. */ + return 0; + } + /* Check for zombies. */ if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE) return 0; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 0adf3a9c769..77aa8e31377 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1023,6 +1023,7 @@ lin_lwp_attach_lwp (ptid_t ptid) /* See if we've got a stop for this new child pending. If so, we're already attached. */ + gdb_assert (lwpid > 0); new_pid = my_waitpid (lwpid, &status, WNOHANG); if (new_pid == -1 && errno == ECHILD) new_pid = my_waitpid (lwpid, &status, __WCLONE | WNOHANG); diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index b7afb039d2c..1417542a6b6 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1610,6 +1610,17 @@ find_new_threads_callback (const td_thrhandle_t *th_p, void *data) error (_("find_new_threads_callback: cannot get thread info: %s"), thread_db_err_str (err)); + if (ti.ti_lid == -1) + { + /* A thread with kernel thread ID -1 is either a thread that + exited and was joined, or a thread that is being created but + hasn't started yet, and that is reusing the tcb/stack of a + thread that previously exited and was joined. (glibc marks + terminated and joined threads with kernel thread ID -1. See + glibc PR17707. */ + return 0; + } + if (ti.ti_tid == 0) { /* A thread ID of zero means that this is the main thread, but