Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: tromey@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: FYI: fix big-endian bug with DWARF_VALUE_STACK
Date: Tue, 23 Feb 2010 19:53:00 -0000	[thread overview]
Message-ID: <201002231953.o1NJrk3x018019@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <m3635o0wan.fsf@fleche.redhat.com> from "Tom Tromey" at Feb 23, 2010 09:08:32 AM

Tom Tromey wrote:

> 2010-02-23  Tom Tromey  <tromey@redhat.com>
> 
> 	* dwarf2loc.c (read_pieced_value) <DWARF_VALUE_STACK>: Correctly
> 	handle big-endian values.
> 	(dwarf2_evaluate_loc_desc) <DWARF_VALUE_STACK>: Likewise.

I'd recently been wondering about this piece of code (and in particular
its use of gdbarch_addr_bit) as well ...


> @@ -298,16 +298,14 @@ read_pieced_value (struct value *v)
>  
>  	case DWARF_VALUE_STACK:
>  	  {
> -	    gdb_byte bytes[sizeof (ULONGEST)];
>  	    size_t n;
>  	    int addr_size = gdbarch_addr_bit (c->arch) / 8;
> -	    store_unsigned_integer (bytes, addr_size,
> -				    gdbarch_byte_order (c->arch),
> -				    p->v.expr.value);
>  	    n = p->size;
>  	    if (n > addr_size)
>  	      n = addr_size;
> -	    memcpy (contents + offset, bytes, n);
> +	    store_unsigned_integer (contents + offset, n,
> +				    gdbarch_byte_order (c->arch),
> +				    p->v.expr.value);
>  	  }
>  	  break;

The original code looks broken to me too.  But even the new code
doesn't seem quite right: if the requested piece size p->size
is larger than addr_size, the remaining bytes of the output value
are left undefined (well, probably zeroed -- but that still doesn't
look correct on a big-endian machine ...).

Why would that code look at gdbarch_addr_bit at all?  I think this
should simply do something like:

	    store_unsigned_integer (contents + offset, p->size,
				    gdbarch_byte_order (c->arch),
				    p->v.expr.value);

> @@ -476,19 +474,17 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
>  
>  	case DWARF_VALUE_STACK:
>  	  {
> -	    gdb_byte bytes[sizeof (ULONGEST)];
>  	    ULONGEST value = (ULONGEST) dwarf_expr_fetch (ctx, 0);
>  	    bfd_byte *contents;
>  	    size_t n = ctx->addr_size;
>  
> -	    store_unsigned_integer (bytes, ctx->addr_size,
> -				    gdbarch_byte_order (ctx->gdbarch),
> -				    value);
>  	    retval = allocate_value (SYMBOL_TYPE (var));
>  	    contents = value_contents_raw (retval);
>  	    if (n > TYPE_LENGTH (SYMBOL_TYPE (var)))
>  	      n = TYPE_LENGTH (SYMBOL_TYPE (var));
> -	    memcpy (contents, bytes, n);
> +	    store_unsigned_integer (contents, n,
> +				    gdbarch_byte_order (ctx->gdbarch),
> +				    value);
>  	  }
>  	  break;

Similiary here; why does this not simply use value_from_longest?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


  parent reply	other threads:[~2010-02-23 19:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23 16:08 Tom Tromey
2010-02-23 16:16 ` Tom Tromey
2010-02-23 19:53 ` Ulrich Weigand [this message]
2010-02-23 20:26   ` Tom Tromey
2010-02-24 14:12     ` Ulrich Weigand
2010-02-24 14:20       ` Mark Wielaard
2010-02-24 16:10         ` Ulrich Weigand
2010-02-24 16:30       ` Tom Tromey
2010-02-25 20:44         ` Ulrich Weigand
2010-02-25 21:03           ` Tom Tromey
2010-02-26 12:50             ` Ulrich Weigand

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=201002231953.o1NJrk3x018019@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@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