From patchwork Sun Dec 8 18:29:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36608 Received: (qmail 102381 invoked by alias); 8 Dec 2019 18:30:43 -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 101144 invoked by uid 89); 8 Dec 2019 18:30:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.7 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=roughly, sk:value_p 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 cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 0BAD52CF9 for ; Sun, 8 Dec 2019 12:30:01 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JhiNEbEOdBHe1JhiXA3s; Sun, 08 Dec 2019 12:30:01 -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=0E8OfKgF7hNdP7dcGbUoZO+o4qFqpsdgc6jMh0E/eBQ=; b=HiyEBK2J/C7/iYqyLVCAycfoMP Kk9A1dA47xknrxfr3FNjNSdImk1kKj6zNVeVtUg11u9PMvCWqisnBHaKOwKuWNpa4jdwOTcmaoy+u THmJhHfEZ+DulzfHDuQ0pLhrt; 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 1ie1Jg-00456j-RB; Sun, 08 Dec 2019 11:30:00 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 02/55] Refactor val_print and common_val_print Date: Sun, 8 Dec 2019 11:29:05 -0700 Message-Id: <20191208182958.10181-3-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This changes val_print and common_val_print to use a new helper function. A theme in the coming patches is that calls to val_print itself should be removed. This is the first such patch; at the end of the series, we'll remove val_print and simplify do_val_print. gdb/ChangeLog 2019-12-08 Tom Tromey * valprint.c (do_val_print): New function, from val_print. (val_print): Use do_val_print. (common_val_print): Use do_val_print. Change-Id: I09056cff7b7154995812029808704223f2e049bd --- gdb/ChangeLog | 6 +++++ gdb/valprint.c | 72 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 5bc860f13f1..62c78b95ad2 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1007,31 +1007,17 @@ generic_val_print (struct type *type, } } -/* Print using the given LANGUAGE the data of type TYPE located at - VAL's contents buffer + EMBEDDED_OFFSET (within GDB), which came - from the inferior at address ADDRESS + EMBEDDED_OFFSET, onto - stdio stream STREAM according to OPTIONS. VAL is the whole object - that came from ADDRESS. - - The language printers will pass down an adjusted EMBEDDED_OFFSET to - further helper subroutines as subfields of TYPE are printed. In - such cases, VAL is passed down unadjusted, so - that VAL can be queried for metadata about the contents data being - printed, using EMBEDDED_OFFSET as an offset into VAL's contents - buffer. For example: "has this field been optimized out", or "I'm - printing an object while inspecting a traceframe; has this - particular piece of data been collected?". +/* Helper function for val_print and common_val_print that does the + work. Arguments are as to val_print, but FULL_VALUE, if given, is + the value to be printed. */ - RECURSE indicates the amount of indentation to supply before - continuation lines; this amount is roughly twice the value of - RECURSE. */ - -void -val_print (struct type *type, LONGEST embedded_offset, - CORE_ADDR address, struct ui_file *stream, int recurse, - struct value *val, - const struct value_print_options *options, - const struct language_defn *language) +static void +do_val_print (struct value *full_value, + struct type *type, LONGEST embedded_offset, + CORE_ADDR address, struct ui_file *stream, int recurse, + struct value *val, + const struct value_print_options *options, + const struct language_defn *language) { int ret = 0; struct value_print_options local_opts = *options; @@ -1091,6 +1077,36 @@ val_print (struct type *type, LONGEST embedded_offset, } } +/* Print using the given LANGUAGE the data of type TYPE located at + VAL's contents buffer + EMBEDDED_OFFSET (within GDB), which came + from the inferior at address ADDRESS + EMBEDDED_OFFSET, onto + stdio stream STREAM according to OPTIONS. VAL is the whole object + that came from ADDRESS. + + The language printers will pass down an adjusted EMBEDDED_OFFSET to + further helper subroutines as subfields of TYPE are printed. In + such cases, VAL is passed down unadjusted, so + that VAL can be queried for metadata about the contents data being + printed, using EMBEDDED_OFFSET as an offset into VAL's contents + buffer. For example: "has this field been optimized out", or "I'm + printing an object while inspecting a traceframe; has this + particular piece of data been collected?". + + RECURSE indicates the amount of indentation to supply before + continuation lines; this amount is roughly twice the value of + RECURSE. */ + +void +val_print (struct type *type, LONGEST embedded_offset, + CORE_ADDR address, struct ui_file *stream, int recurse, + struct value *val, + const struct value_print_options *options, + const struct language_defn *language) +{ + do_val_print (nullptr, type, embedded_offset, address, stream, + recurse, val, options, language); +} + /* See valprint.h. */ bool @@ -1188,10 +1204,10 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse, if (value_lazy (val)) value_fetch_lazy (val); - val_print (value_type (val), - value_embedded_offset (val), value_address (val), - stream, recurse, - val, options, language); + do_val_print (val, value_type (val), + value_embedded_offset (val), value_address (val), + stream, recurse, + val, options, language); } /* Print on stream STREAM the value VAL according to OPTIONS. The value