From patchwork Sun Dec 8 18:29:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36623 Received: (qmail 104934 invoked by alias); 8 Dec 2019 18:31:13 -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 101784 invoked by uid 89); 8 Dec 2019 18:30:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.46.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:30:14 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 052C8400C5B30 for ; Sun, 8 Dec 2019 12:30:13 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JsiNErKOdBHe1JtiXAJo; Sun, 08 Dec 2019 12:30:13 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3pZSQs4kAK/G11cfZKCYH9CxfbV/2hxghdupGnOdczY=; b=WN9wVN74kyTVwxgeL8uuJZmw9j JP3gVdUv53NqnDdC7owbGZRiiffZMB7Ekt2N8t3FoqoCAFDv94pvviPZXSsT6cih+IDMZ4liDr6Pq PjWr0Rlwcnz4GQ3GBQ14GqLxi; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53632 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Js-0045O4-Qh; Sun, 08 Dec 2019 11:30:12 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 52/55] Introduce ada_value_print_array Date: Sun, 8 Dec 2019 11:29:55 -0700 Message-Id: <20191208182958.10181-53-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds ada_value_print_array, a value-based analogue of ada_val_print_array. It also removes some unused parameters from a couple of helper functions. gdb/ChangeLog 2019-12-08 Tom Tromey * ada-valprint.c (val_print_packed_array_elements): Remove bitoffset and val parameters. Call common_val_print. (ada_val_print_string): Remove offset, address, and original_value parameters. (ada_val_print_array): Update. (ada_value_print_array): New function. (ada_value_print_1): Call it. Change-Id: I3f0773f264e70ec95f5e98ab25fd6460d6e5afb8 --- gdb/ChangeLog | 10 +++++++ gdb/ada-valprint.c | 71 +++++++++++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index f0baa9945a2..c83782a0760 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -112,17 +112,15 @@ print_optional_low_bound (struct ui_file *stream, struct type *type, } /* Version of val_print_array_elements for GNAT-style packed arrays. - Prints elements of packed array of type TYPE at bit offset - BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and - separates with commas. RECURSE is the recursion (nesting) level. - TYPE must have been decoded (as by ada_coerce_to_simple_array). */ + Prints elements of packed array of type TYPE from VALADDR on + STREAM. Formats according to OPTIONS and separates with commas. + RECURSE is the recursion (nesting) level. TYPE must have been + decoded (as by ada_coerce_to_simple_array). */ static void val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, - int offset, - int bitoffset, struct ui_file *stream, + int offset, struct ui_file *stream, int recurse, - struct value *val, const struct value_print_options *options) { unsigned int i; @@ -230,9 +228,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, struct value_print_options opts = *options; opts.deref_ref = 0; - val_print (elttype, - value_embedded_offset (v0), 0, stream, - recurse + 1, v0, &opts, current_language); + common_val_print (v0, stream, recurse + 1, &opts, current_language); annotate_elt_rep (i - i0); fprintf_filtered (stream, _(" %p[%p]"), metadata_style.style ().ptr (), i - i0, nullptr); @@ -262,9 +258,8 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, maybe_print_array_index (index_type, j + low, stream, options); } - val_print (elttype, - value_embedded_offset (v0), 0, stream, - recurse + 1, v0, &opts, current_language); + common_val_print (v0, stream, recurse + 1, &opts, + current_language); annotate_elt (); } } @@ -714,9 +709,8 @@ print_field_values (struct type *type, const gdb_byte *valaddr, static void ada_val_print_string (struct type *type, const gdb_byte *valaddr, - int offset, int offset_aligned, CORE_ADDR address, + int offset_aligned, struct ui_file *stream, int recurse, - struct value *original_value, const struct value_print_options *options) { enum bfd_endian byte_order = type_byte_order (type); @@ -1126,9 +1120,8 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, if (ada_is_string_type (type) && (options->format == 0 || options->format == 's')) { - ada_val_print_string (type, valaddr, offset, offset_aligned, - address, stream, recurse, original_value, - options); + ada_val_print_string (type, valaddr, offset_aligned, + stream, recurse, options); return; } @@ -1136,8 +1129,7 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, print_optional_low_bound (stream, type, options); if (TYPE_FIELD_BITSIZE (type, 0) > 0) val_print_packed_array_elements (type, valaddr, offset_aligned, - 0, stream, recurse, - original_value, options); + stream, recurse, options); else val_print_array_elements (type, offset_aligned, address, stream, recurse, original_value, @@ -1145,6 +1137,41 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, ")"); } +/* Implement Ada value_print'ing for the case where TYPE is a + TYPE_CODE_ARRAY. */ + +static void +ada_value_print_array (struct value *val, struct ui_file *stream, int recurse, + const struct value_print_options *options) +{ + struct type *type = ada_check_typedef (value_type (val)); + + /* For an array of characters, print with string syntax. */ + if (ada_is_string_type (type) + && (options->format == 0 || options->format == 's')) + { + const gdb_byte *valaddr = value_contents_for_printing (val); + int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr; + + ada_val_print_string (type, valaddr, offset_aligned, stream, recurse, + options); + return; + } + + fprintf_filtered (stream, "("); + print_optional_low_bound (stream, type, options); + if (TYPE_FIELD_BITSIZE (type, 0) > 0) + { + const gdb_byte *valaddr = value_contents_for_printing (val); + int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr; + val_print_packed_array_elements (type, valaddr, offset_aligned, + stream, recurse, options); + } + else + value_print_array_elements (val, stream, recurse, options, 0); + fprintf_filtered (stream, ")"); +} + /* Implement Ada val_print'ing for the case where TYPE is a TYPE_CODE_REF. */ @@ -1387,9 +1414,7 @@ ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse, break; case TYPE_CODE_ARRAY: - ada_val_print_array (type, valaddr, 0, 0, - address, stream, recurse, val, - options); + ada_value_print_array (val, stream, recurse, options); return; case TYPE_CODE_REF: