+ fprintf_styled (stream, metadata_style.style (), _("<invalid address>"));
+}
+
+/* Print a pointer based on the type of its target.
+
+ Arguments to this functions are roughly the same as those in
+ generic_val_print. A difference is that ADDRESS is the address to print,
+ with embedded_offset already added. ELTTYPE represents
+ the pointed type after check_typedef. */
+
+static void
+print_unpacked_pointer (struct type *type, struct type *elttype,
+ CORE_ADDR address, struct ui_file *stream,
+ const struct value_print_options *options)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+
+ if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
+ {
+ /* Try to print what function it points to. */
+ print_function_pointer_address (options, gdbarch, address, stream);
+ return;
+ }
+
+ if (options->symbol_print)
+ print_address_demangle (options, gdbarch, address, stream, demangle);
+ else if (options->addressprint)
+ fputs_filtered (paddress (gdbarch, address), stream);
+}
+
+/* generic_val_print helper for TYPE_CODE_ARRAY. */
+
+static void
+generic_val_print_array (struct type *type,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream, int recurse,
+ struct value *original_value,
+ const struct value_print_options *options,
+ const struct
+ generic_val_print_decorations *decorations)
+{
+ struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
+ struct type *elttype = check_typedef (unresolved_elttype);
+
+ if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
+ {
+ LONGEST low_bound, high_bound;
+
+ if (!get_array_bounds (type, &low_bound, &high_bound))
+ error (_("Could not determine the array high bound"));
+
+ if (options->prettyformat_arrays)
+ {
+ print_spaces_filtered (2 + 2 * recurse, stream);
+ }
+
+ fputs_filtered (decorations->array_start, stream);
+ val_print_array_elements (type, embedded_offset,
+ address, stream,
+ recurse, original_value, options, 0);
+ fputs_filtered (decorations->array_end, stream);
+ }
+ else
+ {
+ /* Array of unspecified length: treat like pointer to first elt. */
+ print_unpacked_pointer (type, elttype, address + embedded_offset, stream,
+ options);
+ }
+
+}
+
+/* generic_val_print helper for TYPE_CODE_PTR. */
+
+static void
+generic_val_print_ptr (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
+ if (options->format && options->format != 's')
+ {
+ 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 (original_value);
+ CORE_ADDR addr = unpack_pointer (type,
+ valaddr + embedded_offset * unit_size);
+
+ print_unpacked_pointer (type, elttype, addr, stream, options);
+ }
+}
+
+
+/* generic_val_print helper for TYPE_CODE_MEMBERPTR. */
+
+static void
+generic_val_print_memberptr (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, options, 0, stream);
+}
+
+/* Print '@' followed by the address contained in ADDRESS_BUFFER. */
+
+static void
+print_ref_address (struct type *type, const gdb_byte *address_buffer,
+ int embedded_offset, struct ui_file *stream)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+
+ if (address_buffer != NULL)
+ {
+ CORE_ADDR address
+ = extract_typed_address (address_buffer + embedded_offset, type);
+
+ fprintf_filtered (stream, "@");
+ fputs_filtered (paddress (gdbarch, address), stream);
+ }
+ /* Else: we have a non-addressable value, such as a DW_AT_const_value. */
+}
+
+/* If VAL is addressable, return the value contents buffer of a value that
+ represents a pointer to VAL. Otherwise return NULL. */
+
+static const gdb_byte *
+get_value_addr_contents (struct value *deref_val)
+{
+ gdb_assert (deref_val != NULL);
+
+ if (value_lval_const (deref_val) == lval_memory)
+ return value_contents_for_printing_const (value_addr (deref_val));
+ else
+ {
+ /* We have a non-addressable value, such as a DW_AT_const_value. */
+ return NULL;
+ }
+}
+
+/* generic_val_print helper for TYPE_CODE_{RVALUE_,}REF. */
+
+static void
+generic_val_print_ref (struct type *type,
+ int embedded_offset, struct ui_file *stream, int recurse,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
+ struct value *deref_val = NULL;
+ const int value_is_synthetic
+ = value_bits_synthetic_pointer (original_value,
+ TARGET_CHAR_BIT * embedded_offset,
+ TARGET_CHAR_BIT * TYPE_LENGTH (type));
+ 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 (original_value);
+
+ if (must_coerce_ref && type_is_defined)
+ {
+ deref_val = coerce_ref_if_computed (original_value);
+
+ if (deref_val != NULL)
+ {
+ /* More complicated computed references are not supported. */
+ gdb_assert (embedded_offset == 0);
+ }
+ else
+ deref_val = value_at (TYPE_TARGET_TYPE (type),
+ unpack_pointer (type, valaddr + embedded_offset));
+ }
+ /* Else, original_value isn't a synthetic reference or we don't have to print
+ the reference's contents.
+
+ Notice that for references to TYPE_CODE_STRUCT, 'set print object on' will
+ cause original_value to be a not_lval instead of an lval_computed,
+ which will make value_bits_synthetic_pointer return false.
+ This happens because if options->objectprint is true, c_value_print will
+ overwrite original_value's contents with the result of coercing
+ the reference through value_addr, and then set its type back to
+ TYPE_CODE_REF. In that case we don't have to coerce the reference again;
+ we can simply treat it as non-synthetic and move on. */
+
+ if (options->addressprint)
+ {
+ const gdb_byte *address = (value_is_synthetic && type_is_defined
+ ? get_value_addr_contents (deref_val)
+ : valaddr);
+
+ print_ref_address (type, address, embedded_offset, stream);
+
+ if (options->deref_ref)
+ fputs_filtered (": ", stream);
+ }
+
+ if (options->deref_ref)
+ {
+ if (type_is_defined)
+ common_val_print (deref_val, stream, recurse, options,
+ current_language);
+ else
+ fputs_filtered ("???", stream);
+ }
+}
+
+/* Helper function for generic_val_print_enum.
+ This is also used to print enums in TYPE_CODE_FLAGS values. */
+
+static void
+generic_val_print_enum_1 (struct type *type, LONGEST val,
+ struct ui_file *stream)
+{
+ unsigned int i;
+ unsigned int len;
+
+ len = TYPE_NFIELDS (type);
+ for (i = 0; i < len; i++)
+ {
+ QUIT;
+ if (val == TYPE_FIELD_ENUMVAL (type, i))
+ {
+ break;
+ }
+ }
+ if (i < len)
+ {
+ fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+ }
+ else if (TYPE_FLAG_ENUM (type))
+ {
+ int first = 1;
+
+ /* We have a "flag" enum, so we try to decompose it into
+ pieces as appropriate. A flag enum has disjoint
+ constants by definition. */
+ fputs_filtered ("(", stream);
+ for (i = 0; i < len; ++i)
+ {
+ QUIT;
+
+ if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
+ {
+ if (!first)
+ fputs_filtered (" | ", stream);
+ first = 0;
+
+ val &= ~TYPE_FIELD_ENUMVAL (type, i);
+ fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+ }
+ }
+
+ if (first || val != 0)
+ {
+ if (!first)
+ fputs_filtered (" | ", stream);
+ fputs_filtered ("unknown: ", stream);
+ print_longest (stream, 'd', 0, val);
+ }
+
+ fputs_filtered (")", stream);
+ }
+ else
+ print_longest (stream, 'd', 0, val);
+}
+
+/* generic_val_print helper for TYPE_CODE_ENUM. */
+
+static void
+generic_val_print_enum (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ LONGEST val;
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
+ if (options->format)
+ {
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, options, 0, stream);
+ }
+ else
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (original_value);
+
+ 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,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+
+{
+ if (options->format)
+ val_print_scalar_formatted (type, embedded_offset, original_value,
+ options, 0, stream);
+ else
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (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,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+
+ if (options->format)
+ {
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, options, 0, stream);
+ }
+ else
+ {
+ /* FIXME, we should consider, at least for ANSI C language,
+ eliminating the distinction made between FUNCs and POINTERs
+ to FUNCs. */
+ fprintf_filtered (stream, "{");
+ type_print (type, "", stream, -1);
+ fprintf_filtered (stream, "} ");
+ /* Try to print what function it points to, and its address. */
+ print_address_demangle (options, gdbarch, address, stream, demangle);
+ }
+}
+
+/* generic_val_print helper for TYPE_CODE_BOOL. */
+
+static void
+generic_val_print_bool (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options,
+ const struct generic_val_print_decorations *decorations)
+{
+ LONGEST val;
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
+ if (options->format || options->output_format)
+ {
+ struct value_print_options opts = *options;
+ opts.format = (options->format ? options->format
+ : options->output_format);
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, &opts, 0, stream);
+ }
+ else
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (original_value);
+
+ val = unpack_long (type, valaddr + embedded_offset * unit_size);
+ if (val == 0)
+ fputs_filtered (decorations->false_name, stream);
+ else if (val == 1)
+ fputs_filtered (decorations->true_name, stream);
+ else
+ print_longest (stream, 'd', 0, val);
+ }
+}
+
+/* generic_val_print helper for TYPE_CODE_INT. */
+
+static void
+generic_val_print_int (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ struct value_print_options opts = *options;
+
+ opts.format = (options->format ? options->format
+ : options->output_format);
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, &opts, 0, stream);
+}
+
+/* generic_val_print helper for TYPE_CODE_CHAR. */
+
+static void
+generic_val_print_char (struct type *type, struct type *unresolved_type,
+ int embedded_offset,
+ struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ LONGEST val;
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
+ if (options->format || options->output_format)
+ {
+ struct value_print_options opts = *options;
+
+ opts.format = (options->format ? options->format
+ : options->output_format);
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, &opts, 0, stream);
+ }
+ else
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (original_value);
+
+ val = unpack_long (type, valaddr + embedded_offset * unit_size);
+ 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
+generic_val_print_float (struct type *type,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+
+ if (options->format)
+ {
+ val_print_scalar_formatted (type, embedded_offset,
+ original_value, options, 0, stream);
+ }
+ else
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (original_value);
+
+ print_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,
+ int embedded_offset, struct ui_file *stream,
+ struct value *original_value,
+ const struct value_print_options *options,
+ const struct generic_val_print_decorations
+ *decorations)
+{
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+ const gdb_byte *valaddr = value_contents_for_printing (original_value);
+
+ fprintf_filtered (stream, "%s", decorations->complex_prefix);
+ if (options->format)
+ val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+ embedded_offset, original_value, options, 0,
+ stream);
+ else
+ print_floating (valaddr + embedded_offset * unit_size,
+ TYPE_TARGET_TYPE (type), stream);
+ fprintf_filtered (stream, "%s", decorations->complex_infix);
+ if (options->format)
+ val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+ embedded_offset
+ + type_length_units (TYPE_TARGET_TYPE (type)),
+ original_value, options, 0, stream);
+ else
+ print_floating (valaddr + embedded_offset * unit_size
+ + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+ TYPE_TARGET_TYPE (type), stream);
+ fprintf_filtered (stream, "%s", decorations->complex_suffix);