public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Julio Guerra <julio@farjump.io>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH v4] Allow using special files with File I/O functions
Date: Mon, 09 Jul 2018 14:37:00 -0000	[thread overview]
Message-ID: <263942fb-504c-7eeb-7840-fc4b70a76ed1@redhat.com> (raw)
In-Reply-To: <010201647f2fec5a-727b623a-1c7f-4d7e-a9e2-e8076d9e3cc2-000000@eu-west-1.amazonses.com>

On 07/09/2018 02:16 PM, Julio Guerra wrote:
>>> Remove the restriction in remote_fileio_func_open() to regular files only and
>>> add support for special file types in the File IO stat structure.
>>> The link file type is not part of the new definitions as stat() and fstat()
>>> called by remote_fileio_func_stat() and remote_fileio_func_fstat() follow links,
>>> it is thus not possible to obtain this file type in the File IO stat structure.
>>>
>>> Add tests to cover as much cases as possible, limited by the fact that some
>>> types such as FIFOs or character devices cannot be created on non-unix operating
>>> systems. This limits the test cases to a regular file, a directory and the
>>> standard output/input/error descriptors.
>>>
>>> The major goal is to be able to write advanced embedded testing functions, like:
>>> - using a FIFO between the embedded program and the host, instead of being
>>>   restricted to the GDB console only.
>>> - mocking features based on host's by using some host device.
>>>
>>> 2018-07-05  Julio Guerra  <julio@farjump.io>
>>>
>>> 	* remote-fileio.c (remote_fileio_func_open, remote_fileio_func_stat):
>>> 	Allow using File I/O functions open(), stat() and fstat() on special
>>> 	files.
>>> 	* common/fileio.c (fileio_to_host_mode, fileio_mode_pack): Add new
>>> 	special file types in fst_mode's definition.
>>> 	(host_to_fileio_stat): Define fst_dev using the new macro definitions
>>> 	and according to the file's type.
>>> 	* testsuite/gdb.base/fileio.c: Add test cases to cover some special
>>> 	files and file descriptors.
>>> 	* testsuite/gdb.base/fileio.exp: Likewise.
>>> 	* doc/gdb.texinfo: Document the changes.
>>> 	* NEWS: Briefly describe the changes of File I/O operations open, stat,
>>> 	fstat.
>> Note that testsuite and docs have their own ChangeLogs.  Please see:
>>
>>   https://sourceware.org/gdb/wiki/ContributionChecklist#ChangeLog
> 
> Ok.
> 
>>
>>> Signed-off-by: Julio Guerra <julio@farjump.io>
>> I'm not sure whether I asked this before, but, just in case,
>> do you have a copyright assignment on file with the FSF?
>> I looked for one now and couldn't find it.
>>
> 
> No, I don't.

See:

 https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment

The request-assign.future one is most common one.  Please follow the
instructions at the top of the file.

>>> diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
>>> index 313da642ea..168590245e 100644
>>> --- a/gdb/remote-fileio.c
>>> +++ b/gdb/remote-fileio.c
>>> @@ -885,16 +885,9 @@ remote_fileio_func_stat (remote_target *remote, char *buf)
>>>        remote_fileio_return_errno (remote, -1);
>>>        return;
>>>      }
>>> -  /* Only operate on regular files and directories.  */
>>> -  if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
>>> -    {
>>> -      remote_fileio_reply (remote, -1, FILEIO_EACCES);
>>> -      return;
>>> -    }
>>
>> What happens if we stat/open some kind of unsupported file type?
>> Do we end up with st_mode == 0 and report success anyway, or is
>> something else catching it and returning FILEIO_EACCES or some such?
>>
> 
> Yes, bits SFMT of st_mode end up with everything 0 and it doesn't fail.
> It's like not knowing what kind of file it exactly is, but still get
> other values.

Hmm, OK.  I mildly worry whether that that might cause trouble.
I wonder what other filesystem network protocols do here.  Like,
e.g.,  nfs, sshfs, etc.


