1 /* Wrapper implementation for waitpid for GNU/Linux (LWP layer).
3 Copyright (C) 2001-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "nat/linux-nat.h"
28 #include "nat/linux-waitpid.h"
33 /* Print debugging output based on the format string FORMAT and
37 linux_debug (const char *format
, ...)
43 va_start (args
, format
);
44 vfprintf (stderr
, format
, args
);
48 /* GDB-specific debugging output. */
52 /* Convert wait status STATUS to a string. Used for printing debug
56 status_to_str (int status
)
60 if (WIFSTOPPED (status
))
62 if (WSTOPSIG (status
) == SYSCALL_SIGTRAP
)
63 snprintf (buf
, sizeof (buf
), "%s (stopped at syscall)",
66 snprintf (buf
, sizeof (buf
), "%s (stopped)",
67 strsignal (WSTOPSIG (status
)));
69 else if (WIFSIGNALED (status
))
70 snprintf (buf
, sizeof (buf
), "%s (terminated)",
71 strsignal (WTERMSIG (status
)));
73 snprintf (buf
, sizeof (buf
), "%d (exited)", WEXITSTATUS (status
));
78 /* Wrapper function for waitpid which handles EINTR, and emulates
79 __WALL for systems where that is not available. */
82 my_waitpid (int pid
, int *status
, int flags
)
86 linux_debug ("my_waitpid (%d, 0x%x)\n", pid
, flags
);
90 sigset_t block_mask
, org_mask
, wake_mask
;
93 wnohang
= (flags
& WNOHANG
) != 0;
94 flags
&= ~(__WALL
| __WCLONE
);
97 /* Block all signals while here. This avoids knowing about
98 LinuxThread's signals. */
99 sigfillset (&block_mask
);
100 sigprocmask (SIG_BLOCK
, &block_mask
, &org_mask
);
102 /* ... except during the sigsuspend below. */
103 sigemptyset (&wake_mask
);
107 /* Since all signals are blocked, there's no need to check
109 ret
= waitpid (pid
, status
, flags
);
112 if (ret
== -1 && out_errno
!= ECHILD
)
117 if (flags
& __WCLONE
)
119 /* We've tried both flavors now. If WNOHANG is set,
120 there's nothing else to do, just bail out. */
124 linux_debug ("blocking\n");
126 /* Block waiting for signals. */
127 sigsuspend (&wake_mask
);
132 sigprocmask (SIG_SETMASK
, &org_mask
, NULL
);
137 ret
= waitpid (pid
, status
, flags
);
138 while (ret
== -1 && errno
== EINTR
);
142 linux_debug ("my_waitpid (%d, 0x%x): status(%x), %d\n",
143 pid
, flags
, status
? *status
: -1, ret
);
This page took 0.036543 seconds and 4 git commands to generate.