public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Julio Guerra" <julio@farjump.io>
To: "Pedro Alves" <palves@redhat.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: "Mike Frysinger" <vapier@gentoo.org>,
	"Joel Brobecker" <brobecker@adacore.com>
Subject: Re: [PATCH 3/4] Explicit fixed-width integral File I/O protocol types
Date: Wed, 02 May 2018 15:18:00 -0000	[thread overview]
Message-ID: <01020163216ed537-dae77402-9d35-42f2-ad27-64c89137aa03-000000@eu-west-1.amazonses.com> (raw)
In-Reply-To: <fbc4c2f2-df49-6eaf-bb1e-3c36807af8d2@redhat.com>

Hello,

Since I am talking a lot of embedded software, I CC'd Joel Brobecker
from AdaCore to maybe give the final direction for a v2.

On 05/02/2018 12:45, Pedro Alves wrote :
> 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.
I was indeed writing a GCC-based solution. Isn't GDB only compiled with GCC?

When compiling embedded programs doing File IOs, I have always been in
bare-metal cases, thus using CFLAGS "-ffreestanding -nostdinc
-nostdlib". So including "stdint.h" would fail because of -nostdinc. And
since my end goal here is to make fileio.h the single source of truth of
File IO protocol types, to then be able to include it in other C/C++
programs, I need it be compiled with these flags, i.e. without the
standard library. And in my opinion, using the File IO protocol in
bare-metal programs is where File IOs shine the most :)

So, if other compilers than GCC are required, I can rewrite it using
standard unsigned int, etc.
> 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)

Yes, and this is why I rather prefer this fileio.h file to become the
single source of truth instead of redefining them and ending with
mistakes such as memory overflows. For example, note the "sizeof fst",
where we are assuming that the target program has correctly redefined
it. Sharing fileio.h with the target will most likely limit the problem.

I indeed missed the alignment. Can't we simply pack the structure
"__attribute__ ((packed))"? I find these implicit "address-of" used
everywhere in GDB's code very opaque, and I am not sure how it would end
up when included in other C/C++ programs. It is anyway a source of
errors since no one expects integral types to be defined as an array, at
least not named like that (for example, I had problems because I wrote
fio_uint* to pass a File IO integer pointer, which ends up as a
"char(*)[32]"...).
> 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.
Sorry, I missed this documentation entry. I'm totally fine in keeping
current type names since if fielio.h ends up installed, we would still
be able to avoid redefiniton mistakes and reuse them.

-- 
Julio Guerra
Co-founder & CTO of Farjump
Mobile: +33 618 644 164
LinkedIn: https://linkedin.com/in/guerrajulio
Slack: farjump.slack.com


  parent reply	other threads:[~2018-05-02 15:18 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 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
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
     [not found]     ` <332abe88-4b88-3f06-7141-31a798f2b153@farjump.io>
2018-05-02 15:18       ` Julio Guerra [this message]
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

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=01020163216ed537-dae77402-9d35-42f2-ad27-64c89137aa03-000000@eu-west-1.amazonses.com \
    --to=julio@farjump.io \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --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).