gdb_wait.h revision 98944
1231200Smm/* Standard wait macros.
2231200Smm   Copyright 2000 Free Software Foundation, Inc.
3231200Smm
4231200Smm   This file is part of GDB.
5231200Smm
6231200Smm   This program is free software; you can redistribute it and/or modify
7231200Smm   it under the terms of the GNU General Public License as published by
8231200Smm   the Free Software Foundation; either version 2 of the License, or
9231200Smm   (at your option) any later version.
10231200Smm
11231200Smm   This program is distributed in the hope that it will be useful,
12231200Smm   but WITHOUT ANY WARRANTY; without even the implied warranty of
13231200Smm   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14231200Smm   GNU General Public License for more details.
15231200Smm
16231200Smm   You should have received a copy of the GNU General Public License
17231200Smm   along with this program; if not, write to the Free Software
18231200Smm   Foundation, Inc., 59 Temple Place - Suite 330,
19231200Smm   Boston, MA 02111-1307, USA.  */
20231200Smm
21231200Smm#ifndef GDB_WAIT_H
22231200Smm#define GDB_WAIT_H
23231200Smm
24231200Smm#ifdef HAVE_SYS_WAIT_H
25231200Smm#include <sys/wait.h> /* POSIX */
26231200Smm#else
27231200Smm#ifdef HAVE_WAIT_H
28231200Smm#include <wait.h> /* legacy */
29231200Smm#endif
30231200Smm#endif
31231200Smm
32231200Smm/* Define how to access the int that the wait system call stores.
33231200Smm   This has been compatible in all Unix systems since time immemorial,
34231200Smm   but various well-meaning people have defined various different
35231200Smm   words for the same old bits in the same old int (sometimes claimed
36231200Smm   to be a struct).  We just know it's an int and we use these macros
37231200Smm   to access the bits.  */
38231200Smm
39231200Smm/* The following macros are defined equivalently to their definitions
40231200Smm   in POSIX.1.  We fail to define WNOHANG and WUNTRACED, which POSIX.1
41231200Smm   <sys/wait.h> defines, since our code does not use waitpid() (but
42231200Smm   NOTE exception for GNU/Linux below).  We also fail to declare
43231200Smm   wait() and waitpid().  */
44231200Smm
45231200Smm#ifndef	WIFEXITED
46231200Smm#define WIFEXITED(w)	(((w)&0377) == 0)
47231200Smm#endif
48231200Smm
49231200Smm#ifndef	WIFSIGNALED
50231200Smm#define WIFSIGNALED(w)	(((w)&0377) != 0177 && ((w)&~0377) == 0)
51231200Smm#endif
52231200Smm
53231200Smm#ifndef	WIFSTOPPED
54231200Smm#ifdef IBM6000
55231200Smm
56231200Smm/* Unfortunately, the above comment (about being compatible in all Unix
57231200Smm   systems) is not quite correct for AIX, sigh.  And AIX 3.2 can generate
58231200Smm   status words like 0x57c (sigtrap received after load), and gdb would
59231200Smm   choke on it. */
60231200Smm
61231200Smm#define WIFSTOPPED(w)	((w)&0x40)
62231200Smm
63231200Smm#else
64231200Smm#define WIFSTOPPED(w)	(((w)&0377) == 0177)
65231200Smm#endif
66231200Smm#endif
67231200Smm
68231200Smm#ifndef	WEXITSTATUS
69231200Smm#define WEXITSTATUS(w)	(((w) >> 8) & 0377) /* same as WRETCODE */
70231200Smm#endif
71231200Smm
72231200Smm#ifndef	WTERMSIG
73231200Smm#define WTERMSIG(w)	((w) & 0177)
74231200Smm#endif
75231200Smm
76231200Smm#ifndef	WSTOPSIG
77231200Smm#define WSTOPSIG	WEXITSTATUS
78231200Smm#endif
79231200Smm
80231200Smm/* These are not defined in POSIX, but are used by our programs.  */
81231200Smm
82231200Smm#define WAITTYPE	int
83231200Smm
84231200Smm#ifndef	WCOREDUMP
85231200Smm#define WCOREDUMP(w)	(((w)&0200) != 0)
86231200Smm#endif
87231200Smm
88231200Smm#ifndef	WSETEXIT
89231200Smm# ifdef	W_EXITCODE
90231200Smm#define	WSETEXIT(w,status) ((w) = W_EXITCODE(status,0))
91231200Smm# else
92231200Smm#define WSETEXIT(w,status) ((w) = (0 | ((status) << 8)))
93231200Smm# endif
94231200Smm#endif
95231200Smm
96231200Smm#ifndef	WSETSTOP
97231200Smm# ifdef	W_STOPCODE
98231200Smm#define	WSETSTOP(w,sig)    ((w) = W_STOPCODE(sig))
99232153Smm# else
100231200Smm#define WSETSTOP(w,sig)	   ((w) = (0177 | ((sig) << 8)))
101231200Smm# endif
102231200Smm#endif
103231200Smm
104231200Smm/* For native GNU/Linux we may use waitpid and the __WCLONE option.
105231200Smm  <GRIPE> It is of course dangerous not to use the REAL header file...
106231200Smm  </GRIPE>.  */
107231200Smm
108231200Smm/* Bits in the third argument to `waitpid'.  */
109231200Smm#ifndef WNOHANG
110231200Smm#define	WNOHANG		1	/* Don't block waiting.  */
111231200Smm#endif
112231200Smm
113231200Smm#ifndef WUNTRACED
114231200Smm#define	WUNTRACED	2	/* Report status of stopped children.  */
115231200Smm#endif
116231200Smm
117231200Smm#ifndef __WCLONE
118231200Smm#define __WCLONE	0x80000000 /* Wait for cloned process.  */
119231200Smm#endif
120231200Smm
121231200Smm#endif
122231200Smm