1 /* Wrapper implementation for waitpid for GNU/Linux (LWP layer).
3 Copyright (C) 2001-2018 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/>. */
20 #include "common-defs.h"
23 /* FIXME: server.h is required for the definition of debug_threads
24 which is used in the gdbserver-specific debug printing in
25 linux_debug. This code should be made available to GDB also,
26 but the lack of a suitable flag to enable it prevents this. */
30 #include "linux-nat.h"
31 #include "linux-waitpid.h"
34 /* Print debugging output based on the format string FORMAT and
37 static inline void ATTRIBUTE_PRINTF (1,2)
38 linux_debug (const char *format, ...)
44 va_start (args, format);
45 vfprintf (stderr, format, args);
51 /* Convert wait status STATUS to a string. Used for printing debug
55 status_to_str (int status)
59 if (WIFSTOPPED (status))
61 if (WSTOPSIG (status) == SYSCALL_SIGTRAP)
62 snprintf (buf, sizeof (buf), "%s (stopped at syscall)",
65 snprintf (buf, sizeof (buf), "%s (stopped)",
66 strsignal (WSTOPSIG (status)));
68 else if (WIFSIGNALED (status))
69 snprintf (buf, sizeof (buf), "%s (terminated)",
70 strsignal (WTERMSIG (status)));
72 snprintf (buf, sizeof (buf), "%d (exited)", WEXITSTATUS (status));
77 /* See linux-waitpid.h. */
80 my_waitpid (int pid, int *status, int flags)
84 linux_debug ("my_waitpid (%d, 0x%x)\n", pid, flags);
88 ret = waitpid (pid, status, flags);
90 while (ret == -1 && errno == EINTR);
93 linux_debug ("my_waitpid (%d, 0x%x): status(%x), %d\n",
94 pid, flags, (ret > 0 && status != NULL) ? *status : -1, ret);