From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7928 invoked by alias); 23 Feb 2010 19:53:56 -0000 Received: (qmail 7916 invoked by uid 22791); 23 Feb 2010 19:53:55 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,MSGID_FROM_MTA_HEADER X-Spam-Check-By: sourceware.org Received: from mtagate5.de.ibm.com (HELO mtagate5.de.ibm.com) (195.212.17.165) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 23 Feb 2010 19:53:50 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate5.de.ibm.com (8.13.1/8.13.1) with ESMTP id o1NJrlVE006429 for ; Tue, 23 Feb 2010 19:53:47 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o1NJrl1r1740922 for ; Tue, 23 Feb 2010 20:53:47 +0100 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o1NJrlRU018041 for ; Tue, 23 Feb 2010 20:53:47 +0100 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id o1NJrk3x018019; Tue, 23 Feb 2010 20:53:46 +0100 Message-Id: <201002231953.o1NJrk3x018019@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Tue, 23 Feb 2010 20:53:46 +0100 Subject: Re: FYI: fix big-endian bug with DWARF_VALUE_STACK To: tromey@redhat.com Date: Tue, 23 Feb 2010 19:53:00 -0000 From: "Ulrich Weigand" Cc: gdb-patches@sourceware.org In-Reply-To: from "Tom Tromey" at Feb 23, 2010 09:08:32 AM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-02/txt/msg00574.txt.bz2 Tom Tromey wrote: > 2010-02-23 Tom Tromey > > * dwarf2loc.c (read_pieced_value) : Correctly > handle big-endian values. > (dwarf2_evaluate_loc_desc) : 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