diff options
author | Tom Tromey <tom@tromey.com> | 2020-03-13 17:39:52 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-03-13 18:03:42 -0600 |
commit | 426a9c18dddcdd5f640b702734dd8f9c108b7372 (patch) | |
tree | d9ba80f648c60ab6d3a95de00187889200459f8f /gdb/cp-valprint.c | |
parent | 42331a1ea2a13ce15ec202c5f0fbef3e5171253c (diff) | |
download | gdb-426a9c18dddcdd5f640b702734dd8f9c108b7372.zip gdb-426a9c18dddcdd5f640b702734dd8f9c108b7372.tar.gz gdb-426a9c18dddcdd5f640b702734dd8f9c108b7372.tar.bz2 |
Remove val_print
We can finally remove val_print and various helper functions that are
no longer needed.
gdb/ChangeLog
2020-03-13 Tom Tromey <tom@tromey.com>
* value.h (val_print): Don't declare.
* valprint.h (val_print_array_elements)
(val_print_scalar_formatted, generic_val_print): Don't declare.
* valprint.c (generic_val_print_array): Take a struct value.
(generic_val_print_ptr, generic_val_print_memberptr)
(generic_val_print_bool, generic_val_print_int)
(generic_val_print_char, generic_val_print_complex)
(generic_val_print): Remove.
(generic_value_print): Update.
(do_val_print): Remove unused parameters. Don't call
la_val_print.
(val_print): Remove.
(common_val_print): Update. Don't call value_check_printable.
(val_print_scalar_formatted, val_print_array_elements): Remove.
* rust-lang.c (rust_val_print): Remove.
(rust_language_defn): Update.
* p-valprint.c (pascal_val_print): Remove.
(pascal_value_print_inner): Update.
(pascal_object_print_val_fields, pascal_object_print_val):
Remove.
(pascal_object_print_static_field): Update.
* p-lang.h (pascal_val_print): Don't declare.
* p-lang.c (pascal_language_defn): Update.
* opencl-lang.c (opencl_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* m2-valprint.c (m2_print_unbounded_array, m2_val_print): Remove.
* m2-lang.h (m2_val_print): Don't declare.
* m2-lang.c (m2_language_defn): Update.
* language.h (struct language_defn) <la_val_print>: Remove.
* language.c (unk_lang_value_print_inner): Rename. Change
argument types.
(unknown_language_defn, auto_language_defn): Update.
* go-valprint.c (go_val_print): Remove.
* go-lang.h (go_val_print): Don't declare.
* go-lang.c (go_language_defn): Update.
* f-valprint.c (f_val_print): Remove.
* f-lang.h (f_value_print): Don't declare.
* f-lang.c (f_language_defn): Update.
* d-valprint.c (d_val_print): Remove.
* d-lang.h (d_value_print): Don't declare.
* d-lang.c (d_language_defn): Update.
* cp-valprint.c (cp_print_value_fields)
(cp_print_value_fields_rtti, cp_print_value): Remove.
(cp_print_static_field): Update.
* c-valprint.c (c_val_print_array, c_val_print_ptr)
(c_val_print_struct, c_val_print_union, c_val_print_int)
(c_val_print_memberptr, c_val_print): Remove.
* c-lang.h (c_val_print_array, cp_print_value_fields)
(cp_print_value_fields_rtti): Don't declare.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* ada-valprint.c (ada_val_print_ptr, ada_val_print_num): Remove.
(ada_val_print_enum): Take a struct value.
(ada_val_print_flt, ada_val_print_array, ada_val_print_1)
(ada_val_print): Remove.
(ada_value_print_1): Update.
(printable_val_type): Remove.
* ada-lang.h (ada_val_print): Don't declare.
* ada-lang.c (ada_language_defn): Update.
Diffstat (limited to 'gdb/cp-valprint.c')
-rw-r--r-- | gdb/cp-valprint.c | 514 |
1 files changed, 3 insertions, 511 deletions
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 5e4cb3c..5625a58 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -47,13 +47,6 @@ static void cp_print_static_field (struct type *, struct value *, struct ui_file *, int, const struct value_print_options *); -static void cp_print_value (struct type *, struct type *, - LONGEST, - CORE_ADDR, struct ui_file *, - int, struct value *, - const struct value_print_options *, - struct type **); - static void cp_print_value (struct value *, struct ui_file *, int, const struct value_print_options *, struct type **); @@ -125,287 +118,6 @@ cp_is_vtbl_member (struct type *type) or zero if called from top level. */ void -cp_print_value_fields (struct type *type, struct type *real_type, - LONGEST offset, - CORE_ADDR address, struct ui_file *stream, - int recurse, struct value *val, - const struct value_print_options *options, - struct type **dont_print_vb, - int dont_print_statmem) -{ - int i, len, n_baseclasses; - int fields_seen = 0; - static int last_set_recurse = -1; - - type = check_typedef (type); - - if (recurse == 0) - { - /* Any object can be left on obstacks only during an unexpected - error. */ - - if (obstack_object_size (&dont_print_statmem_obstack) > 0) - { - obstack_free (&dont_print_statmem_obstack, NULL); - obstack_begin (&dont_print_statmem_obstack, - 32 * sizeof (CORE_ADDR)); - } - if (obstack_object_size (&dont_print_stat_array_obstack) > 0) - { - obstack_free (&dont_print_stat_array_obstack, NULL); - obstack_begin (&dont_print_stat_array_obstack, - 32 * sizeof (struct type *)); - } - } - - fprintf_filtered (stream, "{"); - len = TYPE_NFIELDS (type); - n_baseclasses = TYPE_N_BASECLASSES (type); - - /* First, print out baseclasses such that we don't print - duplicates of virtual baseclasses. */ - - if (n_baseclasses > 0) - cp_print_value (type, real_type, - offset, address, stream, - recurse + 1, val, options, - dont_print_vb); - - /* Second, print out data fields */ - - /* If there are no data fields, skip this part */ - if (len == n_baseclasses || !len) - fprintf_styled (stream, metadata_style.style (), "<No data fields>"); - else - { - size_t statmem_obstack_initial_size = 0; - size_t stat_array_obstack_initial_size = 0; - struct type *vptr_basetype = NULL; - int vptr_fieldno; - - if (dont_print_statmem == 0) - { - statmem_obstack_initial_size = - obstack_object_size (&dont_print_statmem_obstack); - - if (last_set_recurse != recurse) - { - stat_array_obstack_initial_size = - obstack_object_size (&dont_print_stat_array_obstack); - - last_set_recurse = recurse; - } - } - - vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype); - for (i = n_baseclasses; i < len; i++) - { - const gdb_byte *valaddr = value_contents_for_printing (val); - - /* If requested, skip printing of static fields. */ - if (!options->static_field_print - && field_is_static (&TYPE_FIELD (type, i))) - continue; - - if (fields_seen) - { - fputs_filtered (",", stream); - if (!options->prettyformat) - fputs_filtered (" ", stream); - } - else if (n_baseclasses > 0) - { - if (options->prettyformat) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - fputs_filtered ("members of ", stream); - fputs_filtered (TYPE_NAME (type), stream); - fputs_filtered (":", stream); - } - } - fields_seen = 1; - - if (options->prettyformat) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - } - else - { - wrap_here (n_spaces (2 + 2 * recurse)); - } - - annotate_field_begin (TYPE_FIELD_TYPE (type, i)); - - if (field_is_static (&TYPE_FIELD (type, i))) - { - fputs_filtered ("static ", stream); - fprintf_symbol_filtered (stream, - TYPE_FIELD_NAME (type, i), - current_language->la_language, - DMGL_PARAMS | DMGL_ANSI); - } - else - fputs_styled (TYPE_FIELD_NAME (type, i), - variable_name_style.style (), stream); - annotate_field_name_end (); - - /* We tweak various options in a few cases below. */ - value_print_options options_copy = *options; - value_print_options *opts = &options_copy; - - /* Do not print leading '=' in case of anonymous - unions. */ - if (strcmp (TYPE_FIELD_NAME (type, i), "")) - fputs_filtered (" = ", stream); - else - { - /* If this is an anonymous field then we want to consider it - as though it is at its parent's depth when it comes to the - max print depth. */ - if (opts->max_depth != -1 && opts->max_depth < INT_MAX) - ++opts->max_depth; - } - annotate_field_value (); - - if (!field_is_static (&TYPE_FIELD (type, i)) - && TYPE_FIELD_PACKED (type, i)) - { - struct value *v; - - /* Bitfields require special handling, especially due to - byte order problems. */ - if (TYPE_FIELD_IGNORE (type, i)) - { - fputs_styled ("<optimized out or zero length>", - metadata_style.style (), stream); - } - else if (value_bits_synthetic_pointer (val, - TYPE_FIELD_BITPOS (type, - i), - TYPE_FIELD_BITSIZE (type, - i))) - { - fputs_styled (_("<synthetic pointer>"), - metadata_style.style (), stream); - } - else - { - opts->deref_ref = 0; - - v = value_field_bitfield (type, i, valaddr, offset, val); - - common_val_print (v, stream, recurse + 1, - opts, current_language); - } - } - else - { - if (TYPE_FIELD_IGNORE (type, i)) - { - fputs_styled ("<optimized out or zero length>", - metadata_style.style (), stream); - } - else if (field_is_static (&TYPE_FIELD (type, i))) - { - try - { - struct value *v = value_static_field (type, i); - - cp_print_static_field (TYPE_FIELD_TYPE (type, i), - v, stream, recurse + 1, - opts); - } - catch (const gdb_exception_error &ex) - { - fprintf_styled (stream, metadata_style.style (), - _("<error reading variable: %s>"), - ex.what ()); - } - } - else if (i == vptr_fieldno && type == vptr_basetype) - { - int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; - struct type *i_type = TYPE_FIELD_TYPE (type, i); - - if (valprint_check_validity (stream, i_type, i_offset, val)) - { - CORE_ADDR addr; - - i_offset += value_embedded_offset (val); - addr = extract_typed_address (valaddr + i_offset, i_type); - print_function_pointer_address (opts, - get_type_arch (type), - addr, stream); - } - } - else - { - opts->deref_ref = 0; - val_print (TYPE_FIELD_TYPE (type, i), - offset + TYPE_FIELD_BITPOS (type, i) / 8, - address, - stream, recurse + 1, val, opts, - current_language); - } - } - annotate_field_end (); - } - - if (dont_print_statmem == 0) - { - size_t obstack_final_size = - obstack_object_size (&dont_print_statmem_obstack); - - if (obstack_final_size > statmem_obstack_initial_size) - { - /* In effect, a pop of the printed-statics stack. */ - size_t shrink_bytes - = statmem_obstack_initial_size - obstack_final_size; - obstack_blank_fast (&dont_print_statmem_obstack, shrink_bytes); - } - - if (last_set_recurse != recurse) - { - obstack_final_size = - obstack_object_size (&dont_print_stat_array_obstack); - - if (obstack_final_size > stat_array_obstack_initial_size) - { - void *free_to_ptr = - (char *) obstack_next_free (&dont_print_stat_array_obstack) - - (obstack_final_size - - stat_array_obstack_initial_size); - - obstack_free (&dont_print_stat_array_obstack, - free_to_ptr); - } - last_set_recurse = -1; - } - } - - if (options->prettyformat) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 * recurse, stream); - } - } /* if there are data fields */ - - fprintf_filtered (stream, "}"); -} - -/* Mutually recursive subroutines of cp_print_value and c_value_print - to print out a structure's fields: cp_print_value_fields and - cp_print_value. - - VAL, ADDRESS, STREAM, RECURSE, and OPTIONS have the same meanings - as in cp_print_value and c_value_print. - - DONT_PRINT is an array of baseclass types that we should not print, - or zero if called from top level. */ - -void cp_print_value_fields (struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, struct type **dont_print_vb, @@ -669,222 +381,6 @@ cp_print_value_fields (struct value *val, struct ui_file *stream, fprintf_filtered (stream, "}"); } -/* Like cp_print_value_fields, but find the runtime type of the object - and pass it as the `real_type' argument to cp_print_value_fields. - This function is a hack to work around the fact that - common_val_print passes the embedded offset to val_print, but not - the enclosing type. */ - -void -cp_print_value_fields_rtti (struct type *type, - const gdb_byte *valaddr, LONGEST offset, - CORE_ADDR address, - struct ui_file *stream, int recurse, - struct value *val, - const struct value_print_options *options, - struct type **dont_print_vb, - int dont_print_statmem) -{ - struct type *real_type = NULL; - - /* We require all bits to be valid in order to attempt a - conversion. */ - if (!value_bits_any_optimized_out (val, - TARGET_CHAR_BIT * offset, - TARGET_CHAR_BIT * TYPE_LENGTH (type))) - { - struct value *value; - int full, using_enc; - LONGEST top; - - /* Ugh, we have to convert back to a value here. */ - value = value_from_contents_and_address (type, valaddr + offset, - address + offset); - type = value_type (value); - /* We don't actually care about most of the result here -- just - the type. We already have the correct offset, due to how - val_print was initially called. */ - real_type = value_rtti_type (value, &full, &top, &using_enc); - } - - if (!real_type) - real_type = type; - - cp_print_value_fields (type, real_type, offset, - address, stream, recurse, val, options, - dont_print_vb, dont_print_statmem); -} - -/* Special value_print routine to avoid printing multiple copies of - virtual baseclasses. */ - -static void -cp_print_value (struct type *type, struct type *real_type, - LONGEST offset, - CORE_ADDR address, struct ui_file *stream, - int recurse, struct value *val, - const struct value_print_options *options, - struct type **dont_print_vb) -{ - struct type **last_dont_print - = (struct type **) obstack_next_free (&dont_print_vb_obstack); - struct obstack tmp_obstack = dont_print_vb_obstack; - int i, n_baseclasses = TYPE_N_BASECLASSES (type); - LONGEST thisoffset; - struct type *thistype; - const gdb_byte *valaddr = value_contents_for_printing (val); - - if (dont_print_vb == 0) - { - /* If we're at top level, carve out a completely fresh chunk of - the obstack and use that until this particular invocation - returns. */ - /* Bump up the high-water mark. Now alpha is omega. */ - obstack_finish (&dont_print_vb_obstack); - } - - for (i = 0; i < n_baseclasses; i++) - { - LONGEST boffset = 0; - int skip = 0; - struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); - const char *basename = TYPE_NAME (baseclass); - struct value *base_val = NULL; - - if (BASETYPE_VIA_VIRTUAL (type, i)) - { - struct type **first_dont_print - = (struct type **) obstack_base (&dont_print_vb_obstack); - - int j = (struct type **) - obstack_next_free (&dont_print_vb_obstack) - first_dont_print; - - while (--j >= 0) - if (baseclass == first_dont_print[j]) - goto flush_it; - - obstack_ptr_grow (&dont_print_vb_obstack, baseclass); - } - - thisoffset = offset; - thistype = real_type; - - try - { - boffset = baseclass_offset (type, i, valaddr, offset, address, val); - } - catch (const gdb_exception_error &ex) - { - if (ex.error == NOT_AVAILABLE_ERROR) - skip = -1; - else - skip = 1; - } - - if (skip == 0) - { - if (BASETYPE_VIA_VIRTUAL (type, i)) - { - /* The virtual base class pointer might have been - clobbered by the user program. Make sure that it - still points to a valid memory location. */ - - if ((boffset + offset) < 0 - || (boffset + offset) >= TYPE_LENGTH (real_type)) - { - gdb::byte_vector buf (TYPE_LENGTH (baseclass)); - - if (target_read_memory (address + boffset, buf.data (), - TYPE_LENGTH (baseclass)) != 0) - skip = 1; - base_val = value_from_contents_and_address (baseclass, - buf.data (), - address + boffset); - baseclass = value_type (base_val); - thisoffset = 0; - boffset = 0; - thistype = baseclass; - } - else - { - base_val = val; - } - } - else - { - base_val = val; - } - } - - /* Now do the printing. */ - if (options->prettyformat) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 * recurse, stream); - } - fputs_filtered ("<", stream); - /* Not sure what the best notation is in the case where there is - no baseclass name. */ - fputs_filtered (basename ? basename : "", stream); - fputs_filtered ("> = ", stream); - - if (skip < 0) - val_print_unavailable (stream); - else if (skip > 0) - val_print_invalid_address (stream); - else - { - int result = 0; - - if (options->max_depth > -1 - && recurse >= options->max_depth) - { - const struct language_defn *language = current_language; - gdb_assert (language->la_struct_too_deep_ellipsis != NULL); - fputs_filtered (language->la_struct_too_deep_ellipsis, stream); - } - else - { - /* Attempt to run an extension language pretty-printer on the - baseclass if possible. */ - if (!options->raw) - { - struct value *v - = value_from_component (base_val, baseclass, - thisoffset + boffset); - result - = apply_ext_lang_val_pretty_printer (v, stream, recurse, - options, - current_language); - } - - if (!result) - cp_print_value_fields (baseclass, thistype, - thisoffset + boffset, - value_address (base_val), - stream, recurse, base_val, options, - ((struct type **) - obstack_base (&dont_print_vb_obstack)), - 0); - } - } - fputs_filtered (", ", stream); - - flush_it: - ; - } - - if (dont_print_vb == 0) - { - /* Free the space used to deal with the printing - of this type from top level. */ - obstack_free (&dont_print_vb_obstack, last_dont_print); - /* Reset watermark so that we can continue protecting - ourselves from whatever we were protecting ourselves. */ - dont_print_vb_obstack = tmp_obstack; - } -} - /* Special val_print routine to avoid printing multiple copies of virtual baseclasses. */ @@ -1070,7 +566,7 @@ cp_print_static_field (struct type *type, if (TYPE_CODE (real_type) == TYPE_CODE_STRUCT) { CORE_ADDR *first_dont_print; - CORE_ADDR addr; + CORE_ADDR addr = value_address (val); int i; first_dont_print @@ -1080,7 +576,7 @@ cp_print_static_field (struct type *type, while (--i >= 0) { - if (value_address (val) == first_dont_print[i]) + if (addr == first_dont_print[i]) { fputs_styled (_("<same as static member of an already" " seen type>"), @@ -1089,13 +585,9 @@ cp_print_static_field (struct type *type, } } - addr = value_address (val); obstack_grow (&dont_print_statmem_obstack, (char *) &addr, sizeof (CORE_ADDR)); - cp_print_value_fields (type, value_enclosing_type (val), - value_embedded_offset (val), addr, - stream, recurse, val, - options, NULL, 1); + cp_print_value_fields (val, stream, recurse, options, NULL, 1); return; } |