This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3 12/14] add linux_infcall_mmap


On 11/01/2014 09:47 PM, Jan Kratochvil wrote:
> +/* See gdbarch.sh 'infcall_mmap'.  */
> +
> +static CORE_ADDR
> +linux_infcall_mmap (CORE_ADDR size, unsigned prot)
> +{
> +  struct objfile *objf;
> +  /* Do there still exist any Linux systems without "mmap64"?
> +     "mmap" uses 64-bit off_t on x86_64 and 32-bit off_t on i386 and x32.  */
> +  struct value *mmap_val = find_function_in_inferior ("mmap64", &objf);
> +  struct value *addr_val;
> +  struct gdbarch *gdbarch = get_objfile_arch (objf);
> +  CORE_ADDR retval;
> +  enum
> +    {
> +      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, ARG_MAX
> +    };
> +  struct value *arg[ARG_MAX];
> +
> +  arg[ARG_ADDR] = value_from_pointer (builtin_type (gdbarch)->builtin_data_ptr,
> +				      0);
> +  /* Assuming sizeof (unsigned long) == sizeof (size_t).  */
> +  arg[ARG_LENGTH] = value_from_ulongest
> +		    (builtin_type (gdbarch)->builtin_unsigned_long, size);
> +  gdb_assert ((prot & ~7) == 0);
> +  arg[ARG_PROT] = value_from_longest (builtin_type (gdbarch)->builtin_int,
> +				      0
> +				      | ((prot & 4) != 0 ? PROT_READ : 0)
> +				      | ((prot & 2) != 0 ? PROT_WRITE : 0)
> +				      | ((prot & 1) != 0 ? PROT_EXEC : 0));
> +  arg[ARG_FLAGS] = value_from_longest (builtin_type (gdbarch)->builtin_int,
> +				       MAP_PRIVATE | MAP_ANONYMOUS);

PROT_READ, PROT_WRITE, PROT_EXEC, MAP_PRIVATE, MAP_ANONYMOUS
are host values/macros.

This needs to be made host independent, otherwise cross debugging to
Linux passes the wrong values to mmap.

It also likely breaks --enable-targets=all builds on hosts
that don't have mmap at all.  E.g., this comes out empty on F20:

 $ grep -rn PROT_READ /usr/i686-w64-mingw32/sys-root/mingw/include/

OTOH, the 4, 2 and 1 bits checked against the 'prot' argument
are magical constants; they'd best be put behind macros, like e.g.,
GDB_MMAP_PROT_READ, etc., here and at the callers
of gdbarch_infcall_mmap.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]