From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 0/2] Support ptype/o in Rust
Date: Sat, 23 Jun 2018 23:44:00 -0000 [thread overview]
Message-ID: <87woup9ifk.fsf@redhat.com> (raw)
In-Reply-To: <20180623202227.17259-1-tom@tromey.com> (Tom Tromey's message of "Sat, 23 Jun 2018 14:22:25 -0600")
On Saturday, June 23 2018, Tom Tromey wrote:
> This adds support for ptype/o to the Rust code.
>
> The first patch slightly refactors the existing ptype/o code. The
> utility functions are now public methods on struct print_offset_data.
Thanks for the patches, Tom.
> The second patch changes the Rust language code. I would self-approve
> this one but it required a change outside of Rust. Perhaps this check
> ought to have been a flag on the language_defn.
>
> I noticed that ptype/o generates somewhat funny output:
>
> /* offset | size */ type = union simple::Union {
> /* 1 */ f1: i8,
> /* 1 */ f2: u8,
>
> /* total size (bytes): 1 */
> }
>
> Here, I think it might be cleaner to put the "total size" information
> on the same line as the trailing "}" (and of course not indent it),
> like:
>
> /* offset | size */ type = union simple::Union {
> /* 1 */ f1: i8,
> /* 1 */ f2: u8,
> /* total size 1 */ }
>
> If you agree I can at least file a bug or maybe implement it.
Your version does look better (and IIRC, one of the early versions of
the patch printed "total size" at column 0), but I think it may be a bit
confusing when we're dealing with inner structures. For example:
$ cat 2.c
struct a
{
int a1;
char a2;
int a3;
};
struct b
{
struct a b1;
int b2;
char b3;
};
struct c
{
struct a c1;
struct b c2;
char c3;
int c4;
};
int main ()
{
struct c foo;
return 0;
}
We have:
(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 (bytes): 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 (bytes): 12 */
} b1;
/* 24 | 4 */ int b2;
/* 28 | 1 */ char b3;
/* XXX 3-byte padding */
/* total size (bytes): 20 */
} c2;
/* 32 | 1 */ char c3;
/* XXX 3-byte hole */
/* 36 | 4 */ int c4;
/* total size (bytes): 40 */
}
Even though it's a bit uglier than your solution, IMO it's easier to
understand and correlate the sizes with their respective structs.
Compare this to:
(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 (bytes): 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 (bytes): 12 */
} b1;
/* 24 | 4 */ int b2;
/* 28 | 1 */ char b3;
/* XXX 3-byte padding */
/* total size (bytes): 20 */
} c2;
/* 32 | 1 */ char c3;
/* XXX 3-byte hole */
/* 36 | 4 */ int c4;
/* total size (bytes): 40 */
}
Of course, it's still possible to read the output and interpret it
correctly, but it demands a bit more effort, I think.
Maybe a solution would be to be a bit more verbose, like:
/* total size of struct a (bytes):... */
> Additionally I noticed that in C, in most cases fields are indented 4
> spaces, but with ptype/o the outermost fields are only indented 2
> spaces (relative to the "type =" text). I think this is probably
> unintended as well, but I thought I'd ask... ?
I don't really remember why I made this decision. I guess it had to do
with the fact that using 4 whitespaces to indent would consume a lot of
unnecessary space, and since ptype/o prints more information than the
regular ptype, every whitespace counts. I vaguely remember having this
thought, so that may be the reason, after all. Or maybe it also had
something to do with increasing the readability?
Anyway, TBH I don't have a strong opinion here. If you want to indent
the outermost fields by 4 spaces, I won't oppose.
Thanks,
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
next prev parent reply other threads:[~2018-06-23 23:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-23 20:22 Tom Tromey
2018-06-23 20:22 ` [RFA 2/2] " Tom Tromey
2018-06-26 19:08 ` Simon Marchi
2018-06-26 20:55 ` Tom Tromey
2018-06-23 20:22 ` [RFA 1/2] Move ptype/o printing code to typeprint.c Tom Tromey
2018-06-23 23:51 ` Sergio Durigan Junior
2018-06-26 20:54 ` Tom Tromey
2018-06-23 23:44 ` Sergio Durigan Junior [this message]
2018-06-27 2:59 ` [RFA 0/2] Support ptype/o in Rust Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87woup9ifk.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox