mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
[gdb] Use gdb::waitpid more often
Use gdb::waitpid instead of plain waitpid, making sure that EINTR is handled. Tested on x86_64-linux.
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
#include "gdbsupport/scoped_fd.h"
|
#include "gdbsupport/scoped_fd.h"
|
||||||
#include "gdbsupport/scoped_restore.h"
|
#include "gdbsupport/scoped_restore.h"
|
||||||
#include "nat/fork-inferior.h"
|
#include "nat/fork-inferior.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
/* Quick overview.
|
/* Quick overview.
|
||||||
Darwin kernel is Mach + BSD derived kernel. Note that they share the
|
Darwin kernel is Mach + BSD derived kernel. Note that they share the
|
||||||
@@ -1604,7 +1605,7 @@ darwin_attach_pid (struct inferior *inf)
|
|||||||
if (!inf->attach_flag)
|
if (!inf->attach_flag)
|
||||||
{
|
{
|
||||||
kill (inf->pid, 9);
|
kill (inf->pid, 9);
|
||||||
waitpid (inf->pid, &status, 0);
|
gdb::waitpid (inf->pid, &status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
error
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include "elf-bfd.h"
|
#include "elf-bfd.h"
|
||||||
#include "fbsd-nat.h"
|
#include "fbsd-nat.h"
|
||||||
#include "fbsd-tdep.h"
|
#include "fbsd-tdep.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
#ifndef PT_GETREGSET
|
#ifndef PT_GETREGSET
|
||||||
#define PT_GETREGSET 42 /* Get a target register set */
|
#define PT_GETREGSET 42 /* Get a target register set */
|
||||||
@@ -1150,7 +1151,7 @@ fbsd_wait_for_fork_child (pid_t pid)
|
|||||||
return ptid;
|
return ptid;
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
pid_t wpid = waitpid (pid, &status, 0);
|
pid_t wpid = gdb::waitpid (pid, &status, 0);
|
||||||
if (wpid == -1)
|
if (wpid == -1)
|
||||||
perror_with_name (("waitpid"));
|
perror_with_name (("waitpid"));
|
||||||
|
|
||||||
@@ -2156,7 +2157,7 @@ fbsd_nat_target::kill ()
|
|||||||
perror_with_name (("ptrace (PT_KILL)"));
|
perror_with_name (("ptrace (PT_KILL)"));
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
waitpid (pid, &status, 0);
|
gdb::waitpid (pid, &status, 0);
|
||||||
|
|
||||||
target_mourn_inferior (inferior_ptid);
|
target_mourn_inferior (inferior_ptid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "nat/fork-inferior.h"
|
#include "nat/fork-inferior.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "gdbarch.h"
|
#include "gdbarch.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ inf_ptrace_target::mourn_inferior ()
|
|||||||
Do not check whether this succeeds though, since we may be
|
Do not check whether this succeeds though, since we may be
|
||||||
dealing with a process that we attached to. Such a process will
|
dealing with a process that we attached to. Such a process will
|
||||||
only report its exit status to its original parent. */
|
only report its exit status to its original parent. */
|
||||||
waitpid (inferior_ptid.pid (), &status, 0);
|
gdb::waitpid (inferior_ptid.pid (), &status, 0);
|
||||||
|
|
||||||
inf_child_target::mourn_inferior ();
|
inf_child_target::mourn_inferior ();
|
||||||
}
|
}
|
||||||
@@ -227,7 +228,7 @@ inf_ptrace_target::kill ()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ptrace (PT_KILL, pid, (PTRACE_TYPE_ARG3)0, 0);
|
ptrace (PT_KILL, pid, (PTRACE_TYPE_ARG3)0, 0);
|
||||||
waitpid (pid, &status, 0);
|
gdb::waitpid (pid, &status, 0);
|
||||||
|
|
||||||
target_mourn_inferior (inferior_ptid);
|
target_mourn_inferior (inferior_ptid);
|
||||||
}
|
}
|
||||||
@@ -307,12 +308,8 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
|
|||||||
{
|
{
|
||||||
set_sigint_trap ();
|
set_sigint_trap ();
|
||||||
|
|
||||||
do
|
pid = gdb::waitpid (ptid.pid (), &status, options);
|
||||||
{
|
save_errno = errno;
|
||||||
pid = waitpid (ptid.pid (), &status, options);
|
|
||||||
save_errno = errno;
|
|
||||||
}
|
|
||||||
while (pid == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
clear_sigint_trap ();
|
clear_sigint_trap ();
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "nat/gdb_ptrace.h"
|
#include "nat/gdb_ptrace.h"
|
||||||
#include "gdbsupport/gdb_wait.h"
|
#include "gdbsupport/gdb_wait.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
#include "target/waitstatus.h"
|
#include "target/waitstatus.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -314,7 +315,7 @@ linux_fork_killall (void)
|
|||||||
/* Use SIGKILL instead of PTRACE_KILL because the former works even
|
/* Use SIGKILL instead of PTRACE_KILL because the former works even
|
||||||
if the thread is running, while the later doesn't. */
|
if the thread is running, while the later doesn't. */
|
||||||
kill (pid, SIGKILL);
|
kill (pid, SIGKILL);
|
||||||
ret = waitpid (pid, &status, 0);
|
ret = gdb::waitpid (pid, &status, 0);
|
||||||
/* We might get a SIGCHLD instead of an exit status. This is
|
/* We might get a SIGCHLD instead of an exit status. This is
|
||||||
aggravated by the first kill above - a child has just
|
aggravated by the first kill above - a child has just
|
||||||
died. MVS comment cut-and-pasted from linux-nat. */
|
died. MVS comment cut-and-pasted from linux-nat. */
|
||||||
@@ -339,7 +340,7 @@ linux_fork_mourn_inferior (void)
|
|||||||
Do not check whether this succeeds though, since we may be
|
Do not check whether this succeeds though, since we may be
|
||||||
dealing with a process that we attached to. Such a process will
|
dealing with a process that we attached to. Such a process will
|
||||||
only report its exit status to its original parent. */
|
only report its exit status to its original parent. */
|
||||||
waitpid (inferior_ptid.pid (), &status, 0);
|
gdb::waitpid (inferior_ptid.pid (), &status, 0);
|
||||||
|
|
||||||
/* OK, presumably inferior_ptid is the one who has exited.
|
/* OK, presumably inferior_ptid is the one who has exited.
|
||||||
We need to delete that one from the fork_list, and switch
|
We need to delete that one from the fork_list, and switch
|
||||||
@@ -548,7 +549,7 @@ Please switch to another checkpoint before deleting the current one"));
|
|||||||
this succeeds though, since we may be dealing with a process that we
|
this succeeds though, since we may be dealing with a process that we
|
||||||
attached to. Such a process will only report its exit status to its
|
attached to. Such a process will only report its exit status to its
|
||||||
original parent. */
|
original parent. */
|
||||||
waitpid (ptid.pid (), &status, 0);
|
gdb::waitpid (ptid.pid (), &status, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include "gdbsupport/scope-exit.h"
|
#include "gdbsupport/scope-exit.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
/* See nat/linux-namespaces.h. */
|
/* See nat/linux-namespaces.h. */
|
||||||
bool debug_linux_namespaces;
|
bool debug_linux_namespaces;
|
||||||
@@ -722,7 +723,7 @@ mnsh_maybe_mourn_peer (void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = waitpid (helper->pid, &status, WNOHANG);
|
pid = gdb::waitpid (helper->pid, &status, WNOHANG);
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
/* The helper is still alive. */
|
/* The helper is still alive. */
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#ifdef HAVE_SYS_PROCFS_H
|
#ifdef HAVE_SYS_PROCFS_H
|
||||||
#include <sys/procfs.h>
|
#include <sys/procfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
/* Stores the ptrace options supported by the running kernel.
|
/* Stores the ptrace options supported by the running kernel.
|
||||||
A value of -1 means we did not check for features yet. A value
|
A value of -1 means we did not check for features yet. A value
|
||||||
@@ -177,7 +178,7 @@ linux_ptrace_test_ret_to_nx (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
got_pid = waitpid (child, &status, 0);
|
got_pid = gdb::waitpid (child, &status, 0);
|
||||||
if (got_pid != child)
|
if (got_pid != child)
|
||||||
{
|
{
|
||||||
warning (_("linux_ptrace_test_ret_to_nx: waitpid returned %ld: %s"),
|
warning (_("linux_ptrace_test_ret_to_nx: waitpid returned %ld: %s"),
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "inferior.h"
|
#include "inferior.h"
|
||||||
#include "gdbarch.h"
|
#include "gdbarch.h"
|
||||||
#include "gdbsupport/buildargv.h"
|
#include "gdbsupport/buildargv.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
@@ -547,12 +548,8 @@ nbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus,
|
|||||||
|
|
||||||
set_sigint_trap ();
|
set_sigint_trap ();
|
||||||
|
|
||||||
do
|
/* The common code passes WNOHANG that leads to crashes, overwrite it. */
|
||||||
{
|
pid = gdb::waitpid (ptid.pid (), &status, 0);
|
||||||
/* The common code passes WNOHANG that leads to crashes, overwrite it. */
|
|
||||||
pid = waitpid (ptid.pid (), &status, 0);
|
|
||||||
}
|
|
||||||
while (pid == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
clear_sigint_trap ();
|
clear_sigint_trap ();
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "inf-ptrace.h"
|
#include "inf-ptrace.h"
|
||||||
#include "obsd-nat.h"
|
#include "obsd-nat.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
/* OpenBSD 5.2 and later include rthreads which uses a thread model
|
/* OpenBSD 5.2 and later include rthreads which uses a thread model
|
||||||
that maps userland threads directly onto kernel threads in a 1:1
|
that maps userland threads directly onto kernel threads in a 1:1
|
||||||
@@ -105,7 +106,7 @@ obsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
|
|||||||
ourstatus->set_forked (ptid_t (pe.pe_other_pid));
|
ourstatus->set_forked (ptid_t (pe.pe_other_pid));
|
||||||
|
|
||||||
/* Make sure the other end of the fork is stopped too. */
|
/* Make sure the other end of the fork is stopped too. */
|
||||||
pid_t fpid = waitpid (pe.pe_other_pid, nullptr, 0);
|
pid_t fpid = gdb::waitpid (pe.pe_other_pid, nullptr, 0);
|
||||||
if (fpid == -1)
|
if (fpid == -1)
|
||||||
perror_with_name (("waitpid"));
|
perror_with_name (("waitpid"));
|
||||||
|
|
||||||
|
|||||||
@@ -2560,7 +2560,7 @@ unconditionally_kill_inferior (procinfo *pi)
|
|||||||
#if 0
|
#if 0
|
||||||
int status, ret;
|
int status, ret;
|
||||||
|
|
||||||
ret = waitpid (pi->pid, &status, 0);
|
ret = gdb::waitpid (pi->pid, &status, 0);
|
||||||
#else
|
#else
|
||||||
wait (NULL);
|
wait (NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
#include <a.out.h>
|
#include <a.out.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
@@ -865,12 +866,8 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
|
|||||||
{
|
{
|
||||||
set_sigint_trap ();
|
set_sigint_trap ();
|
||||||
|
|
||||||
do
|
pid = gdb::waitpid (ptid.pid (), &status, 0);
|
||||||
{
|
save_errno = errno;
|
||||||
pid = waitpid (ptid.pid (), &status, 0);
|
|
||||||
save_errno = errno;
|
|
||||||
}
|
|
||||||
while (pid == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
clear_sigint_trap ();
|
clear_sigint_trap ();
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
#include "run-on-main-thread.h"
|
#include "run-on-main-thread.h"
|
||||||
#include "gdbsupport/gdb_tilde_expand.h"
|
#include "gdbsupport/gdb_tilde_expand.h"
|
||||||
|
#include "gdbsupport/eintr.h"
|
||||||
|
|
||||||
void (*deprecated_error_begin_hook) (void);
|
void (*deprecated_error_begin_hook) (void);
|
||||||
|
|
||||||
@@ -3483,7 +3484,7 @@ wait_to_die_with_timeout (pid_t pid, int *status, int timeout)
|
|||||||
alarm (timeout);
|
alarm (timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
waitpid_result = waitpid (pid, status, 0);
|
waitpid_result = gdb::waitpid (pid, status, 0);
|
||||||
|
|
||||||
#ifdef SIGALRM
|
#ifdef SIGALRM
|
||||||
alarm (0);
|
alarm (0);
|
||||||
@@ -3495,7 +3496,7 @@ wait_to_die_with_timeout (pid_t pid, int *status, int timeout)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
waitpid_result = waitpid (pid, status, WNOHANG);
|
waitpid_result = gdb::waitpid (pid, status, WNOHANG);
|
||||||
|
|
||||||
if (waitpid_result == pid)
|
if (waitpid_result == pid)
|
||||||
return pid;
|
return pid;
|
||||||
|
|||||||
Reference in New Issue
Block a user