diff options
author | Pedro Alves <palves@redhat.com> | 2015-07-24 14:57:20 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2015-07-24 15:12:15 +0100 |
commit | 54019719152ab269fb4cec2c6a8a245ba6af6e49 (patch) | |
tree | d1252dcf1e0543ff063fde98919eaa8d55a05c0d /gdb/ptrace.m4 | |
parent | e379037592ff71dc633c6d3de0828babe805ae96 (diff) | |
download | gdb-54019719152ab269fb4cec2c6a8a245ba6af6e49.zip gdb-54019719152ab269fb4cec2c6a8a245ba6af6e49.tar.gz gdb-54019719152ab269fb4cec2c6a8a245ba6af6e49.tar.bz2 |
C++: handle glibc's ptrace(enum __ptrace_request, ...)
Building in C++ mode issues ~40 warnings like this:
../../src/gdb/linux-nat.c: In function ‘int linux_handle_extended_wait(lwp_info*, int, int)’:
../../src/gdb/linux-nat.c:2016:51: warning: invalid conversion from ‘int’ to ‘__ptrace_request’ [-fpermissive]
ptrace (PTRACE_GETEVENTMSG, pid, 0, &new_pid);
The issue is that in glibc, ptrace's first parameter is an enum.
That's not a problem if we pick the PTRACE_XXX requests from
sys/ptrace.h, as those will be values of the corresponding enum.
However, we have fallback definitions for PTRACE_XXX symbols when the
system headers miss them (such as PTRACE_GETEVENTMSG above), and those
are plain integer constants. E.g., nat/linux-ptrace.h:
#define PTRACE_GETEVENTMSG 0x4201
One idea would be to fix this by defining those fallbacks like:
-#define PTRACE_GETEVENTMSG 0x4201
+#define PTRACE_GETEVENTMSG ((enum __ptrace_request) 0x4201)
However, while glibc's ptrace uses enum __ptrace_request for first
parameter:
extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
other libc's, like e.g., Android's bionic do not -- in that case, the
first parameter is int:
long ptrace(int request, pid_t pid, void * addr, void * data);
So the fix I came up is to make configure/ptrace.m4 also detect the
type of the ptrace's first parameter and defin PTRACE_TYPE_ARG1, as
already does the for parameters 3-4, and then simply wrap ptrace with
a macro that casts the first argument to the detected type. (I'm
leaving adding a nicer wrapper for when we drop building in C).
While this adds the wrapper, GNU/Linux files won't use it until the
next patch, which makes all native GNU/Linux files include
gdb_ptrace.h.
gdb/ChangeLog:
2015-07-24 Pedro Alves <palves@redhat.com>
* ptrace.m4 (ptrace tests): Test in C++ mode. Try with 'enum
__ptrace_request as first parameter type instead of int.
(PTRACE_TYPE_ARG1): Define.
* nat/gdb_ptrace.h [!PTRACE_TYPE_ARG5] (ptrace): Define as wrapper
that casts first argument to PTRACE_TYPE_ARG1.
* config.in: Regenerate.
* configure: Regenerate.
gdb/gdbserver/ChangeLog:
2015-07-24 Pedro Alves <palves@redhat.com>
* config.in: Regenerate.
* configure: Regenerate.
Diffstat (limited to 'gdb/ptrace.m4')
-rw-r--r-- | gdb/ptrace.m4 | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/gdb/ptrace.m4 b/gdb/ptrace.m4 index e5fe7fa..f01c692 100644 --- a/gdb/ptrace.m4 +++ b/gdb/ptrace.m4 @@ -22,6 +22,12 @@ AC_DEFUN([GDB_AC_PTRACE], AC_CHECK_HEADERS([sys/ptrace.h ptrace.h]) +# Needs to be tested in C++ mode, to detect whether we need to cast +# the first argument to enum __ptrace_request. +if test "$enable_build_with_cxx" = "yes"; then + AC_LANG_PUSH([C++]) +fi + gdb_ptrace_headers=' #include <sys/types.h> #if HAVE_SYS_PTRACE_H @@ -52,7 +58,7 @@ AC_DEFINE_UNQUOTED(PTRACE_TYPE_RET, $gdb_cv_func_ptrace_ret, AC_CACHE_CHECK([types of arguments for ptrace], gdb_cv_func_ptrace_args, [ AC_TRY_COMPILE($gdb_ptrace_headers, [extern long ptrace (enum __ptrace_request, ...);], - [gdb_cv_func_ptrace_args='int,int,long,long'],[ + [gdb_cv_func_ptrace_args='enum __ptrace_request,int,long,long'],[ for gdb_arg1 in 'int' 'long'; do for gdb_arg2 in 'pid_t' 'int' 'long'; do for gdb_arg3 in 'int *' 'caddr_t' 'int' 'long' 'void *'; do @@ -81,6 +87,8 @@ ac_save_IFS=$IFS; IFS=',' set dummy `echo "$gdb_cv_func_ptrace_args" | sed 's/\*/\*/g'` IFS=$ac_save_IFS shift +AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG1, $[1], + [Define to the type of arg 1 for ptrace.]) AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG3, $[3], [Define to the type of arg 3 for ptrace.]) AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG4, $[4], @@ -89,4 +97,8 @@ if test -n "$[5]"; then AC_DEFINE_UNQUOTED(PTRACE_TYPE_ARG5, $[5], [Define to the type of arg 5 for ptrace.]) fi + +if test "$enable_build_with_cxx" = "yes"; then + AC_LANG_POP([C++]) +fi ]) |