]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/nat/gdb_ptrace.h
C++: handle glibc's ptrace(enum __ptrace_request, ...)
authorPedro Alves <palves@redhat.com>
Fri, 24 Jul 2015 13:57:20 +0000 (14:57 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 24 Jul 2015 14:12:15 +0000 (15:12 +0100)
commit54019719152ab269fb4cec2c6a8a245ba6af6e49
treed1252dcf1e0543ff063fde98919eaa8d55a05c0d
parente379037592ff71dc633c6d3de0828babe805ae96
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.
gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/gdbserver/ChangeLog
gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/nat/gdb_ptrace.h
gdb/ptrace.m4