gdb: print details of unnamed struct and union

Currently gdb's "ptype" command does not print the details of unnamed
structure and union deeper than second level in a structure, it prints
only "{...}" instead.  And crash's "struct" and similar commands also
inherit this behavior, so we cannot get the full information of them.

To print the details of them, change the show variable when it is an
unnamed one like crash-7.x.

Without the patch:
   crash> struct -o page
   struct page {
      [0] unsigned long flags;
          union {
              struct {...};
              struct {...};
   ...

With the patch:
   crash> struct -o page
   struct page {
      [0] unsigned long flags;
          union {
              struct {
      [8]         struct list_head lru;
     [24]         struct address_space *mapping;
     [32]         unsigned long index;
     [40]         unsigned long private;
              };
              struct {
      [8]         dma_addr_t dma_addr;
              };
   ...

Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
This commit is contained in:
Kazuhito Hagio 2022-05-31 17:12:16 +09:00
parent 0f162febeb
commit dda5b2d02b

View File

@ -1638,3 +1638,15 @@ exit 0
$(ECHO_CXXLD) $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
-o $(shell /bin/cat mergeobj) $(LIBGDB_OBS) \
$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) $(shell /bin/cat mergelibs)
--- gdb-10.2/gdb/c-typeprint.c.orig
+++ gdb-10.2/gdb/c-typeprint.c
@@ -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),