/* Support for printing Ada values for GDB, the GNU debugger.
- Copyright (C) 1986-2021 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
This file is part of GDB.
case TYPE_CODE_ENUM:
if (low_bound == 0)
return 0;
- low_bound = TYPE_FIELD_ENUMVAL (index_type, low_bound);
+ low_bound = index_type->field (low_bound).loc_enumval ();
break;
case TYPE_CODE_UNDEF:
index_type = NULL;
}
ada_print_scalar (index_type, low_bound, stream);
- fprintf_filtered (stream, " => ");
+ gdb_printf (stream, " => ");
return 1;
}
{
if (options->prettyformat_arrays)
{
- fprintf_filtered (stream, ",\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
+ gdb_printf (stream, ",\n");
+ print_spaces (2 + 2 * recurse, stream);
}
else
{
- fprintf_filtered (stream, ", ");
+ gdb_printf (stream, ", ");
}
}
else if (options->prettyformat_arrays)
{
- fprintf_filtered (stream, "\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
+ gdb_printf (stream, "\n");
+ print_spaces (2 + 2 * recurse, stream);
}
- wrap_here (n_spaces (2 + 2 * recurse));
+ stream->wrap_here (2 + 2 * recurse);
maybe_print_array_index (index_type, i + low, stream, options);
i0 = i;
opts.deref_ref = 0;
common_val_print (v0, stream, recurse + 1, &opts, current_language);
annotate_elt_rep (i - i0);
- fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
- metadata_style.style ().ptr (), i - i0, nullptr);
+ gdb_printf (stream, _(" %p[<repeats %u times>%p]"),
+ metadata_style.style ().ptr (), i - i0, nullptr);
annotate_elt_rep_end ();
}
{
if (options->prettyformat_arrays)
{
- fprintf_filtered (stream, ",\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
+ gdb_printf (stream, ",\n");
+ print_spaces (2 + 2 * recurse, stream);
}
else
{
- fprintf_filtered (stream, ", ");
+ gdb_printf (stream, ", ");
}
- wrap_here (n_spaces (2 + 2 * recurse));
+ stream->wrap_here (2 + 2 * recurse);
maybe_print_array_index (index_type, j + low,
stream, options);
}
annotate_array_section_end ();
if (i < len)
{
- fprintf_filtered (stream, "...");
+ gdb_printf (stream, "...");
}
value_free_to_mark (mark);
if (c <= UCHAR_MAX && isascii (c) && isprint (c))
{
if (c == quoter && c == '"')
- fprintf_filtered (stream, "\"\"");
+ gdb_printf (stream, "\"\"");
else
- fprintf_filtered (stream, "%c", c);
+ gdb_printf (stream, "%c", c);
}
else
- fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
+ {
+ /* Follow GNAT's lead here and only use 6 digits for
+ wide_wide_character. */
+ gdb_printf (stream, "[\"%0*x\"]", std::min (6, type_len * 2), c);
+ }
}
/* Character #I of STRING, given that TYPE_LEN is the size in bytes
print_floating (valaddr, type, &tmp_stream);
- std::string &s = tmp_stream.string ();
+ std::string s = tmp_stream.release ();
size_t skip_count = 0;
+ /* Don't try to modify a result representing an error. */
+ if (s[0] == '<')
+ {
+ gdb_puts (s.c_str (), stream);
+ return;
+ }
+
/* Modify for Ada rules. */
size_t pos = s.find ("inf");
{
pos = s.find ('e');
if (pos == std::string::npos)
- fprintf_filtered (stream, "%s.0", s.c_str ());
+ gdb_printf (stream, "%s.0", s.c_str ());
else
- fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
+ gdb_printf (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
}
else
- fprintf_filtered (stream, "%s", &s[skip_count]);
+ gdb_printf (stream, "%s", &s[skip_count]);
}
void
ada_printchar (int c, struct type *type, struct ui_file *stream)
{
- fputs_filtered ("'", stream);
+ gdb_puts ("'", stream);
ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
- fputs_filtered ("'", stream);
+ gdb_puts ("'", stream);
}
/* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
len = type->num_fields ();
for (i = 0; i < len; i++)
{
- if (TYPE_FIELD_ENUMVAL (type, i) == val)
+ if (type->field (i).loc_enumval () == val)
{
break;
}
break;
case TYPE_CODE_CHAR:
- LA_PRINT_CHAR (val, type, stream);
+ current_language->printchar (val, type, stream);
break;
case TYPE_CODE_BOOL:
- fprintf_filtered (stream, val ? "true" : "false");
+ gdb_printf (stream, val ? "true" : "false");
break;
case TYPE_CODE_RANGE:
if (length == 0)
{
- fputs_filtered ("\"\"", stream);
+ gdb_puts ("\"\"", stream);
return;
}
if (need_comma)
{
- fputs_filtered (", ", stream);
+ gdb_puts (", ", stream);
need_comma = 0;
}
{
if (in_quotes)
{
- fputs_filtered ("\", ", stream);
+ gdb_puts ("\", ", stream);
in_quotes = 0;
}
- fputs_filtered ("'", stream);
+ gdb_puts ("'", stream);
ada_emit_char (char_at (string, i, type_len, byte_order),
elttype, stream, '\'', type_len);
- fputs_filtered ("'", stream);
- fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
- metadata_style.style ().ptr (), reps, nullptr);
+ gdb_puts ("'", stream);
+ gdb_printf (stream, _(" %p[<repeats %u times>%p]"),
+ metadata_style.style ().ptr (), reps, nullptr);
i = rep1 - 1;
things_printed += options->repeat_count_threshold;
need_comma = 1;
{
if (!in_quotes)
{
- fputs_filtered ("\"", stream);
+ gdb_puts ("\"", stream);
in_quotes = 1;
}
ada_emit_char (char_at (string, i, type_len, byte_order),
/* Terminate the quotes if necessary. */
if (in_quotes)
- fputs_filtered ("\"", stream);
+ gdb_puts ("\"", stream);
if (force_ellipses || i < length)
- fputs_filtered ("...", stream);
+ gdb_puts ("...", stream);
}
void
}
if (comma_needed)
- fprintf_filtered (stream, ", ");
+ gdb_printf (stream, ", ");
comma_needed = 1;
if (options->prettyformat)
{
- fprintf_filtered (stream, "\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
+ gdb_printf (stream, "\n");
+ print_spaces (2 + 2 * recurse, stream);
}
else
{
- wrap_here (n_spaces (2 + 2 * recurse));
+ stream->wrap_here (2 + 2 * recurse);
}
annotate_field_begin (type->field (i).type ());
- fprintf_filtered (stream, "%.*s",
- ada_name_prefix_len (type->field (i).name ()),
- type->field (i).name ());
+ gdb_printf (stream, "%.*s",
+ ada_name_prefix_len (type->field (i).name ()),
+ type->field (i).name ());
annotate_field_name_end ();
- fputs_filtered (" => ", stream);
+ gdb_puts (" => ", stream);
annotate_field_value ();
if (TYPE_FIELD_PACKED (type, i))
else
{
struct value *v;
- int bit_pos = TYPE_FIELD_BITPOS (type, i);
+ int bit_pos = type->field (i).loc_bitpos ();
int bit_size = TYPE_FIELD_BITSIZE (type, i);
struct value_print_options opts;
&& TYPE_TARGET_TYPE (value_type (val))->code () == TYPE_CODE_INT
&& TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val))) == 0)
{
- fputs_filtered ("null", stream);
+ gdb_puts ("null", stream);
return;
}
gdb::unique_xmalloc_ptr<char> name = ada_tag_name (val);
if (name != NULL)
- fprintf_filtered (stream, " (%s)", name.get ());
+ gdb_printf (stream, " (%s)", name.get ());
}
}
struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
CORE_ADDR addr = extract_typed_address (valaddr, ptr_type);
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") ");
- fputs_filtered (paddress (gdbarch, addr), stream);
+ gdb_printf (stream, ") ");
+ gdb_puts (paddress (gdbarch, addr), stream);
}
else
{
{
LONGEST c;
- fputs_filtered (" ", stream);
+ gdb_puts (" ", stream);
c = unpack_long (type, valaddr);
ada_printchar (c, type, stream);
}
for (i = 0; i < len; i++)
{
QUIT;
- if (val == TYPE_FIELD_ENUMVAL (type, i))
+ if (val == type->field (i).loc_enumval ())
break;
}
const char *name = ada_enum_name (type->field (i).name ());
if (name[0] == '\'')
- fprintf_filtered (stream, "%ld %ps", (long) val,
- styled_string (variable_name_style.style (),
- name));
+ gdb_printf (stream, "%ld %ps", (long) val,
+ styled_string (variable_name_style.style (),
+ name));
else
fputs_styled (name, variable_name_style.style (), stream);
}
{
if (ada_is_bogus_array_descriptor (value_type (value)))
{
- fprintf_filtered (stream, "(...?)");
+ gdb_printf (stream, "(...?)");
return;
}
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
if (print_field_values (value, value, stream, recurse, options,
0, language_def (language_ada)) != 0
&& options->prettyformat)
{
- fprintf_filtered (stream, "\n");
- print_spaces_filtered (2 * recurse, stream);
+ gdb_printf (stream, "\n");
+ print_spaces (2 * recurse, stream);
}
- fprintf_filtered (stream, ")");
+ gdb_printf (stream, ")");
}
/* Implement Ada value_print'ing for the case where TYPE is a
return;
}
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
print_optional_low_bound (stream, type, options);
if (value_entirely_optimized_out (val))
}
else
value_print_array_elements (val, stream, recurse, options, 0);
- fprintf_filtered (stream, ")");
+ gdb_printf (stream, ")");
}
/* Implement Ada val_print'ing for the case where TYPE is
deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
if (deref_val_int == 0)
{
- fputs_filtered ("(null)", stream);
+ gdb_puts ("(null)", stream);
return;
}
}
/* See the comment on ada_value_print. This function differs in that
- it does not catch evaluation errors (leaving that to
- ada_value_print). */
+ it does not catch evaluation errors (leaving that to its
+ caller). */
-static void
-ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse,
- const struct value_print_options *options)
+void
+ada_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
{
struct type *type = ada_check_typedef (value_type (val));
if (val == nullptr)
{
gdb_assert (type->code () == TYPE_CODE_TYPEDEF);
- fprintf_filtered (stream, "0x0");
+ gdb_printf (stream, "0x0");
return;
}
}
}
}
-/* See ada-lang.h. */
-
-void
-ada_value_print_inner (struct value *val, struct ui_file *stream,
- int recurse,
- const struct value_print_options *options)
-{
- try
- {
- ada_value_print_1 (val, stream, recurse, options);
- }
- catch (const gdb_exception_error &except)
- {
- fprintf_styled (stream, metadata_style.style (),
- _("<error reading variable: %s>"),
- except.what ());
- }
-}
-
void
ada_value_print (struct value *val0, struct ui_file *stream,
const struct value_print_options *options)
|| TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_INT
|| TYPE_TARGET_TYPE (type)->is_unsigned ())
{
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") ");
+ gdb_printf (stream, ") ");
}
}
else if (ada_is_array_descriptor_type (type))
a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
if (type->code () == TYPE_CODE_TYPEDEF)
{
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") ");
+ gdb_printf (stream, ") ");
}
}
else if (ada_is_bogus_array_descriptor (type))
{
- fprintf_filtered (stream, "(");
+ gdb_printf (stream, "(");
type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") (...?)");
+ gdb_printf (stream, ") (...?)");
return;
}