public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Julio Guerra <guerr@julio.in>, gdb-patches@sourceware.org
Cc: Mike Frysinger <vapier@gentoo.org>
Subject: Re: [PATCH 3/4] Explicit fixed-width integral File I/O protocol types
Date: Wed, 02 May 2018 10:46:00 -0000	[thread overview]
Message-ID: <fbc4c2f2-df49-6eaf-bb1e-3c36807af8d2@redhat.com> (raw)
In-Reply-To: <20180428011940.115515-4-julio@farjump.io>

On 04/28/2018 02:19 AM, Julio Guerra wrote:
> The File I/O extension defines portable types of there host-specific
> counterparts, such as `struct stat` and `struct timeval`. This patch improves
> these type definitions in `include/gdb/fileio.h` to make possible sharing them
> with target programs, and avoid redefining them by being able to include this
> header, even with cross-compiled programs.
> 
> The patch thus removes several drawbacks:
> - avoid implicit pointers when defining fixed-width integers as array typedefs.
> - explicitly state the sizes of fixed-width integers (e.g. fio_ulong_t becomes
>   fio_uint64_t).
> It also renames a few misnamed conversion functions with the convention
> `host_to_fileio_*` used everywhere else.
> 
> Note that fixed-width integer types are defined using GCC's preprocessor builtin
> macros to avoid using the libc's stdint.h which might not be available on the
> target compiler. Therefore, `include/gdb/fileio.h` is standalone.

Sorry, but NAK.

I don't see how using GCC preprocessor builtins would be more
portable than stdint.h.  That doesn't make the file
standalone -- it makes it dependent on gcc instead.

But regardless, the major problem here is that this approach
does not work, because it ignores the issue of alignment and
padding holes.
With the current approach, all structure fields are aligned
to 1 byte.  With the explicit types approach, fields are
aligned to their natural alignment.  E.g., from a glance,
it seems like we'd be creating a 4-byte padding hole after
fst_rdev.  Even if by chance the fields end up aligned,
that's not something we should be relying on.  Both host
and client must agree on the layout of the data structures.
fio_stat objects are copied directly into target memory,
see tail end of remote-fileio.c:remote_fileio_func_stat,
for example:

  if (statptr)
    {
      host_to_fileio_stat (&st, &fst);
      host_to_fileio_uint (0, fst.fst_dev);

      errno = target_write_memory (statptr, (gdb_byte *) &fst, sizeof fst);
      if (errno != 0)

As for the "int"/"long"/etc naming vs explicitly-sized uint32_t etc.,
note that the File I/O protocol's "int" "long" etc. types are defined here:

 https://sourceware.org/gdb/current/onlinedocs/gdb/Integral-Datatypes.html#Integral-Datatypes

I don't have a strong opinion, but I'm not sure it's worth it to
deviate from the documentation.

Thanks,
Pedro Alves

  reply	other threads:[~2018-05-02 10:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-28  1:19 [PATCH 0/4] Some File I/O improvements for embedded programming Julio Guerra
2018-04-28  1:19 ` [PATCH 3/4] Explicit fixed-width integral File I/O protocol types Julio Guerra
2018-05-02 10:46   ` Pedro Alves [this message]
     [not found]     ` <332abe88-4b88-3f06-7141-31a798f2b153@farjump.io>
2018-05-02 15:18       ` Julio Guerra
2018-05-02 16:14         ` Joel Brobecker
     [not found]           ` <a5149a53-09e3-2a08-607a-38d81dfa5eac@farjump.io>
2018-05-02 16:31             ` Julio Guerra
2018-04-28  1:19 ` [PATCH 1/4] Remove the restriction of File I/O functions to regular files only Julio Guerra
2018-04-30  1:54   ` Simon Marchi
2018-04-28  1:19 ` [PATCH 4/4] Install gdb/fileio.h Julio Guerra
2018-04-28  1:19 ` [PATCH 2/4] Do not clear the value of st_dev in File I/O's stat() Julio Guerra

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=fbc4c2f2-df49-6eaf-bb1e-3c36807af8d2@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guerr@julio.in \
    --cc=vapier@gentoo.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).