aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2011-08-26 19:26:40 +0000
committerPedro Alves <palves@redhat.com>2011-08-26 19:26:40 +0000
commita9f4bb212331d41206c8acdf58b7031b0ad4ac03 (patch)
tree381c46fdd8352237fac3d58fb0631d35b8c408a7
parente5798bef38435b582d9fc1c51efbf36b2b7fbe20 (diff)
downloadgdb-a9f4bb212331d41206c8acdf58b7031b0ad4ac03.zip
gdb-a9f4bb212331d41206c8acdf58b7031b0ad4ac03.tar.gz
gdb-a9f4bb212331d41206c8acdf58b7031b0ad4ac03.tar.bz2
2011-08-26 Pedro Alves <pedro@codesourcery.com>
gdb/ * linux-nat.c (wait_lwp): Avoid assuming errno is preserved by a library call. Avoid reading the `status' local if all waitpid calls failed.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/linux-nat.c41
2 files changed, 26 insertions, 21 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 140b3c6..f64aca2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2011-08-26 Pedro Alves <pedro@codesourcery.com>
+ * linux-nat.c (wait_lwp): Avoid assuming errno is preserved by a
+ library call. Avoid reading the `status' local if all waitpid
+ calls failed.
+
+2011-08-26 Pedro Alves <pedro@codesourcery.com>
+
* common/linux-osdata.c (get_cores_used_by_process): Don't assume
opening /proc/PID/task always succeeds.
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index b146888..d02edb8 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -2377,6 +2377,18 @@ wait_lwp (struct lwp_info *lp)
pid = my_waitpid (GET_LWP (lp->ptid), &status, WNOHANG);
if (pid == -1 && errno == ECHILD)
pid = my_waitpid (GET_LWP (lp->ptid), &status, __WCLONE | WNOHANG);
+ if (pid == -1 && errno == ECHILD)
+ {
+ /* The thread has previously exited. We need to delete it
+ now because, for some vendor 2.4 kernels with NPTL
+ support backported, there won't be an exit event unless
+ it is the main thread. 2.6 kernels will report an exit
+ event for each thread that exits, as expected. */
+ thread_dead = 1;
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog, "WL: %s vanished.\n",
+ target_pid_to_str (lp->ptid));
+ }
if (pid != 0)
break;
@@ -2418,19 +2430,6 @@ wait_lwp (struct lwp_info *lp)
restore_child_signals_mask (&prev_mask);
- if (pid == -1 && errno == ECHILD)
- {
- /* The thread has previously exited. We need to delete it
- now because, for some vendor 2.4 kernels with NPTL
- support backported, there won't be an exit event unless
- it is the main thread. 2.6 kernels will report an exit
- event for each thread that exits, as expected. */
- thread_dead = 1;
- if (debug_linux_nat)
- fprintf_unfiltered (gdb_stdlog, "WL: %s vanished.\n",
- target_pid_to_str (lp->ptid));
- }
-
if (!thread_dead)
{
gdb_assert (pid == GET_LWP (lp->ptid));
@@ -2442,15 +2441,15 @@ wait_lwp (struct lwp_info *lp)
target_pid_to_str (lp->ptid),
status_to_str (status));
}
- }
- /* Check if the thread has exited. */
- if (WIFEXITED (status) || WIFSIGNALED (status))
- {
- thread_dead = 1;
- if (debug_linux_nat)
- fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n",
- target_pid_to_str (lp->ptid));
+ /* Check if the thread has exited. */
+ if (WIFEXITED (status) || WIFSIGNALED (status))
+ {
+ thread_dead = 1;
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n",
+ target_pid_to_str (lp->ptid));
+ }
}
if (thread_dead)