From patchwork Fri Jun 2 19:36:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 20744 Received: (qmail 87035 invoked by alias); 2 Jun 2017 19:37:00 -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 86923 invoked by uid 89); 2 Jun 2017 19:36:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*m:3173, HX-HELO:sk:gproxy4, Hx-spam-relays-external:cmgw2, Hx-spam-relays-external:sk:gproxy4 X-HELO: gproxy4.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Jun 2017 19:36:58 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 80F03176A0B for ; Fri, 2 Jun 2017 13:37:00 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id Tvcx1v00P2f2jeq01vd0ju; Fri, 02 Jun 2017 13:37:00 -0600 X-Authority-Analysis: v=2.2 cv=Ibz3YSia c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=LWSFodeU3zMA:10 a=zstS-IiYAAAA:8 a=z79CWDlMNy-Mbo3LlDUA:9 a=g8bUrEOI-5S6zdWJ:21 a=iakuC9BKnQtIiAjT:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:55096 helo=pokyo.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dGsNV-0003ge-6D; Fri, 02 Jun 2017 13:36:57 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/5] Simplify print_scalar_formatted Date: Fri, 2 Jun 2017 13:36:49 -0600 Message-Id: <20170602193651.3173-4-tom@tromey.com> In-Reply-To: <20170602193651.3173-1-tom@tromey.com> References: <20170602193651.3173-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dGsNV-0003ge-6D X-Source-Sender: 174-29-39-24.hlrn.qwest.net (pokyo.Home) [174.29.39.24]:55096 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This unifies the two switches in print_scalar_formatted, removing some now-redundant code. Now scalar types are never converted to LONGEST, instead printing is done using print_*_chars, operating on the byte representation. ChangeLog 2017-06-02 Tom Tromey * printcmd.c (print_scalar_formatted): Unify the two switches. Don't convert scalars to LONGEST. --- gdb/ChangeLog | 5 ++ gdb/printcmd.c | 181 ++++++++++++++++++--------------------------------------- 2 files changed, 61 insertions(+), 125 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a529694..731d908 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-06-02 Tom Tromey + * printcmd.c (print_scalar_formatted): Unify the two switches. + Don't convert scalars to LONGEST. + +2017-06-02 Tom Tromey + PR exp/16225: * valprint.h (print_decimal_chars): Update. * valprint.c (maybe_negate_by_bytes): New function. diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 84f41f5..91cc4ff 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -356,47 +356,12 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, int size, struct ui_file *stream) { struct gdbarch *gdbarch = get_type_arch (type); - LONGEST val_long = 0; unsigned int len = TYPE_LENGTH (type); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); /* String printing should go through val_print_scalar_formatted. */ gdb_assert (options->format != 's'); - if (len > sizeof(LONGEST) - && (TYPE_CODE (type) == TYPE_CODE_INT - || TYPE_CODE (type) == TYPE_CODE_ENUM)) - { - switch (options->format) - { - case 'o': - print_octal_chars (stream, valaddr, len, byte_order); - return; - case 'u': - case 'd': - print_decimal_chars (stream, valaddr, len, !TYPE_UNSIGNED (type), - byte_order); - return; - case 't': - print_binary_chars (stream, valaddr, len, byte_order, size > 0); - return; - case 'x': - print_hex_chars (stream, valaddr, len, byte_order, size > 0); - return; - case 'z': - print_hex_chars (stream, valaddr, len, byte_order, true); - return; - case 'c': - print_char_chars (stream, type, valaddr, len, byte_order); - return; - default: - break; - }; - } - - if (options->format != 'f') - val_long = unpack_long (type, valaddr); - /* If the value is a pointer, and pointers and addresses are not the same, then at this point, the value's length (in target bytes) is gdbarch_addr_bit/TARGET_CHAR_BIT, not TYPE_LENGTH (type). */ @@ -406,58 +371,76 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, /* If we are printing it as unsigned, truncate it in case it is actually a negative signed value (e.g. "print/u (short)-1" should print 65535 (if shorts are 16 bits) instead of 4294967295). */ - if (options->format != 'd' || TYPE_UNSIGNED (type)) + if (options->format != 'c' + && (options->format != 'd' || TYPE_UNSIGNED (type))) { - if (len < sizeof (LONGEST)) - val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1; + if (len < TYPE_LENGTH (type) && byte_order == BFD_ENDIAN_BIG) + valaddr += TYPE_LENGTH (type) - len; } - switch (options->format) + if (size != 0 && (options->format == 'x' || options->format == 't')) { - case 'x': - if (!size) + /* Truncate to fit. */ + unsigned newlen; + switch (size) { - /* No size specified, like in print. Print varying # of digits. */ - print_longest (stream, 'x', 1, val_long); + case 'b': + newlen = 1; + break; + case 'h': + newlen = 2; + break; + case 'w': + newlen = 4; + break; + case 'g': + newlen = 8; + break; + default: + error (_("Undefined output size \"%c\"."), size); } - else - switch (size) - { - case 'b': - case 'h': - case 'w': - case 'g': - print_longest (stream, size, 1, val_long); - break; - default: - error (_("Undefined output size \"%c\"."), size); - } - break; + if (newlen < len && byte_order == BFD_ENDIAN_BIG) + valaddr += len - newlen; + len = newlen; + } - case 'd': - print_longest (stream, 'd', 1, val_long); + switch (options->format) + { + case 'o': + print_octal_chars (stream, valaddr, len, byte_order); break; - case 'u': - print_longest (stream, 'u', 0, val_long); + print_decimal_chars (stream, valaddr, len, false, byte_order); break; - - case 'o': - print_longest (stream, 'o', 1, val_long); + case 0: + case 'd': + if (TYPE_CODE (type) != TYPE_CODE_FLT) + { + print_decimal_chars (stream, valaddr, len, !TYPE_UNSIGNED (type), + byte_order); + break; + } + /* FALLTHROUGH */ + case 'f': + type = float_type_from_length (type); + print_floating (valaddr, type, stream); break; - case 'a': - { - CORE_ADDR addr = unpack_pointer (type, valaddr); - - print_address (gdbarch, addr, stream); - } + case 't': + print_binary_chars (stream, valaddr, len, byte_order, size > 0); + break; + case 'x': + print_hex_chars (stream, valaddr, len, byte_order, size > 0); + break; + case 'z': + print_hex_chars (stream, valaddr, len, byte_order, true); break; - case 'c': { struct value_print_options opts = *options; + LONGEST val_long = unpack_long (type, valaddr); + opts.format = 0; if (TYPE_UNSIGNED (type)) type = builtin_type (gdbarch)->builtin_true_unsigned_char; @@ -468,66 +451,14 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, } break; - case 'f': - type = float_type_from_length (type); - print_floating (valaddr, type, stream); - break; - - case 0: - internal_error (__FILE__, __LINE__, - _("failed internal consistency check")); - - case 't': - /* Binary; 't' stands for "two". */ + case 'a': { - char bits[8 * (sizeof val_long) + 1]; - char buf[8 * (sizeof val_long) + 32]; - char *cp = bits; - int width; - - if (!size) - width = 8 * (sizeof val_long); - else - switch (size) - { - case 'b': - width = 8; - break; - case 'h': - width = 16; - break; - case 'w': - width = 32; - break; - case 'g': - width = 64; - break; - default: - error (_("Undefined output size \"%c\"."), size); - } + CORE_ADDR addr = unpack_pointer (type, valaddr); - bits[width] = '\0'; - while (width-- > 0) - { - bits[width] = (val_long & 1) ? '1' : '0'; - val_long >>= 1; - } - if (!size) - { - while (*cp && *cp == '0') - cp++; - if (*cp == '\0') - cp--; - } - strncpy (buf, cp, sizeof (bits)); - fputs_filtered (buf, stream); + print_address (gdbarch, addr, stream); } break; - case 'z': - print_hex_chars (stream, valaddr, len, byte_order, true); - break; - default: error (_("Undefined output format \"%c\"."), options->format); }