From patchwork Sun Dec 8 18:29:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36616 Received: (qmail 102867 invoked by alias); 8 Dec 2019 18:31:01 -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 101157 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=consolidate, SIZE, sk:value_p, H*r:esmtpa X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.47.80) 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 gateway23.websitewelcome.com (Postfix) with ESMTP id 885193AC0 for ; Sun, 8 Dec 2019 12:30:03 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1Jji5sDJW4fre1JjiS03e; 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=Zw+gYWBquptGcUQ0xRTqhigF/0xYFmcg0cgDP6ePaUE=; b=vd/xwsNHBHjcVnV86HF160TxQ5 MzSChJSsPsYGbWktpo4Pn2NNKs0Zlta2qThUvP7HGqSvOLP635De+FgcsHwWZkUtaBxDG0QcBLKWH OziN0YS0BavcfY/dNPE2OM1Pz; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53620 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Jj-0045Dk-5z; Sun, 08 Dec 2019 11:30:03 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/55] Introduce value_print_scalar_formatted Date: Sun, 8 Dec 2019 11:29:15 -0700 Message-Id: <20191208182958.10181-13-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This introduces a value_print_scalar_formatted, which is an analogue of val_print_scalar_formatted that uses the value API. gdb/ChangeLog 2019-12-08 Tom Tromey * valprint.h (value_print_scalar_formatted): Declare. * valprint.c (value_print_scalar_formatted): New function. Change-Id: Ie2b9ee80d53af8a99116b4b7a93dc16f420fb404 --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 40 ++++++++++++++++++++++++++++++++++++++++ gdb/valprint.h | 10 ++++++++++ 3 files changed, 55 insertions(+) diff --git a/gdb/valprint.c b/gdb/valprint.c index 0e13e2b2d62..d09a42926e2 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1365,6 +1365,46 @@ val_print_scalar_formatted (struct type *type, options, size, stream); } +/* See valprint.h. */ + +void +value_print_scalar_formatted (struct value *val, + const struct value_print_options *options, + int size, + struct ui_file *stream) +{ + struct type *type = check_typedef (value_type (val)); + + gdb_assert (val != NULL); + + /* If we get here with a string format, try again without it. Go + all the way back to the language printers, which may call us + again. */ + if (options->format == 's') + { + struct value_print_options opts = *options; + opts.format = 0; + opts.deref_ref = 0; + common_val_print (val, stream, 0, &opts, current_language); + return; + } + + /* value_contents_for_printing fetches all VAL's contents. They are + needed to check whether VAL is optimized-out or unavailable + below. */ + const gdb_byte *valaddr = value_contents_for_printing (val); + + /* A scalar object that does not have all bits available can't be + printed, because all bits contribute to its representation. */ + if (value_bits_any_optimized_out (val, 0, + TARGET_CHAR_BIT * TYPE_LENGTH (type))) + val_print_optimized_out (val, stream); + else if (!value_bytes_available (val, 0, TYPE_LENGTH (type))) + val_print_unavailable (stream); + else + print_scalar_formatted (valaddr, type, options, size, stream); +} + /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. The raison d'etre of this function is to consolidate printing of LONG_LONG's into this one function. The format chars b,h,w,g are diff --git a/gdb/valprint.h b/gdb/valprint.h index e4b90404fa2..f1c93aa26b6 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -141,6 +141,16 @@ extern void val_print_scalar_formatted (struct type *, int, struct ui_file *); +/* Print a scalar according to OPTIONS and SIZE on STREAM. Format i + is not supported at this level. + + This is how the elements of an array or structure are printed + with a format. */ + +extern void value_print_scalar_formatted (struct value *, + const struct value_print_options *, + int, struct ui_file *); + extern void print_binary_chars (struct ui_file *, const gdb_byte *, unsigned int, enum bfd_endian, bool);