ptrace.m4 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. dnl Copyright (C) 2012-2022 Free Software Foundation, Inc.
  2. dnl
  3. dnl This file is part of GDB.
  4. dnl
  5. dnl This program is free software; you can redistribute it and/or modify
  6. dnl it under the terms of the GNU General Public License as published by
  7. dnl the Free Software Foundation; either version 3 of the License, or
  8. dnl (at your option) any later version.
  9. dnl
  10. dnl This program is distributed in the hope that it will be useful,
  11. dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. dnl GNU General Public License for more details.
  14. dnl
  15. dnl You should have received a copy of the GNU General Public License
  16. dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. dnl Check the return and argument types of ptrace.
  18. AC_DEFUN([GDB_AC_PTRACE],
  19. [
  20. AC_CHECK_HEADERS([sys/ptrace.h ptrace.h])
  21. gdb_ptrace_headers='
  22. #include <sys/types.h>
  23. #if HAVE_SYS_PTRACE_H
  24. # include <sys/ptrace.h>
  25. #endif
  26. #if HAVE_UNISTD_H
  27. # include <unistd.h>
  28. #endif
  29. '
  30. # Check return type. Varargs (used on GNU/Linux) conflict with the
  31. # empty argument list, so check for that explicitly.
  32. AC_CACHE_CHECK(
  33. [return type of ptrace],
  34. [gdb_cv_func_ptrace_ret],
  35. [AC_COMPILE_IFELSE(
  36.  [AC_LANG_PROGRAM(
  37. [$gdb_ptrace_headers],
  38. [extern long ptrace (enum __ptrace_request, ...);]
  39. )],
  40. [gdb_cv_func_ptrace_ret='long'],
  41. [AC_COMPILE_IFELSE(
  42. [AC_LANG_PROGRAM(
  43. [$gdb_ptrace_headers],
  44. [extern int ptrace ();]
  45. )],
  46. [gdb_cv_func_ptrace_ret='int'],
  47. [gdb_cv_func_ptrace_ret='long']
  48. )]
  49. )]
  50. )
  51. AC_DEFINE_UNQUOTED(
  52. [PTRACE_TYPE_RET],
  53. [$gdb_cv_func_ptrace_ret],
  54. [Define as the return type of ptrace.]
  55. )
  56. # Check argument types.
  57. AC_CACHE_CHECK(
  58. [types of arguments for ptrace],
  59. [gdb_cv_func_ptrace_args],
  60. [AC_COMPILE_IFELSE(
  61. [AC_LANG_PROGRAM(
  62. [$gdb_ptrace_headers],
  63. [extern long ptrace (enum __ptrace_request, ...);]
  64. )],
  65. [gdb_cv_func_ptrace_args='enum __ptrace_request,int,long,long'],
  66. [for gdb_arg1 in 'int' 'long'; do
  67. for gdb_arg2 in 'pid_t' 'int' 'long'; do
  68. for gdb_arg3 in 'int *' 'caddr_t' 'int' 'long' 'void *'; do
  69. for gdb_arg4 in 'int' 'long' 'void *'; do
  70. AC_COMPILE_IFELSE(
  71. [AC_LANG_PROGRAM(
  72. [$gdb_ptrace_headers],
  73. [extern $gdb_cv_func_ptrace_ret ptrace ($gdb_arg1, $gdb_arg2, $gdb_arg3, $gdb_arg4);]
  74. )],
  75. [gdb_cv_func_ptrace_args="$gdb_arg1,$gdb_arg2,$gdb_arg3,$gdb_arg4";
  76. break 4;]
  77. )
  78. for gdb_arg5 in 'int *' 'int' 'long'; do
  79. AC_COMPILE_IFELSE(
  80. [AC_LANG_PROGRAM(
  81. [$gdb_ptrace_headers],
  82. [extern $gdb_cv_func_ptrace_ret ptrace ($gdb_arg1, $gdb_arg2, $gdb_arg3, $gdb_arg4, $gdb_arg5);]
  83. )],
  84. [gdb_cv_func_ptrace_args="$gdb_arg1,$gdb_arg2,$gdb_arg3,$gdb_arg4,$gdb_arg5";
  85. break 5;]
  86. )
  87. done
  88. done
  89. done
  90. done
  91. done
  92. # Provide a safe default value.
  93. : ${gdb_cv_func_ptrace_args='int,int,long,long'}]
  94. )]
  95. )
  96. ac_save_IFS=$IFS; IFS=','
  97. set dummy `echo "$gdb_cv_func_ptrace_args" | sed 's/\*/\*/g'`
  98. IFS=$ac_save_IFS
  99. shift
  100. AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG1, $[1],
  101. [Define to the type of arg 1 for ptrace.])
  102. AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG3, $[3],
  103. [Define to the type of arg 3 for ptrace.])
  104. AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG4, $[4],
  105. [Define to the type of arg 4 for ptrace.])
  106. if test -n "$[5]"; then
  107. AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG5, $[5],
  108. [Define to the type of arg 5 for ptrace.])
  109. fi
  110. ])