Hi Lianbo,
On 2022/05/27 18:56, lijiang wrote:
> On Fri, May 27, 2022 at 5:14 PM HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@nec.com <mailto:k-hagio-ab@nec.com>> wrote:
>
> On 2022/05/27 16:03, lijiang wrote:
> > >> If no another gdb setting, we will need to rewrite the parser.
> > >> So first, I'd like to know whether there is no another setting.
> > >
> > > Otherwise, maybe we can patch the gdb code...
> > >
> > > That '{...}' is probably printed in c_type_print_base_struct_union().
> > > And found a comment for c_type_print_base_1() in gdb/c-typeprint.c:
> > >
> > > SHOW negative means just print the type name or struct tag if there
> > > is one. If there is no name, print something sensible but concise
> > > like "struct {...}".
> > >
> > > Just an idea and clue.
> >
> >
> > I like the good idea.
> >
> > Just a rough try and I've not tested enough, but this patch might be
> > somewhat good.
> >
> > --- gdb-10.2.orig/gdb/c-typeprint.c 2022-05-27 14:49:53.079853333 +0900
> > +++ gdb-10.2/gdb/c-typeprint.c 2022-05-27 14:47:18.729165094 +0900
> > @@ -1043,6 +1043,8 @@
> > struct type_print_options local_flags = *flags;
> > local_flags.local_typedefs = NULL;
> >
> > + show = 1;
> > +
> > std::unique_ptr<typedef_hash_table> hash_holder;
> > if (!flags->raw)
> > {
> >
> >
> > This looks more reasonable to me. Could you please post a patch with this fix?
>
> Sure. But more understanding and testing are needed, I will look into it
> next week.
I found that gdb-7.6 also prints "{...}" for unnamed struct/union.
(gdb) ptype struct page
type = struct page {
unsigned long flags;
struct address_space *mapping;
struct {
union {...};
union {...};
};
...
And crash-7.x (gdb-7.6.patch) had the following patch to print the details
of unnamed struct/union.
--- gdb-7.6/gdb/c-typeprint.c.orig
+++ gdb-7.6/gdb/c-typeprint.c
@@ -1097,7 +1097,8 @@ c_type_print_base (struct type *type, st
fprintf_filtered (stream, "static ");
c_print_type (TYPE_FIELD_TYPE (type, i),
TYPE_FIELD_NAME (type, i),
- stream, show - 1, level + 4,
+ stream, strlen(TYPE_FIELD_NAME (type, i)) ?
+ show - 1 : show, level + 4,
&local_flags);
if (!field_is_static (&TYPE_FIELD (type, i))
&& TYPE_FIELD_PACKED (type, i))
But gdb-10.2.patch does not have it, and prints "{...}" again.
Good findings, Kazu.
So I will post the following patch later to do the same thing in gdb-10.2.
--- gdb-10.2/gdb/c-typeprint.c.orig 2022-05-31 13:15:39.099537173 +0900
+++ gdb-10.2/gdb/c-typeprint.c 2022-05-31 13:17:02.076909579 +0900
@@ -1202,6 +1202,9 @@ c_type_print_base_struct_union (struct t
= podata->end_bitpos
- TYPE_LENGTH (type->field (i).type ()) * TARGET_CHAR_BIT;
}
+ else if (strlen(TYPE_FIELD_NAME (type, i)) == 0)
+ /* crash: Print details for unnamed struct and union. */
+ newshow = show;
c_print_type_1 (type->field (i).type (),
TYPE_FIELD_NAME (type, i),
This looks good, it can keep the same behavior as gdb-7.6.
Thanks.
Lianbo
Thanks,
Kazu