From patchwork Sat Oct 10 18:19:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 9038 Received: (qmail 7066 invoked by alias); 10 Oct 2015 18:19:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7057 invoked by uid 89); 10 Oct 2015 18:19:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 10 Oct 2015 18:19:26 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id C9D96C057874; Sat, 10 Oct 2015 18:19:24 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9AIJMmZ005480; Sat, 10 Oct 2015 14:19:23 -0400 Message-ID: <561956AA.9020904@redhat.com> Date: Sat, 10 Oct 2015 19:19:22 +0100 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Joel Brobecker , gdb-patches@sourceware.org Subject: Re: FYI: [Ada] Rework ada_value_primitive_packed_val References: <1444426921-19985-1-git-send-email-brobecker@adacore.com> In-Reply-To: <1444426921-19985-1-git-send-email-brobecker@adacore.com> Hi Joel, On 10/09/2015 10:41 PM, Joel Brobecker wrote: > FYI, I have just pushed a set of commits we made a while ago at AdaCore > after I realized ada_value_primitive_packed_val could be written in > a way that makes it easier to understand. I noticed that this series regressed the C++ build: ../../src/gdb/ada-lang.c: In function ‘value* ada_value_primitive_packed_val(value*, const gdb_byte*, long int, int, int, type*)’: ../../src/gdb/ada-lang.c:2553:36: error: invalid conversion from ‘void*’ to ‘gdb_byte* {aka unsigned char*}’ [-fpermissive] staging = malloc (staging_len); ^ (similarly for alloca.) Looking at the code, I noticed the newly added casts, and thought of giving it a try at eliminating them. See patches below. WDYT? From be61a6e02fc3dce50f4ce16faa3b8a458d2a451a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sat, 10 Oct 2015 13:53:47 +0100 Subject: [PATCH 2/2] ada-lang.c:ada_value_primitive_packed_val: const correctness gdb/ChangeLog: 2015-10-10 Pedro Alves * ada-lang.c (ada_value_primitive_packed_val): Constify locals. Use value_contents_writeable. Remove casts. --- gdb/ada-lang.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 6d1998a..383db99 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2525,7 +2525,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, struct type *type) { struct value *v; - gdb_byte *src; /* First byte containing data to unpack */ + const gdb_byte *src; /* First byte containing data to unpack */ gdb_byte *unpacked; const int is_scalar = is_scalar_type (type); const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type)); @@ -2536,9 +2536,9 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, type = ada_check_typedef (type); if (obj == NULL) - src = (gdb_byte *) valaddr + offset; + src = valaddr + offset; else - src = (gdb_byte *) value_contents (obj) + offset; + src = value_contents (obj) + offset; if (is_dynamic_type (type)) { @@ -2574,20 +2574,22 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, if (obj == NULL) { v = allocate_value (type); - src = (gdb_byte *) valaddr + offset; + src = valaddr + offset; } else if (VALUE_LVAL (obj) == lval_memory && value_lazy (obj)) { int src_len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8; + gdb_byte *buf; v = value_at (type, value_address (obj) + offset); - src = (gdb_byte *) alloca (src_len); - read_memory (value_address (v), src, src_len); + buf = (gdb_byte *) alloca (src_len); + read_memory (value_address (v), buf, src_len); + src = buf; } else { v = allocate_value (type); - src = (gdb_byte *) value_contents (obj) + offset; + src = value_contents (obj) + offset; } if (obj != NULL) @@ -2610,7 +2612,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, } else set_value_bitsize (v, bit_size); - unpacked = (gdb_byte *) value_contents (v); + unpacked = value_contents_writeable (v); if (bit_size == 0) { -- 1.9.3