From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 6D77E394B02F; Sat, 14 Mar 2020 00:07:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D77E394B02F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1584144447; bh=7DuSdU/5z5+hK2D3t5+rPXefGXTyY+M+zk20dUfgMS4=; h=From:To:Subject:Date:From; b=LSMNtpSwV+12vnjJAdNym/aoAAtcEnovq2+nraNaoJni2twr50Bd7mL4vF0EuP9h1 NULE0ScV3pBDrH08dR003aAxsBK7FMDXNOU/iYPAjP3oidlO8SwegPzpd3Pht7+Y9V huszIZSIjwARWK6epX12nmP3y3mry9ITv1zj6kzg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Introduce generic_value_print_char X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: fdddfccba1cc4f70089873441b7e6c38de09ae37 X-Git-Newrev: 3eec3b05b9ecf5e726c606f0bba916e095dcbe98 Message-Id: <20200314000727.6D77E394B02F@sourceware.org> Date: Sat, 14 Mar 2020 00:07:27 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Mar 2020 00:07:27 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3eec3b05b9ecf5e726c606f0bba916e095dcbe98 commit 3eec3b05b9ecf5e726c606f0bba916e095dcbe98 Author: Tom Tromey Date: Fri Mar 13 17:39:52 2020 -0600 Introduce generic_value_print_char This adds generic_value_print_char, a value-based analogue of generic_val_print_char. gdb/ChangeLog 2020-03-13 Tom Tromey * valprint.c (generic_value_print_char): New function (generic_value_print): Use it. Diff: --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2ca8e66a122..ccf0d1e421d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-03-13 Tom Tromey + + * valprint.c (generic_value_print_char): New function + (generic_value_print): Use it. + 2020-03-13 Tom Tromey * valprint.c (generic_value_print_int): New function. diff --git a/gdb/valprint.c b/gdb/valprint.c index c9ad2749272..8c2d1aa1955 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -883,6 +883,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 @@ -1084,7 +1114,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)) @@ -1151,8 +1180,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: