From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103004 invoked by alias); 4 Nov 2016 17:15:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 100990 invoked by uid 89); 4 Nov 2016 17:15:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy=1046, 11567, 6157, 1042,7 X-HELO: mail-pf0-f194.google.com Received: from mail-pf0-f194.google.com (HELO mail-pf0-f194.google.com) (209.85.192.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Nov 2016 17:15:00 +0000 Received: by mail-pf0-f194.google.com with SMTP id i88so8467733pfk.2 for ; Fri, 04 Nov 2016 10:15:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=/xT+S408eOi2/FfRagmCjv6jCqV8HOthRDwqi3k4kNA=; b=SDzyiUD8V1R4Zvp5QgB8CUXjFcw7dTdqug14LXxtVhMw/H/1roCg6h0IYCpQLjSe3Q va+1n5XwZeK3Mo0unjm7cH19aGpaNkQKYF+EWu7XmD6F4LqYy4KtA4GTcNozTPBXaY1I CvPLf8Z2G6ELFkVG9Wzj2ogK6oTITemOw8jMkQKpykU1sLGe/Ix1oBWAP1hZjXIFNHrm yxh2LPWRxbnCElYHlbMe/B04iIUjnHuEeikUrhMx71n7rQndTNGmCOpRe56sxIeaxZz8 M1vqdAs+lRhVFlCgKA1SZ7Qo9zWyj8r03o7+yniImWTiNTx1bZ+6Kr/feeDc1y0gWhM9 nBZA== X-Gm-Message-State: ABUngve4hnb+Knofs1xv42JFCTI1t8dPmXCJ8s+R240PInAJ+DG5+qI3aO5oMCKrEqYGkA== X-Received: by 10.98.8.84 with SMTP id c81mr9917772pfd.114.1478279697365; Fri, 04 Nov 2016 10:14:57 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id xn11sm21769337pac.38.2016.11.04.10.14.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Nov 2016 10:14:57 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Remove parameter valaddr from la_val_print Date: Fri, 04 Nov 2016 17:15:00 -0000 Message-Id: <1478279691-25682-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1478279691-25682-1-git-send-email-yao.qi@linaro.org> References: <1478279691-25682-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00099.txt.bz2 Nowadays, we pass both val and return value of value_contents_for_printing (val) to la_val_print. The latter is unnecessary. This patch removes the second parameter of la_val_print, and get valaddr in each language's implementation by calling value_contents_for_printing_const. This change makes a little difference, because value_contents_for_printing calls value_fetch_lazy additionally, so I call value_fetch_lazy in the caller of val_print if needed. Note that - I don't clean up the valaddr usages in each language's routines, - I don't remove valaddr from apply_ext_lang_val_pretty_printer, and extension language ops apply_val_pretty_printer. They can be done in followup patches. gdb: 2016-11-04 Yao Qi * ada-lang.h (ada_val_print): Remove the second parameter. * ada-valprint.c (val_print_packed_array_elements): Call value_fetch_lazy. (print_field_values): Likewise. (ada_val_print_1): Remove parameter valaddr. (ada_val_print): Likewise. * c-lang.h (c_val_print): Remove the second parameter. * c-valprint.c (c_val_print): Likewise. Callers updated. * d-lang.h (d_val_print): Remove the second parameter. * d-valprint.c (d_val_print): Likewise. * f-lang.h (f_val_print): Likewise. * f-valprint.c (f_val_print): Likewise. * go-lang.h (go_val_print): Likewise. * go-valprint.c (go_val_print): Likewise. * language.h (struct language_defn) : Remove the second parameter. Update comments. (LA_VAL_PRINT): Remove. * m2-lang.h (m2_val_print): Remove the second parameter. * m2-valprint.c (m2_val_print): Likewise. * p-lang.h (pascal_val_print): Likewise. * p-valprint.c (pascal_val_print): Likewise. * rust-lang.c (rust_val_print): Remove the second parameter. * valprint.c (generic_val_print_array): Likewise. (generic_val_print_ptr): Likewise. Callers updated. (generic_val_print_memberptr): Likewise. Callers updated. (generic_val_print_ref): Likewise. (generic_val_print_enum): Likewise. (generic_val_print_flags): Likewise. (generic_val_print_func): Likewise. (generic_val_print_bool): Likewise. (generic_val_print_int): Likewise. (generic_val_print_char): Likewise. (generic_val_print_float): Likewise. (generic_val_print_decfloat): Likewise. (generic_val_print_complex): Likewise. (generic_val_print): Likewise. (val_print): Remove parameter valaddr. Update comments. Callers updated. Assert VAL must not be lazy. (value_print): Call value_fetch_lazy. (val_print_scalar_formatted): Remove parameter valaddr. Callers updated. Remove one assert. (val_print_array_elements): Remove parameter valaddr. * valprint.h (val_print_array_elements): Remove the second parameter. (val_print_scalar_formatted): Likewise. (generic_val_print): Likewise. * value.h (val_print): Remove the second parameter. --- gdb/ada-lang.h | 2 +- gdb/ada-valprint.c | 59 +++++++++++------- gdb/c-lang.h | 2 +- gdb/c-valprint.c | 23 ++++--- gdb/cp-valprint.c | 3 +- gdb/d-lang.h | 2 +- gdb/d-valprint.c | 7 ++- gdb/f-lang.h | 2 +- gdb/f-valprint.c | 17 +++-- gdb/go-lang.h | 2 +- gdb/go-valprint.c | 7 ++- gdb/infcmd.c | 3 - gdb/language.c | 2 +- gdb/language.h | 7 --- gdb/m2-lang.h | 2 +- gdb/m2-valprint.c | 14 +++-- gdb/mi/mi-main.c | 1 - gdb/mips-tdep.c | 1 - gdb/mt-tdep.c | 1 - gdb/p-lang.h | 2 +- gdb/p-valprint.c | 12 ++-- gdb/printcmd.c | 18 +++--- gdb/rust-lang.c | 13 ++-- gdb/sh64-tdep.c | 4 +- gdb/valprint.c | 177 +++++++++++++++++++++++++++++++++-------------------- gdb/valprint.h | 6 +- gdb/value.h | 2 +- 27 files changed, 230 insertions(+), 161 deletions(-) diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index 7de71eb..ddab592 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -168,7 +168,7 @@ extern void ada_print_type (struct type *, const char *, struct ui_file *, int, extern void ada_print_typedef (struct type *type, struct symbol *new_symbol, struct ui_file *stream); -extern void ada_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, +extern void ada_val_print (struct type *, int, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *); diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 6b4b6d4..8a84bbe 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -191,12 +191,15 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, break; } + if (value_lazy (v0)) + value_fetch_lazy (v0); + if (i - i0 > options->repeat_count_threshold) { struct value_print_options opts = *options; opts.deref_ref = 0; - val_print (elttype, value_contents_for_printing (v0), + val_print (elttype, value_embedded_offset (v0), 0, stream, recurse + 1, v0, &opts, current_language); annotate_elt_rep (i - i0); @@ -227,7 +230,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, maybe_print_array_index (index_type, j + low, stream, options); } - val_print (elttype, value_contents_for_printing (v0), + val_print (elttype, value_embedded_offset (v0), 0, stream, recurse + 1, v0, &opts, current_language); annotate_elt (); @@ -633,8 +636,6 @@ print_field_values (struct type *type, const gdb_byte *valaddr, if (TYPE_FIELD_PACKED (type, i)) { - struct value *v; - /* Bitfields require special handling, especially due to byte order problems. */ if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i)) @@ -643,6 +644,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, } else { + struct value *v; int bit_pos = TYPE_FIELD_BITPOS (type, i); int bit_size = TYPE_FIELD_BITSIZE (type, i); struct value_print_options opts; @@ -655,8 +657,9 @@ print_field_values (struct type *type, const gdb_byte *valaddr, bit_size, TYPE_FIELD_TYPE (type, i)); opts = *options; opts.deref_ref = 0; + if (value_lazy (v)) + value_fetch_lazy (v); val_print (TYPE_FIELD_TYPE (type, i), - value_contents_for_printing (v), value_embedded_offset (v), 0, stream, recurse + 1, v, &opts, language); @@ -667,7 +670,7 @@ print_field_values (struct type *type, const gdb_byte *valaddr, struct value_print_options opts = *options; opts.deref_ref = 0; - val_print (TYPE_FIELD_TYPE (type, i), valaddr, + val_print (TYPE_FIELD_TYPE (type, i), (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), 0, stream, recurse + 1, val, &opts, language); } @@ -754,9 +757,14 @@ ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr, fprintf_filtered (stream, "0x0"); } else - val_print (value_type (val), value_contents_for_printing (val), - value_embedded_offset (val), value_address (val), - stream, recurse, val, options, language); + { + if (value_lazy (val)) + value_fetch_lazy (val); + + val_print (value_type (val), + value_embedded_offset (val), value_address (val), + stream, recurse, val, options, language); + } value_free_to_mark (mark); } @@ -771,7 +779,7 @@ ada_val_print_ptr (struct type *type, const gdb_byte *valaddr, const struct value_print_options *options, const struct language_defn *language) { - val_print (type, valaddr, offset, address, stream, recurse, + val_print (type, offset, address, stream, recurse, original_value, options, language_def (language_c)); if (ada_is_tag_type (type)) @@ -820,12 +828,12 @@ ada_val_print_num (struct type *type, const gdb_byte *valaddr, = value_from_contents_and_address (type, valaddr + offset, 0); struct value *v = value_cast (target_type, v1); - val_print (target_type, value_contents_for_printing (v), + val_print (target_type, value_embedded_offset (v), 0, stream, recurse + 1, v, options, language); } else - val_print (TYPE_TARGET_TYPE (type), valaddr, offset, + val_print (TYPE_TARGET_TYPE (type), offset, address, stream, recurse, original_value, options, language); return; @@ -840,7 +848,7 @@ ada_val_print_num (struct type *type, const gdb_byte *valaddr, struct value_print_options opts = *options; opts.format = format; - val_print_scalar_formatted (type, valaddr, offset_aligned, + val_print_scalar_formatted (type, offset_aligned, original_value, &opts, 0, stream); } else if (ada_is_system_address_type (type)) @@ -894,12 +902,12 @@ ada_val_print_enum (struct type *type, const gdb_byte *valaddr, if (options->format) { - val_print_scalar_formatted (type, valaddr, offset_aligned, + val_print_scalar_formatted (type, offset_aligned, original_value, options, 0, stream); return; } - len = TYPE_NFIELDS (type); + val = unpack_long (type, valaddr + offset_aligned); for (i = 0; i < len; i++) { @@ -934,7 +942,7 @@ ada_val_print_flt (struct type *type, const gdb_byte *valaddr, { if (options->format) { - val_print (type, valaddr, offset, address, stream, recurse, + val_print (type, offset, address, stream, recurse, original_value, options, language_def (language_c)); return; } @@ -1000,7 +1008,7 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr, 0, stream, recurse, original_value, options); else - val_print_array_elements (type, valaddr, offset_aligned, address, + val_print_array_elements (type, offset_aligned, address, stream, recurse, original_value, options, 0); fprintf_filtered (stream, ")"); @@ -1062,8 +1070,9 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr, (Eg: an array whose bounds are not set yet). */ ada_ensure_varsize_limit (value_type (deref_val)); + if (value_lazy (deref_val)) + value_fetch_lazy (deref_val); val_print (value_type (deref_val), - value_contents_for_printing (deref_val), value_embedded_offset (deref_val), value_address (deref_val), stream, recurse + 1, deref_val, options, language); @@ -1073,7 +1082,7 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr, does not catch evaluation errors (leaving that to ada_val_print). */ static void -ada_val_print_1 (struct type *type, const gdb_byte *valaddr, +ada_val_print_1 (struct type *type, int offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, @@ -1081,6 +1090,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr, const struct language_defn *language) { int offset_aligned; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); type = ada_check_typedef (type); @@ -1102,7 +1113,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr, switch (TYPE_CODE (type)) { default: - val_print (type, valaddr, offset, address, stream, recurse, + val_print (type, offset, address, stream, recurse, original_value, options, language_def (language_c)); break; @@ -1156,7 +1167,7 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr, function; they are identical. */ void -ada_val_print (struct type *type, const gdb_byte *valaddr, +ada_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, @@ -1166,7 +1177,7 @@ ada_val_print (struct type *type, const gdb_byte *valaddr, /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */ TRY { - ada_val_print_1 (type, valaddr, embedded_offset, address, + ada_val_print_1 (type, embedded_offset, address, stream, recurse, val, options, current_language); } @@ -1219,9 +1230,11 @@ ada_value_print (struct value *val0, struct ui_file *stream, return; } + if (value_lazy (val)) + value_fetch_lazy (val); opts = *options; opts.deref_ref = 1; - val_print (type, value_contents_for_printing (val), + val_print (type, value_embedded_offset (val), address, stream, 0, val, &opts, current_language); } diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 12be8bf..dffba33 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -76,7 +76,7 @@ extern void c_print_typedef (struct type *, struct symbol *, struct ui_file *); -extern void c_val_print (struct type *, const gdb_byte *, +extern void c_val_print (struct type *, int, CORE_ADDR, struct ui_file *, int, const struct value *, diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 2cb418d..784541c 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -325,7 +325,7 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr, { i = 0; } - val_print_array_elements (type, valaddr, embedded_offset, + val_print_array_elements (type, embedded_offset, address, stream, recurse, original_value, options, i); fprintf_filtered (stream, "}"); @@ -353,7 +353,7 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr, if (options->format && options->format != 's') { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); } else if (options->vtblprint && cp_is_vtbl_ptr_type (type)) @@ -449,7 +449,7 @@ c_val_print_int (struct type *type, struct type *unresolved_type, opts.format = (options->format ? options->format : options->output_format); - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, &opts, 0, stream); } else @@ -485,7 +485,7 @@ c_val_print_memberptr (struct type *type, const gdb_byte *valaddr, } else { - generic_val_print (type, valaddr, embedded_offset, address, stream, + generic_val_print (type, embedded_offset, address, stream, recurse, original_value, options, &c_decorations); } } @@ -494,13 +494,15 @@ c_val_print_memberptr (struct type *type, const gdb_byte *valaddr, function; they are identical. */ void -c_val_print (struct type *type, const gdb_byte *valaddr, +c_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options) { struct type *unresolved_type = type; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); type = check_typedef (type); switch (TYPE_CODE (type)) @@ -554,7 +556,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, case TYPE_CODE_COMPLEX: case TYPE_CODE_CHAR: default: - generic_val_print (type, valaddr, embedded_offset, address, + generic_val_print (type, embedded_offset, address, stream, recurse, original_value, options, &c_decorations); break; @@ -666,10 +668,13 @@ c_value_print (struct value *val, struct ui_file *stream, fprintf_filtered (stream, "(%s%s) ", TYPE_NAME (real_type), full ? "" : _(" [incomplete object]")); + + if (value_lazy (val)) + value_fetch_lazy (val); /* Print out object: enclosing type is same as real_type if full. */ val_print (value_enclosing_type (val), - value_contents_for_printing (val), 0, + 0, value_address (val), stream, 0, val, &opts, current_language); return; @@ -682,7 +687,7 @@ c_value_print (struct value *val, struct ui_file *stream, fprintf_filtered (stream, "(%s ?) ", TYPE_NAME (value_enclosing_type (val))); val_print (value_enclosing_type (val), - value_contents_for_printing (val), 0, + 0, value_address (val), stream, 0, val, &opts, current_language); return; @@ -690,7 +695,7 @@ c_value_print (struct value *val, struct ui_file *stream, /* Otherwise, we end up at the return outside this "if". */ } - val_print (val_type, value_contents_for_printing (val), + val_print (val_type, value_embedded_offset (val), value_address (val), stream, 0, diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 5fb2561..227f591 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -353,7 +353,6 @@ cp_print_value_fields (struct type *type, struct type *real_type, opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), - valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, address, stream, recurse + 1, val, &opts, @@ -708,7 +707,7 @@ cp_print_static_field (struct type *type, opts = *options; opts.deref_ref = 0; - val_print (type, value_contents_for_printing (val), + val_print (type, value_embedded_offset (val), value_address (val), stream, recurse, val, diff --git a/gdb/d-lang.h b/gdb/d-lang.h index 74be7a5..b0ae514 100644 --- a/gdb/d-lang.h +++ b/gdb/d-lang.h @@ -80,7 +80,7 @@ extern struct block_symbol d_lookup_nested_symbol (struct type *, const char *, /* Defined in d-valprint.c */ -extern void d_val_print (struct type *type, const gdb_byte *valaddr, +extern void d_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c index 620688b..8c522ff 100644 --- a/gdb/d-valprint.c +++ b/gdb/d-valprint.c @@ -63,7 +63,6 @@ dynamic_array_type (struct type *type, const gdb_byte *valaddr, true_type = value_type (ival); d_val_print (true_type, - value_contents_for_printing (ival), value_embedded_offset (ival), addr, stream, recurse + 1, ival, options); return 0; @@ -73,12 +72,14 @@ dynamic_array_type (struct type *type, const gdb_byte *valaddr, /* Implements the la_val_print routine for language D. */ void -d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, +d_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options) { int ret; + const gdb_byte *valaddr + = value_contents_for_printing_const (val); type = check_typedef (type); switch (TYPE_CODE (type)) @@ -89,7 +90,7 @@ d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, if (ret == 0) break; default: - c_val_print (type, valaddr, embedded_offset, address, stream, + c_val_print (type, embedded_offset, address, stream, recurse, val, options); } } diff --git a/gdb/f-lang.h b/gdb/f-lang.h index 827785a..daffec9 100644 --- a/gdb/f-lang.h +++ b/gdb/f-lang.h @@ -30,7 +30,7 @@ extern void f_yyerror (char *); /* Defined in f-exp.y */ extern void f_print_type (struct type *, const char *, struct ui_file *, int, int, const struct type_print_options *); -extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, +extern void f_val_print (struct type *, int, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *); diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index e1a677e..3ca1ede 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -151,8 +151,10 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type, { struct value *elt = value_subscript ((struct value *)val, i); + if (value_lazy (elt)) + value_fetch_lazy (elt); + val_print (value_type (elt), - value_contents_for_printing (elt), value_embedded_offset (elt), value_address (elt), stream, recurse, elt, options, current_language); @@ -211,7 +213,7 @@ static const struct generic_val_print_decorations f_decorations = function; they are identical. */ void -f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, +f_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options) @@ -222,6 +224,8 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, struct type *elttype; CORE_ADDR addr; int index; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); type = check_typedef (type); switch (TYPE_CODE (type)) @@ -256,7 +260,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_PTR: if (options->format && options->format != 's') { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); break; } @@ -306,7 +310,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, opts.format = (options->format ? options->format : options->output_format); - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, &opts, 0, stream); } else @@ -354,8 +358,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, fputs_filtered (" = ", stream); } + if (value_lazy (field)) + value_fetch_lazy (field); val_print (value_type (field), - value_contents_for_printing (field), value_embedded_offset (field), value_address (field), stream, recurse + 1, field, options, current_language); @@ -378,7 +383,7 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: default: - generic_val_print (type, valaddr, embedded_offset, address, + generic_val_print (type, embedded_offset, address, stream, recurse, original_value, options, &f_decorations); break; diff --git a/gdb/go-lang.h b/gdb/go-lang.h index 5eb298e..cec62e8 100644 --- a/gdb/go-lang.h +++ b/gdb/go-lang.h @@ -84,7 +84,7 @@ extern void go_print_type (struct type *type, const char *varstring, /* Defined in go-valprint.c. */ -extern void go_val_print (struct type *type, const gdb_byte *valaddr, +extern void go_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, diff --git a/gdb/go-valprint.c b/gdb/go-valprint.c index 34ed8e0..1e5f33b 100644 --- a/gdb/go-valprint.c +++ b/gdb/go-valprint.c @@ -86,7 +86,7 @@ print_go_string (struct type *type, const gdb_byte *valaddr, /* Implements the la_val_print routine for language Go. */ void -go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, +go_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options) @@ -104,6 +104,9 @@ go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case GO_TYPE_STRING: if (! options->raw) { + const gdb_byte *valaddr + = value_contents_for_printing_const (val); + print_go_string (type, valaddr, embedded_offset, address, stream, recurse, val, options); return; @@ -116,7 +119,7 @@ go_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, /* Fall through. */ default: - c_val_print (type, valaddr, embedded_offset, address, stream, + c_val_print (type, embedded_offset, address, stream, recurse, val, options); break; } diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8e34b7e..05eb89e 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2320,7 +2320,6 @@ default_print_one_register_info (struct ui_file *file, opts.deref_ref = 1; val_print (regtype, - value_contents_for_printing (val), value_embedded_offset (val), 0, file, 0, val, &opts, current_language); @@ -2339,7 +2338,6 @@ default_print_one_register_info (struct ui_file *file, get_formatted_print_options (&opts, 'x'); opts.deref_ref = 1; val_print (regtype, - value_contents_for_printing (val), value_embedded_offset (val), 0, file, 0, val, &opts, current_language); /* If not a vector register, print it also according to its @@ -2350,7 +2348,6 @@ default_print_one_register_info (struct ui_file *file, opts.deref_ref = 1; fprintf_filtered (file, "\t"); val_print (regtype, - value_contents_for_printing (val), value_embedded_offset (val), 0, file, 0, val, &opts, current_language); } diff --git a/gdb/language.c b/gdb/language.c index 39faecc..f1ed5af 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -783,7 +783,7 @@ unk_lang_print_type (struct type *type, const char *varstring, } static void -unk_lang_val_print (struct type *type, const gdb_byte *valaddr, +unk_lang_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, diff --git a/gdb/language.h b/gdb/language.h index d6f932e..1dfb8d1 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -219,9 +219,6 @@ struct language_defn TYPE is the type of the sub-object to be printed. - CONTENTS holds the bits of the value. This holds the entire - enclosing object. - EMBEDDED_OFFSET is the offset into the outermost object of the sub-object represented by TYPE. This is the object which this call should print. Note that the enclosing type is not @@ -237,7 +234,6 @@ struct language_defn printing. */ void (*la_val_print) (struct type *type, - const gdb_byte *contents, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, @@ -515,9 +511,6 @@ extern enum language set_language (enum language); #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ (current_language->la_print_typedef(type,new_symbol,stream)) -#define LA_VAL_PRINT(type,valaddr,offset,addr,stream,val,recurse,options) \ - (current_language->la_val_print(type,valaddr,offset,addr,stream, \ - val,recurse,options)) #define LA_VALUE_PRINT(val,stream,options) \ (current_language->la_value_print(val,stream,options)) diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index b749b21..ed55c9c 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -34,7 +34,7 @@ extern void m2_print_typedef (struct type *, struct symbol *, extern int m2_is_long_set (struct type *type); extern int m2_is_unbounded_array (struct type *type); -extern void m2_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, +extern void m2_val_print (struct type *, int, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *); diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c index a53aa84..bfb8192 100644 --- a/gdb/m2-valprint.c +++ b/gdb/m2-valprint.c @@ -282,7 +282,7 @@ m2_print_array_contents (struct type *type, const gdb_byte *valaddr, else { fprintf_filtered (stream, "{"); - val_print_array_elements (type, valaddr, embedded_offset, + val_print_array_elements (type, embedded_offset, address, stream, recurse, val, options, 0); fprintf_filtered (stream, "}"); @@ -308,7 +308,7 @@ static const struct generic_val_print_decorations m2_decorations = function; they are identical. */ void -m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, +m2_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options) @@ -317,6 +317,8 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, unsigned len; struct type *elttype; CORE_ADDR addr; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); type = check_typedef (type); switch (TYPE_CODE (type)) @@ -356,7 +358,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, else { fprintf_filtered (stream, "{"); - val_print_array_elements (type, valaddr, embedded_offset, + val_print_array_elements (type, embedded_offset, address, stream, recurse, original_value, options, 0); @@ -373,7 +375,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, print_variable_at_address (type, valaddr + embedded_offset, stream, recurse, options); else if (options->format && options->format != 's') - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); else { @@ -469,7 +471,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_RANGE: if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type))) { - m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset, + m2_val_print (TYPE_TARGET_TYPE (type), embedded_offset, address, stream, recurse, original_value, options); break; } @@ -494,7 +496,7 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: default: - generic_val_print (type, valaddr, embedded_offset, address, + generic_val_print (type, embedded_offset, address, stream, recurse, original_value, options, &m2_decorations); break; diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 3b071af..3901203 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1290,7 +1290,6 @@ output_register (struct frame_info *frame, int regnum, int format, get_formatted_print_options (&opts, format); opts.deref_ref = 1; val_print (value_type (val), - value_contents_for_printing (val), value_embedded_offset (val), 0, stb, 0, val, &opts, current_language); ui_out_field_stream (uiout, "value", stb); diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index da4bef6..677c60c 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -6356,7 +6356,6 @@ mips_print_register (struct ui_file *file, struct frame_info *frame, get_formatted_print_options (&opts, 'x'); val_print_scalar_formatted (value_type (val), - value_contents_for_printing (val), value_embedded_offset (val), val, &opts, 0, file); diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c index c08e805..e958cc4 100644 --- a/gdb/mt-tdep.c +++ b/gdb/mt-tdep.c @@ -726,7 +726,6 @@ mt_registers_info (struct gdbarch *gdbarch, get_no_prettyformat_print_options (&opts); opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), - value_contents_for_printing (val), 0, 0, file, 0, val, &opts, current_language); fputs_filtered ("\n", file); diff --git a/gdb/p-lang.h b/gdb/p-lang.h index 287c0f4..66cb074 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -36,7 +36,7 @@ extern void pascal_print_type (struct type *, const char *, struct ui_file *, extern void pascal_print_typedef (struct type *, struct symbol *, struct ui_file *); -extern void pascal_val_print (struct type *, const gdb_byte *, int, +extern void pascal_val_print (struct type *, int, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *); diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index f639e29..b998501 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -58,7 +58,7 @@ static const struct generic_val_print_decorations p_decorations = function; they are identical. */ void -pascal_val_print (struct type *type, const gdb_byte *valaddr, +pascal_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, @@ -75,6 +75,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, struct type *char_type; CORE_ADDR addr; int want_space = 0; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); type = check_typedef (type); switch (TYPE_CODE (type)) @@ -132,7 +134,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, { i = 0; } - val_print_array_elements (type, valaddr, embedded_offset, + val_print_array_elements (type, embedded_offset, address, stream, recurse, original_value, options, i); fprintf_filtered (stream, "}"); @@ -146,7 +148,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, case TYPE_CODE_PTR: if (options->format && options->format != 's') { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); break; } @@ -287,7 +289,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, case TYPE_CODE_UNDEF: case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: - generic_val_print (type, valaddr, embedded_offset, address, + generic_val_print (type, embedded_offset, address, stream, recurse, original_value, options, &p_decorations); break; @@ -670,7 +672,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, address + TYPE_FIELD_BITPOS (type, i) / 8, 0, stream, format, 0, recurse + 1, pretty); */ val_print (TYPE_FIELD_TYPE (type, i), - valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, + offset + TYPE_FIELD_BITPOS (type, i) / 8, address, stream, recurse + 1, val, &opts, current_language); } diff --git a/gdb/printcmd.c b/gdb/printcmd.c index ea36009..c03541c 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -319,13 +319,17 @@ print_formatted (struct value *val, int size, || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) value_print (val, stream, options); else - /* User specified format, so don't look to the type to tell us - what to do. */ - val_print_scalar_formatted (type, - value_contents_for_printing (val), - value_embedded_offset (val), - val, - options, size, stream); + { + if (value_lazy (val)) + value_fetch_lazy (val); + + /* User specified format, so don't look to the type to tell us + what to do. */ + val_print_scalar_formatted (type, + value_embedded_offset (val), + val, + options, size, stream); + } } /* Return builtin floating point type of same length as TYPE. diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index edf65e5..a5095cf 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -236,7 +236,7 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, cleanup = make_cleanup_ui_file_delete (temp_file); /* The first value of the first field (or any field) is the discriminant value. */ - c_val_print (TYPE_FIELD_TYPE (disr_type, 0), valaddr, + c_val_print (TYPE_FIELD_TYPE (disr_type, 0), (embedded_offset + TYPE_FIELD_BITPOS (type, 0) / 8 + TYPE_FIELD_BITPOS (disr_type, 0) / 8), address, temp_file, @@ -538,7 +538,6 @@ val_print_struct (struct type *type, const gdb_byte *valaddr, } val_print (TYPE_FIELD_TYPE (type, i), - valaddr, embedded_offset + TYPE_FIELD_BITPOS (type, i) / 8, address, stream, recurse + 1, val, &opts, @@ -574,11 +573,14 @@ static const struct generic_val_print_decorations rust_decorations = /* la_val_print implementation for Rust. */ static void -rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, +rust_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options) { + const gdb_byte *valaddr + = value_contents_for_printing_const (val); + type = check_typedef (type); switch (TYPE_CODE (type)) { @@ -615,7 +617,7 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, case TYPE_CODE_METHODPTR: case TYPE_CODE_MEMBERPTR: - c_val_print (type, valaddr, embedded_offset, address, stream, + c_val_print (type, embedded_offset, address, stream, recurse, val, options); break; @@ -732,7 +734,6 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, TYPE_FIELD_NAME (variant_type, j)); val_print (TYPE_FIELD_TYPE (variant_type, j), - valaddr, (embedded_offset + TYPE_FIELD_BITPOS (type, disr.field_no) / 8 + TYPE_FIELD_BITPOS (variant_type, j) / 8), @@ -759,7 +760,7 @@ rust_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, default: generic_print: /* Nothing special yet. */ - generic_val_print (type, valaddr, embedded_offset, address, stream, + generic_val_print (type, embedded_offset, address, stream, recurse, val, options, &rust_decorations); } } diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c index 9054e20..bd2d4f7 100644 --- a/gdb/sh64-tdep.c +++ b/gdb/sh64-tdep.c @@ -2048,13 +2048,13 @@ sh64_do_register (struct gdbarch *gdbarch, struct ui_file *file, get_formatted_print_options (&opts, 'x'); opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), - value_contents_for_printing (val), 0, 0, + 0, 0, file, 0, val, &opts, current_language); fprintf_filtered (file, "\t"); get_formatted_print_options (&opts, 0); opts.deref_ref = 1; val_print (register_type (gdbarch, regnum), - value_contents_for_printing (val), 0, 0, + 0, 0, file, 0, val, &opts, current_language); fprintf_filtered (file, "\n"); } diff --git a/gdb/valprint.c b/gdb/valprint.c index ca30a7f..e25bd49 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -421,7 +421,7 @@ print_unpacked_pointer (struct type *type, struct type *elttype, /* generic_val_print helper for TYPE_CODE_ARRAY. */ static void -generic_val_print_array (struct type *type, const gdb_byte *valaddr, +generic_val_print_array (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, @@ -445,7 +445,7 @@ generic_val_print_array (struct type *type, const gdb_byte *valaddr, } fputs_filtered (decorations->array_start, stream); - val_print_array_elements (type, valaddr, embedded_offset, + val_print_array_elements (type, embedded_offset, address, stream, recurse, original_value, options, 0); fputs_filtered (decorations->array_end, stream); @@ -462,7 +462,7 @@ generic_val_print_array (struct type *type, const gdb_byte *valaddr, /* generic_val_print helper for TYPE_CODE_PTR. */ static void -generic_val_print_ptr (struct type *type, const gdb_byte *valaddr, +generic_val_print_ptr (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -472,13 +472,15 @@ generic_val_print_ptr (struct type *type, const gdb_byte *valaddr, if (options->format && options->format != 's') { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); } else { struct type *unresolved_elttype = TYPE_TARGET_TYPE(type); struct type *elttype = check_typedef (unresolved_elttype); + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset * unit_size); @@ -490,12 +492,12 @@ generic_val_print_ptr (struct type *type, const gdb_byte *valaddr, /* generic_val_print helper for TYPE_CODE_MEMBERPTR. */ static void -generic_val_print_memberptr (struct type *type, const gdb_byte *valaddr, +generic_val_print_memberptr (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); } @@ -538,7 +540,7 @@ get_value_addr_contents (struct value *deref_val) /* generic_val_print helper for TYPE_CODE_REF. */ static void -generic_val_print_ref (struct type *type, const gdb_byte *valaddr, +generic_val_print_ref (struct type *type, int embedded_offset, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options) @@ -552,6 +554,8 @@ generic_val_print_ref (struct type *type, const gdb_byte *valaddr, const int must_coerce_ref = ((options->addressprint && value_is_synthetic) || options->deref_ref); const int type_is_defined = TYPE_CODE (elttype) != TYPE_CODE_UNDEF; + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); if (must_coerce_ref && type_is_defined) { @@ -663,7 +667,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val, /* generic_val_print helper for TYPE_CODE_ENUM. */ static void -generic_val_print_enum (struct type *type, const gdb_byte *valaddr, +generic_val_print_enum (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -674,35 +678,45 @@ generic_val_print_enum (struct type *type, const gdb_byte *valaddr, if (options->format) { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); - return; } - val = unpack_long (type, valaddr + embedded_offset * unit_size); + else + { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); - generic_val_print_enum_1 (type, val, stream); + val = unpack_long (type, valaddr + embedded_offset * unit_size); + + generic_val_print_enum_1 (type, val, stream); + } } /* generic_val_print helper for TYPE_CODE_FLAGS. */ static void -generic_val_print_flags (struct type *type, const gdb_byte *valaddr, +generic_val_print_flags (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) { if (options->format) - val_print_scalar_formatted (type, valaddr, embedded_offset, original_value, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); else - val_print_type_code_flags (type, valaddr + embedded_offset, stream); + { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + + val_print_type_code_flags (type, valaddr + embedded_offset, stream); + } } /* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD. */ static void -generic_val_print_func (struct type *type, const gdb_byte *valaddr, +generic_val_print_func (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, const struct value *original_value, @@ -712,7 +726,7 @@ generic_val_print_func (struct type *type, const gdb_byte *valaddr, if (options->format) { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); } else @@ -731,7 +745,7 @@ generic_val_print_func (struct type *type, const gdb_byte *valaddr, /* generic_val_print helper for TYPE_CODE_BOOL. */ static void -generic_val_print_bool (struct type *type, const gdb_byte *valaddr, +generic_val_print_bool (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options, @@ -746,11 +760,14 @@ generic_val_print_bool (struct type *type, const gdb_byte *valaddr, struct value_print_options opts = *options; opts.format = (options->format ? options->format : options->output_format); - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, &opts, 0, stream); } else { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + val = unpack_long (type, valaddr + embedded_offset * unit_size); if (val == 0) fputs_filtered (decorations->false_name, stream); @@ -764,7 +781,7 @@ generic_val_print_bool (struct type *type, const gdb_byte *valaddr, /* generic_val_print helper for TYPE_CODE_INT. */ static void -generic_val_print_int (struct type *type, const gdb_byte *valaddr, +generic_val_print_int (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -778,19 +795,24 @@ generic_val_print_int (struct type *type, const gdb_byte *valaddr, opts.format = (options->format ? options->format : options->output_format); - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, &opts, 0, stream); } else - val_print_type_code_int (type, valaddr + embedded_offset * unit_size, - stream); + { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + + val_print_type_code_int (type, valaddr + embedded_offset * unit_size, + stream); + } } /* generic_val_print helper for TYPE_CODE_CHAR. */ static void generic_val_print_char (struct type *type, struct type *unresolved_type, - const gdb_byte *valaddr, int embedded_offset, + int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -805,11 +827,14 @@ generic_val_print_char (struct type *type, struct type *unresolved_type, opts.format = (options->format ? options->format : options->output_format); - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, &opts, 0, stream); } else { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + val = unpack_long (type, valaddr + embedded_offset * unit_size); if (TYPE_UNSIGNED (type)) fprintf_filtered (stream, "%u", (unsigned int) val); @@ -823,7 +848,7 @@ generic_val_print_char (struct type *type, struct type *unresolved_type, /* generic_val_print helper for TYPE_CODE_FLT. */ static void -generic_val_print_float (struct type *type, const gdb_byte *valaddr, +generic_val_print_float (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -833,11 +858,14 @@ generic_val_print_float (struct type *type, const gdb_byte *valaddr, if (options->format) { - val_print_scalar_formatted (type, valaddr, embedded_offset, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); } else { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + print_floating (valaddr + embedded_offset * unit_size, type, stream); } } @@ -845,7 +873,7 @@ generic_val_print_float (struct type *type, const gdb_byte *valaddr, /* generic_val_print helper for TYPE_CODE_DECFLOAT. */ static void -generic_val_print_decfloat (struct type *type, const gdb_byte *valaddr, +generic_val_print_decfloat (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options) @@ -854,17 +882,22 @@ generic_val_print_decfloat (struct type *type, const gdb_byte *valaddr, int unit_size = gdbarch_addressable_memory_unit_size (gdbarch); if (options->format) - val_print_scalar_formatted (type, valaddr, embedded_offset, original_value, + val_print_scalar_formatted (type, embedded_offset, original_value, options, 0, stream); else - print_decimal_floating (valaddr + embedded_offset * unit_size, type, - stream); + { + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); + + print_decimal_floating (valaddr + embedded_offset * unit_size, type, + stream); + } } /* generic_val_print helper for TYPE_CODE_COMPLEX. */ static void -generic_val_print_complex (struct type *type, const gdb_byte *valaddr, +generic_val_print_complex (struct type *type, int embedded_offset, struct ui_file *stream, const struct value *original_value, const struct value_print_options *options, @@ -873,10 +906,12 @@ generic_val_print_complex (struct type *type, const gdb_byte *valaddr, { struct gdbarch *gdbarch = get_type_arch (type); int unit_size = gdbarch_addressable_memory_unit_size (gdbarch); + const gdb_byte *valaddr + = value_contents_for_printing_const (original_value); fprintf_filtered (stream, "%s", decorations->complex_prefix); if (options->format) - val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr, + val_print_scalar_formatted (TYPE_TARGET_TYPE (type), embedded_offset, original_value, options, 0, stream); else @@ -884,7 +919,7 @@ generic_val_print_complex (struct type *type, const gdb_byte *valaddr, TYPE_TARGET_TYPE (type), stream); fprintf_filtered (stream, "%s", decorations->complex_infix); if (options->format) - val_print_scalar_formatted (TYPE_TARGET_TYPE (type), valaddr, + val_print_scalar_formatted (TYPE_TARGET_TYPE (type), embedded_offset + type_length_units (TYPE_TARGET_TYPE (type)), original_value, options, 0, stream); @@ -907,7 +942,7 @@ generic_val_print_complex (struct type *type, const gdb_byte *valaddr, output in some small, language-specific ways. */ void -generic_val_print (struct type *type, const gdb_byte *valaddr, +generic_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, @@ -920,43 +955,43 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: - generic_val_print_array (type, valaddr, embedded_offset, address, stream, + generic_val_print_array (type, embedded_offset, address, stream, recurse, original_value, options, decorations); break; case TYPE_CODE_MEMBERPTR: - generic_val_print_memberptr (type, valaddr, embedded_offset, stream, + generic_val_print_memberptr (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_PTR: - generic_val_print_ptr (type, valaddr, embedded_offset, stream, + generic_val_print_ptr (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_REF: - generic_val_print_ref (type, valaddr, embedded_offset, stream, recurse, + generic_val_print_ref (type, embedded_offset, stream, recurse, original_value, options); break; case TYPE_CODE_ENUM: - generic_val_print_enum (type, valaddr, embedded_offset, stream, + generic_val_print_enum (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_FLAGS: - generic_val_print_flags (type, valaddr, embedded_offset, stream, + generic_val_print_flags (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_FUNC: case TYPE_CODE_METHOD: - generic_val_print_func (type, valaddr, embedded_offset, address, stream, + generic_val_print_func (type, embedded_offset, address, stream, original_value, options); break; case TYPE_CODE_BOOL: - generic_val_print_bool (type, valaddr, embedded_offset, stream, + generic_val_print_bool (type, embedded_offset, stream, original_value, options, decorations); break; @@ -972,22 +1007,22 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, /* FALLTHROUGH */ case TYPE_CODE_INT: - generic_val_print_int (type, valaddr, embedded_offset, stream, + generic_val_print_int (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_CHAR: - generic_val_print_char (type, unresolved_type, valaddr, embedded_offset, + generic_val_print_char (type, unresolved_type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_FLT: - generic_val_print_float (type, valaddr, embedded_offset, stream, + generic_val_print_float (type, embedded_offset, stream, original_value, options); break; case TYPE_CODE_DECFLOAT: - generic_val_print_decfloat (type, valaddr, embedded_offset, stream, + generic_val_print_decfloat (type, embedded_offset, stream, original_value, options); break; @@ -1007,7 +1042,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_COMPLEX: - generic_val_print_complex (type, valaddr, embedded_offset, stream, + generic_val_print_complex (type, embedded_offset, stream, original_value, options, decorations); break; @@ -1022,15 +1057,14 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, } /* Print using the given LANGUAGE the data of type TYPE located at - VALADDR + EMBEDDED_OFFSET (within GDB), which came from the - inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream - STREAM according to OPTIONS. VAL is the whole object that came - from ADDRESS. VALADDR must point to the head of VAL's contents - buffer. + VAL's contents buffer + EMBEDDED_OFFSET (within GDB), which came + from the inferior at address ADDRESS + EMBEDDED_OFFSET, onto + stdio stream STREAM according to OPTIONS. VAL is the whole object + that came from ADDRESS. The language printers will pass down an adjusted EMBEDDED_OFFSET to further helper subroutines as subfields of TYPE are printed. In - such cases, VALADDR is passed down unadjusted, as well as VAL, so + such cases, VAL is passed down unadjusted, so that VAL can be queried for metadata about the contents data being printed, using EMBEDDED_OFFSET as an offset into VAL's contents buffer. For example: "has this field been optimized out", or "I'm @@ -1042,7 +1076,7 @@ generic_val_print (struct type *type, const gdb_byte *valaddr, RECURSE. */ void -val_print (struct type *type, const gdb_byte *valaddr, LONGEST embedded_offset, +val_print (struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, const struct value_print_options *options, @@ -1072,8 +1106,13 @@ val_print (struct type *type, const gdb_byte *valaddr, LONGEST embedded_offset, if (!valprint_check_validity (stream, real_type, embedded_offset, val)) return; + /* All its contents must be fetched before printing. */ + gdb_assert (!value_lazy (val)); + if (!options->raw) { + const gdb_byte *valaddr = value_contents_for_printing_const (val); + ret = apply_ext_lang_val_pretty_printer (type, valaddr, embedded_offset, address, stream, recurse, val, options, language); @@ -1091,7 +1130,7 @@ val_print (struct type *type, const gdb_byte *valaddr, LONGEST embedded_offset, TRY { - language->la_val_print (type, valaddr, embedded_offset, address, + language->la_val_print (type, embedded_offset, address, stream, recurse, val, &local_opts); } @@ -1177,7 +1216,10 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse, get a fixed representation of our value. */ val = ada_to_fixed_value (val); - val_print (value_type (val), value_contents_for_printing (val), + if (value_lazy (val)) + value_fetch_lazy (val); + + val_print (value_type (val), value_embedded_offset (val), value_address (val), stream, recurse, val, options, language); @@ -1207,6 +1249,8 @@ value_print (struct value *val, struct ui_file *stream, return; } + if (value_lazy (val)) + value_fetch_lazy (val); LA_VALUE_PRINT (val, stream, options); } @@ -1303,7 +1347,7 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr, void val_print_scalar_formatted (struct type *type, - const gdb_byte *valaddr, LONGEST embedded_offset, + LONGEST embedded_offset, const struct value *val, const struct value_print_options *options, int size, @@ -1313,7 +1357,6 @@ val_print_scalar_formatted (struct type *type, int unit_size = gdbarch_addressable_memory_unit_size (arch); gdb_assert (val != NULL); - gdb_assert (valaddr == value_contents_for_printing_const (val)); /* 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 @@ -1323,7 +1366,7 @@ val_print_scalar_formatted (struct type *type, struct value_print_options opts = *options; opts.format = 0; opts.deref_ref = 0; - val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts, + val_print (type, embedded_offset, 0, stream, 0, val, &opts, current_language); return; } @@ -1337,8 +1380,12 @@ val_print_scalar_formatted (struct type *type, else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) val_print_unavailable (stream); else - print_scalar_formatted (valaddr + embedded_offset * unit_size, type, - options, size, stream); + { + const gdb_byte *valaddr = value_contents_for_printing_const (val); + + print_scalar_formatted (valaddr + embedded_offset * unit_size, type, + options, size, stream); + } } /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. @@ -1965,7 +2012,7 @@ maybe_print_array_index (struct type *index_type, LONGEST index, void val_print_array_elements (struct type *type, - const gdb_byte *valaddr, LONGEST embedded_offset, + LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, @@ -2066,7 +2113,7 @@ val_print_array_elements (struct type *type, if (reps > options->repeat_count_threshold) { - val_print (elttype, valaddr, embedded_offset + i * eltlen, + val_print (elttype, embedded_offset + i * eltlen, address, stream, recurse + 1, val, options, current_language); annotate_elt_rep (reps); @@ -2078,7 +2125,7 @@ val_print_array_elements (struct type *type, } else { - val_print (elttype, valaddr, embedded_offset + i * eltlen, + val_print (elttype, embedded_offset + i * eltlen, address, stream, recurse + 1, val, options, current_language); annotate_elt (); diff --git a/gdb/valprint.h b/gdb/valprint.h index a0f7391..99e29a1 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -115,7 +115,7 @@ extern void maybe_print_array_index (struct type *index_type, LONGEST index, struct ui_file *stream, const struct value_print_options *); -extern void val_print_array_elements (struct type *, const gdb_byte *, LONGEST, +extern void val_print_array_elements (struct type *, LONGEST, CORE_ADDR, struct ui_file *, int, const struct value *, const struct value_print_options *, @@ -125,7 +125,7 @@ extern void val_print_type_code_int (struct type *, const gdb_byte *, struct ui_file *); extern void val_print_scalar_formatted (struct type *, - const gdb_byte *, LONGEST, + LONGEST, const struct value *, const struct value_print_options *, int, @@ -193,7 +193,7 @@ struct generic_val_print_decorations }; -extern void generic_val_print (struct type *type, const gdb_byte *valaddr, +extern void generic_val_print (struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, diff --git a/gdb/value.h b/gdb/value.h index 3299e87..fe4033d 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1016,7 +1016,7 @@ extern void value_print_array_elements (struct value *val, extern struct value *value_release_to_mark (const struct value *mark); -extern void val_print (struct type *type, const gdb_byte *valaddr, +extern void val_print (struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *val, -- 1.9.1