From patchwork Sun Dec 8 18:29:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36596 Received: (qmail 101441 invoked by alias); 8 Dec 2019 18:30:25 -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 101284 invoked by uid 89); 8 Dec 2019 18:30:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 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=H*r:esmtpa, HX-Spam-Relays-External:esmtpa, H*RU:esmtpa X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.187.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:30:13 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 04FD14028F12D for ; Sun, 8 Dec 2019 11:40:29 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JoiY9Q3iJ43e1JoizFJr; Sun, 08 Dec 2019 12:30:08 -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=Yo6q/SOPrjnvaN5LRw5+PcqzVACe4XN0Nv4OxRIT7G4=; b=uPNnm7PR6k2Kz6ZZrdzXUEZwO5 vmJARw3WR55jDTbjTOYLeeFfnzMj8jvTiCesg8zA2CzxjB1QxxzNVHP9ViUVD4e23D1nOwgCKgxTE 3h3TKOyL3NJd0/mIWnjZBPXPt; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53624 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Jo-0045Im-EO; Sun, 08 Dec 2019 11:30:08 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 34/55] Introduce generic_value_print_bool Date: Sun, 8 Dec 2019 11:29:37 -0700 Message-Id: <20191208182958.10181-35-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds generic_value_print_bool, a value-based analogue of generic_val_print_bool. gdb/ChangeLog 2019-12-08 Tom Tromey * valprint.c (generic_value_print_bool): New function. (generic_value_print): Use it. Change-Id: I4f802a26430d4f430c32b605273d927e460bb20a --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 5c25f98faf8..5b1b9cff804 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -763,6 +763,35 @@ generic_val_print_bool (struct type *type, } } +/* generic_value_print helper for TYPE_CODE_BOOL. */ + +static void +generic_value_print_bool + (struct value *value, struct ui_file *stream, + const struct value_print_options *options, + const struct generic_val_print_decorations *decorations) +{ + if (options->format || options->output_format) + { + struct value_print_options opts = *options; + opts.format = (options->format ? options->format + : options->output_format); + value_print_scalar_formatted (value, &opts, 0, stream); + } + else + { + const gdb_byte *valaddr = value_contents_for_printing (value); + struct type *type = check_typedef (value_type (value)); + LONGEST val = unpack_long (type, valaddr); + if (val == 0) + fputs_filtered (decorations->false_name, stream); + else if (val == 1) + fputs_filtered (decorations->true_name, stream); + else + print_longest (stream, 'd', 0, val); + } +} + /* generic_val_print helper for TYPE_CODE_INT. */ static void @@ -1064,8 +1093,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse, break; case TYPE_CODE_BOOL: - generic_val_print_bool (type, 0, stream, - val, options, decorations); + generic_value_print_bool (val, stream, options, decorations); break; case TYPE_CODE_RANGE: