From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68988 invoked by alias); 9 Jul 2018 14:37:10 -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 68917 invoked by uid 89); 9 Jul 2018 14:37:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jul 2018 14:37:07 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18B1D401EF25; Mon, 9 Jul 2018 14:37:06 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60053111DCE8; Mon, 9 Jul 2018 14:37:05 +0000 (UTC) Subject: Re: [PATCH v4] Allow using special files with File I/O functions To: Julio Guerra , "gdb-patches@sourceware.org" References: <20180705091618.33743-1-julio@farjump.io> <0102016469ba9beb-e8338b53-74bd-46ea-91c7-eea909052532-000000@eu-west-1.amazonses.com> <50cbe319-5b79-24dd-c615-25209d6dd390@redhat.com> <010201647f2fec5a-727b623a-1c7f-4d7e-a9e2-e8076d9e3cc2-000000@eu-west-1.amazonses.com> From: Pedro Alves Message-ID: <263942fb-504c-7eeb-7840-fc4b70a76ed1@redhat.com> Date: Mon, 09 Jul 2018 14:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <010201647f2fec5a-727b623a-1c7f-4d7e-a9e2-e8076d9e3cc2-000000@eu-west-1.amazonses.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-07/txt/msg00214.txt.bz2 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 >>> >>> * 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 >> 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