/* Support for printing C++ values for GDB, the GNU debugger.
- Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbcmd.h"
#include "demangle.h"
#include "annotate.h"
-#include "gdb_string.h"
#include "c-lang.h"
#include "target.h"
#include "cp-abi.h"
#include "valprint.h"
#include "cp-support.h"
#include "language.h"
-#include "python/python.h"
+#include "extension.h"
+#include "typeprint.h"
/* Controls printing of vtbl's. */
static void
int
cp_is_vtbl_ptr_type (struct type *type)
{
- char *typename = type_name_no_tag (type);
+ const char *typename = type_name_no_tag (type);
return (typename != NULL && !strcmp (typename, vtbl_ptr_name));
}
fprintf_filtered (stream, "<No data fields>");
else
{
- int statmem_obstack_initial_size = 0;
- int stat_array_obstack_initial_size = 0;
-
+ 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 =
}
}
+ vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype);
for (i = n_baseclasses; i < len; i++)
{
/* If requested, skip printing of static fields. */
fprintf_filtered (stream, ", ");
else if (n_baseclasses > 0)
{
- if (options->pretty)
+ if (options->prettyformat)
{
fprintf_filtered (stream, "\n");
print_spaces_filtered (2 + 2 * recurse, stream);
}
fields_seen = 1;
- if (options->pretty)
+ if (options->prettyformat)
{
fprintf_filtered (stream, "\n");
print_spaces_filtered (2 + 2 * recurse, stream);
{
wrap_here (n_spaces (2 + 2 * recurse));
}
- if (options->inspect_it)
- {
- if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
- fputs_filtered ("\"( ptr \"", stream);
- else
- fputs_filtered ("\"( nodef \"", stream);
- 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);
- fputs_filtered ("\" \"", stream);
- fprintf_symbol_filtered (stream,
- TYPE_FIELD_NAME (type, i),
- current_language->la_language,
- DMGL_PARAMS | DMGL_ANSI);
- fputs_filtered ("\") \"", stream);
- }
- else
- {
- 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);
- annotate_field_name_end ();
- /* Do not print leading '=' in case of anonymous
- unions. */
- if (strcmp (TYPE_FIELD_NAME (type, i), ""))
- fputs_filtered (" = ", stream);
- annotate_field_value ();
- }
+
+ 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);
+ annotate_field_name_end ();
+ /* Do not print leading '=' in case of anonymous
+ unions. */
+ if (strcmp (TYPE_FIELD_NAME (type, i), ""))
+ fputs_filtered (" = ", stream);
+ annotate_field_value ();
if (!field_is_static (&TYPE_FIELD (type, i))
&& TYPE_FIELD_PACKED (type, i))
{
fputs_filtered (_("<synthetic pointer>"), stream);
}
- else if (!value_bits_valid (val,
- TYPE_FIELD_BITPOS (type, i),
- TYPE_FIELD_BITSIZE (type, i)))
- {
- fputs_filtered (_("<value optimized out>"), stream);
- }
else
{
struct value_print_options opts = *options;
opts.deref_ref = 0;
- v = value_from_longest
- (TYPE_FIELD_TYPE (type, i),
- unpack_field_as_long (type, valaddr + offset, i));
+
+ v = value_field_bitfield (type, i, valaddr, offset, val);
common_val_print (v, stream, recurse + 1, &opts,
current_language);
}
else if (field_is_static (&TYPE_FIELD (type, i)))
{
- struct value *v = value_static_field (type, i);
-
- if (v == NULL)
- fputs_filtered ("<optimized out>", stream);
- else
- cp_print_static_field (TYPE_FIELD_TYPE (type, i),
- v, stream, recurse + 1,
- options);
+ volatile struct gdb_exception ex;
+ struct value *v = NULL;
+
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
+ {
+ v = value_static_field (type, i);
+ }
+
+ if (ex.reason < 0)
+ fprintf_filtered (stream,
+ _("<error reading variable: %s>"),
+ ex.message);
+ cp_print_static_field (TYPE_FIELD_TYPE (type, i),
+ v, stream, recurse + 1,
+ options);
+ }
+ 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;
+
+ addr = extract_typed_address (valaddr + i_offset, i_type);
+ print_function_pointer_address (options,
+ get_type_arch (type),
+ addr, stream);
+ }
}
else
{
if (dont_print_statmem == 0)
{
- int obstack_final_size =
+ 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. */
void *free_to_ptr =
- obstack_next_free (&dont_print_statmem_obstack) -
+ (char *) obstack_next_free (&dont_print_statmem_obstack) -
(obstack_final_size - statmem_obstack_initial_size);
obstack_free (&dont_print_statmem_obstack,
if (last_set_recurse != recurse)
{
- int obstack_final_size =
+ size_t obstack_final_size =
obstack_object_size (&dont_print_stat_array_obstack);
if (obstack_final_size > stat_array_obstack_initial_size)
{
void *free_to_ptr =
- obstack_next_free (&dont_print_stat_array_obstack)
+ (char *) obstack_next_free (&dont_print_stat_array_obstack)
- (obstack_final_size
- stat_array_obstack_initial_size);
}
}
- if (options->pretty)
+ if (options->prettyformat)
{
fprintf_filtered (stream, "\n");
print_spaces_filtered (2 * recurse, stream);
/* We require all bits to be valid in order to attempt a
conversion. */
- if (value_bits_valid (val, TARGET_CHAR_BIT * offset,
- TARGET_CHAR_BIT * TYPE_LENGTH (type)))
+ if (!value_bits_any_optimized_out (val,
+ TARGET_CHAR_BIT * offset,
+ TARGET_CHAR_BIT * TYPE_LENGTH (type)))
{
struct value *value;
int full, top, using_enc;
/* 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. */
for (i = 0; i < n_baseclasses; i++)
{
- int boffset;
+ int boffset = 0;
int skip;
struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
- char *basename = TYPE_NAME (baseclass);
- const gdb_byte *base_valaddr;
- const struct value *base_val;
+ const char *basename = TYPE_NAME (baseclass);
+ const gdb_byte *base_valaddr = NULL;
+ const struct value *base_val = NULL;
+ volatile struct gdb_exception ex;
if (BASETYPE_VIA_VIRTUAL (type, i))
{
thisoffset = offset;
thistype = real_type;
- boffset = baseclass_offset (type, i, valaddr + offset,
- address + offset);
- skip = ((boffset == -1) || (boffset + offset) < 0);
-
- if (BASETYPE_VIA_VIRTUAL (type, i))
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
{
- /* The virtual base class pointer might have been clobbered
- by the user program. Make sure that it still points to a
- valid memory location. */
+ boffset = baseclass_offset (type, i, valaddr, offset, address, val);
+ }
+ if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
+ skip = -1;
+ else if (ex.reason < 0)
+ skip = 1;
+ else
+ {
+ skip = 0;
- if (boffset != -1
- && ((boffset + offset) < 0
- || (boffset + offset) >= TYPE_LENGTH (real_type)))
+ if (BASETYPE_VIA_VIRTUAL (type, i))
{
- /* FIXME (alloca): unsafe if baseclass is really really
- large. */
- gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
-
- if (target_read_memory (address + boffset, buf,
- TYPE_LENGTH (baseclass)) != 0)
- skip = 1;
- base_val = value_from_contents_and_address (baseclass,
- buf,
- address + boffset);
- thisoffset = 0;
- boffset = 0;
- thistype = baseclass;
- base_valaddr = value_contents_for_printing_const (base_val);
+ /* 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 *buf;
+ struct cleanup *back_to;
+
+ buf = xmalloc (TYPE_LENGTH (baseclass));
+ back_to = make_cleanup (xfree, buf);
+
+ if (target_read_memory (address + boffset, buf,
+ TYPE_LENGTH (baseclass)) != 0)
+ skip = 1;
+ base_val = value_from_contents_and_address (baseclass,
+ buf,
+ address + boffset);
+ baseclass = value_type (base_val);
+ thisoffset = 0;
+ boffset = 0;
+ thistype = baseclass;
+ base_valaddr = value_contents_for_printing_const (base_val);
+ do_cleanups (back_to);
+ }
+ else
+ {
+ base_valaddr = valaddr;
+ base_val = val;
+ }
}
else
{
base_val = val;
}
}
- else
- {
- base_valaddr = valaddr;
- base_val = val;
- }
/* Now do the printing. */
- if (options->pretty)
+ if (options->prettyformat)
{
fprintf_filtered (stream, "\n");
print_spaces_filtered (2 * recurse, stream);
fputs_filtered (basename ? basename : "", stream);
fputs_filtered ("> = ", stream);
-
- if (skip)
- fprintf_filtered (stream, "<invalid address>");
+ if (skip < 0)
+ val_print_unavailable (stream);
+ else if (skip > 0)
+ val_print_invalid_address (stream);
else
{
int result = 0;
- /* Attempt to run the Python pretty-printers on the
+ /* Attempt to run an extension language pretty-printer on the
baseclass if possible. */
if (!options->raw)
- result = apply_val_pretty_printer (baseclass, base_valaddr,
- thisoffset + boffset,
- value_address (base_val),
- stream, recurse, base_val,
- options, current_language);
-
+ result
+ = apply_ext_lang_val_pretty_printer (baseclass, base_valaddr,
+ thisoffset + boffset,
+ value_address (base_val),
+ stream, recurse,
+ base_val, options,
+ current_language);
-
if (!result)
cp_print_value_fields (baseclass, thistype, base_valaddr,
thisoffset + boffset,
const struct value_print_options *options)
{
struct value_print_options opts;
-
+
+ if (value_entirely_optimized_out (val))
+ {
+ val_print_optimized_out (val, stream);
+ return;
+ }
+
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
CORE_ADDR *first_dont_print;
/* VAL is a byte offset into the structure type DOMAIN.
Find the name of the field for that offset and
print it. */
- struct type *domain = TYPE_DOMAIN_TYPE (type);
+ struct type *domain = TYPE_SELF_TYPE (type);
LONGEST val;
- unsigned int fieldno;
+ int fieldno;
val = extract_signed_integer (valaddr,
TYPE_LENGTH (type),
if (domain != NULL)
{
- char *name;
+ const char *name;
fputs_filtered (prefix, stream);
name = type_name_no_tag (domain);
if (name)
fputs_filtered (name, stream);
else
- c_type_print_base (domain, stream, 0, 0);
+ c_type_print_base (domain, stream, 0, 0, &type_print_raw_options);
fprintf_filtered (stream, "::");
fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream);
}