From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 5/7] Factor out struct and union printing code from c_val_print
Date: Wed, 08 Jul 2015 21:08:00 -0000 [thread overview]
Message-ID: <1436389629-18754-6-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1436389629-18754-1-git-send-email-simon.marchi@ericsson.com>
gdb/ChangeLog:
* c-valprint.c (c_val_print): Factor out struct and union
printing code to ...
(c_val_print_struct): ... this new function ...
(c_val_print_union): ... and this new function.
---
gdb/c-valprint.c | 88 +++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 58 insertions(+), 30 deletions(-)
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 9f68815..d950de3 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -369,6 +369,58 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
}
}
+/* c_val_print helper for TYPE_CODE_STRUCT. */
+
+static void
+c_val_print_struct (struct type *type, const gdb_byte *valaddr,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream, int recurse,
+ const struct value *original_value,
+ const struct value_print_options *options)
+{
+ 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 = (embedded_offset
+ + TYPE_FIELD_BITPOS (type,
+ VTBL_FNADDR_OFFSET) / 8);
+ struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
+ CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
+
+ print_function_pointer_address (options, gdbarch, addr, stream);
+ }
+ else
+ cp_print_value_fields_rtti (type, valaddr,
+ embedded_offset, address,
+ stream, recurse,
+ original_value, options,
+ NULL, 0);
+}
+
+/* c_val_print helper for TYPE_CODE_UNION. */
+
+static void
+c_val_print_union (struct type *type, const gdb_byte *valaddr,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream, int recurse,
+ const struct value *original_value,
+ const struct value_print_options *options)
+{
+ if (recurse && !options->unionprint)
+ {
+ fprintf_filtered (stream, "{...}");
+ }
+ else
+ {
+ c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+ recurse, original_value, options);
+ }
+}
+
/* See val_print for a description of the various parameters of this
function; they are identical. */
@@ -379,7 +431,6 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
const struct value *original_value,
const struct value_print_options *options)
{
- struct gdbarch *gdbarch = get_type_arch (type);
struct type *unresolved_type = type;
CHECK_TYPEDEF (type);
@@ -400,36 +451,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
break;
case TYPE_CODE_UNION:
- if (recurse && !options->unionprint)
- {
- fprintf_filtered (stream, "{...}");
- break;
- }
- /* Fall through. */
+ c_val_print_union (type, valaddr, embedded_offset, address, stream,
+ recurse, original_value, options);
+ break;
+
case TYPE_CODE_STRUCT:
- /*FIXME: Abstract this away. */
- 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.) */
- int offset = (embedded_offset
- + TYPE_FIELD_BITPOS (type,
- VTBL_FNADDR_OFFSET) / 8);
- struct type *field_type = TYPE_FIELD_TYPE (type,
- VTBL_FNADDR_OFFSET);
- CORE_ADDR addr
- = extract_typed_address (valaddr + offset, field_type);
-
- print_function_pointer_address (options, gdbarch, addr, stream);
- }
- else
- cp_print_value_fields_rtti (type, valaddr,
- embedded_offset, address,
- stream, recurse,
- original_value, options,
- NULL, 0);
+ c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+ recurse, original_value, options);
break;
case TYPE_CODE_INT:
--
2.1.4
next prev parent reply other threads:[~2015-07-08 21:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-08 21:08 [PATCH 0/7] Split c_val_print Simon Marchi
2015-07-08 21:08 ` [PATCH 2/7] Factor out print_unpacked_pointer from c_val_print Simon Marchi
2015-07-09 15:30 ` Simon Marchi
2015-07-08 21:08 ` [PATCH 1/7] Remove unneeded variable assignment Simon Marchi
2015-07-08 21:08 ` [PATCH 4/7] Factor out pointer printing code from c_val_print Simon Marchi
2015-07-09 15:32 ` Simon Marchi
2015-07-08 21:08 ` [PATCH 3/7] Factor out array " Simon Marchi
2015-07-08 21:08 ` Simon Marchi [this message]
2015-07-08 21:08 ` [PATCH 7/7] Factor out memberptr " Simon Marchi
2015-07-08 21:08 ` [PATCH 6/7] Factor out int " Simon Marchi
2015-07-09 10:53 ` [PATCH 0/7] Split c_val_print Pedro Alves
2015-07-09 15:28 ` Simon Marchi
2015-07-09 15:30 ` Pedro Alves
2015-07-09 23:42 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436389629-18754-6-git-send-email-simon.marchi@ericsson.com \
--to=simon.marchi@ericsson.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).