Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Aleksandar Ristovski <ARistovski@qnx.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move
Date: Mon, 15 Apr 2013 13:36:00 -0000	[thread overview]
Message-ID: <20130414141556.GB23227@host2.jankratochvil.net> (raw)
In-Reply-To: <1365521265-28870-5-git-send-email-ARistovski@qnx.com>

On Tue, 09 Apr 2013 17:27:41 +0200, Aleksandar Ristovski wrote:
[...]
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -3476,55 +3476,67 @@ target_fileio_close_cleanup (void *opaque)
>    target_fileio_close (fd, &target_errno);
>  }
>  
> +/* Helper for target_fileio_read_alloc_1 to make it interruptible.  */

Here should be added (reason: so that one can easily find all the
read_alloc_pread_ftype instances):

static read_alloc_pread_ftype target_fileio_read_alloc_1_pread;

(And move the read_alloc_pread_ftype definition above.)


> +
> +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
>     target_fileio_read_alloc; see the declaration of that function for more
>     information.  */
>  
> +typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len,
> +                                      ULONGEST offset, int *target_errno);

Use tabs.


> +
>  static LONGEST
> -target_fileio_read_alloc_1 (const char *filename,
> -			    gdb_byte **buf_p, int padding)
> +read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func,
> +	    int padding, void **memory_to_free_ptr)
>  {
> -  struct cleanup *close_cleanup;
>    size_t buf_alloc, buf_pos;
>    gdb_byte *buf;
>    LONGEST n;
> -  int fd;
>    int target_errno;
>  
> -  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);
> -
>    /* Start by reading up to 4K at a time.  The target will throttle
>       this number down if necessary.  */
>    buf_alloc = 4096;
>    buf = xmalloc (buf_alloc);
> +  if (memory_to_free_ptr != NULL)
> +    {
> +      gdb_assert (*memory_to_free_ptr == NULL);
> +      *memory_to_free_ptr = buf;
> +    }
>    buf_pos = 0;
>    while (1)
>      {
> -      n = target_fileio_pread (fd, &buf[buf_pos],
> -			       buf_alloc - buf_pos - padding, buf_pos,
> -			       &target_errno);
> -      if (n < 0)
> +      n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding,
> +		      buf_pos, &target_errno);
> +      if (n <= 0)
>  	{
> -	  /* An error occurred.  */
> -	  do_cleanups (close_cleanup);
> -	  xfree (buf);
> -	  return -1;
> -	}
> -      else if (n == 0)
> -	{
> -	  /* Read all there was.  */
> -	  do_cleanups (close_cleanup);
> -	  if (buf_pos == 0)
> +	  if (n < 0 || (n == 0 && buf_pos == 0))
>  	    xfree (buf);
>  	  else
>  	    *buf_p = buf;
> -	  return buf_pos;
> +	  if (memory_to_free_ptr != NULL)
> +	    *memory_to_free_ptr = NULL;
> +	  if (n < 0)
> +	    {
> +	      /* An error occurred.  */
> +	      return -1;
> +	    }
> +	  else
> +	    {
> +	      /* Read all there was.  */
> +	      return buf_pos;
> +	    }
>  	}
>  
>        buf_pos += n;
> @@ -3534,12 +3546,34 @@ 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;
>      }
>  }
>  


Here could be (so that one can easily find all the read_stralloc_func_ftype
instances):

static read_stralloc_func_ftype target_fileio_read_alloc_1;

(And move the read_stralloc_func_ftype definition above.)


> +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


  reply	other threads:[~2013-04-14 14:16 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 16:15 [PATCH 0/8] v2 - validate binary before use Aleksandar Ristovski
2013-04-09 15:53 ` [PATCH 1/8] Move utility functions to common/ Aleksandar Ristovski
2013-04-09 16:01 ` [PATCH 2/8] Merge multiple hex conversions Aleksandar Ristovski
2013-04-09 16:03 ` [PATCH 3/8] Create empty common/linux-maps.[ch] and common/common-target.[ch] Aleksandar Ristovski
2013-04-15 13:34   ` Jan Kratochvil
2013-04-09 16:39 ` [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move Aleksandar Ristovski
2013-04-15 13:36   ` Jan Kratochvil [this message]
2013-04-16 17:19     ` Aleksandar Ristovski
2013-04-09 16:48 ` [PATCH 5/8] Move linux_find_memory_regions_full & co Aleksandar Ristovski
2013-04-15 13:52   ` Jan Kratochvil
2013-04-16 15:46     ` Aleksandar Ristovski
2013-04-09 16:55 ` [PATCH 6/8] gdbserver build-id attribute generator Aleksandar Ristovski
2013-04-09 18:52   ` Eli Zaretskii
2013-04-15 14:23   ` Jan Kratochvil
2013-04-16 16:40     ` Aleksandar Ristovski
2013-04-18 10:08       ` Jan Kratochvil
2013-04-09 17:37 ` [PATCH 8/8] Tests for validate symbol file using build-id Aleksandar Ristovski
2013-04-15 15:12   ` Jan Kratochvil
2013-04-16 17:25     ` Aleksandar Ristovski
2013-04-18  5:37       ` Jan Kratochvil
2013-04-09 17:50 ` [PATCH 7/8] Validate " Aleksandar Ristovski
2013-04-10 22:35   ` Aleksandar Ristovski
2013-04-10 19:58     ` Aleksandar Ristovski
2013-04-11  1:26     ` Jan Kratochvil
2013-04-11  2:43       ` Aleksandar Ristovski
2013-04-15 14:58   ` Jan Kratochvil
2013-04-16 19:14     ` Aleksandar Ristovski
2013-04-18 10:23       ` Jan Kratochvil
2013-04-09 17:53 ` [PATCH 0/8] v2 - validate binary before use Jan Kratochvil
2013-04-09 18:09   ` Aleksandar Ristovski
2013-04-16 18:03 ` Aleksandar Ristovski
2013-04-16 18:30   ` [PATCH 2/8] Merge multiple hex conversions Aleksandar Ristovski
2013-04-16 18:30   ` [PATCH 7/8] Validate symbol file using build-id Aleksandar Ristovski
2013-04-16 18:31   ` [PATCH 4/8] Prepare linux_find_memory_regions_full & co. for move Aleksandar Ristovski
2013-04-18  8:58     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 1/8] Move utility functions to common/ Aleksandar Ristovski
2013-04-16 18:31   ` [PATCH 6/8] gdbserver build-id attribute generator Aleksandar Ristovski
2013-04-18  7:40     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 8/8] Tests for validate symbol file using build-id Aleksandar Ristovski
2013-04-18 10:15     ` Jan Kratochvil
2013-04-16 18:31   ` [PATCH 5/8] Move linux_find_memory_regions_full & co Aleksandar Ristovski
2013-04-16 20:24   ` [PATCH 3/8] Create empty common/linux-maps.[ch] and common/common-target.[ch] Aleksandar Ristovski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130414141556.GB23227@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=ARistovski@qnx.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox