From patchwork Sun Dec 8 18:29:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36639 Received: (qmail 45176 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 45071 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 1BB8D5245 for ; Sun, 8 Dec 2019 12:30:12 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JsiMgl7Hunhe1Jsiex5y; Sun, 08 Dec 2019 12:30:12 -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=IxFBl39yClR33QDrIVrPA6+34r5IA72iHbvgl86mSVI=; b=Azm7WI0eJ4lp4bxyb0D3EIRRws MCppPnROHK7JI0tWzwr6vqTnvpQj1VltZclYrHZlacKDUKnhb0QXZj5491dLtnfCGGhtTA7YFBvZK WKN/VDmkbrRM1rgvV3ARRP8lZ; 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 1ie1Jr-0045L6-Td; Sun, 08 Dec 2019 11:30:11 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 49/55] Introduce ada_value_print_num Date: Sun, 8 Dec 2019 11:29:52 -0700 Message-Id: <20191208182958.10181-50-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds ada_value_print_num, a value-based analogue of ada_val_print_num. gdb/ChangeLog 2019-12-08 Tom Tromey * ada-valprint.c (ada_value_print_num): New function. (ada_value_print_1): Use it. Change-Id: I45be06938ef8712d30541942f4682ec7244ae407 --- gdb/ChangeLog | 5 +++ gdb/ada-valprint.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 0286ced7c30..b5d113e1713 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -936,6 +936,88 @@ ada_val_print_num (struct type *type, const gdb_byte *valaddr, } } +/* Implement Ada val_print'ing for the case where TYPE is + a TYPE_CODE_INT or TYPE_CODE_RANGE. */ + +static void +ada_value_print_num (struct value *val, struct ui_file *stream, int recurse, + const struct value_print_options *options) +{ + struct type *type = ada_check_typedef (value_type (val)); + const gdb_byte *valaddr = value_contents_for_printing (val); + + if (ada_is_fixed_point_type (type)) + { + struct value *scale = ada_scaling_factor (type); + val = value_cast (value_type (scale), val); + val = value_binop (val, scale, BINOP_MUL); + + const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g"; + std::string str + = target_float_to_string (value_contents (val), value_type (val), fmt); + fputs_filtered (str.c_str (), stream); + return; + } + else if (TYPE_CODE (type) == TYPE_CODE_RANGE + && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ENUM + || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_BOOL + || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CHAR)) + { + /* For enum-valued ranges, we want to recurse, because we'll end + up printing the constant's name rather than its numeric + value. Character and fixed-point types are also printed + differently, so recuse for those as well. */ + struct type *target_type = TYPE_TARGET_TYPE (type); + val = value_cast (target_type, val); + common_val_print (val, stream, recurse + 1, options, + language_def (language_ada)); + return; + } + else + { + int format = (options->format ? options->format + : options->output_format); + + if (format) + { + struct value_print_options opts = *options; + + opts.format = format; + value_print_scalar_formatted (val, &opts, 0, stream); + } + else if (ada_is_system_address_type (type)) + { + /* FIXME: We want to print System.Address variables using + the same format as for any access type. But for some + reason GNAT encodes the System.Address type as an int, + so we have to work-around this deficiency by handling + System.Address values as a special case. */ + + struct gdbarch *gdbarch = get_type_arch (type); + struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; + CORE_ADDR addr = extract_typed_address (valaddr, ptr_type); + + fprintf_filtered (stream, "("); + type_print (type, "", stream, -1); + fprintf_filtered (stream, ") "); + fputs_filtered (paddress (gdbarch, addr), stream); + } + else + { + value_print_scalar_formatted (val, options, 0, stream); + if (ada_is_character_type (type)) + { + LONGEST c; + + fputs_filtered (" ", stream); + c = unpack_long (type, valaddr); + ada_printchar (c, type, stream); + } + } + return; + } +} + /* Implement Ada val_print'ing for the case where TYPE is a TYPE_CODE_ENUM. */ @@ -1279,9 +1361,7 @@ ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse, case TYPE_CODE_INT: case TYPE_CODE_RANGE: - ada_val_print_num (type, valaddr, 0, 0, - address, stream, recurse, val, - options); + ada_value_print_num (val, stream, recurse, options); break; case TYPE_CODE_ENUM: