From patchwork Sun Dec 8 18:29:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36605 Received: (qmail 101624 invoked by alias); 8 Dec 2019 18:30:26 -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 101174 invoked by uid 89); 8 Dec 2019 18:30:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 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=quoted, rtti X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.31) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:30:13 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 884F91A42 for ; Sun, 8 Dec 2019 12:30:03 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1Jii5sC2W4fre1JiiS02O; Sun, 08 Dec 2019 12:30:03 -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=EoXERIGn+mdLz422NJzjFXMWi5fjE2KIWZ+pOYaU7qk=; b=v6cAJO/W4n1XsrvSJdSWAcrMFh Dfiqb5E9N8UZlXZWQZQWQJrDJp86SgjaMDpKABdh/zZvroX87FatS6vvSbATohN4Bzk6S58oLfxM2 SfuZF0JENubsEzdVhzb/BV06k; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53618 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1ie1Ji-00456j-8n; Sun, 08 Dec 2019 11:30:02 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 09/55] Use common_val_print in c-valprint.c Date: Sun, 8 Dec 2019 11:29:12 -0700 Message-Id: <20191208182958.10181-10-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This changes c_value_print to call common_val_print. This is more complicated than the usual sort of common_val_print change, due to the handling of RTTI. gdb/ChangeLog 2019-12-08 Tom Tromey * c-valprint.c (c_value_print): Use common_val_print. Change-Id: Ifae442de4e508a90a2ccdc4f31792bfe47f79e6f --- gdb/ChangeLog | 4 ++++ gdb/c-valprint.c | 53 ++++++++++++++++-------------------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 607fb80c58f..d20a411252f 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -567,7 +567,7 @@ void c_value_print (struct value *val, struct ui_file *stream, const struct value_print_options *options) { - struct type *type, *real_type, *val_type; + struct type *type, *real_type; int full, using_enc; LONGEST top; struct value_print_options opts = *options; @@ -581,11 +581,7 @@ c_value_print (struct value *val, struct ui_file *stream, C++: if it is a member pointer, we will take care of that when we print it. */ - /* Preserve the original type before stripping typedefs. We prefer - to pass down the original type when possible, but for local - checks it is better to look past the typedefs. */ - val_type = value_type (val); - type = check_typedef (val_type); + type = check_typedef (value_type (val)); if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type)) { @@ -593,12 +589,12 @@ c_value_print (struct value *val, struct ui_file *stream, type is indicated by the quoted string anyway. (Don't use c_textual_element_type here; quoted strings are always exactly (char *), (wchar_t *), or the like. */ - if (TYPE_CODE (val_type) == TYPE_CODE_PTR - && TYPE_NAME (val_type) == NULL - && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL - && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)), + if (TYPE_CODE (type) == TYPE_CODE_PTR + && TYPE_NAME (type) == NULL + && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL + && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0 - || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type))))) + || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (type))))) { /* Print nothing. */ } @@ -624,7 +620,6 @@ c_value_print (struct value *val, struct ui_file *stream, if (real_type) { /* RTTI entry found. */ - type = real_type; /* Need to adjust pointer value. */ val = value_from_pointer (real_type, @@ -637,14 +632,11 @@ c_value_print (struct value *val, struct ui_file *stream, } if (is_ref) - { - val = value_ref (value_ind (val), refcode); - type = value_type (val); - } + val = value_ref (value_ind (val), refcode); + type = value_type (val); type_print (type, "", stream, -1); fprintf_filtered (stream, ") "); - val_type = type; } else { @@ -667,36 +659,27 @@ c_value_print (struct value *val, struct ui_file *stream, /* We have RTTI information, so use it. */ val = value_full_object (val, real_type, full, top, using_enc); + /* In a destructor we might see a real type that is a + superclass of the object's type. In this case it is + better to leave the object as-is. */ + if (!(full + && (TYPE_LENGTH (real_type) + < TYPE_LENGTH (value_enclosing_type (val))))) + val = value_cast (real_type, val); fprintf_filtered (stream, "(%s%s) ", TYPE_NAME (real_type), full ? "" : _(" [incomplete object]")); /* Print out object: enclosing type is same as real_type if full. */ - val_print (value_enclosing_type (val), - 0, - value_address (val), stream, 0, - val, &opts, current_language); - return; - /* Note: When we look up RTTI entries, we don't get any - information on const or volatile attributes. */ } else if (type != check_typedef (value_enclosing_type (val))) { /* No RTTI information, so let's do our best. */ fprintf_filtered (stream, "(%s ?) ", TYPE_NAME (value_enclosing_type (val))); - val_print (value_enclosing_type (val), - 0, - value_address (val), stream, 0, - val, &opts, current_language); - return; + val = value_cast (value_enclosing_type (val), val); } - /* Otherwise, we end up at the return outside this "if". */ } - val_print (val_type, - value_embedded_offset (val), - value_address (val), - stream, 0, - val, &opts, current_language); + common_val_print (val, stream, 0, &opts, current_language); }