+ enum bfd_endian byte_order = type_byte_order (type);
+ struct type *elttype = TYPE_TARGET_TYPE (type);
+ unsigned int eltlen;
+ unsigned int len;
+
+ /* We know that ELTTYPE cannot possibly be null, because we assume
+ that we're called only when TYPE is a string-like type.
+ Similarly, the size of ELTTYPE should also be non-null, since
+ it's a character-like type. */
+ gdb_assert (elttype != NULL);
+ gdb_assert (TYPE_LENGTH (elttype) != 0);
+
+ eltlen = TYPE_LENGTH (elttype);
+ len = TYPE_LENGTH (type) / eltlen;
+
+ /* If requested, look for the first null char and only print
+ elements up to it. */
+ if (options->stop_print_at_null)
+ {
+ int temp_len;
+
+ /* Look for a NULL char. */
+ for (temp_len = 0;
+ (temp_len < len
+ && temp_len < options->print_max
+ && char_at (valaddr + offset_aligned,
+ temp_len, eltlen, byte_order) != 0);
+ temp_len += 1);
+ len = temp_len;
+ }
+
+ printstr (stream, elttype, valaddr + offset_aligned, len, 0,
+ eltlen, options);
+}
+
+/* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
+ thin pointers, etc). */
+
+static void
+ada_val_print_gnat_array (struct value *val,
+ struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
+{
+ scoped_value_mark free_values;
+
+ struct type *type = ada_check_typedef (value_type (val));
+
+ /* If this is a reference, coerce it now. This helps taking care
+ of the case where ADDRESS is meaningless because original_value
+ was not an lval. */
+ val = coerce_ref (val);
+ if (type->code () == TYPE_CODE_TYPEDEF) /* array access type. */
+ val = ada_coerce_to_simple_array_ptr (val);
+ else
+ val = ada_coerce_to_simple_array (val);
+ if (val == NULL)
+ {
+ gdb_assert (type->code () == TYPE_CODE_TYPEDEF);
+ fprintf_filtered (stream, "0x0");
+ }
+ else
+ common_val_print (val, stream, recurse, options,
+ language_def (language_ada));
+}
+
+/* Implement Ada value_print'ing for the case where TYPE is a
+ TYPE_CODE_PTR. */
+
+static void
+ada_value_print_ptr (struct value *val,
+ struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
+{
+ common_val_print (val, stream, recurse, options, language_def (language_c));
+
+ struct type *type = ada_check_typedef (value_type (val));
+ if (ada_is_tag_type (type))
+ {
+ gdb::unique_xmalloc_ptr<char> name = ada_tag_name (val);
+
+ if (name != NULL)
+ fprintf_filtered (stream, " (%s)", name.get ());
+ }
+}
+
+/* Implement Ada val_print'ing for the case where TYPE is
+ a TYPE_CODE_INT or TYPE_CODE_RANGE. */
+
+static void
+ada_value_print_num (struct value *val, struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
+{
+ struct type *type = ada_check_typedef (value_type (val));
+ const gdb_byte *valaddr = value_contents_for_printing (val);
+
+ if (ada_is_gnat_encoded_fixed_point_type (type))
+ {
+ struct value *scale = ada_scaling_factor (type);
+ val = value_cast (value_type (scale), val);
+ val = value_binop (val, scale, BINOP_MUL);
+
+ const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g";
+ std::string str
+ = target_float_to_string (value_contents (val), value_type (val), fmt);
+ fputs_filtered (str.c_str (), stream);
+ return;
+ }
+ else if (type->code () == TYPE_CODE_RANGE
+ && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM
+ || TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_BOOL
+ || TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR))
+ {
+ /* For enum-valued ranges, we want to recurse, because we'll end
+ up printing the constant's name rather than its numeric
+ value. Character and fixed-point types are also printed
+ differently, so recuse for those as well. */
+ struct type *target_type = TYPE_TARGET_TYPE (type);
+ val = value_cast (target_type, val);
+ common_val_print (val, stream, recurse + 1, options,
+ language_def (language_ada));
+ return;
+ }
+ else
+ {
+ int format = (options->format ? options->format
+ : options->output_format);
+
+ if (format)
+ {
+ struct value_print_options opts = *options;
+
+ opts.format = format;
+ value_print_scalar_formatted (val, &opts, 0, stream);
+ }
+ else if (ada_is_system_address_type (type))
+ {
+ /* FIXME: We want to print System.Address variables using
+ the same format as for any access type. But for some
+ reason GNAT encodes the System.Address type as an int,
+ so we have to work-around this deficiency by handling
+ System.Address values as a special case. */
+
+ struct gdbarch *gdbarch = get_type_arch (type);
+ struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
+ CORE_ADDR addr = extract_typed_address (valaddr, ptr_type);
+
+ fprintf_filtered (stream, "(");
+ type_print (type, "", stream, -1);
+ fprintf_filtered (stream, ") ");
+ fputs_filtered (paddress (gdbarch, addr), stream);
+ }
+ else
+ {
+ value_print_scalar_formatted (val, options, 0, stream);
+ if (ada_is_character_type (type))
+ {
+ LONGEST c;
+
+ fputs_filtered (" ", stream);
+ c = unpack_long (type, valaddr);
+ ada_printchar (c, type, stream);
+ }
+ }
+ return;
+ }
+}
+
+/* Implement Ada val_print'ing for the case where TYPE is
+ a TYPE_CODE_ENUM. */
+
+static void
+ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
+{
+ int i;
+ unsigned int len;
+ LONGEST val;
+
+ if (options->format)
+ {
+ value_print_scalar_formatted (value, options, 0, stream);
+ return;
+ }
+
+ struct type *type = ada_check_typedef (value_type (value));
+ const gdb_byte *valaddr = value_contents_for_printing (value);
+ int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
+
+ len = type->num_fields ();
+ val = unpack_long (type, valaddr + offset_aligned);
+ for (i = 0; i < len; i++)
+ {
+ QUIT;
+ if (val == TYPE_FIELD_ENUMVAL (type, i))
+ break;
+ }
+
+ if (i < len)
+ {
+ const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
+
+ if (name[0] == '\'')
+ fprintf_filtered (stream, "%ld %ps", (long) val,
+ styled_string (variable_name_style.style (),
+ name));
+ else
+ fputs_styled (name, variable_name_style.style (), stream);
+ }
+ else
+ print_longest (stream, 'd', 0, val);
+}
+
+/* Implement Ada val_print'ing for the case where the type is
+ TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
+
+static void
+ada_val_print_struct_union (struct value *value,
+ struct ui_file *stream,
+ int recurse,
+ const struct value_print_options *options)
+{
+ if (ada_is_bogus_array_descriptor (value_type (value)))
+ {
+ fprintf_filtered (stream, "(...?)");
+ return;
+ }