Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Rich Felker <dalias@aerifal.cx>,
	Romain Naour <romain.naour@smile.fr>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Romain Naour <romain.naour@gmail.com>,
	Pedro Alves <palves@redhat.com>,
	Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH] Move 'is_regular_file' from common-utils.c to filestuff.c
Date: Wed, 12 Sep 2018 17:31:00 -0000	[thread overview]
Message-ID: <20180912173113.2007-1-sergiodj@redhat.com> (raw)
In-Reply-To: <d588888e-dccc-50c8-5a6e-9c5c46a512cb@smile.fr>

There is no reason for 'is_regular_file' to be in common-utils.c; it
belongs to 'filestuff.c'.  This commit moves the function definition
and its prototype to the appropriate files.

The motivation behind this move is a failure that happens on certain
cross-compilation environments when compiling the IPA library, due to
the way gnulib probes the need for a 'stat' call replacement.  Because
configure checks when cross-compiling are more limited, gnulib decides
that it needs to substitute the 'stat' calls its own 'rpl_stat';
however, the IPA library doesn't link with gnulib, which leads to an
error when compiling 'common-utils.c':

  ...
  /opt/x86-core2--musl--bleeding-edge-2018.09-1/bin/i686-buildroot-linux-musl-g++  -shared -fPIC -Wl,--soname=libinproctrace.so -Wl,--no-undefined -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os      -I. -I. -I./../common -I./../regformats -I./.. -I./../../include -I./../gnulib/import -Ibuild-gnulib-gdbserver/import -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-narrowing -Wno-error=maybe-uninitialized  -DGDBSERVER \
   -Wl,--dynamic-list=./proc-service.list -o libinproctrace.so ax-ipa.o common-utils-ipa.o errors-ipa.o format-ipa.o print-utils-ipa.o regcache-ipa.o remote-utils-ipa.o rsp-low-ipa.o tdesc-ipa.o tracepoint-ipa.o utils-ipa.o vec-ipa.o linux-i386-ipa.o linux-x86-tdesc-ipa.o arch/i386-ipa.o -ldl -pthread
  /opt/x86-core2--musl--bleeding-edge-2018.09-1/lib/gcc/i686-buildroot-linux-musl/8.2.0/../../../../i686-buildroot-linux-musl/bin/ld: common-utils-ipa.o: in function `is_regular_file(char const*, int*)':
  common-utils.c:(.text+0x695): undefined reference to `rpl_stat'
  collect2: error: ld returned 1 exit status
  Makefile:413: recipe for target 'libinproctrace.so' failed
  make[1]: *** [libinproctrace.so] Error 1
  ...

More details can also be found at:

  https://sourceware.org/ml/gdb-patches/2018-09/msg00304.html

The most simple fix for this problem is to move 'is_regular_file' to
'filestuff.c', which is not used by IPA.  This ends up making the
files more logically organized as well, since 'is_regular_file' is a
file operation.

No regressions found.

gdb/ChangeLog:
2018-09-12  Sergio Durigan Junior  <sergiodj@redhat.com>

	* common/common-utils.c: Don't include '<sys/stat.h>'.
	(is_regular_file): Move to...
	* common/filestuff.c (is_regular_file): ... here.
	* common/common-utils.h (is_regular_file): Move to...
	* common/filestuff.h (is_regular_file): ... here.
---
 gdb/common/common-utils.c | 32 --------------------------------
 gdb/common/common-utils.h |  5 -----
 gdb/common/filestuff.c    | 31 +++++++++++++++++++++++++++++++
 gdb/common/filestuff.h    |  5 +++++
 4 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 8d839d10fa..24b3936f3d 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -20,7 +20,6 @@
 #include "common-defs.h"
 #include "common-utils.h"
 #include "host-defs.h"
-#include <sys/stat.h>
 #include <ctype.h>
 
 /* The xmalloc() (libiberty.h) family of memory management routines.
@@ -412,37 +411,6 @@ stringify_argv (const std::vector<char *> &args)
 
 /* See common/common-utils.h.  */
 
-bool
-is_regular_file (const char *name, int *errno_ptr)
-{
-  struct stat st;
-  const int status = stat (name, &st);
-
-  /* Stat should never fail except when the file does not exist.
-     If stat fails, analyze the source of error and return true
-     unless the file does not exist, to avoid returning false results
-     on obscure systems where stat does not work as expected.  */
-
-  if (status != 0)
-    {
-      if (errno != ENOENT)
-	return true;
-      *errno_ptr = ENOENT;
-      return false;
-    }
-
-  if (S_ISREG (st.st_mode))
-    return true;
-
-  if (S_ISDIR (st.st_mode))
-    *errno_ptr = EISDIR;
-  else
-    *errno_ptr = EINVAL;
-  return false;
-}
-
-/* See common/common-utils.h.  */
-
 ULONGEST
 align_up (ULONGEST v, int n)
 {
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 7bc6e90f05..a961514fd6 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -146,11 +146,6 @@ in_inclusive_range (T value, T low, T high)
   return value >= low && value <= high;
 }
 
-/* Return true if the file NAME exists and is a regular file.
-   If the result is false then *ERRNO_PTR is set to a useful value assuming
-   we're expecting a regular file.  */
-extern bool is_regular_file (const char *name, int *errno_ptr);
-
 /* Ensure that V is aligned to an N byte boundary (B's assumed to be a
    power of 2).  Round up/down when necessary.  Examples of correct
    use include:
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index f5a754ffa6..fa10165a7c 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -417,3 +417,34 @@ make_cleanup_close (int fd)
   *saved_fd = fd;
   return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
 }
+
+/* See common/filestuff.h.  */
+
+bool
+is_regular_file (const char *name, int *errno_ptr)
+{
+  struct stat st;
+  const int status = stat (name, &st);
+
+  /* Stat should never fail except when the file does not exist.
+     If stat fails, analyze the source of error and return true
+     unless the file does not exist, to avoid returning false results
+     on obscure systems where stat does not work as expected.  */
+
+  if (status != 0)
+    {
+      if (errno != ENOENT)
+	return true;
+      *errno_ptr = ENOENT;
+      return false;
+    }
+
+  if (S_ISREG (st.st_mode))
+    return true;
+
+  if (S_ISDIR (st.st_mode))
+    *errno_ptr = EISDIR;
+  else
+    *errno_ptr = EINVAL;
+  return false;
+}
diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
index 1a09c729f6..e9328f5358 100644
--- a/gdb/common/filestuff.h
+++ b/gdb/common/filestuff.h
@@ -117,4 +117,9 @@ struct gdb_dir_deleter
 
 typedef std::unique_ptr<DIR, gdb_dir_deleter> gdb_dir_up;
 
+/* Return true if the file NAME exists and is a regular file.
+   If the result is false then *ERRNO_PTR is set to a useful value assuming
+   we're expecting a regular file.  */
+extern bool is_regular_file (const char *name, int *errno_ptr);
+
 #endif /* FILESTUFF_H */
-- 
2.17.1


  parent reply	other threads:[~2018-09-12 17:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180909163750.14196-1-romain.naour@gmail.com>
     [not found] ` <20180909163750.14196-2-romain.naour@gmail.com>
     [not found]   ` <20180910174900.0b9f4133@windsurf>
2018-09-10 21:21     ` [Buildroot] [PATCH 2/2] package/gdb: use stat() privided by the system Romain Naour
2018-09-10 22:41       ` Rich Felker
2018-09-11  0:38         ` Sergio Durigan Junior
2018-09-11  9:51           ` Pedro Alves
2018-09-11 14:13             ` Rich Felker
2018-09-11 16:04               ` Pedro Alves
2018-09-11 18:22             ` Sergio Durigan Junior
2018-09-12 15:26               ` Pedro Alves
2018-09-12 17:11                 ` Sergio Durigan Junior
2018-09-12 17:40                   ` Pedro Alves
2018-09-11 10:13           ` Pedro Alves
2018-09-11  6:47         ` Thomas Petazzoni
2018-09-12 17:31       ` Sergio Durigan Junior [this message]
2018-09-12 17:41         ` [PATCH] Move 'is_regular_file' from common-utils.c to filestuff.c Pedro Alves
2018-09-12 17:59           ` Sergio Durigan Junior
2018-09-14 21:27             ` Romain Naour
2018-09-14 21:41               ` Tom Tromey
2018-09-14 21:48                 ` Sergio Durigan Junior
2018-09-14 21:55                   ` Romain Naour
2018-09-14 22:09                     ` Joel Brobecker
2018-09-15 13:16                       ` Romain Naour
2018-09-15 13:28                         ` Romain Naour
2018-09-15 20:42                           ` Sergio Durigan Junior
2018-09-17 17:01                           ` Joel Brobecker
2018-09-15 20:35                         ` Sergio Durigan Junior
2018-09-15 21:14                           ` Romain Naour
2018-09-16  4:59                             ` Sergio Durigan Junior

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=20180912173113.2007-1-sergiodj@redhat.com \
    --to=sergiodj@redhat.com \
    --cc=dalias@aerifal.cx \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=romain.naour@gmail.com \
    --cc=romain.naour@smile.fr \
    --cc=thomas.petazzoni@bootlin.com \
    /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