/* Print values for GDB, the GNU debugger.
- Copyright (C) 1986-2016 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 Free Software Foundation, Inc.
This file is part of GDB.
#include "charset.h"
#include "typeprint.h"
#include <ctype.h>
+#include <algorithm>
/* Maximum number of wchars returned from wchar_iterate. */
#define MAX_WCHARS 4
val_print_scalar_type_p (struct type *type)
{
type = check_typedef (type);
- while (TYPE_CODE (type) == TYPE_CODE_REF)
+ while (TYPE_IS_REFERENCE (type))
{
type = TYPE_TARGET_TYPE (type);
type = check_typedef (type);
/* 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,
+ struct value *original_value,
const struct value_print_options *options,
const struct
generic_val_print_decorations *decorations)
}
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);
/* 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,
+ struct value *original_value,
const struct value_print_options *options)
{
struct gdbarch *gdbarch = get_type_arch (type);
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 (original_value);
CORE_ADDR addr = unpack_pointer (type,
valaddr + embedded_offset * unit_size);
/* 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,
+ 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);
}
}
}
-/* generic_val_print helper for TYPE_CODE_REF. */
+/* generic_val_print helper for TYPE_CODE_{RVALUE_,}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,
+ struct value *original_value,
const struct value_print_options *options)
{
struct type *elttype = check_typedef (TYPE_TARGET_TYPE (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)
{
/* 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,
+ struct value *original_value,
const struct value_print_options *options)
{
LONGEST val;
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 (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,
+ 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 (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,
+ 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, valaddr, embedded_offset,
+ val_print_scalar_formatted (type, embedded_offset,
original_value, options, 0, stream);
}
else
/* 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,
+ struct value *original_value,
const struct value_print_options *options,
const struct generic_val_print_decorations *decorations)
{
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 (original_value);
+
val = unpack_long (type, valaddr + embedded_offset * unit_size);
if (val == 0)
fputs_filtered (decorations->false_name, stream);
/* 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,
+ struct value *original_value,
const struct value_print_options *options)
{
struct gdbarch *gdbarch = get_type_arch (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
- val_print_type_code_int (type, valaddr + embedded_offset * unit_size,
- stream);
+ {
+ const gdb_byte *valaddr = value_contents_for_printing (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,
+ struct value *original_value,
const struct value_print_options *options)
{
LONGEST val;
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 (original_value);
+
val = unpack_long (type, valaddr + embedded_offset * unit_size);
if (TYPE_UNSIGNED (type))
fprintf_filtered (stream, "%u", (unsigned int) val);
/* 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,
+ 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, valaddr, embedded_offset,
+ 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_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,
+ 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, 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 (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,
+ 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), valaddr,
+ val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
embedded_offset, original_value, options, 0,
stream);
else
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);
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,
+ struct value *original_value,
const struct value_print_options *options,
const struct generic_val_print_decorations *decorations)
{
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,
+ case TYPE_CODE_RVALUE_REF:
+ 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;
/* 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;
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;
}
/* 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
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,
+ struct value *val,
const struct value_print_options *options,
const struct language_defn *language)
{
if (!options->raw)
{
- ret = apply_ext_lang_val_pretty_printer (type, valaddr, embedded_offset,
+ ret = apply_ext_lang_val_pretty_printer (type, embedded_offset,
address, stream, recurse,
val, options, language);
if (ret)
TRY
{
- language->la_val_print (type, valaddr, embedded_offset, address,
+ language->la_val_print (type, embedded_offset, address,
stream, recurse, val,
&local_opts);
}
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);
{
int r
= apply_ext_lang_val_pretty_printer (value_type (val),
- value_contents_for_printing (val),
value_embedded_offset (val),
value_address (val),
stream, 0,
void
val_print_scalar_formatted (struct type *type,
- const gdb_byte *valaddr, LONGEST embedded_offset,
- const struct value *val,
+ LONGEST embedded_offset,
+ struct value *val,
const struct value_print_options *options,
int size,
struct ui_file *stream)
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
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;
}
+ /* value_contents_for_printing fetches all VAL's contents. They are
+ needed to check whether VAL is optimized-out or unavailable
+ below. */
+ const gdb_byte *valaddr = value_contents_for_printing (val);
+
/* A scalar object that does not have all bits available can't be
printed, because all bits contribute to its representation. */
if (value_bits_any_optimized_out (val,
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,
+ struct value *val,
const struct value_print_options *options,
unsigned int i)
{
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);
}
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 ();
{
/* We want fetchlimit chars, so we might as well read them all in
one operation. */
- unsigned int fetchlen = min (len, fetchlimit);
+ unsigned int fetchlen = std::min ((unsigned) len, fetchlimit);
*buffer = (gdb_byte *) xmalloc (fetchlen * width);
bufptr = *buffer;
So we choose the minimum of 8 and fetchlimit. We used to use 200
instead of 8 but 200 is way too big for remote debugging over a
serial line. */
- chunksize = min (8, fetchlimit);
+ chunksize = std::min (8u, fetchlimit);
do
{
QUIT;
- nfetch = min (chunksize, fetchlimit - bufsize);
+ nfetch = std::min ((unsigned long) chunksize, fetchlimit - bufsize);
if (*buffer == NULL)
*buffer = (gdb_byte *) xmalloc (nfetch * width);
struct obstack wchar_buf, output;
struct cleanup *cleanups;
gdb_byte *buf;
- struct wchar_iterator *iter;
int need_escape = 0;
buf = (gdb_byte *) alloca (TYPE_LENGTH (type));
pack_long (buf, type, c);
- iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
- encoding, TYPE_LENGTH (type));
- cleanups = make_cleanup_wchar_iterator (iter);
+ wchar_iterator iter (buf, TYPE_LENGTH (type), encoding, TYPE_LENGTH (type));
/* This holds the printable form of the wchar_t data. */
obstack_init (&wchar_buf);
- make_cleanup_obstack_free (&wchar_buf);
+ cleanups = make_cleanup_obstack_free (&wchar_buf);
while (1)
{
int print_escape = 1;
enum wchar_iterate_result result;
- num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
+ num_chars = iter.iterate (&result, &chars, &buf, &buflen);
if (num_chars < 0)
break;
if (num_chars > 0)
storing the result in VEC. */
static int
-count_next_character (struct wchar_iterator *iter,
+count_next_character (wchar_iterator *iter,
VEC (converted_character_d) **vec)
{
struct converted_character *current;
gdb_wchar_t *chars;
tmp.num_chars
- = wchar_iterate (iter, &tmp.result, &chars, &tmp.buf, &tmp.buflen);
+ = iter->iterate (&tmp.result, &chars, &tmp.buf, &tmp.buflen);
if (tmp.num_chars > 0)
{
gdb_assert (tmp.num_chars < MAX_WCHARS);
while (1)
{
/* Get the next character. */
- d.num_chars
- = wchar_iterate (iter, &d.result, &chars, &d.buf, &d.buflen);
+ d.num_chars = iter->iterate (&d.result, &chars, &d.buf, &d.buflen);
/* If a character was successfully converted, save the character
into the converted character. */
int width = TYPE_LENGTH (type);
struct obstack wchar_buf, output;
struct cleanup *cleanup;
- struct wchar_iterator *iter;
int finished = 0;
struct converted_character *last;
VEC (converted_character_d) *converted_chars;
}
/* Arrange to iterate over the characters, in wchar_t form. */
- iter = make_wchar_iterator (string, length * width, encoding, width);
- cleanup = make_cleanup_wchar_iterator (iter);
+ wchar_iterator iter (string, length * width, encoding, width);
converted_chars = NULL;
- make_cleanup (VEC_cleanup (converted_character_d), &converted_chars);
+ cleanup = make_cleanup (VEC_cleanup (converted_character_d),
+ &converted_chars);
/* Convert characters until the string is over or the maximum
number of printed characters has been reached. */
QUIT;
/* Grab the next character and repeat count. */
- r = count_next_character (iter, &converted_chars);
+ r = count_next_character (&iter, &converted_chars);
/* If less than zero, the end of the input string was reached. */
if (r < 0)
because finding the null byte (or available memory) is what actually
limits the fetch. */
- fetchlimit = (len == -1 ? options->print_max : min (len,
- options->print_max));
+ fetchlimit = (len == -1 ? options->print_max : std::min ((unsigned) len,
+ options->print_max));
err = read_string (addr, len, width, fetchlimit, byte_order,
&buffer, &bytes_read);