From patchwork Sun Dec 8 18:29:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36600 Received: (qmail 101589 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 101313 invoked by uid 89); 8 Dec 2019 18:30:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.2 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= X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.87) 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 gateway33.websitewelcome.com (Postfix) with ESMTP id 7FCB03F6CDC for ; Sun, 8 Dec 2019 12:30:10 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1Jqi5sOsW4fre1JqiS0FG; Sun, 08 Dec 2019 12:30:10 -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=XQ9OiQGQGg9ds4eAUh8kQ66K2P8HWsJu2kuG4yxUfsc=; b=gQn4Qa8YCTPhwl9j3Q/+r446aU /AyoFhoC9cF+nTPHpepRE6epBswZP2yo85VjxmjrwcFHN++y+rkid4hL1jTh3fN75zy0aPU97XevV lOgi2iby1vYmZsrog4q0YkzaQ; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:53626 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1ie1Jq-0045L6-AH; Sun, 08 Dec 2019 11:30:10 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 41/55] Introduce c_value_print_int Date: Sun, 8 Dec 2019 11:29:44 -0700 Message-Id: <20191208182958.10181-42-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds c_value_print_int, a value-based analogue of c_val_print_int. gdb/ChangeLog 2019-12-08 Tom Tromey * c-valprint.c (c_value_print_int): New function. (c_value_print_inner): Use it. Change-Id: I49259bd8bdbb14a66a98df4de449fb3bdfb1e157 --- gdb/ChangeLog | 5 +++++ gdb/c-valprint.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index f50c49abbfd..9b75d4d0404 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -502,6 +502,37 @@ c_val_print_int (struct type *type, struct type *unresolved_type, } } +/* c_value_print helper for TYPE_CODE_INT. */ + +static void +c_value_print_int (struct value *val, 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 (val, &opts, 0, stream); + } + else + { + value_print_scalar_formatted (val, options, 0, stream); + /* C and C++ has no single byte int type, char is used + instead. Since we don't know whether the value is really + intended to be used as an integer or a character, print + the character equivalent as well. */ + struct type *type = value_type (val); + const gdb_byte *valaddr = value_contents_for_printing (val); + if (c_textual_element_type (type, options->format)) + { + fputs_filtered (" ", stream); + LA_PRINT_CHAR (unpack_long (type, valaddr), type, stream); + } + } +} + /* c_val_print helper for TYPE_CODE_MEMBERPTR. */ static void @@ -602,7 +633,6 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options) { struct type *type = value_type (val); - struct type *unresolved_type = type; CORE_ADDR address = value_address (val); const gdb_byte *valaddr = value_contents_for_printing (val); @@ -633,8 +663,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse, break; case TYPE_CODE_INT: - c_val_print_int (type, unresolved_type, valaddr, 0, stream, - val, options); + c_value_print_int (val, stream, options); break; case TYPE_CODE_MEMBERPTR: