Require kinfo_get_file and kinfo_get_vmmap for FreeBSD hosts.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Wed, 16 Sep 2020 18:40:05 +0000 (11:40 -0700)
FreeBSD systems have provided these functions in libutil since 7.1
release.  The most recent release without support is 6.4 released in
November of 2008.

This also requires libutil-freebsd on GNU/kFreeBSD systems.  I assume
that those systems have supported kinfo_get_file and kinfo_get_vmmap
over a similar timeframe.

gdb/ChangeLog:

* configure.ac: Remove check for kinfo_getvmmap().
* configure, config.in: Regenerate.
* fbsd-nat.c (fbsd_read_mapping): Remove
(fbsd_nat_target::find_memory_regions): Remove the procfs version.
(fbsd_nat_target::info_proc): Assume kinfo_getfile() and
kinfo_get_vmmap() are always present.

gdbsupport/ChangeLog:

* common.m4 (GDB_AC_COMMON): Refactor checks for kinfo_getfile().
* configure, config.in: Regenerate.

gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/configure.ac
gdb/fbsd-nat.c
gdbsupport/ChangeLog
gdbsupport/common.m4
gdbsupport/config.in
gdbsupport/configure

index ff50aee57e38e9f8213d0b31f3d476fcbc475042..7159398dfc7fd26995cbea5189938b3a73e0e427 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-16  John Baldwin  <jhb@FreeBSD.org>
+
+       * configure.ac: Remove check for kinfo_getvmmap().
+       * configure, config.in: Regenerate.
+       * fbsd-nat.c (fbsd_read_mapping): Remove
+       (fbsd_nat_target::find_memory_regions): Remove the procfs version.
+       (fbsd_nat_target::info_proc): Assume kinfo_getfile() and
+       kinfo_get_vmmap() are always present.
+
 2020-09-16  John Baldwin  <jhb@FreeBSD.org>
 
        * fbsd-nat.c: Always include support for
index 9755458f9c67dc5d81824a1b7bba7e3f6cbee66f..3e741c6ee71462472ce19e184f181f0b60490c3e 100644 (file)
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
-/* Define to 1 if your system has the kinfo_getfile function. */
+/* Define to 1 if you have the `kinfo_getfile' function. */
 #undef HAVE_KINFO_GETFILE
 
-/* Define to 1 if your system has the kinfo_getvmmap function. */
-#undef HAVE_KINFO_GETVMMAP
-
 /* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
 #undef HAVE_LANGINFO_CODESET
 
index e7811e807a6b42db1b28f46bdf43afb321f0ae05..a8942ecbd5d654ec522b769adeab2a5cdc03d7c6 100755 (executable)
@@ -8270,67 +8270,6 @@ fi
 
 
 
-# On FreeBSD we may need libutil for kinfo_getvmmap (used by fbsd-nat.c).
-# On GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kinfo_getvmmap" >&5
-$as_echo_n "checking for library containing kinfo_getvmmap... " >&6; }
-if ${ac_cv_search_kinfo_getvmmap+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_func_search_save_LIBS=$LIBS
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char kinfo_getvmmap ();
-int
-main ()
-{
-return kinfo_getvmmap ();
-  ;
-  return 0;
-}
-_ACEOF
-for ac_lib in '' util util-freebsd; do
-  if test -z "$ac_lib"; then
-    ac_res="none required"
-  else
-    ac_res=-l$ac_lib
-    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
-  fi
-  if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_search_kinfo_getvmmap=$ac_res
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext
-  if ${ac_cv_search_kinfo_getvmmap+:} false; then :
-  break
-fi
-done
-if ${ac_cv_search_kinfo_getvmmap+:} false; then :
-
-else
-  ac_cv_search_kinfo_getvmmap=no
-fi
-rm conftest.$ac_ext
-LIBS=$ac_func_search_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_kinfo_getvmmap" >&5
-$as_echo "$ac_cv_search_kinfo_getvmmap" >&6; }
-ac_res=$ac_cv_search_kinfo_getvmmap
-if test "$ac_res" != no; then :
-  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
-
-$as_echo "#define HAVE_KINFO_GETVMMAP 1" >>confdefs.h
-
-fi
-
-
 
       if test "X$prefix" = "XNONE"; then
     acl_final_prefix="$ac_default_prefix"
@@ -13567,6 +13506,9 @@ _ACEOF
 fi
 
 
+  # On FreeBSD we need libutil for the kinfo_get* functions.  On
+  # GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
+  # Figure out which one to use.
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kinfo_getfile" >&5
 $as_echo_n "checking for library containing kinfo_getfile... " >&6; }
 if ${ac_cv_search_kinfo_getfile+:} false; then :
@@ -13621,9 +13563,20 @@ ac_res=$ac_cv_search_kinfo_getfile
 if test "$ac_res" != no; then :
   test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
-$as_echo "#define HAVE_KINFO_GETFILE 1" >>confdefs.h
+fi
+
+
+  # Define HAVE_KINFO_GETFILE if kinfo_getfile is available.
+  for ac_func in kinfo_getfile
+do :
+  ac_fn_c_check_func "$LINENO" "kinfo_getfile" "ac_cv_func_kinfo_getfile"
+if test "x$ac_cv_func_kinfo_getfile" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_KINFO_GETFILE 1
+_ACEOF
 
 fi
+done
 
 
   # Check for std::thread.  This does not work on some platforms, like
index 620ae23e3435a60861d8ea5c17f8a90e809b5ed4..6b4b0fa85109d1e0d0a1610fece2ce13295befb9 100644 (file)
@@ -474,12 +474,6 @@ AC_SEARCH_LIBS(socketpair, socket)
 # Link in zlib if we can.  This allows us to read compressed debug sections.
 AM_ZLIB
 
-# On FreeBSD we may need libutil for kinfo_getvmmap (used by fbsd-nat.c).
-# On GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
-AC_SEARCH_LIBS(kinfo_getvmmap, util util-freebsd,
-  [AC_DEFINE(HAVE_KINFO_GETVMMAP, 1,
-            [Define to 1 if your system has the kinfo_getvmmap function. ])])
-
 AM_ICONV
 
 # GDB may fork/exec the iconv program to get the list of supported character
index aa5d9ccd12722ad084c5cf67e48ffbc4b98380b4..ac88fbc87f7d5228bafab51cad69d20ce5674526 100644 (file)
 #include <sys/signal.h>
 #include <sys/sysctl.h>
 #include <sys/user.h>
-#if defined(HAVE_KINFO_GETFILE) || defined(HAVE_KINFO_GETVMMAP)
 #include <libutil.h>
-#endif
-#if !defined(HAVE_KINFO_GETVMMAP)
-#include "gdbsupport/filestuff.h"
-#endif
 
 #include "elf-bfd.h"
 #include "fbsd-nat.h"
@@ -71,7 +66,6 @@ fbsd_nat_target::pid_to_exec_file (int pid)
   return NULL;
 }
 
-#ifdef HAVE_KINFO_GETVMMAP
 /* Iterate over all the memory regions in the current inferior,
    calling FUNC for each memory region.  DATA is passed as the last
    argument to FUNC.  */
@@ -124,77 +118,6 @@ fbsd_nat_target::find_memory_regions (find_memory_region_ftype func,
     }
   return 0;
 }
-#else
-static int
-fbsd_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
-                  char *protection)
-{
-  /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
-  char buf[256];
-  int resident, privateresident;
-  unsigned long obj;
-  int ret = EOF;
-
-  /* As of FreeBSD 5.0-RELEASE, the layout is described in
-     /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
-     new column was added to the procfs map.  Therefore we can't use
-     fscanf since we need to support older releases too.  */
-  if (fgets (buf, sizeof buf, mapfile) != NULL)
-    ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
-                 &resident, &privateresident, &obj, protection);
-
-  return (ret != 0 && ret != EOF);
-}
-
-/* Iterate over all the memory regions in the current inferior,
-   calling FUNC for each memory region.  DATA is passed as the last
-   argument to FUNC.  */
-
-int
-fbsd_nat_target::find_memory_regions (find_memory_region_ftype func,
-                                     void *data)
-{
-  pid_t pid = inferior_ptid.pid ();
-  unsigned long start, end, size;
-  char protection[4];
-  int read, write, exec;
-
-  std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid);
-  gdb_file_up mapfile (fopen (mapfilename.c_str (), "r"));
-  if (mapfile == NULL)
-    error (_("Couldn't open %s."), mapfilename.c_str ());
-
-  if (info_verbose)
-    fprintf_filtered (gdb_stdout, 
-                     "Reading memory regions from %s\n", mapfilename.c_str ());
-
-  /* Now iterate until end-of-file.  */
-  while (fbsd_read_mapping (mapfile.get (), &start, &end, &protection[0]))
-    {
-      size = end - start;
-
-      read = (strchr (protection, 'r') != 0);
-      write = (strchr (protection, 'w') != 0);
-      exec = (strchr (protection, 'x') != 0);
-
-      if (info_verbose)
-       {
-         fprintf_filtered (gdb_stdout, 
-                           "Save segment, %ld bytes at %s (%c%c%c)\n",
-                           size, paddress (target_gdbarch (), start),
-                           read ? 'r' : '-',
-                           write ? 'w' : '-',
-                           exec ? 'x' : '-');
-       }
-
-      /* Invoke the callback function to create the corefile segment.
-        Pass MODIFIED as true, we do not know the real modification state.  */
-      func (start, size, read, write, exec, 1, data);
-    }
-
-  return 0;
-}
-#endif
 
 /* Fetch the command line for a running process.  */
 
@@ -251,21 +174,15 @@ fbsd_fetch_kinfo_proc (pid_t pid, struct kinfo_proc *kp)
 bool
 fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
 {
-#ifdef HAVE_KINFO_GETFILE
   gdb::unique_xmalloc_ptr<struct kinfo_file> fdtbl;
   int nfd = 0;
-#endif
   struct kinfo_proc kp;
   pid_t pid;
   bool do_cmdline = false;
   bool do_cwd = false;
   bool do_exe = false;
-#ifdef HAVE_KINFO_GETFILE
   bool do_files = false;
-#endif
-#ifdef HAVE_KINFO_GETVMMAP
   bool do_mappings = false;
-#endif
   bool do_status = false;
 
   switch (what)
@@ -275,11 +192,9 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       do_cwd = true;
       do_exe = true;
       break;
-#ifdef HAVE_KINFO_GETVMMAP
     case IP_MAPPINGS:
       do_mappings = true;
       break;
-#endif
     case IP_STATUS:
     case IP_STAT:
       do_status = true;
@@ -293,21 +208,15 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
     case IP_CWD:
       do_cwd = true;
       break;
-#ifdef HAVE_KINFO_GETFILE
     case IP_FILES:
       do_files = true;
       break;
-#endif
     case IP_ALL:
       do_cmdline = true;
       do_cwd = true;
       do_exe = true;
-#ifdef HAVE_KINFO_GETFILE
       do_files = true;
-#endif
-#ifdef HAVE_KINFO_GETVMMAP
       do_mappings = true;
-#endif
       do_status = true;
       break;
     default:
@@ -327,10 +236,8 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
     error (_("Invalid arguments."));
 
   printf_filtered (_("process %d\n"), pid);
-#ifdef HAVE_KINFO_GETFILE
   if (do_cwd || do_exe || do_files)
     fdtbl.reset (kinfo_getfile (pid, &nfd));
-#endif
 
   if (do_cmdline)
     {
@@ -343,7 +250,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
   if (do_cwd)
     {
       const char *cwd = NULL;
-#ifdef HAVE_KINFO_GETFILE
       struct kinfo_file *kf = fdtbl.get ();
       for (int i = 0; i < nfd; i++, kf++)
        {
@@ -353,7 +259,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
              break;
            }
        }
-#endif
       if (cwd != NULL)
        printf_filtered ("cwd = '%s'\n", cwd);
       else
@@ -362,7 +267,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
   if (do_exe)
     {
       const char *exe = NULL;
-#ifdef HAVE_KINFO_GETFILE
       struct kinfo_file *kf = fdtbl.get ();
       for (int i = 0; i < nfd; i++, kf++)
        {
@@ -372,7 +276,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
              break;
            }
        }
-#endif
       if (exe == NULL)
        exe = pid_to_exec_file (pid);
       if (exe != NULL)
@@ -380,7 +283,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       else
        warning (_("unable to fetch executable path name"));
     }
-#ifdef HAVE_KINFO_GETFILE
   if (do_files)
     {
       struct kinfo_file *kf = fdtbl.get ();
@@ -398,8 +300,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       else
        warning (_("unable to fetch list of open files"));
     }
-#endif
-#ifdef HAVE_KINFO_GETVMMAP
   if (do_mappings)
     {
       int nvment;
@@ -421,7 +321,6 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       else
        warning (_("unable to fetch virtual memory map"));
     }
-#endif
   if (do_status)
     {
       if (!fbsd_fetch_kinfo_proc (pid, &kp))
index 2c35ee709a249478c5c9502c68a755d95ae1a24a..d46f8c77bb02a0eec10e91f932e090f0b47d035a 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-16  John Baldwin  <jhb@FreeBSD.org>
+
+       * common.m4 (GDB_AC_COMMON): Refactor checks for kinfo_getfile().
+       * configure, config.in: Regenerate.
+
 2020-09-14  Pedro Alves  <pedro@palves.net>
 
        * enum-flags.h: Include "traits.h".
index e8fd64c7a8e18a9f85ea6a111b9177b0257476f2..2b5750e81d1f855f46c9f0cb65a43823552b1220 100644 (file)
@@ -86,9 +86,13 @@ AC_DEFUN([GDB_AC_COMMON], [
 
   AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
 
-  AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd,
-    [AC_DEFINE(HAVE_KINFO_GETFILE, 1,
-             [Define to 1 if your system has the kinfo_getfile function. ])])
+  # On FreeBSD we need libutil for the kinfo_get* functions.  On
+  # GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
+  # Figure out which one to use.
+  AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd)
+
+  # Define HAVE_KINFO_GETFILE if kinfo_getfile is available.
+  AC_CHECK_FUNCS(kinfo_getfile)
 
   # Check for std::thread.  This does not work on some platforms, like
   # mingw and DJGPP.
index 973561b117045d301112dab081839b955501f532..ecc6fa559f7cb35667702df34d9a4ec9f207bcaf 100644 (file)
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
-/* Define to 1 if your system has the kinfo_getfile function. */
+/* Define to 1 if you have the `kinfo_getfile' function. */
 #undef HAVE_KINFO_GETFILE
 
 /* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
index bd95b6d7f490797fcb8a7305a60cfcdf6d27fc5f..a37f3c232ce525f8e59a8698a3a9511e463ad2a5 100755 (executable)
@@ -8976,6 +8976,9 @@ _ACEOF
 fi
 
 
+  # On FreeBSD we need libutil for the kinfo_get* functions.  On
+  # GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
+  # Figure out which one to use.
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kinfo_getfile" >&5
 $as_echo_n "checking for library containing kinfo_getfile... " >&6; }
 if ${ac_cv_search_kinfo_getfile+:} false; then :
@@ -9030,9 +9033,20 @@ ac_res=$ac_cv_search_kinfo_getfile
 if test "$ac_res" != no; then :
   test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
-$as_echo "#define HAVE_KINFO_GETFILE 1" >>confdefs.h
+fi
+
+
+  # Define HAVE_KINFO_GETFILE if kinfo_getfile is available.
+  for ac_func in kinfo_getfile
+do :
+  ac_fn_c_check_func "$LINENO" "kinfo_getfile" "ac_cv_func_kinfo_getfile"
+if test "x$ac_cv_func_kinfo_getfile" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_KINFO_GETFILE 1
+_ACEOF
 
 fi
+done
 
 
   # Check for std::thread.  This does not work on some platforms, like
This page took 0.0577 seconds and 4 git commands to generate.