Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@codesourcery.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Pedro Alves <palves@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: [patch] Re: Regression for gdbserver  [Re: [PATCH] Linux/gdbserver: Fix memory read ptrace fallback issues]
Date: Tue, 22 May 2012 20:06:00 -0000	[thread overview]
Message-ID: <alpine.DEB.1.10.1205222050590.11227@tp.orcam.me.uk> (raw)
In-Reply-To: <20120522193521.GA26213@host2.jankratochvil.net>

On Tue, 22 May 2012, Jan Kratochvil wrote:

> > Can you check that these are not intermittent failures
> 
> It was very 0% vs. 100% reproducible and for the single testcase.

 Oh well, thanks for double-checking, it's difficult to chase something 
you can't reproduce.

> diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
> index 19f7be6..c33c976 100644
> --- a/gdb/gdbserver/linux-low.c
> +++ b/gdb/gdbserver/linux-low.c
> @@ -4450,10 +4450,12 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
>  
>    /* Copy appropriate bytes out of the buffer.  */
>    i *= sizeof (PTRACE_XFER_TYPE);
> -  i -= memaddr & (sizeof (PTRACE_XFER_TYPE) - 1);
> -  memcpy (myaddr,
> -	  (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)),
> -	  i < len ? i : len);
> +  if (i > 0)
> +    memcpy (myaddr,
> +	    (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)),
> +	    (MIN ((memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE)) + i,
> +		  memaddr + len)
> +	     - memaddr));
>  
>    return ret;
>  }

 Doh, it looks like my final correction of the copy size (not to overrun 
the buffer supplied) missed the zero case, sorry and thanks for catching 
this.  Presumably your alignment is different or suchlike.

 I think however, that this memcpy call needs a rewrite now, I find your 
proposal unreadable.  Would you please make use of an auxiliary variable 
or suchlike to make this calculation?  Also can we rely on MIN?  It's not 
a standard macro AFAIK and we don't define our own copy, except from one 
place in gdb/target.c (I checked before making the original change 
already).

 Perhaps a piece like this would actually be enough, i.e. the original 
code, only guarded against zero, where we're not going to copy anything 
anyway, so we can skip the whole calculation altogether:

  /* Copy appropriate bytes out of the buffer.  */
  if (i > 0)
    {
      i *= sizeof (PTRACE_XFER_TYPE);
      i -= memaddr & (sizeof (PTRACE_XFER_TYPE) - 1);
      memcpy (myaddr,
	      (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)),
	      i < len ? i : len);
    }

?

  Maciej


  reply	other threads:[~2012-05-22 20:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-16 22:57 [PATCH] Linux/gdbserver: Fix memory read ptrace fallback issues Maciej W. Rozycki
2012-05-18 16:53 ` Pedro Alves
2012-05-18 18:46   ` Maciej W. Rozycki
2012-05-18 20:11     ` Pedro Alves
2012-05-22  0:05       ` Maciej W. Rozycki
2012-05-22  8:04         ` Regression for gdbserver [Re: [PATCH] Linux/gdbserver: Fix memory read ptrace fallback issues] Jan Kratochvil
2012-05-22 12:43           ` Maciej W. Rozycki
2012-05-22 19:35             ` [patch] " Jan Kratochvil
2012-05-22 20:06               ` Maciej W. Rozycki [this message]
2012-05-22 20:42                 ` Jan Kratochvil
2012-05-22 23:34                   ` Maciej W. Rozycki
2012-05-23  5:29                     ` Jan Kratochvil

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=alpine.DEB.1.10.1205222050590.11227@tp.orcam.me.uk \
    --to=macro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=palves@redhat.com \
    /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