From patchwork Sun Dec 8 18:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36630 Received: (qmail 114618 invoked by alias); 8 Dec 2019 18:32:23 -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 112636 invoked by uid 89); 8 Dec 2019 18:32:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.4 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: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Dec 2019 18:32:06 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway31.websitewelcome.com (Postfix) with ESMTP id D38CFA143 for ; Sun, 8 Dec 2019 12:30:10 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id e1JqiZZCn4kpje1Jqi9V93; 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=oBGaOuKJ/3LKZQLtHdzOCJ9o1Mii1h77el8hcRX6Hgk=; b=YtIEKRFHhFHXpsb5TdZ8IqVhS6 fajm01qi9MHmno0sNhD+vQrFwwwr4XhXzrjN3m7t9mIoWSgBGszaTN7tsM7pF5UM8RK7PliUJbkVV ndmBxNT/UF+mgs591K0lzajlS; 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-M1; Sun, 08 Dec 2019 11:30:10 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 43/55] Introduce c_value_print_array Date: Sun, 8 Dec 2019 11:29:46 -0700 Message-Id: <20191208182958.10181-44-tom@tromey.com> In-Reply-To: <20191208182958.10181-1-tom@tromey.com> References: <20191208182958.10181-1-tom@tromey.com> This adds c_value_print_array, a value-based analogue of c_val_print_array. gdb/ChangeLog 2019-12-08 Tom Tromey * c-valprint.c (c_value_print_array): New function. (c_value_print_inner): Use it. Change-Id: I4dd5af7c5cb0ad48922bc1bac818246f7645343f --- gdb/ChangeLog | 5 +++ gdb/c-valprint.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 694f87fea95..eaf7ef2eafe 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -335,6 +335,102 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr, } } +/* c_value_print helper for TYPE_CODE_ARRAY. */ + +static void +c_value_print_array (struct value *val, + struct ui_file *stream, int recurse, + const struct value_print_options *options) +{ + struct type *type = check_typedef (value_type (val)); + CORE_ADDR address = value_address (val); + const gdb_byte *valaddr = value_contents_for_printing (val); + struct type *unresolved_elttype = TYPE_TARGET_TYPE (type); + struct type *elttype = check_typedef (unresolved_elttype); + + if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0) + { + LONGEST low_bound, high_bound; + int eltlen, len; + enum bfd_endian byte_order = type_byte_order (type); + + if (!get_array_bounds (type, &low_bound, &high_bound)) + error (_("Could not determine the array high bound")); + + eltlen = TYPE_LENGTH (elttype); + len = high_bound - low_bound + 1; + if (options->prettyformat_arrays) + { + print_spaces_filtered (2 + 2 * recurse, stream); + } + + /* Print arrays of textual chars with a string syntax, as + long as the entire array is valid. */ + if (c_textual_element_type (unresolved_elttype, + options->format) + && value_bytes_available (val, 0, TYPE_LENGTH (type)) + && !value_bits_any_optimized_out (val, 0, + TARGET_CHAR_BIT * TYPE_LENGTH (type))) + { + int force_ellipses = 0; + + /* If requested, look for the first null char and only + print elements up to it. */ + if (options->stop_print_at_null) + { + unsigned int temp_len; + + for (temp_len = 0; + (temp_len < len + && temp_len < options->print_max + && extract_unsigned_integer (valaddr + temp_len * eltlen, + eltlen, byte_order) != 0); + ++temp_len) + ; + + /* Force LA_PRINT_STRING to print ellipses if + we've printed the maximum characters and + the next character is not \000. */ + if (temp_len == options->print_max && temp_len < len) + { + ULONGEST ival + = extract_unsigned_integer (valaddr + temp_len * eltlen, + eltlen, byte_order); + if (ival != 0) + force_ellipses = 1; + } + + len = temp_len; + } + + LA_PRINT_STRING (stream, unresolved_elttype, valaddr, len, + NULL, force_ellipses, options); + } + else + { + unsigned int i = 0; + fprintf_filtered (stream, "{"); + /* If this is a virtual function table, print the 0th + entry specially, and the rest of the members + normally. */ + if (cp_is_vtbl_ptr_type (elttype)) + { + i = 1; + fprintf_filtered (stream, _("%d vtable entries"), + len - 1); + } + value_print_array_elements (val, stream, recurse, options, i); + fprintf_filtered (stream, "}"); + } + } + else + { + /* Array of unspecified length: treat like pointer to first elt. */ + print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, + 0, address, stream, recurse, options); + } +} + /* c_val_print helper for TYPE_CODE_PTR. */ static void @@ -657,8 +753,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse, switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: - c_val_print_array (type, valaddr, 0, address, stream, - recurse, val, options); + c_value_print_array (val, stream, recurse, options); break; case TYPE_CODE_METHODPTR: