[1/4] Remove the restriction of File I/O functions to regular files only

Message ID 20180428011940.115515-2-julio@farjump.io
State New, archived
Headers

Commit Message

Julio Guerra April 28, 2018, 1:19 a.m. UTC
  The major goal is being able to write advanced embedded testing functions, like:
- reading/writing to a dedicated fifo between the embedded program and the host,
  instead of using the GDB console only.
- mocking features based on host's.

Tested with https://github.com/farjump/raspberry-pi/blob/ea31c48d7c7eed27d39fb1bec2d3a1d308cb8ae7/src/semihosting/semihosting.c

Also answers to an old RFC I did on the ML: https://sourceware.org/ml/gdb/2016-07/msg00003.html

2018-04-28  Julio Guerra  <julio@farjump.io>

	* gdb/remote-fileio.c: allow using File I/O functions with special
	files.

Signed-off-by: Julio Guerra <julio@farjump.io>
---
 gdb/ChangeLog       |  5 +++++
 gdb/remote-fileio.c | 24 ------------------------
 2 files changed, 5 insertions(+), 24 deletions(-)
  

Comments

Simon Marchi April 30, 2018, 1:54 a.m. UTC | #1
Hi Julio,

Thanks for the patch.  I was not familiar with the fileio feature until 
now, but I have some generic comments (until someone that might be more 
familiar takes a look).

We seem to have a test for fileio already, in 
testsuite/gdb.base/fileio.exp.  The test sort of runs on native Linux, 
but I suppose it doesn't actually test fileio (the debugged program just 
accesses the filesystem directly).  It's also not supported by 
gdbserver.  Would it be possible for you to run this test using your 
target, see if if it passes before and after your patch?  Also, it might 
be a good idea to enhance that test to check for the capabilities that 
this patch adds (opening/reading a non-regular file).

If you (or Mike who is in CC) would know how to run it, maybe using some 
simulator available upstream, I'd be curious to know how.

On 2018-04-27 21:19, Julio Guerra wrote:
> The major goal is being able to write advanced embedded testing 
> functions, like:
> - reading/writing to a dedicated fifo between the embedded program and 
> the host,
>   instead of using the GDB console only.
> - mocking features based on host's.
> 
> Tested with
> https://github.com/farjump/raspberry-pi/blob/ea31c48d7c7eed27d39fb1bec2d3a1d308cb8ae7/src/semihosting/semihosting.c
> 
> Also answers to an old RFC I did on the ML:
> https://sourceware.org/ml/gdb/2016-07/msg00003.html
> 
> 2018-04-28  Julio Guerra  <julio@farjump.io>
> 
> 	* gdb/remote-fileio.c: allow using File I/O functions with special
> 	files.

Remove the "gdb/" part of the filename (the name should be relative to 
the ChangeLog location), and capitalize "allow".

Thanks,

Simon
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 55e640581a..a9ddac5f98 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-04-28  Julio Guerra  <julio@farjump.io>
+
+	* gdb/remote-fileio.c: allow using File I/O functions with special
+	files.
+
 2018-04-27  Alexandre Oliva  <aoliva@redhat.com>
 
 	* compile/compile-c-types.c (convert_int, convert_float):
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 4c648a9c83..fa3cb15033 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -407,24 +407,6 @@  remote_fileio_func_open (char *buf)
       return;
     }
 
-  /* Check if pathname exists and is not a regular file or directory.  If so,
-     return an appropriate error code.  Same for trying to open directories
-     for writing.  */
-  if (!stat (pathname, &st))
-    {
-      if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
-	{
-	  remote_fileio_reply (-1, FILEIO_ENODEV);
-	  return;
-	}
-      if (S_ISDIR (st.st_mode)
-	  && ((flags & O_WRONLY) == O_WRONLY || (flags & O_RDWR) == O_RDWR))
-	{
-	  remote_fileio_reply (-1, FILEIO_EISDIR);
-	  return;
-	}
-    }
-
   fd = gdb_open_cloexec (pathname, flags, mode);
   if (fd < 0)
     {
@@ -885,12 +867,6 @@  remote_fileio_func_stat (char *buf)
       remote_fileio_return_errno (-1);
       return;
     }
-  /* Only operate on regular files and directories.  */
-  if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
-    {
-      remote_fileio_reply (-1, FILEIO_EACCES);
-      return;
-    }
   if (statptr)
     {
       host_to_fileio_stat (&st, &fst);