From patchwork Sun Dec 8 18:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36620 Received: (qmail 103869 invoked by alias); 8 Dec 2019 18:31:06 -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 101570 invoked by uid 89); 8 Dec 2019 18:30:25 -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=thin X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.187) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:30:13 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 6BD97C256 for ; Sun, 8 Dec 2019 12:30:11 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JriNEq0OdBHe1JriXAIW; Sun, 08 Dec 2019 12:30:11 -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=Trqt4QokUPaO8r+VsrvOY95hUxWnxdeqITXldSlwZNo=; b=vSkzdPNr/BHpuHU3eotKXLDW29 T9Wi8nTahf7/5aYGR9GuTMPfC4Agc7dLJAbOWVEqGK2p6CSZwJ+TO3HMLcskWTV4VMQZu3iSqI1T7 acn06vUToMUmrY7Jf2nBEolQF; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53626 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Jr-0045L6-7w; Sun, 08 Dec 2019 11:30:11 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 46/55] Rewrite ada_value_print_inner Date: Sun, 8 Dec 2019 11:29:49 -0700 Message-Id: <20191208182958.10181-47-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This rewrites ada_value_print_inner, introducing a new ada_value_print_1, an analogue of ada_val_print_1. Because it was simple to do, this also converts ada_val_print_gnat_array to be valued-based and updates the uses. gdb/ChangeLog 2019-12-08 Tom Tromey * ada-valprint.c (ada_val_print_gnat_array): Take a struct value; call common_val_print. (ada_val_print_1): Update. (ada_value_print_1): New function. (ada_value_print_inner): Rewrite. Change-Id: If2525ec5bb1ac46b828d41105eca2a616d94819b --- gdb/ChangeLog | 8 +++ gdb/ada-valprint.c | 120 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 16 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 609e5af7481..83033d9ee8c 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -761,16 +761,14 @@ ada_val_print_string (struct type *type, const gdb_byte *valaddr, thin pointers, etc). */ static void -ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr, - int offset, CORE_ADDR address, +ada_val_print_gnat_array (struct value *val, struct ui_file *stream, int recurse, - struct value *original_value, const struct value_print_options *options) { - struct value *mark = value_mark (); - struct value *val; + scoped_value_mark free_values; + + struct type *type = ada_check_typedef (value_type (val)); - val = value_from_contents_and_address (type, valaddr + offset, address); /* If this is a reference, coerce it now. This helps taking care of the case where ADDRESS is meaningless because original_value was not an lval. */ @@ -785,11 +783,8 @@ ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, "0x0"); } else - val_print (value_type (val), - value_embedded_offset (val), value_address (val), - stream, recurse, val, options, - language_def (language_ada)); - value_free_to_mark (mark); + common_val_print (val, stream, recurse, options, + language_def (language_ada)); } /* Implement Ada val_print'ing for the case where TYPE is @@ -1132,9 +1127,10 @@ ada_val_print_1 (struct type *type, || (ada_is_constrained_packed_array_type (type) && TYPE_CODE (type) != TYPE_CODE_PTR)) { - ada_val_print_gnat_array (type, valaddr, offset, address, - stream, recurse, original_value, - options); + struct value *val = value_from_contents_and_address (type, + valaddr + offset, + address); + ada_val_print_gnat_array (val, stream, recurse, options); return; } @@ -1219,6 +1215,90 @@ ada_val_print (struct type *type, } } +/* See the comment on ada_value_print. This function differs in that + it does not catch evaluation errors (leaving that to + ada_value_print). */ + +static void +ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse, + const struct value_print_options *options) +{ + struct type *type = ada_check_typedef (value_type (val)); + + if (ada_is_array_descriptor_type (type) + || (ada_is_constrained_packed_array_type (type) + && TYPE_CODE (type) != TYPE_CODE_PTR)) + { + ada_val_print_gnat_array (val, stream, recurse, options); + return; + } + + val = ada_to_fixed_value (val); + type = value_type (val); + struct type *saved_type = type; + + const gdb_byte *valaddr = value_contents_for_printing (val); + CORE_ADDR address = value_address (val); + type = ada_check_typedef (resolve_dynamic_type (type, valaddr, address)); + if (type != saved_type) + { + val = value_copy (val); + deprecated_set_value_type (val, saved_type); + } + + switch (TYPE_CODE (type)) + { + default: + common_val_print (val, stream, recurse, options, + language_def (language_c)); + break; + + case TYPE_CODE_PTR: + ada_val_print_ptr (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + break; + + case TYPE_CODE_INT: + case TYPE_CODE_RANGE: + ada_val_print_num (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + break; + + case TYPE_CODE_ENUM: + ada_val_print_enum (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + break; + + case TYPE_CODE_FLT: + ada_val_print_flt (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + break; + + case TYPE_CODE_UNION: + case TYPE_CODE_STRUCT: + ada_val_print_struct_union (type, valaddr, 0, 0, + address, stream, recurse, + val, options); + break; + + case TYPE_CODE_ARRAY: + ada_val_print_array (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + return; + + case TYPE_CODE_REF: + ada_val_print_ref (type, valaddr, 0, 0, + address, stream, recurse, val, + options); + break; + } +} + /* See ada-lang.h. */ void @@ -1226,8 +1306,16 @@ ada_value_print_inner (struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options) { - ada_val_print (value_type (val), value_embedded_offset (val), - value_address (val), stream, recurse, val, options); + try + { + ada_value_print_1 (val, stream, recurse, options); + } + catch (const gdb_exception_error &except) + { + fprintf_styled (stream, metadata_style.style (), + _(""), + except.what ()); + } } void