[PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move

Jan Kratochvil jan.kratochvil@redhat.com
Thu Apr 18 08:58:00 GMT 2013


On Tue, 16 Apr 2013 17:44:52 +0200, Aleksandar Ristovski wrote:
[...]
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -3476,6 +3476,22 @@ target_fileio_close_cleanup (void *opaque)
>    target_fileio_close (fd, &target_errno);
>  }
>  
> +typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len,
> +				      ULONGEST offset, int *target_errno);

This typedef is in the end duplicate both in target.c and in
common/common-target.h.  It should remain only in common/common-target.h.


> +
> +static read_alloc_pread_ftype target_fileio_read_alloc_1_pread;
> +
> +/* Helper for target_fileio_read_alloc_1 to make it interruptible.  */
> +
> +static int
> +target_fileio_read_alloc_1_pread (int handle, gdb_byte *read_buf, int len,
> +				  ULONGEST offset, int *target_errno)
> +{
> +  QUIT;
> +
> +  return target_fileio_pread (handle, read_buf, len, offset, target_errno);
> +}
> +
>  /* Read target file FILENAME.  Store the result in *BUF_P and
>     return the size of the transferred data.  PADDING additional bytes are
>     available in *BUF_P.  This is a helper function for
[...]
> @@ -3534,12 +3548,39 @@ target_fileio_read_alloc_1 (const char *filename,
>  	{
>  	  buf_alloc *= 2;
>  	  buf = xrealloc (buf, buf_alloc);
> +	  if (memory_to_free_ptr != NULL)
> +	    *memory_to_free_ptr = buf;
>  	}
> -
> -      QUIT;
>      }
>  }
>  
> +typedef LONGEST (read_stralloc_func_ftype) (const char *filename,
> +					    gdb_byte **buf_p, int padding);

This typedef is in the end duplicate both in target.c and in
common/common-target.h.  It should remain only in common/common-target.h.


> +
> +static read_stralloc_func_ftype target_fileio_read_alloc_1;
> +
> +static LONGEST
> +target_fileio_read_alloc_1 (const char *filename,
> +			    gdb_byte **buf_p, int padding)
> +{
> +  struct cleanup *close_cleanup;
> +  int fd, target_errno;
> +  void *memory_to_free = NULL;
> +  LONGEST retval;
> +
> +  fd = target_fileio_open (filename, FILEIO_O_RDONLY, 0700, &target_errno);
> +  if (fd == -1)
> +    return -1;
> +
> +  close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd);
> +
> +  make_cleanup (free_current_contents, &memory_to_free);
> +  retval = read_alloc (buf_p, fd, target_fileio_read_alloc_1_pread, padding,
> +		       &memory_to_free);
> +  do_cleanups (close_cleanup);
> +  return retval;
> +}
> +
>  /* Read target file FILENAME.  Store the result in *BUF_P and return
>     the size of the transferred data.  See the declaration in "target.h"
>     function for more information about the return value.  */
[...]


Thanks,
Jan



More information about the Gdb-patches mailing list