From patchwork Sun Dec 8 18:29:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36638 Received: (qmail 45082 invoked by alias); 8 Dec 2019 18:54: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 45066 invoked by uid 89); 8 Dec 2019 18:54:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway22.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:54:05 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 0AFFE522B for ; Sun, 8 Dec 2019 12:30:09 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JpiMgigHunhe1Jpiex3V; Sun, 08 Dec 2019 12:30:09 -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=vvENZJFzJBY2T95gVQplsGj2SFst126+4YIWEoQPF58=; b=FJgWZzdgkeaiYzDqkOGLr4m3VW 7ZAXgDsoA55vZa11+bIuwSIFyW6PWqBvCG6bBdSReF+N33WeO3BGotiv66KCcWN/maeNQEkqcPYH6 UdMcJuJdQBBy3avfJos54XZLd; 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-Qu; Sun, 08 Dec 2019 11:30:08 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 36/55] Introduce generic_value_print_char Date: Sun, 8 Dec 2019 11:29:39 -0700 Message-Id: <20191208182958.10181-37-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds generic_value_print_char, a value-based analogue of generic_val_print_char. gdb/ChangeLog 2019-12-08 Tom Tromey * valprint.c (generic_value_print_char): New function (generic_value_print): Use it. Change-Id: I7baf1cb6cebc78388010c9cce68b3d865fdb50e0 --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 44ae99783b6..4e65115cf97 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -857,6 +857,36 @@ generic_val_print_char (struct type *type, struct type *unresolved_type, } } +/* generic_value_print helper for TYPE_CODE_CHAR. */ + +static void +generic_value_print_char (struct value *value, struct ui_file *stream, + const struct value_print_options *options) +{ + 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 + { + struct type *unresolved_type = value_type (value); + struct type *type = check_typedef (unresolved_type); + const gdb_byte *valaddr = value_contents_for_printing (value); + + LONGEST val = unpack_long (type, valaddr); + if (TYPE_UNSIGNED (type)) + fprintf_filtered (stream, "%u", (unsigned int) val); + else + fprintf_filtered (stream, "%d", (int) val); + fputs_filtered (" ", stream); + LA_PRINT_CHAR (val, unresolved_type, stream); + } +} + /* generic_val_print helper for TYPE_CODE_FLT and TYPE_CODE_DECFLOAT. */ static void @@ -1058,7 +1088,6 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse, const struct generic_val_print_decorations *decorations) { struct type *type = value_type (val); - struct type *unresolved_type = type; type = check_typedef (type); switch (TYPE_CODE (type)) @@ -1125,8 +1154,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse, break; case TYPE_CODE_CHAR: - generic_val_print_char (type, unresolved_type, 0, - stream, val, options); + generic_value_print_char (val, stream, options); break; case TYPE_CODE_FLT: