gdb_wait.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Standard wait macros.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef COMMON_GDB_WAIT_H
  15. #define COMMON_GDB_WAIT_H
  16. #ifdef HAVE_SYS_WAIT_H
  17. #include <sys/wait.h> /* POSIX */
  18. #else
  19. #ifdef HAVE_WAIT_H
  20. #include <wait.h> /* legacy */
  21. #endif
  22. #endif
  23. /* Define how to access the int that the wait system call stores.
  24. This has been compatible in all Unix systems since time immemorial,
  25. but various well-meaning people have defined various different
  26. words for the same old bits in the same old int (sometimes claimed
  27. to be a struct). We just know it's an int and we use these macros
  28. to access the bits. */
  29. /* The following macros are defined equivalently to their definitions
  30. in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1
  31. <sys/wait.h> defines, since our code does not use waitpid() (but
  32. NOTE exception for GNU/Linux below). We also fail to declare
  33. wait() and waitpid().
  34. For MinGW, we use the fact that when a Windows program is
  35. terminated by a fatal exception, its exit code is the value of that
  36. exception, as defined by the various EXCEPTION_* symbols in the
  37. Windows API headers. See also gdb_wait.c. */
  38. #ifndef WIFEXITED
  39. # ifdef __MINGW32__
  40. # define WIFEXITED(w) (((w) & 0xC0000000) == 0)
  41. # else
  42. # define WIFEXITED(w) (((w)&0377) == 0)
  43. # endif
  44. #endif
  45. #ifndef WIFSIGNALED
  46. # ifdef __MINGW32__
  47. # define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
  48. # else
  49. # define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
  50. # endif
  51. #endif
  52. #ifndef WIFSTOPPED
  53. #ifdef IBM6000
  54. /* Unfortunately, the above comment (about being compatible in all Unix
  55. systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
  56. status words like 0x57c (sigtrap received after load), and gdb would
  57. choke on it. */
  58. #define WIFSTOPPED(w) ((w)&0x40)
  59. #else
  60. #define WIFSTOPPED(w) (((w)&0377) == 0177)
  61. #endif
  62. #endif
  63. #ifndef WEXITSTATUS
  64. # ifdef __MINGW32__
  65. # define WEXITSTATUS(w) ((w) & ~0xC0000000)
  66. # else
  67. # define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
  68. # endif
  69. #endif
  70. #ifndef WTERMSIG
  71. # ifdef __MINGW32__
  72. extern int windows_status_to_termsig (unsigned long);
  73. # define WTERMSIG(w) windows_status_to_termsig (w)
  74. # else
  75. # define WTERMSIG(w) ((w) & 0177)
  76. # endif
  77. #endif
  78. #ifndef WSTOPSIG
  79. #define WSTOPSIG WEXITSTATUS
  80. #endif
  81. /* These are not defined in POSIX, but are used by our programs. */
  82. #ifndef WSETEXIT
  83. # ifdef W_EXITCODE
  84. #define WSETEXIT(w,status) ((w) = W_EXITCODE(status,0))
  85. # else
  86. #define WSETEXIT(w,status) ((w) = (0 | ((status) << 8)))
  87. # endif
  88. #endif
  89. #ifndef W_STOPCODE
  90. #define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
  91. #endif
  92. #ifndef WSETSTOP
  93. #define WSETSTOP(w,sig) ((w) = W_STOPCODE(sig))
  94. #endif
  95. /* For native GNU/Linux we may use waitpid and the __WCLONE option.
  96. <GRIPE> It is of course dangerous not to use the REAL header file...
  97. </GRIPE>. */
  98. /* Bits in the third argument to `waitpid'. */
  99. #ifndef WNOHANG
  100. #define WNOHANG 1 /* Don't block waiting. */
  101. #endif
  102. #ifndef WUNTRACED
  103. #define WUNTRACED 2 /* Report status of stopped children. */
  104. #endif
  105. #ifndef __WCLONE
  106. #define __WCLONE 0x80000000 /* Wait for cloned process. */
  107. #endif
  108. #endif /* COMMON_GDB_WAIT_H */