[RFA 0/2] Support ptype/o in Rust

Tom Tromey tom@tromey.com
Wed Jun 27 02:59:00 GMT 2018


>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> Even though it's a bit uglier than your solution, IMO it's easier to
Sergio> understand and correlate the sizes with their respective structs.
Sergio> Compare this to:

Sergio>   (gdb) ptype /o struct c
Sergio>   /* offset    |  size */  type = struct c {
Sergio>   /*    0      |    12 */    struct a {
Sergio>   /*    0      |     4 */        int a1;
Sergio>   /*    4      |     1 */        char a2;
Sergio>   /* XXX  3-byte hole */
Sergio>   /*    8      |     4 */        int a3;
Sergio>   /* total size (bytes):   12 */
Sergio>                              } c1;
Sergio>   /*   12      |    20 */    struct b {
Sergio>   /*   12      |    12 */        struct a {
Sergio>   /*   12      |     4 */            int a1;
Sergio>   /*   16      |     1 */            char a2;
Sergio>   /* XXX  3-byte hole */
Sergio>   /*   20      |     4 */            int a3;
Sergio>   /* total size (bytes):   12 */
Sergio>                                  } b1;
Sergio>   /*   24      |     4 */        int b2;
Sergio>   /*   28      |     1 */        char b3;
Sergio>   /* XXX  3-byte padding */
Sergio>   /* total size (bytes):   20 */
Sergio>                              } c2;
Sergio>   /*   32      |     1 */    char c3;
Sergio>   /* XXX  3-byte hole */
Sergio>   /*   36      |     4 */    int c4;
Sergio>   /* total size (bytes):   40 */
Sergio>                            }

My idea was to line up the total size with the "}" so it would instead
appear as:

  (gdb) ptype /o struct c
  /* offset    |  size */  type = struct c {
  /*    0      |    12 */    struct a {
  /*    0      |     4 */        int a1;
  /*    4      |     1 */        char a2;
  /* XXX  3-byte hole */
  /*    8      |     4 */        int a3;
  /* total size:    12 */    } c1;
  /*   12      |    20 */    struct b {
  /*   12      |    12 */        struct a {
  /*   12      |     4 */            int a1;
  /*   16      |     1 */            char a2;
  /* XXX  3-byte hole */
  /*   20      |     4 */            int a3;
  /* total size:    12 */    } b1;
  /*   24      |     4 */        int b2;
  /*   28      |     1 */        char b3;
  /* XXX  3-byte padding */
  /* total size:    20 */    } c2;
  /*   32      |     1 */    char c3;
  /* XXX  3-byte hole */
  /*   36      |     4 */    int c4;
  /* total size:    40 */  }

But yeah, maybe that's a bit harder to read than the status quo.

Sergio> Anyway, TBH I don't have a strong opinion here.  If you want to indent
Sergio> the outermost fields by 4 spaces, I won't oppose.

I'm on the fence.  It works ok now; it just made some of the code a
little uglier.

Tom



More information about the Gdb-patches mailing list