summaryrefslogtreecommitdiff
path: root/gdb/c-valprint.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-03-13 17:39:52 -0600
committerTom Tromey <tom@tromey.com>2020-03-13 18:03:41 -0600
commit64b653ca7058bfd4f91879dea628809d398b488e (patch)
tree83ea5b40798b6782b733992385d12020bdd9667d /gdb/c-valprint.c
parent6999f067c1b30c1a2c3e41a0f68f74e459652560 (diff)
downloadbinutils-gdb-64b653ca7058bfd4f91879dea628809d398b488e.tar.gz
Introduce cp_print_value_fields and c_value_print_struct
This adds cp_print_value_fields and c_value_print_struct, value-based analogues of the corresponding val-printing functions. Note that the Modula-2 printing code also calls cp_print_val_fields, and so is updated to call the function function. gdb/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * m2-valprint.c (m2_value_print_inner): Use cp_print_value_fields. * cp-valprint.c (cp_print_value_fields): New function. * c-valprint.c (c_value_print_struct): New function. (c_value_print_inner): Use c_value_print_struct. * c-lang.h (cp_print_value_fields): Declare.
Diffstat (limited to 'gdb/c-valprint.c')
-rw-r--r--gdb/c-valprint.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index dd4ab728c21..0f40a86872a 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -540,6 +540,34 @@ c_val_print_struct (struct type *type, const gdb_byte *valaddr,
NULL, 0);
}
+/* c_value_print helper for TYPE_CODE_STRUCT and TYPE_CODE_UNION. */
+
+static void
+c_value_print_struct (struct value *val, struct ui_file *stream, int recurse,
+ const struct value_print_options *options)
+{
+ struct type *type = check_typedef (value_type (val));
+
+ if (TYPE_CODE (type) == TYPE_CODE_UNION && recurse && !options->unionprint)
+ fprintf_filtered (stream, "{...}");
+ else if (options->vtblprint && cp_is_vtbl_ptr_type (type))
+ {
+ /* Print the unmangled name if desired. */
+ /* Print vtable entry - we only get here if NOT using
+ -fvtable_thunks. (Otherwise, look under
+ TYPE_CODE_PTR.) */
+ struct gdbarch *gdbarch = get_type_arch (type);
+ int offset = TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8;
+ struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
+ const gdb_byte *valaddr = value_contents_for_printing (val);
+ CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
+
+ print_function_pointer_address (options, gdbarch, addr, stream);
+ }
+ else
+ cp_print_value_fields (val, stream, recurse, options, NULL, 0);
+}
+
/* c_val_print helper for TYPE_CODE_UNION. */
static void
@@ -746,7 +774,6 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
const struct value_print_options *options)
{
struct type *type = value_type (val);
- CORE_ADDR address = value_address (val);
const gdb_byte *valaddr = value_contents_for_printing (val);
type = check_typedef (type);
@@ -765,13 +792,8 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
break;
case TYPE_CODE_UNION:
- c_val_print_union (type, valaddr, 0, address, stream,
- recurse, val, options);
- break;
-
case TYPE_CODE_STRUCT:
- c_val_print_struct (type, valaddr, 0, address, stream,
- recurse, val, options);
+ c_value_print_struct (val, stream, recurse, options);
break;
case TYPE_CODE_INT: