From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35251 invoked by alias); 28 Jun 2018 19:27:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 35232 invoked by uid 89); 28 Jun 2018 19:27:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=julio, H*MI:000000, H*M:000000, H*M:amazonses X-HELO: a6-212.smtp-out.eu-west-1.amazonses.com Received: from a6-212.smtp-out.eu-west-1.amazonses.com (HELO a6-212.smtp-out.eu-west-1.amazonses.com) (54.240.6.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Jun 2018 19:27:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=jl7vyxitgsfircfdhxflkj2c3tgxidze; d=farjump.io; t=1530214021; h=Subject:From:To:Cc:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=qvyNFu01uyeqd7+HcRC815LX85MUSDvGPNue3Ftsu+c=; b=WDOGr8JSv8ZQOjg1/M5V/BPgPlz9kmzdxSvZMuzMLaPdKn/1khAyPnwVT0W+XNh/ 6JB2C9dGPvkDCwZa5Kqk+vGL0Qn9ccoTrBUSE1gqaHahatCO54oBR3lqUS+q5Y8hh7a 6z2MQ9FrcxrBPPWoh2mlC1esxgqhSyC60eC7G08Q= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1530214021; h=Subject:From:To:Cc:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=qvyNFu01uyeqd7+HcRC815LX85MUSDvGPNue3Ftsu+c=; b=fY8Zyc+qya9iTs8Yz0O12EHsFg1f2FN6iaYaiTsiaJHCU77LNEzoyN9LRSN7yzT6 8M3VPaDmv+yJ1LrL3a/K8lVmjuWRbw5ba6pKPOa1lXV+GD4pAvd0tm/X5RLnddG8W40 VRJtMXoMm+EphB+IuBkIZfGQdA+bW4lqyoM0p1C8= Subject: [PATCH v3] Allow using special files with File I/O functions From: =?UTF-8?Q?Julio_Guerra?= To: =?UTF-8?Q?gdb-patches=40sourceware=2Eorg?= Cc: =?UTF-8?Q?Pedro_Alves?= , =?UTF-8?Q?Julio_Guerra?= Date: Thu, 28 Jun 2018 19:27:00 -0000 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable References: <20180628192635.44056-1-julio@farjump.io> X-Original-Mailer: git-send-email 2.18.0 Message-ID: <0102016447dcf9e9-3989bcd9-1272-4a05-93c5-77823c7a0921-000000@eu-west-1.amazonses.com> X-SW-Source: 2018-06/txt/msg00701.txt.bz2 - Remove the restriction to regular files only and add support for special = file=0D types in the File IO stat structure.=0D - Define a few more macro definitions of file types such as FIFOs, etc.=0D =0D The major goal is being able to write advanced embedded testing functions, = like:=0D - using a FIFO between the embedded program and the host, instead of being= =0D restricted only to the GDB console.=0D - mocking features based on host's by opening some /dev special files.=0D =0D 2018-06-28 Julio Guerra =0D =0D * remote-fileio.c (remote_fileio_func_open, remote_fileio_func_stat= ):=0D Allow using File I/O functions open(), stat() and fstat() on specia= l=0D files.=0D * ../include/gdb/fileio.h: Add macro definitions for special files,= =0D both for fst_dev and fst_mode fields of struct fst_stat.=0D * common/fileio.c (fileio_to_host_mode, fileio_mode_pack): Add new= =0D special file types in fst_mode's definition.=0D (host_to_fileio_stat): Define fst_dev using the new macro definitio= ns=0D and according to the file's type.=0D =0D Signed-off-by: Julio Guerra =0D ---=0D gdb/ChangeLog | 12 ++++++++=0D gdb/common/fileio.c | 66 +++++++++++++++++++++++++++++++++++---------=0D gdb/remote-fileio.c | 28 ++-----------------=0D include/gdb/fileio.h | 19 +++++++++++--=0D 4 files changed, 83 insertions(+), 42 deletions(-)=0D =0D diff --git a/gdb/ChangeLog b/gdb/ChangeLog=0D index 18c1915675..19cf5e38a6 100644=0D --- a/gdb/ChangeLog=0D +++ b/gdb/ChangeLog=0D @@ -1,3 +1,15 @@=0D +2018-06-28 Julio Guerra =0D +=0D + * remote-fileio.c (remote_fileio_func_open, remote_fileio_func_stat):=0D + Allow using File I/O functions open(), stat() and fstat() on special=0D + files.=0D + * ../include/gdb/fileio.h: Add macro definitions for special files,=0D + both for fst_dev and fst_mode fields of struct fst_stat.=0D + * common/fileio.c (fileio_to_host_mode, fileio_mode_pack): Add new=0D + special file types in fst_mode's definition.=0D + (host_to_fileio_stat): Define fst_dev using the new macro definitions=0D + and according to the file's type.=0D +=0D 2018-06-27 Simon Marchi =0D =0D * gdb-gdb.py.in (StructMainTypePrettyPrinter) : Don't=0D diff --git a/gdb/common/fileio.c b/gdb/common/fileio.c=0D index 912a7ede3c..9ee78e227c 100644=0D --- a/gdb/common/fileio.c=0D +++ b/gdb/common/fileio.c=0D @@ -119,12 +119,31 @@ fileio_to_host_mode (int fileio_mode, mode_t *mode_p)= =0D if (fileio_mode & ~FILEIO_S_SUPPORTED)=0D return -1;=0D =0D - if (fileio_mode & FILEIO_S_IFREG)=0D - mode |=3D S_IFREG;=0D - if (fileio_mode & FILEIO_S_IFDIR)=0D - mode |=3D S_IFDIR;=0D - if (fileio_mode & FILEIO_S_IFCHR)=0D - mode |=3D S_IFCHR;=0D + switch (fileio_mode & FILEIO_S_IFMT)=0D + {=0D + case FILEIO_S_IFSOCK:=0D + *mode_p |=3D S_IFSOCK;=0D + break;=0D + case FILEIO_S_IFLNK:=0D + mode |=3D S_IFLNK;=0D + break;=0D + case FILEIO_S_IFREG:=0D + mode |=3D S_IFREG;=0D + break;=0D + case FILEIO_S_IFBLK:=0D + mode |=3D S_IFBLK;=0D + break;=0D + case FILEIO_S_IFDIR:=0D + mode |=3D S_IFDIR;=0D + break;=0D + case FILEIO_S_IFCHR:=0D + mode |=3D S_IFCHR;=0D + break;=0D + case FILEIO_S_IFIFO:=0D + mode |=3D S_IFIFO;=0D + break;=0D + }=0D +=0D if (fileio_mode & FILEIO_S_IRUSR)=0D mode |=3D S_IRUSR;=0D if (fileio_mode & FILEIO_S_IWUSR)=0D @@ -165,12 +184,31 @@ fileio_mode_pack (mode_t mode)=0D {=0D mode_t tmode =3D 0;=0D =0D - if (S_ISREG (mode))=0D - tmode |=3D FILEIO_S_IFREG;=0D - if (S_ISDIR (mode))=0D - tmode |=3D FILEIO_S_IFDIR;=0D - if (S_ISCHR (mode))=0D - tmode |=3D FILEIO_S_IFCHR;=0D + switch (mode & S_IFMT)=0D + {=0D + case S_IFSOCK:=0D + tmode |=3D FILEIO_S_IFSOCK;=0D + break;=0D + case S_IFLNK:=0D + tmode |=3D FILEIO_S_IFLNK;=0D + break;=0D + case S_IFREG:=0D + tmode |=3D FILEIO_S_IFREG;=0D + break;=0D + case S_IFBLK:=0D + tmode |=3D FILEIO_S_IFBLK;=0D + break;=0D + case S_IFDIR:=0D + tmode |=3D FILEIO_S_IFDIR;=0D + break;=0D + case S_IFCHR:=0D + tmode |=3D FILEIO_S_IFCHR;=0D + break;=0D + case S_IFIFO:=0D + tmode |=3D FILEIO_S_IFIFO;=0D + break;=0D + }=0D +=0D if (mode & S_IRUSR)=0D tmode |=3D FILEIO_S_IRUSR;=0D if (mode & S_IWUSR)=0D @@ -224,8 +262,10 @@ void=0D host_to_fileio_stat (struct stat *st, struct fio_stat *fst)=0D {=0D LONGEST blksize;=0D + long fst_dev;=0D =0D - host_to_fileio_uint ((long) st->st_dev, fst->fst_dev);=0D + fst_dev =3D S_ISREG(st->st_mode) ? FILEIO_STDEV_FILE : FILEIO_STDEV_SPEC= IAL;=0D + host_to_fileio_uint (fst_dev, fst->fst_dev);=0D host_to_fileio_uint ((long) st->st_ino, fst->fst_ino);=0D host_to_fileio_mode (st->st_mode, fst->fst_mode);=0D host_to_fileio_uint ((long) st->st_nlink, fst->fst_nlink);=0D diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c=0D index 313da642ea..837081269a 100644=0D --- a/gdb/remote-fileio.c=0D +++ b/gdb/remote-fileio.c=0D @@ -407,24 +407,6 @@ remote_fileio_func_open (remote_target *remote, char *= buf)=0D return;=0D }=0D =0D - /* Check if pathname exists and is not a regular file or directory. If = so,=0D - return an appropriate error code. Same for trying to open directorie= s=0D - for writing. */=0D - if (!stat (pathname, &st))=0D - {=0D - if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))=0D - {=0D - remote_fileio_reply (remote, -1, FILEIO_ENODEV);=0D - return;=0D - }=0D - if (S_ISDIR (st.st_mode)=0D - && ((flags & O_WRONLY) =3D=3D O_WRONLY || (flags & O_RDWR) =3D=3D O_RDW= R))=0D - {=0D - remote_fileio_reply (remote, -1, FILEIO_EISDIR);=0D - return;=0D - }=0D - }=0D -=0D fd =3D gdb_open_cloexec (pathname, flags, mode);=0D if (fd < 0)=0D {=0D @@ -885,16 +867,9 @@ remote_fileio_func_stat (remote_target *remote, char *= buf)=0D remote_fileio_return_errno (remote, -1);=0D return;=0D }=0D - /* Only operate on regular files and directories. */=0D - if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))=0D - {=0D - remote_fileio_reply (remote, -1, FILEIO_EACCES);=0D - return;=0D - }=0D if (statptr)=0D {=0D host_to_fileio_stat (&st, &fst);=0D - host_to_fileio_uint (0, fst.fst_dev);=0D =0D errno =3D target_write_memory (statptr, (gdb_byte *) &fst, sizeof fs= t);=0D if (errno !=3D 0)=0D @@ -939,7 +914,6 @@ remote_fileio_func_fstat (remote_target *remote, char *= buf)=0D =0D if (fd =3D=3D FIO_FD_CONSOLE_IN || fd =3D=3D FIO_FD_CONSOLE_OUT)=0D {=0D - host_to_fileio_uint (1, fst.fst_dev);=0D memset (&st, 0, sizeof (st));=0D st.st_mode =3D S_IFCHR | (fd =3D=3D FIO_FD_CONSOLE_IN ? S_IRUSR : S_= IWUSR);=0D st.st_nlink =3D 1;=0D @@ -972,6 +946,8 @@ remote_fileio_func_fstat (remote_target *remote, char *= buf)=0D if (ptrval)=0D {=0D host_to_fileio_stat (&st, &fst);=0D + if (fd =3D=3D FIO_FD_CONSOLE_IN || fd =3D=3D FIO_FD_CONSOLE_OUT)=0D + host_to_fileio_uint (FILEIO_STDEV_CONSOLE, fst.fst_dev);=0D =0D errno =3D target_write_memory (ptrval, (gdb_byte *) &fst, sizeof fst= );=0D if (errno !=3D 0)=0D diff --git a/include/gdb/fileio.h b/include/gdb/fileio.h=0D index 7bb55f579f..ada84c5f10 100644=0D --- a/include/gdb/fileio.h=0D +++ b/include/gdb/fileio.h=0D @@ -37,10 +37,24 @@=0D FILEIO_O_CREAT | FILEIO_O_TRUNC| \=0D FILEIO_O_EXCL)=0D =0D +/* Device id values of fst_dev field */=0D +/* Regular file */=0D +#define FILEIO_STDEV_FILE 0=0D +/* GDB's console */=0D +#define FILEIO_STDEV_CONSOLE 1=0D +/* Not a regular file nor the console.=0D + Bits FILEIO_S_IFMT of fst_mode give the exact file type. */=0D +#define FILEIO_STDEV_SPECIAL 2=0D +=0D /* mode_t bits */=0D +#define FILEIO_S_IFSOCK 0140000=0D +#define FILEIO_S_IFLNK 0120000=0D #define FILEIO_S_IFREG 0100000=0D +#define FILEIO_S_IFBLK 060000=0D #define FILEIO_S_IFDIR 040000=0D #define FILEIO_S_IFCHR 020000=0D +#define FILEIO_S_IFIFO 010000=0D +#define FILEIO_S_IFMT 0170000=0D #define FILEIO_S_IRUSR 0400=0D #define FILEIO_S_IWUSR 0200=0D #define FILEIO_S_IXUSR 0100=0D @@ -53,9 +67,8 @@=0D #define FILEIO_S_IWOTH 02=0D #define FILEIO_S_IXOTH 01=0D #define FILEIO_S_IRWXO 07=0D -#define FILEIO_S_SUPPORTED (FILEIO_S_IFREG|FILEIO_S_IFDIR| \=0D - FILEIO_S_IRWXU|FILEIO_S_IRWXG| \=0D - FILEIO_S_IRWXO)=0D +#define FILEIO_S_SUPPORTED (FILEIO_S_IFMT | FILEIO_S_IRWXU| \=0D + FILEIO_S_IRWXG | FILEIO_S_IRWXO)=0D =0D /* lseek(2) flags */=0D #define FILEIO_SEEK_SET 0=0D -- =0D 2.18.0=0D =0D