This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] printing/setting flag register fields
>>>>> "Doug" == Doug Evans <dje@google.com> writes:
Doug> An off-the-cuff example is an option to ptype to print field
Doug> offsets for structs in general. [I'm assuming such a facility
Doug> doesn't already exist.] That would probably be more useful than
Doug> always printing the offsets anyway.
I once wrote a simple, C/C++-only patch to add pahole-like output to
ptype. I appended it.
Also in the archer repository there is a "pahole" command written in
Python. It does something similar.
I like the idea of an option to ptype.
Tom
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 56d12f9..c38fc31 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -744,6 +744,9 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show,
}
else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
{
+ int bitpos, field_size;
+ int is_union = TYPE_CODE (type) == TYPE_CODE_UNION;
+
cp_type_print_derivation_info (stream, type);
fprintf_filtered (stream, "{\n");
@@ -830,6 +833,7 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show,
/* If there is a base class for this type,
do not print the field that it occupies. */
+ bitpos = 0;
len = TYPE_NFIELDS (type);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
{
@@ -871,6 +875,25 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show,
}
}
+ if (!is_union && bitpos != TYPE_FIELD_BITPOS (type, i))
+ {
+ fprintf_filtered (stream,
+ "\n /* XXX %d bit hole, try to pack */\n\n",
+ TYPE_FIELD_BITPOS (type, i) - bitpos);
+ bitpos = TYPE_FIELD_BITPOS (type, i);
+ }
+ if (TYPE_FIELD_PACKED (type, i))
+ field_size = TYPE_FIELD_BITSIZE (type, i);
+ else
+ field_size = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)); /* FIXME */
+
+ if (is_union)
+ print_spaces_filtered (14, stream);
+ else
+ fprintf_filtered (stream, " /* %3d %3d */",
+ bitpos / 8, field_size / 8);
+ bitpos += field_size;
+
print_spaces_filtered (level + 4, stream);
if (TYPE_FIELD_STATIC (type, i))
{
@@ -1036,6 +1059,8 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show,
}
}
+ if (level)
+ print_spaces_filtered (14, stream);
fprintfi_filtered (level, stream, "}");
if (TYPE_LOCALTYPE_PTR (type) && show >= 0)