Currently, the 'struct -o' command does not display the offsets
of struct fields like this:

  crash> struct page -ox ffffce98870a0d40
  struct page {
    [ffffce98870a0d40] unsigned long flags;
           union {
               struct {...};
               struct {...};
               struct {...};
               struct {...};
               struct {...};
               struct {...};
               struct {...};
    [ffffce98870a0d48]     struct callback_head callback_head;
           };
    ...
  }
  SIZE: 0x40

The gdb-10.2 added a new option '/o' for the 'ptype' command, which
prints the offsets and sizes of struct fields, let's use it now to
fix the above issue.

Signed-off-by: Lianbo Jiang <[email protected]>
---
 symbols.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/symbols.c b/symbols.c
index 5d12a021c769..9ba43dee61c8 100644
--- a/symbols.c
+++ b/symbols.c
@@ -6845,6 +6845,16 @@ do_datatype_declaration(struct datatype_member *dm, 
ulong flags)
        len = dm->size;
        multiline = NULL;
         while (fgets(buf, BUFSIZE, pc->tmpfile)) {
+               char *p = NULL;
+
+               p =  strstr(buf, "*/");
+               if (p) {
+                       p += strlen("*/");
+                       shift_string_left(buf, p - buf);
+                       if (strstr(buf, "type = "))
+                               strip_beginning_whitespace(buf);
+               }
+
                 if (STRNEQ(buf, "type = ")) {
                        multiline = strstr(buf, "{");
                        if (flags & TYPEDEF)
@@ -7802,7 +7812,7 @@ whatis_datatype(char *st, ulong flags, FILE *ofp)
         else if (flags & UNION_REQUEST)
                 sprintf(lookbuf, "ptype union %s", st);
         else if (flags & STRUCT_REQUEST)
-                sprintf(lookbuf, "ptype struct %s", st);
+                sprintf(lookbuf, "ptype /o struct %s", st);
         else
                 return;
 
-- 
2.20.1

--
Crash-utility mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/crash-utility
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Reply via email to