>>>  
>>>  #define STRING      "Hello World"
>>>  
>>> @@ -292,7 +301,8 @@ test_stat (void)
>>>    ret = stat (OUTDIR FILENAME, &st);
>>>    if (!ret)
>>>      printf ("stat 1: ret = %d, errno = %d %s\n", ret, errno,
>>> -	    st.st_size == 11 ? "OK" : "");
>>> +	    st.st_dev == 0 && S_ISREG (st.st_mode) && st.st_size == 11 ?
>>> +	    "OK" : "");
>>>    else
>>>      printf ("stat 1: ret = %d, errno = %d\n", ret, errno);
>>>    stop ();
>>> @@ -311,8 +321,20 @@ test_stat (void)
>>>    /* Nonexistant file */
>>>    errno = 0;
>>>    ret = stat (NONEXISTANT, &st);
>>> -  printf ("stat 4: ret = %d, errno = %d %s\n", ret, errno,
>>> -  	  strerrno (errno));
>>> +  if (!ret)
>>> +    printf ("stat 4: ret = %d, errno = %d %s\n", ret, errno,
>>> +	    strerrno (errno));
>>> +  else
>>> +    printf ("stat 1: ret = %d, errno = %d\n", ret, errno);
>> Do we want to print errno in the !ret case?  That indicates the
>> stat call succeeded (even though we expect it to fail).
>> Might be that helps simplify the .exp, I haven't checked.
>>
>> But at least the strerrno call should be on the else
>> branch, as that's the branch where errno is meaninful, and
>> the .exp expects it:
>>
>>   FAIL: gdb.base/fileio.exp: Stat a nonexistant file returns ENOENT
>>
>> Did this pass against your stub?
> 
> Yes, here are logs of GDB's execution on this case:
> 
>> Continuing.
>> stat 4: ret = -1, errno = 2 ENOENT

I don't see how that could have been logs for the patch you sent,
because if ret really was -1, then that would have said "stat 1",
and would not have printed ENOENT.  Maybe you tested a
different patch?

>>> diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
>>> index bc409c26aa..234f304ac7 100644
>>> --- a/gdb/testsuite/gdb.base/fileio.exp
>>> +++ b/gdb/testsuite/gdb.base/fileio.exp
>>> @@ -31,7 +31,7 @@ if {[is_remote host]} {
>>>  
>>>  if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
>>>  	   executable \
>>> -	   [list debug "additional_flags=-DOUTDIR=\"$outdir/\""]] != "" } {
>>> +					 [list debug "additional_flags=-DOUTDIR=\"$outdir/\" [target_info fileio,cflags]" "ldflags=[target_info fileio,ldflags]"]] != "" } {
>> I couldn't tell what's this change for?  Why did you need it?
> 
> I couldn't find any other way of adding some CFLAGS and LDFLAGS to the
> call to the cross-compiler to link against the libc using File IOs, to
> add target-specific compilation flags, etc. For example, in my case:
> 
>> set_board_info fileio,cflags "--specs=$sdk/Alpha.specs
> -mfloat-abi=hard -mfpu=vfp -march=armv6zk -mtune=arm1176jzf-s"
>> set_board_info fileio,ldflags "-Wl,-T$sdk/link.ld"

Is this something really specific to this testcase?  Don't you
need to do the same for all other testcases?

Did you try CC_FOR_TARGET/LD_FOR_TARGET?

Thanks,
Pedro Alves

  reply	other threads:[~2018-07-09 14:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180705091618.33743-1-julio@farjump.io>
2018-07-05  9:16 ` Julio Guerra
2018-07-09 12:47   ` Pedro Alves
     [not found]     ` <a74d27a4-64c9-adcd-deaf-f36e0c03e73d@farjump.io>
2018-07-09 13:16       ` Julio Guerra
2018-07-09 14:37         ` Pedro Alves [this message]
     [not found]           ` <28e7d8d4-7a1a-8fe0-a868-bed711cdb417@farjump.io>
2018-07-09 15:22             ` Julio Guerra
2018-07-09 15:37               ` Pedro Alves

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=263942fb-504c-7eeb-7840-fc4b70a76ed1@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=julio@farjump.io \
    /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).