From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E6DE83AAA088; Sat, 14 Mar 2020 00:05:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6DE83AAA088 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1584144320; bh=OY1wlogkjuczHXLZoO/sMKSvNrzfmhsMsFwO8R+expA=; h=From:To:Subject:Date:From; b=dJYMwgBda6aCC4w2pSz5ZTBtVStu8ZX5hUJXpskLwinwXhiUNHBC/Bx6ub3y2Iuzz yOCNaZRPb3P6ZNyBV/jK+IHLcIaGG/JmA3I2xirfjY2u6dMSWUbsQ/UB9CMI3rl1uN fLl9SzVtmoG9wKJpr17rsnqGa+VQViNzKgbylygU= 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 value_print_scalar_formatted X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 156bfec999186e3eccaf51fa3b81280bf51dbaa4 X-Git-Newrev: 4f9ae810130bc4202ec1c5eae934900c542a9016 Message-Id: <20200314000520.E6DE83AAA088@sourceware.org> Date: Sat, 14 Mar 2020 00:05:20 +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:05:21 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4f9ae810130bc4202ec1c5eae934900c542a9016 commit 4f9ae810130bc4202ec1c5eae934900c542a9016 Author: Tom Tromey Date: Fri Mar 13 17:39:52 2020 -0600 Introduce value_print_scalar_formatted This introduces a value_print_scalar_formatted, which is an analogue of val_print_scalar_formatted that uses the value API. gdb/ChangeLog 2020-03-13 Tom Tromey * valprint.h (value_print_scalar_formatted): Declare. * valprint.c (value_print_scalar_formatted): New function. Diff: --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 40 ++++++++++++++++++++++++++++++++++++++++ gdb/valprint.h | 10 ++++++++++ 3 files changed, 55 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 48572cb4d2a..264565edf19 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-03-13 Tom Tromey + + * valprint.h (value_print_scalar_formatted): Declare. + * valprint.c (value_print_scalar_formatted): New function. + 2020-03-13 Tom Tromey * valprint.h (generic_value_print): Declare. diff --git a/gdb/valprint.c b/gdb/valprint.c index 7b0365a3ba8..9cdf18ee864 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1394,6 +1394,46 @@ val_print_scalar_formatted (struct type *type, options, size, stream); } +/* See valprint.h. */ + +void +value_print_scalar_formatted (struct value *val, + const struct value_print_options *options, + int size, + struct ui_file *stream) +{ + struct type *type = check_typedef (value_type (val)); + + gdb_assert (val != NULL); + + /* If we get here with a string format, try again without it. Go + all the way back to the language printers, which may call us + again. */ + if (options->format == 's') + { + struct value_print_options opts = *options; + opts.format = 0; + opts.deref_ref = 0; + common_val_print (val, stream, 0, &opts, current_language); + return; + } + + /* value_contents_for_printing fetches all VAL's contents. They are + needed to check whether VAL is optimized-out or unavailable + below. */ + const gdb_byte *valaddr = value_contents_for_printing (val); + + /* A scalar object that does not have all bits available can't be + printed, because all bits contribute to its representation. */ + if (value_bits_any_optimized_out (val, 0, + TARGET_CHAR_BIT * TYPE_LENGTH (type))) + val_print_optimized_out (val, stream); + else if (!value_bytes_available (val, 0, TYPE_LENGTH (type))) + val_print_unavailable (stream); + else + print_scalar_formatted (valaddr, type, options, size, stream); +} + /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. The raison d'etre of this function is to consolidate printing of LONG_LONG's into this one function. The format chars b,h,w,g are diff --git a/gdb/valprint.h b/gdb/valprint.h index 1aca29463f4..90df12dbd7e 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -141,6 +141,16 @@ extern void val_print_scalar_formatted (struct type *, int, struct ui_file *); +/* Print a scalar according to OPTIONS and SIZE on STREAM. Format 'i' + is not supported at this level. + + This is how the elements of an array or structure are printed + with a format. */ + +extern void value_print_scalar_formatted + (struct value *val, const struct value_print_options *options, + int size, struct ui_file *stream); + extern void print_binary_chars (struct ui_file *, const gdb_byte *, unsigned int, enum bfd_endian, bool);