public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v7 01/10] Move utility functions to common/
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
@ 2015-06-14 19:25 ` Jan Kratochvil
  2015-06-15 13:22   ` Joel Brobecker
  2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* " Jan Kratochvil
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

some parts of the former patch have been reimplemented in the meantime by
other patches so this is only a part of the former cleanup.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00363.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Move utility functions to common/.
	* cli/cli-utils.c (skip_spaces, skip_spaces_const, skip_to_space_const):
	Move defs to common/common-utils.c.
	* cli/cli-utils.h (skip_spaces, skip_spaces_const, skip_to_space)
	(skip_to_space_const): Move decls to common/common-utils.h.
	* common/common-defs.h: Move include of common-types.h before
	common-utils.h.
	* common/common-utils.c: Include host-defs.h and ctype.h.
	(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
	from utils.c.
	(skip_spaces, skip_spaces_const, skip_to_space_const): Move from
	cli/cli-utils.c.
	* common/common-utils.h (strtoulst): Move decl from utils.h.
	(skip_spaces, skip_spaces_const, skip_to_space, skip_to_space_const):
	Move from cli/cli-utils.h.
	* common/host-defs.h: Include limits.h.
	(TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved from defs.h.
	(skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
	* defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
	common/common-utils.h.
	* utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int)
	(strtoulst): Move to common/common-utils.c.
	* utils.h (strtoulst): Moved decl to common/common-utils.h.
---
 gdb/cli/cli-utils.c       |   36 ------------
 gdb/cli/cli-utils.h       |   18 ------
 gdb/common/common-defs.h  |    2 -
 gdb/common/common-utils.c |  137 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/common/common-utils.h |   20 +++++++
 gdb/common/host-defs.h    |   21 +++++++
 gdb/defs.h                |   19 ------
 gdb/utils.c               |   99 ---------------------------------
 gdb/utils.h               |    2 -
 9 files changed, 179 insertions(+), 175 deletions(-)

diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f3586b6..5c6338b 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -225,42 +225,6 @@ number_is_in_list (const char *list, int number)
 /* See documentation in cli-utils.h.  */
 
 char *
-skip_spaces (char *chp)
-{
-  if (chp == NULL)
-    return NULL;
-  while (*chp && isspace (*chp))
-    chp++;
-  return chp;
-}
-
-/* A const-correct version of the above.  */
-
-const char *
-skip_spaces_const (const char *chp)
-{
-  if (chp == NULL)
-    return NULL;
-  while (*chp && isspace (*chp))
-    chp++;
-  return chp;
-}
-
-/* See documentation in cli-utils.h.  */
-
-const char *
-skip_to_space_const (const char *chp)
-{
-  if (chp == NULL)
-    return NULL;
-  while (*chp && !isspace (*chp))
-    chp++;
-  return chp;
-}
-
-/* See documentation in cli-utils.h.  */
-
-char *
 remove_trailing_whitespace (const char *start, char *s)
 {
   while (s > start && isspace (*(s - 1)))
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 5e191ec..ad46581 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -93,24 +93,6 @@ extern int get_number_or_range (struct get_number_or_range_state *state);
 
 extern int number_is_in_list (const char *list, int number);
 
-/* Skip leading whitespace characters in INP, returning an updated
-   pointer.  If INP is NULL, return NULL.  */
-
-extern char *skip_spaces (char *inp);
-
-/* A const-correct version of the above.  */
-
-extern const char *skip_spaces_const (const char *inp);
-
-/* Skip leading non-whitespace characters in INP, returning an updated
-   pointer.  If INP is NULL, return NULL.  */
-
-#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
-
-/* A const-correct version of the above.  */
-
-extern const char *skip_to_space_const (const char *inp);
-
 /* Reverse S to the last non-whitespace character without skipping past
    START.  */
 
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 62d9de5..2be0d7d 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -41,10 +41,10 @@
 #include "gdb/signals.h"
 #include "gdb_locale.h"
 #include "ptid.h"
+#include "common-types.h"
 #include "common-utils.h"
 #include "gdb_assert.h"
 #include "errors.h"
-#include "common-types.h"
 #include "print-utils.h"
 #include "common-debug.h"
 #include "cleanups.h"
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 2925dd5..e86ed5b 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -18,6 +18,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "common-defs.h"
+#include "host-defs.h"
+#include <ctype.h>
 
 /* The xmalloc() (libiberty.h) family of memory management routines.
 
@@ -151,3 +153,138 @@ savestring (const char *ptr, size_t len)
   p[len] = 0;
   return p;
 }
+
+/* The bit offset of the highest byte in a ULONGEST, for overflow
+   checking.  */
+
+#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
+
+/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
+   where 2 <= BASE <= 36.  */
+
+static int
+is_digit_in_base (unsigned char digit, int base)
+{
+  if (!isalnum (digit))
+    return 0;
+  if (base <= 10)
+    return (isdigit (digit) && digit < base + '0');
+  else
+    return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
+}
+
+static int
+digit_to_int (unsigned char c)
+{
+  if (isdigit (c))
+    return c - '0';
+  else
+    return tolower (c) - 'a' + 10;
+}
+
+/* As for strtoul, but for ULONGEST results.  */
+
+ULONGEST
+strtoulst (const char *num, const char **trailer, int base)
+{
+  unsigned int high_part;
+  ULONGEST result;
+  int minus = 0;
+  int i = 0;
+
+  /* Skip leading whitespace.  */
+  while (isspace (num[i]))
+    i++;
+
+  /* Handle prefixes.  */
+  if (num[i] == '+')
+    i++;
+  else if (num[i] == '-')
+    {
+      minus = 1;
+      i++;
+    }
+
+  if (base == 0 || base == 16)
+    {
+      if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
+	{
+	  i += 2;
+	  if (base == 0)
+	    base = 16;
+	}
+    }
+
+  if (base == 0 && num[i] == '0')
+    base = 8;
+
+  if (base == 0)
+    base = 10;
+
+  if (base < 2 || base > 36)
+    {
+      errno = EINVAL;
+      return 0;
+    }
+
+  result = high_part = 0;
+  for (; is_digit_in_base (num[i], base); i += 1)
+    {
+      result = result * base + digit_to_int (num[i]);
+      high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
+      result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
+      if (high_part > 0xff)
+	{
+	  errno = ERANGE;
+	  result = ~ (ULONGEST) 0;
+	  high_part = 0;
+	  minus = 0;
+	  break;
+	}
+    }
+
+  if (trailer != NULL)
+    *trailer = &num[i];
+
+  result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
+  if (minus)
+    return -result;
+  else
+    return result;
+}
+
+/* See documentation in cli-utils.h.  */
+
+char *
+skip_spaces (char *chp)
+{
+  if (chp == NULL)
+    return NULL;
+  while (*chp && isspace (*chp))
+    chp++;
+  return chp;
+}
+
+/* A const-correct version of the above.  */
+
+const char *
+skip_spaces_const (const char *chp)
+{
+  if (chp == NULL)
+    return NULL;
+  while (*chp && isspace (*chp))
+    chp++;
+  return chp;
+}
+
+/* See documentation in cli-utils.h.  */
+
+const char *
+skip_to_space_const (const char *chp)
+{
+  if (chp == NULL)
+    return NULL;
+  while (*chp && !isspace (*chp))
+    chp++;
+  return chp;
+}
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index cd2665a..eef5e6b 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -77,4 +77,24 @@ startswith (const char *string, const char *pattern)
   return strncmp (string, pattern, strlen (pattern)) == 0;
 }
 
+ULONGEST strtoulst (const char *num, const char **trailer, int base);
+
+/* Skip leading whitespace characters in INP, returning an updated
+   pointer.  If INP is NULL, return NULL.  */
+
+extern char *skip_spaces (char *inp);
+
+/* A const-correct version of the above.  */
+
+extern const char *skip_spaces_const (const char *inp);
+
+/* Skip leading non-whitespace characters in INP, returning an updated
+   pointer.  If INP is NULL, return NULL.  */
+
+#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
+
+/* A const-correct version of the above.  */
+
+extern const char *skip_to_space_const (const char *inp);
+
 #endif
diff --git a/gdb/common/host-defs.h b/gdb/common/host-defs.h
index 6c67034..7bc41a2 100644
--- a/gdb/common/host-defs.h
+++ b/gdb/common/host-defs.h
@@ -19,6 +19,27 @@
 #ifndef HOST_DEFS_H
 #define HOST_DEFS_H
 
+#include <limits.h>
+
+/* Static host-system-dependent parameters for GDB.  */
+
+/* * Number of bits in a char or unsigned char for the target machine.
+   Just like CHAR_BIT in <limits.h> but describes the target machine.  */
+#if !defined (TARGET_CHAR_BIT)
+#define TARGET_CHAR_BIT 8
+#endif
+
+/* * If we picked up a copy of CHAR_BIT from a configuration file
+   (which may get it by including <limits.h>) then use it to set
+   the number of bits in a host char.  If not, use the same size
+   as the target.  */
+
+#if defined (CHAR_BIT)
+#define HOST_CHAR_BIT CHAR_BIT
+#else
+#define HOST_CHAR_BIT TARGET_CHAR_BIT
+#endif
+
 #ifdef __MSDOS__
 # define CANT_FORK
 # define GLOBAL_CURDIR
diff --git a/gdb/defs.h b/gdb/defs.h
index 44702ea..32b08bb 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -591,25 +591,6 @@ extern double atof (const char *);	/* X3.159-1989  4.10.1.1 */
 
 enum { MAX_REGISTER_SIZE = 64 };
 
-/* Static target-system-dependent parameters for GDB.  */
-
-/* * Number of bits in a char or unsigned char for the target machine.
-   Just like CHAR_BIT in <limits.h> but describes the target machine.  */
-#if !defined (TARGET_CHAR_BIT)
-#define TARGET_CHAR_BIT 8
-#endif
-
-/* * If we picked up a copy of CHAR_BIT from a configuration file
-   (which may get it by including <limits.h>) then use it to set
-   the number of bits in a host char.  If not, use the same size
-   as the target.  */
-
-#if defined (CHAR_BIT)
-#define HOST_CHAR_BIT CHAR_BIT
-#else
-#define HOST_CHAR_BIT TARGET_CHAR_BIT
-#endif
-
 /* In findvar.c.  */
 
 extern LONGEST extract_signed_integer (const gdb_byte *, int,
diff --git a/gdb/utils.c b/gdb/utils.c
index 1c1ced4..acb4c7d 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2987,105 +2987,6 @@ dummy_obstack_deallocate (void *object, void *data)
   return;
 }
 
-/* The bit offset of the highest byte in a ULONGEST, for overflow
-   checking.  */
-
-#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
-
-/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
-   where 2 <= BASE <= 36.  */
-
-static int
-is_digit_in_base (unsigned char digit, int base)
-{
-  if (!isalnum (digit))
-    return 0;
-  if (base <= 10)
-    return (isdigit (digit) && digit < base + '0');
-  else
-    return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
-}
-
-static int
-digit_to_int (unsigned char c)
-{
-  if (isdigit (c))
-    return c - '0';
-  else
-    return tolower (c) - 'a' + 10;
-}
-
-/* As for strtoul, but for ULONGEST results.  */
-
-ULONGEST
-strtoulst (const char *num, const char **trailer, int base)
-{
-  unsigned int high_part;
-  ULONGEST result;
-  int minus = 0;
-  int i = 0;
-
-  /* Skip leading whitespace.  */
-  while (isspace (num[i]))
-    i++;
-
-  /* Handle prefixes.  */
-  if (num[i] == '+')
-    i++;
-  else if (num[i] == '-')
-    {
-      minus = 1;
-      i++;
-    }
-
-  if (base == 0 || base == 16)
-    {
-      if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
-	{
-	  i += 2;
-	  if (base == 0)
-	    base = 16;
-	}
-    }
-
-  if (base == 0 && num[i] == '0')
-    base = 8;
-
-  if (base == 0)
-    base = 10;
-
-  if (base < 2 || base > 36)
-    {
-      errno = EINVAL;
-      return 0;
-    }
-
-  result = high_part = 0;
-  for (; is_digit_in_base (num[i], base); i += 1)
-    {
-      result = result * base + digit_to_int (num[i]);
-      high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
-      result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
-      if (high_part > 0xff)
-	{
-	  errno = ERANGE;
-	  result = ~ (ULONGEST) 0;
-	  high_part = 0;
-	  minus = 0;
-	  break;
-	}
-    }
-
-  if (trailer != NULL)
-    *trailer = &num[i];
-
-  result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
-  if (minus)
-    return -result;
-  else
-    return result;
-}
-
 /* Simple, portable version of dirname that does not modify its
    argument.  */
 
diff --git a/gdb/utils.h b/gdb/utils.h
index 0e93ead..995a1cf 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -37,8 +37,6 @@ extern int streq (const char *, const char *);
 
 extern int subset_compare (char *, char *);
 
-ULONGEST strtoulst (const char *num, const char **trailer, int base);
-
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 00/10] Validate binary before use
@ 2015-06-14 19:25 Jan Kratochvil
  2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
                   ` (10 more replies)
  0 siblings, 11 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

git://sourceware.org/git/archer.git
jankratochvil/gdbserverbuildid

an update.  Patch below is an overall v6->v7 diff of the whole series.


Jan


v7
 * move linux-maps.[ch] common/->nat/ and target-utils.[ch] common/->target/
 * remove GDBSERVER #ifdefs
 * rebase on top of the new 'struct inferior *inf' parameter

v6
 * move also gdb_regex* to common/ as discussed above, also in config*.ac
 * skip_to_space{,_const}() were moved to common/
 * common/common-defs.h #include reordering
 * new passing of enum filterflags from linux_qxfer_libraries_svr4()
 * dropped refactoring of code moved to common/ that avoided GDB exceptions
 * new svr4_copy_library_list() needs to handle new so_list->build_id

v5
 * svr4_validate() considers missing local build-id as not-a-match
 * target_so_ops->validate() now returns not-a-match reason as a string
 * rename common/common-target.[ch] -> common/target-utils.[ch]
 * testcase runs (but broken) even on different-filesystem remote target
 * testcase simplified by using with_test_prefix()

v4
 * NEWS, doc/gdb.texinfo additions.
 * Used host-defs.h.
 * New set/show solib-build-id-force.
 * testsuite: Do not run on non-localhost remote targets.

v3
	[patchv3 0/8] Validate binary before use
	https://sourceware.org/ml/gdb-patches/2014-02/msg00842.html
	Message-ID: <20140227213229.GA21121@host2.jankratochvil.net>
 * Implemented the review comments I made.
 * Removed fetching build-id in solib-svr4.c for NAT run.

v2
	[PATCH 0/8] v2 - validate binary before use
	https://sourceware.org/ml/gdb-patches/2013-04/msg00472.html
	Message-ID: <1366127096-5744-1-git-send-email-ARistovski@qnx.com>

---

 gdb/Makefile.in                                |   21 +
 gdb/NEWS                                       |   12 +
 gdb/cli/cli-utils.c                            |   36 --
 gdb/cli/cli-utils.h                            |   18 -
 gdb/common/common-defs.h                       |    2 
 gdb/common/common-utils.c                      |  137 ++++++
 gdb/common/common-utils.h                      |   20 +
 gdb/common/common.m4                           |   29 +
 gdb/common/gdb_regex.c                         |   73 +++
 gdb/common/gdb_regex.h                         |   36 ++
 gdb/common/host-defs.h                         |   21 +
 gdb/config/i386/linux.mh                       |    2 
 gdb/config/i386/linux64.mh                     |    2 
 gdb/configure                                  |  102 ++--
 gdb/configure.ac                               |   29 -
 gdb/defs.h                                     |   19 -
 gdb/doc/gdb.texinfo                            |   55 ++
 gdb/features/library-list-svr4.dtd             |   13 -
 gdb/gdb_regex.h                                |   36 --
 gdb/gdbserver/Makefile.in                      |   12 -
 gdb/gdbserver/config.in                        |    3 
 gdb/gdbserver/configure                        |   56 ++
 gdb/gdbserver/configure.srv                    |    2 
 gdb/gdbserver/gdbreplay.c                      |    6 
 gdb/gdbserver/linux-low.c                      |  398 +++++++++++++++--
 gdb/gdbserver/target.c                         |   36 ++
 gdb/linux-tdep.c                               |  566 ++----------------------
 gdb/monitor.c                                  |   16 -
 gdb/nat/linux-maps.c                           |  493 +++++++++++++++++++++
 gdb/nat/linux-maps.h                           |   64 +++
 gdb/solib-darwin.c                             |    1 
 gdb/solib-dsbt.c                               |    1 
 gdb/solib-frv.c                                |    1 
 gdb/solib-spu.c                                |    1 
 gdb/solib-svr4.c                               |   91 ++++
 gdb/solib-target.c                             |    2 
 gdb/solib.c                                    |   62 +++
 gdb/solib.h                                    |    4 
 gdb/solist.h                                   |   21 +
 gdb/target.c                                   |   95 +---
 gdb/target.h                                   |   10 
 gdb/target/target-utils.c                      |  100 ++++
 gdb/target/target-utils.h                      |   35 +
 gdb/target/target.h                            |   11 
 gdb/testsuite/gdb.base/solib-mismatch-lib.c    |   29 +
 gdb/testsuite/gdb.base/solib-mismatch-libmod.c |   29 +
 gdb/testsuite/gdb.base/solib-mismatch.c        |   56 ++
 gdb/testsuite/gdb.base/solib-mismatch.exp      |  156 +++++++
 gdb/utils.c                                    |  154 -------
 gdb/utils.h                                    |    2 
 50 files changed, 2151 insertions(+), 1025 deletions(-)
 create mode 100644 gdb/common/gdb_regex.c
 create mode 100644 gdb/common/gdb_regex.h
 delete mode 100644 gdb/gdb_regex.h
 create mode 100644 gdb/nat/linux-maps.c
 create mode 100644 gdb/nat/linux-maps.h
 create mode 100644 gdb/target/target-utils.c
 create mode 100644 gdb/target/target-utils.h
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-lib.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-libmod.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.exp

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 05/10] Move gdb_regex* to common/
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
  2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-07-08 14:39   ` Pedro Alves
  2015-06-14 19:26 ` [PATCH v7 07/10] Move linux_find_memory_regions_full & co Jan Kratochvil
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

later patches need regex support also in gdbserver.

New patch, not yet reviewed before.


Jan


gdb/ChangeLog
2015-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Change gdb_regex.h to
	common/gdb_regex.h.
	(COMMON_OBS): Add gdb_regex.o.
	(gdb_regex.o): New.
	* common/common.m4 (GDB_AC_COMMON): Add gdb_use_included_regex,
	--without-included-regex and USE_INCLUDED_REGEX.
	* common/gdb_regex.c: New file from utils.c functions.
	* common/gdb_regex.h: Move it here from gdb_regex.h, update include
	file wrapping define name.
	* configure: Rebuilt.
	* configure.ac (gdb_use_included_regex, --without-included-regex)
	(USE_INCLUDED_REGEX): Move them to common/common.m4.
	* gdb_regex.h: Move it to common/gdb_regex.h.
	* utils.c: Remove include gdb_regex.h.
	(do_regfree_cleanup, make_regfree_cleanup, get_regcomp_error)
	(compile_rx_or_error): Move them to common/gdb_regex.c.

gdb/gdbserver/ChangeLog
2015-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* Makefile.in (OBS): Add gdb_regex.o.
	(gdb_regex.o): New.
	* config.in: Rebuilt.
	* configure: Rebuilt.
---
 gdb/Makefile.in           |    7 +++
 gdb/common/common.m4      |   29 +++++++++++++
 gdb/common/gdb_regex.c    |   73 ++++++++++++++++++++++++++++++++
 gdb/common/gdb_regex.h    |   36 ++++++++++++++++
 gdb/configure             |  102 +++++++++++++++++++++++----------------------
 gdb/configure.ac          |   29 -------------
 gdb/gdb_regex.h           |   36 ----------------
 gdb/gdbserver/Makefile.in |    4 ++
 gdb/gdbserver/config.in   |    3 +
 gdb/gdbserver/configure   |   56 +++++++++++++++++++++++++
 gdb/utils.c               |   55 ------------------------
 11 files changed, 258 insertions(+), 172 deletions(-)
 create mode 100644 gdb/common/gdb_regex.c
 create mode 100644 gdb/common/gdb_regex.h
 delete mode 100644 gdb/gdb_regex.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 5fefd49..2d03e2a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -934,7 +934,7 @@ extension.h extension-priv.h \
 build-id.h buildsym.h valprint.h \
 typeprint.h mi/mi-getopt.h mi/mi-parse.h mi/mi-console.h \
 mi/mi-out.h mi/mi-main.h mi/mi-common.h mi/mi-cmds.h linux-nat.h \
-complaints.h gdb_proc_service.h gdb_regex.h xtensa-tdep.h inf-loop.h \
+complaints.h gdb_proc_service.h common/gdb_regex.h xtensa-tdep.h inf-loop.h \
 common/gdb_wait.h common/gdb_assert.h solib.h ppc-tdep.h cp-support.h glibc-tdep.h \
 interps.h auxv.h gdbcmd.h tramp-frame.h mipsnbsd-tdep.h	\
 amd64-linux-tdep.h linespec.h i387-tdep.h mn10300-tdep.h \
@@ -1081,6 +1081,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
 	common-exceptions.o btrace-common.o fileio.o target-utils.o \
+	gdb_regex.o \
 	$(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
@@ -2269,6 +2270,10 @@ btrace-common.o: ${srcdir}/common/btrace-common.c
 fileio.o: ${srcdir}/common/fileio.c
 	$(COMPILE) $(srcdir)/common/fileio.c
 	$(POSTCOMPILE)
+
+gdb_regex.o: ${srcdir}/common/gdb_regex.c
+	$(COMPILE) $(srcdir)/common/gdb_regex.c
+	$(POSTCOMPILE)
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common.m4 b/gdb/common/common.m4
index a87579a..e48dd5a 100644
--- a/gdb/common/common.m4
+++ b/gdb/common/common.m4
@@ -44,4 +44,33 @@ gdb_cv_func_sigsetjmp=yes, gdb_cv_func_sigsetjmp=no)])
 if test $gdb_cv_func_sigsetjmp = yes; then
   AC_DEFINE(HAVE_SIGSETJMP, 1, [Define if sigsetjmp is available. ])
 fi
+
+  # Assume we'll default to using the included libiberty regex.
+  gdb_use_included_regex=yes
+
+  # However, if the system regex is GNU regex, then default to *not*
+  # using the included regex.
+  AC_CACHE_CHECK(
+    [for GNU regex],
+    [gdb_cv_have_gnu_regex],
+    [AC_TRY_COMPILE(
+      [#include <gnu-versions.h>],
+      [#define REGEX_INTERFACE_VERSION 1
+  #if _GNU_REGEX_INTERFACE_VERSION != REGEX_INTERFACE_VERSION
+  # error "Version mismatch"
+  #endif],
+      gdb_cv_have_gnu_regex=yes,
+      gdb_cv_have_gnu_regex=no)])
+  if test $gdb_cv_have_gnu_regex = yes; then
+    gdb_use_included_regex=no
+  fi
+
+  AC_ARG_WITH(included-regex,
+    AS_HELP_STRING([--without-included-regex], [don't use included regex; this is the default on systems with version 2 of the GNU C library (use with caution on other system)]),
+    gdb_with_regex=$withval,
+    gdb_with_regex=$gdb_use_included_regex)
+  if test "$gdb_with_regex" = yes; then
+    AC_DEFINE(USE_INCLUDED_REGEX, 1,
+      [Define to 1 if the regex included in libiberty should be used.])
+  fi
 ])
diff --git a/gdb/common/gdb_regex.c b/gdb/common/gdb_regex.c
new file mode 100644
index 0000000..73f30a7
--- /dev/null
+++ b/gdb/common/gdb_regex.c
@@ -0,0 +1,73 @@
+/* Shared utility routines for GDB to interact with agent.
+
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "gdb_regex.h"
+
+/* A cleanup function that calls regfree.  */
+
+static void
+do_regfree_cleanup (void *r)
+{
+  regfree (r);
+}
+
+/* Create a new cleanup that frees the compiled regular expression R.  */
+
+struct cleanup *
+make_regfree_cleanup (regex_t *r)
+{
+  return make_cleanup (do_regfree_cleanup, r);
+}
+
+/* Return an xmalloc'd error message resulting from a regular
+   expression compilation failure.  */
+
+char *
+get_regcomp_error (int code, regex_t *rx)
+{
+  size_t length = regerror (code, rx, NULL, 0);
+  char *result = xmalloc (length);
+
+  regerror (code, rx, result, length);
+  return result;
+}
+
+/* Compile a regexp and throw an exception on error.  This returns a
+   cleanup to free the resulting pattern on success.  RX must not be
+   NULL.  */
+
+struct cleanup *
+compile_rx_or_error (regex_t *pattern, const char *rx, const char *message)
+{
+  int code;
+
+  gdb_assert (rx != NULL);
+
+  code = regcomp (pattern, rx, REG_NOSUB);
+  if (code != 0)
+    {
+      char *err = get_regcomp_error (code, pattern);
+
+      make_cleanup (xfree, err);
+      error (("%s: %s"), message, err);
+    }
+
+  return make_regfree_cleanup (pattern);
+}
diff --git a/gdb/common/gdb_regex.h b/gdb/common/gdb_regex.h
new file mode 100644
index 0000000..85c9c72
--- /dev/null
+++ b/gdb/common/gdb_regex.h
@@ -0,0 +1,36 @@
+/* Portable <regex.h>.
+   Copyright (C) 2000-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef COMMON_GDB_REGEX_H
+#define COMMON_GDB_REGEX_H 1
+
+#ifdef USE_INCLUDED_REGEX
+# include "xregex.h"
+#else
+/* Request 4.2 BSD regex functions.  */
+# define _REGEX_RE_COMP
+# include <regex.h>
+#endif
+
+/* From utils.c.  */
+struct cleanup *make_regfree_cleanup (regex_t *);
+char *get_regcomp_error (int, regex_t *);
+struct cleanup *compile_rx_or_error (regex_t *pattern, const char *rx,
+				     const char *message);
+
+#endif /* not COMMON_GDB_REGEX_H */
diff --git a/gdb/configure b/gdb/configure
index 5100921..02c865d 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11427,6 +11427,57 @@ $as_echo "#define HAVE_SIGSETJMP 1" >>confdefs.h
 
 fi
 
+  # Assume we'll default to using the included libiberty regex.
+  gdb_use_included_regex=yes
+
+  # However, if the system regex is GNU regex, then default to *not*
+  # using the included regex.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU regex" >&5
+$as_echo_n "checking for GNU regex... " >&6; }
+if test "${gdb_cv_have_gnu_regex+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <gnu-versions.h>
+int
+main ()
+{
+#define REGEX_INTERFACE_VERSION 1
+  #if _GNU_REGEX_INTERFACE_VERSION != REGEX_INTERFACE_VERSION
+  # error "Version mismatch"
+  #endif
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gdb_cv_have_gnu_regex=yes
+else
+  gdb_cv_have_gnu_regex=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_have_gnu_regex" >&5
+$as_echo "$gdb_cv_have_gnu_regex" >&6; }
+  if test $gdb_cv_have_gnu_regex = yes; then
+    gdb_use_included_regex=no
+  fi
+
+
+# Check whether --with-included-regex was given.
+if test "${with_included_regex+set}" = set; then :
+  withval=$with_included_regex; gdb_with_regex=$withval
+else
+  gdb_with_regex=$gdb_use_included_regex
+fi
+
+  if test "$gdb_with_regex" = yes; then
+
+$as_echo "#define USE_INCLUDED_REGEX 1" >>confdefs.h
+
+  fi
+
 
 # Check the return and argument types of ptrace.  No canned test for
 # this, so roll our own.
@@ -11689,57 +11740,6 @@ if test $ac_cv_func_setpgrp_void = yes; then
 fi
 fi
 
-# Assume we'll default to using the included libiberty regex.
-gdb_use_included_regex=yes
-
-# However, if the system regex is GNU regex, then default to *not*
-# using the included regex.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU regex" >&5
-$as_echo_n "checking for GNU regex... " >&6; }
-if test "${gdb_cv_have_gnu_regex+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <gnu-versions.h>
-int
-main ()
-{
-#define REGEX_INTERFACE_VERSION 1
-#if _GNU_REGEX_INTERFACE_VERSION != REGEX_INTERFACE_VERSION
-# error "Version mismatch"
-#endif
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  gdb_cv_have_gnu_regex=yes
-else
-  gdb_cv_have_gnu_regex=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_have_gnu_regex" >&5
-$as_echo "$gdb_cv_have_gnu_regex" >&6; }
-if test $gdb_cv_have_gnu_regex = yes; then
-  gdb_use_included_regex=no
-fi
-
-
-# Check whether --with-included-regex was given.
-if test "${with_included_regex+set}" = set; then :
-  withval=$with_included_regex; gdb_with_regex=$withval
-else
-  gdb_with_regex=$gdb_use_included_regex
-fi
-
-if test "$gdb_with_regex" = yes; then
-
-$as_echo "#define USE_INCLUDED_REGEX 1" >>confdefs.h
-
-fi
-
 # Check if <sys/proc.h> defines `struct thread' with a td_pcb member.
 ac_fn_c_check_member "$LINENO" "struct thread" "td_pcb" "ac_cv_member_struct_thread_td_pcb" "#include <sys/param.h>
 #include <sys/proc.h>
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 2035a37..07b412a 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1424,35 +1424,6 @@ if test $ac_cv_func_setpgrp_void = yes; then
 fi
 fi
 
-# Assume we'll default to using the included libiberty regex.
-gdb_use_included_regex=yes
-
-# However, if the system regex is GNU regex, then default to *not*
-# using the included regex.
-AC_CACHE_CHECK(
-  [for GNU regex],
-  [gdb_cv_have_gnu_regex],
-  [AC_TRY_COMPILE(
-    [#include <gnu-versions.h>],
-    [#define REGEX_INTERFACE_VERSION 1
-#if _GNU_REGEX_INTERFACE_VERSION != REGEX_INTERFACE_VERSION
-# error "Version mismatch"
-#endif],
-    gdb_cv_have_gnu_regex=yes,
-    gdb_cv_have_gnu_regex=no)])
-if test $gdb_cv_have_gnu_regex = yes; then
-  gdb_use_included_regex=no
-fi
-
-AC_ARG_WITH(included-regex,
-  AS_HELP_STRING([--without-included-regex], [don't use included regex; this is the default on systems with version 2 of the GNU C library (use with caution on other system)]),
-  gdb_with_regex=$withval,
-  gdb_with_regex=$gdb_use_included_regex)
-if test "$gdb_with_regex" = yes; then
-  AC_DEFINE(USE_INCLUDED_REGEX, 1,
-    [Define to 1 if the regex included in libiberty should be used.])
-fi
-
 # Check if <sys/proc.h> defines `struct thread' with a td_pcb member.
 AC_CHECK_MEMBERS([struct thread.td_pcb], [], [],
 [#include <sys/param.h>
diff --git a/gdb/gdb_regex.h b/gdb/gdb_regex.h
deleted file mode 100644
index 3173a54..0000000
--- a/gdb/gdb_regex.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Portable <regex.h>.
-   Copyright (C) 2000-2015 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef GDB_REGEX_H
-#define GDB_REGEX_H 1
-
-#ifdef USE_INCLUDED_REGEX
-# include "xregex.h"
-#else
-/* Request 4.2 BSD regex functions.  */
-# define _REGEX_RE_COMP
-# include <regex.h>
-#endif
-
-/* From utils.c.  */
-struct cleanup *make_regfree_cleanup (regex_t *);
-char *get_regcomp_error (int, regex_t *);
-struct cleanup *compile_rx_or_error (regex_t *pattern, const char *rx,
-				     const char *message);
-
-#endif /* not GDB_REGEX_H */
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 908061a..fea8e1b 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -195,6 +195,7 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
       tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
       common-exceptions.o symbol.o btrace-common.o fileio.o target-utils.o \
+      gdb_regex.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -582,6 +583,9 @@ waitstatus.o: ../target/waitstatus.c
 fileio.o: ../common/fileio.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+gdb_regex.o: ../common/gdb_regex.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 # Native object files rules from ../nat
 
diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index f24e6bb..90ea95d 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -317,6 +317,9 @@
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define to 1 if the regex included in libiberty should be used. */
+#undef USE_INCLUDED_REGEX
+
 /* Define if we should use libthread_db directly. */
 #undef USE_LIBTHREAD_DB_DIRECTLY
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index e8cf136..c7ae6be 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -694,6 +694,7 @@ enable_maintainer_mode
 enable_largefile
 enable_build_with_cxx
 enable_libmcheck
+with_included_regex
 with_ust
 with_ust_include
 with_ust_lib
@@ -1345,6 +1346,10 @@ Optional Features:
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --without-included-regex
+                          don't use included regex; this is the default on
+                          systems with version 2 of the GNU C library (use
+                          with caution on other system)
   --with-ust=PATH       Specify prefix directory for the installed UST package
                           Equivalent to --with-ust-include=PATH/include
                           plus --with-ust-lib=PATH/lib
@@ -5747,6 +5752,57 @@ $as_echo "#define HAVE_SIGSETJMP 1" >>confdefs.h
 
 fi
 
+  # Assume we'll default to using the included libiberty regex.
+  gdb_use_included_regex=yes
+
+  # However, if the system regex is GNU regex, then default to *not*
+  # using the included regex.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU regex" >&5
+$as_echo_n "checking for GNU regex... " >&6; }
+if test "${gdb_cv_have_gnu_regex+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <gnu-versions.h>
+int
+main ()
+{
+#define REGEX_INTERFACE_VERSION 1
+  #if _GNU_REGEX_INTERFACE_VERSION != REGEX_INTERFACE_VERSION
+  # error "Version mismatch"
+  #endif
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gdb_cv_have_gnu_regex=yes
+else
+  gdb_cv_have_gnu_regex=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_have_gnu_regex" >&5
+$as_echo "$gdb_cv_have_gnu_regex" >&6; }
+  if test $gdb_cv_have_gnu_regex = yes; then
+    gdb_use_included_regex=no
+  fi
+
+
+# Check whether --with-included-regex was given.
+if test "${with_included_regex+set}" = set; then :
+  withval=$with_included_regex; gdb_with_regex=$withval
+else
+  gdb_with_regex=$gdb_use_included_regex
+fi
+
+  if test "$gdb_with_regex" = yes; then
+
+$as_echo "#define USE_INCLUDED_REGEX 1" >>confdefs.h
+
+  fi
+
 
 # Check for UST
 ustlibs=""
diff --git a/gdb/utils.c b/gdb/utils.c
index acb4c7d..a2c2710 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -67,7 +67,6 @@
 
 #include "gdb_usleep.h"
 #include "interps.h"
-#include "gdb_regex.h"
 
 #if !HAVE_DECL_MALLOC
 extern PTR malloc ();		/* ARI: PTR */
@@ -1114,60 +1113,6 @@ make_hex_string (const gdb_byte *data, size_t length)
 
 \f
 
-/* A cleanup function that calls regfree.  */
-
-static void
-do_regfree_cleanup (void *r)
-{
-  regfree (r);
-}
-
-/* Create a new cleanup that frees the compiled regular expression R.  */
-
-struct cleanup *
-make_regfree_cleanup (regex_t *r)
-{
-  return make_cleanup (do_regfree_cleanup, r);
-}
-
-/* Return an xmalloc'd error message resulting from a regular
-   expression compilation failure.  */
-
-char *
-get_regcomp_error (int code, regex_t *rx)
-{
-  size_t length = regerror (code, rx, NULL, 0);
-  char *result = xmalloc (length);
-
-  regerror (code, rx, result, length);
-  return result;
-}
-
-/* Compile a regexp and throw an exception on error.  This returns a
-   cleanup to free the resulting pattern on success.  RX must not be
-   NULL.  */
-
-struct cleanup *
-compile_rx_or_error (regex_t *pattern, const char *rx, const char *message)
-{
-  int code;
-
-  gdb_assert (rx != NULL);
-
-  code = regcomp (pattern, rx, REG_NOSUB);
-  if (code != 0)
-    {
-      char *err = get_regcomp_error (code, pattern);
-
-      make_cleanup (xfree, err);
-      error (("%s: %s"), message, err);
-    }
-
-  return make_regfree_cleanup (pattern);
-}
-
-\f
-
 /* This function supports the query, nquery, and yquery functions.
    Ask user a y-or-n question and return 0 if answer is no, 1 if
    answer is yes, or default the answer to the specified default

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (5 preceding siblings ...)
  2015-06-14 19:26 ` [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-06-14 19:27 ` [PATCH v7 09/10] Validate symbol file using build-id Jan Kratochvil
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

prepare new files for later move.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00367.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
	* Makefile.in (HFILES_NO_SRCDIR); Add nat/linux-maps.h,
	common/target-utils.h.
	(COMMON_OBS): Add target-utils.o.
	(linux-maps.o, target-utils.o): New.
	* target/target-utils.c: New file.
	* target/target-utils.h: New file.
	* config/i386/linux.mh (NATDEPFILES): Add linux-maps.o.
	* config/i386/linux64.mh (NATDEPFILES): Ditto.
	* nat/linux-maps.c: New file.
	* nat/linux-maps.h: New file.

gdb/gdbserver/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
	* Makefile.in (OBS): Add target-utils.o.
	(linux-maps.o, target-utils.o): New.
	* configure.srv (srv_linux_obj): Add linux-maps.o.
---
 gdb/Makefile.in             |   14 +++++++++++---
 gdb/config/i386/linux.mh    |    2 +-
 gdb/config/i386/linux64.mh  |    2 +-
 gdb/gdbserver/Makefile.in   |    8 +++++++-
 gdb/gdbserver/configure.srv |    2 +-
 gdb/nat/linux-maps.c        |   20 ++++++++++++++++++++
 gdb/nat/linux-maps.h        |   22 ++++++++++++++++++++++
 gdb/target/target-utils.c   |   21 +++++++++++++++++++++
 gdb/target/target-utils.h   |   23 +++++++++++++++++++++++
 9 files changed, 107 insertions(+), 7 deletions(-)
 create mode 100644 gdb/nat/linux-maps.c
 create mode 100644 gdb/nat/linux-maps.h
 create mode 100644 gdb/target/target-utils.c
 create mode 100644 gdb/target/target-utils.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 3008177..5fefd49 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -900,7 +900,7 @@ LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
 # right, it is probably easiest just to list .h files here directly.
 
 HFILES_NO_SRCDIR = \
-common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h \
+common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h nat/linux-maps.h \
 common/x86-xstate.h nat/linux-ptrace.h nat/mips-linux-watch.h \
 proc-utils.h aarch64-tdep.h arm-tdep.h ax-gdb.h ppcfbsd-tdep.h \
 ppcnbsd-tdep.h cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
@@ -980,7 +980,7 @@ common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h common/symbol.h \
 common/common-regcache.h fbsd-tdep.h nat/linux-personality.h \
 common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h \
-nat/linux-namespaces.h
+nat/linux-namespaces.h target/target-utils.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -1080,7 +1080,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
-	common-exceptions.o btrace-common.o fileio.o \
+	common-exceptions.o btrace-common.o fileio.o target-utils.o \
 	$(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
@@ -2218,6 +2218,10 @@ common-agent.o: $(srcdir)/common/agent.c
 	$(COMPILE) $(srcdir)/common/agent.c
 	$(POSTCOMPILE)
 
+linux-maps.o: ${srcdir}/nat/linux-maps.c
+	$(COMPILE) $(srcdir)/nat/linux-maps.c
+	$(POSTCOMPILE)
+
 vec.o: ${srcdir}/common/vec.c
 	$(COMPILE) $(srcdir)/common/vec.c
 	$(POSTCOMPILE)
@@ -2234,6 +2238,10 @@ errors.o: ${srcdir}/common/errors.c
 	$(COMPILE) $(srcdir)/common/errors.c
 	$(POSTCOMPILE)
 
+target-utils.o: ${srcdir}/target/target-utils.c
+	$(COMPILE) $(srcdir)/target/target-utils.c
+	$(POSTCOMPILE)
+
 common-debug.o: ${srcdir}/common/common-debug.c
 	$(COMPILE) $(srcdir)/common/common-debug.c
 	$(POSTCOMPILE)
diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh
index 421c56f..f7ee5ff 100644
--- a/gdb/config/i386/linux.mh
+++ b/gdb/config/i386/linux.mh
@@ -3,7 +3,7 @@
 NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	x86-nat.o x86-dregs.o i386-linux-nat.o x86-linux-nat.o \
-	proc-service.o linux-thread-db.o \
+	proc-service.o linux-thread-db.o linux-maps.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
 	linux-btrace.o linux-waitpid.o linux-personality.o x86-linux.o \
 	x86-linux-dregs.o linux-namespaces.o
diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh
index 04cbb95..81968fd 100644
--- a/gdb/config/i386/linux64.mh
+++ b/gdb/config/i386/linux64.mh
@@ -2,7 +2,7 @@
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	x86-nat.o x86-dregs.o amd64-nat.o amd64-linux-nat.o \
 	x86-linux-nat.o \
-	linux-nat.o linux-osdata.o \
+	linux-maps.o linux-nat.o linux-osdata.o \
 	proc-service.o linux-thread-db.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-btrace.o \
 	linux-waitpid.o linux-personality.o x86-linux.o \
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index fc250fb..908061a 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -194,7 +194,7 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
       tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
-      common-exceptions.o symbol.o btrace-common.o fileio.o \
+      common-exceptions.o symbol.o btrace-common.o fileio.o target-utils.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -519,6 +519,9 @@ ax.o: ax.c
 signals.o: ../common/signals.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+linux-maps.o: ../nat/linux-maps.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 print-utils.o: ../common/print-utils.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
@@ -531,6 +534,9 @@ common-utils.o: ../common/common-utils.c
 posix-strerror.o: ../common/posix-strerror.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+target-utils.o: ../target/target-utils.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 mingw-strerror.o: ../common/mingw-strerror.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 7f89f2f..ac324ff 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,7 @@ srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
 
 # Linux object files.  This is so we don't have to repeat
 # these files over and over again.
-srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
+srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-maps.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
 
 # Input is taken from the "${target}" variable.
 
diff --git a/gdb/nat/linux-maps.c b/gdb/nat/linux-maps.c
new file mode 100644
index 0000000..01c8836
--- /dev/null
+++ b/gdb/nat/linux-maps.c
@@ -0,0 +1,20 @@
+/* Linux-specific memory maps manipulation routines.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "linux-maps.h"
diff --git a/gdb/nat/linux-maps.h b/gdb/nat/linux-maps.h
new file mode 100644
index 0000000..2cff321
--- /dev/null
+++ b/gdb/nat/linux-maps.h
@@ -0,0 +1,22 @@
+/* Linux-specific memory maps manipulation routines.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef NAT_LINUX_MAPS_H
+#define NAT_LINUX_MAPS_H
+
+#endif /* NAT_LINUX_MAPS_H */
diff --git a/gdb/target/target-utils.c b/gdb/target/target-utils.c
new file mode 100644
index 0000000..4e8fae7
--- /dev/null
+++ b/gdb/target/target-utils.c
@@ -0,0 +1,21 @@
+/* Utility target functions for GDB, and GDBserver.
+
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "target/target-utils.h"
diff --git a/gdb/target/target-utils.h b/gdb/target/target-utils.h
new file mode 100644
index 0000000..443ffc3
--- /dev/null
+++ b/gdb/target/target-utils.h
@@ -0,0 +1,23 @@
+/* Utility target functions for GDB, and GDBserver.
+
+   Copyright (C) 2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef TARGET_TARGET_UTILS_H
+#define TARGET_TARGET_UTILS_H
+
+#endif /* TARGET_TARGET_UTILS_H */

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (2 preceding siblings ...)
  2015-06-14 19:26 ` [PATCH v7 07/10] Move linux_find_memory_regions_full & co Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-06-15 13:34   ` Joel Brobecker
  2015-07-08 14:38   ` Pedro Alves
  2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi Sergio,

this is an unrelated cleanup, bit mask ints are better to make enums as GDB
already has support to automatically decode them:

before this patch:
	(gdb) p filterflags
	$1 = 51
	(gdb) p/x filterflags
	$2 = 0x33

after this patch:
	(gdb) p filterflags
	$1 = (COREFILTER_ANON_PRIVATE | COREFILTER_ANON_SHARED | COREFILTER_ELF_HEADERS | COREFILTER_HUGETLB_PRIVATE)

New patch, not yet reviewed before.


Jan


gdb/ChangeLog
2015-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-tdep.c (enum filterflags): Make it from anonymous enum.
	(dump_mapping_p): Use it for parameter filterflags.
	(linux_find_memory_regions_full): Use it for variable filterflags.
---
 gdb/linux-tdep.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index f0cdc9c..c81f71b 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -46,7 +46,7 @@
    Documentation/filesystems/proc.txt, inside the Linux kernel
    tree.  */
 
-enum
+enum filterflags
   {
     COREFILTER_ANON_PRIVATE = 1 << 0,
     COREFILTER_ANON_SHARED = 1 << 1,
@@ -598,7 +598,7 @@ mapping_is_anonymous_p (const char *filename)
      This should work OK enough, however.  */
 
 static int
-dump_mapping_p (unsigned int filterflags, const struct smaps_vmflags *v,
+dump_mapping_p (enum filterflags filterflags, const struct smaps_vmflags *v,
 		int maybe_private_p, int mapping_anon_p, int mapping_file_p,
 		const char *filename)
 {
@@ -1119,10 +1119,10 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
   /* Default dump behavior of coredump_filter (0x33), according to
      Documentation/filesystems/proc.txt from the Linux kernel
      tree.  */
-  unsigned int filterflags = (COREFILTER_ANON_PRIVATE
-			      | COREFILTER_ANON_SHARED
-			      | COREFILTER_ELF_HEADERS
-			      | COREFILTER_HUGETLB_PRIVATE);
+  enum filterflags filterflags = (COREFILTER_ANON_PRIVATE
+				  | COREFILTER_ANON_SHARED
+				  | COREFILTER_ELF_HEADERS
+				  | COREFILTER_HUGETLB_PRIVATE);
 
   /* We need to know the real target PID to access /proc.  */
   if (current_inferior ()->fake_pid_p)

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 02/10] Merge multiple hex conversions
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (3 preceding siblings ...)
  2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-06-15 13:33   ` Joel Brobecker
  2015-06-14 19:26 ` [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

here most of the patch has been reimplemented in the meantime and this is only
a small remaint.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00366.html


Jan


gdb/gdbserver/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Merge multiple hex conversions.
	* gdbreplay.c (tohex): Rename to 'fromhex'.
	(logchar): Use fromhex.

gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Merge multiple hex conversions.
	* monitor.c: Include rsp-low.h.
	(fromhex): Remove definition.
---
 gdb/gdbserver/gdbreplay.c |    6 +++---
 gdb/monitor.c             |   16 +---------------
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index a02a824..79aa8aa 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -259,7 +259,7 @@ remote_open (char *name)
 }
 
 static int
-tohex (int ch)
+fromhex (int ch)
 {
   if (ch >= '0' && ch <= '9')
     {
@@ -322,11 +322,11 @@ logchar (FILE *fp)
 	  ch2 = fgetc (fp);
 	  fputc (ch2, stdout);
 	  fflush (stdout);
-	  ch = tohex (ch2) << 4;
+	  ch = fromhex (ch2) << 4;
 	  ch2 = fgetc (fp);
 	  fputc (ch2, stdout);
 	  fflush (stdout);
-	  ch |= tohex (ch2);
+	  ch |= fromhex (ch2);
 	  break;
 	default:
 	  /* Treat any other char as just itself */
diff --git a/gdb/monitor.c b/gdb/monitor.c
index 548dae3..c7f5fc7 100644
--- a/gdb/monitor.c
+++ b/gdb/monitor.c
@@ -54,6 +54,7 @@
 #include "regcache.h"
 #include "gdbthread.h"
 #include "readline/readline.h"
+#include "rsp-low.h"
 
 static char *dev_name;
 static struct target_ops *targ_ops;
@@ -225,21 +226,6 @@ monitor_error (char *function, char *message,
 	   message, safe_string);
 }
 
-/* Convert hex digit A to a number.  */
-
-static int
-fromhex (int a)
-{
-  if (a >= '0' && a <= '9')
-    return a - '0';
-  else if (a >= 'a' && a <= 'f')
-    return a - 'a' + 10;
-  else if (a >= 'A' && a <= 'F')
-    return a - 'A' + 10;
-  else
-    error (_("Invalid hex digit %d"), a);
-}
-
 /* monitor_vsprintf - similar to vsprintf but handles 64-bit addresses
 
    This function exists to get around the problem that many host platforms

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 07/10] Move linux_find_memory_regions_full & co.
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
  2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
  2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* " Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

this should be just a move with no changes.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00372.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Move linux_find_memory_regions_full & co.
	* linux-tdep.c (nat/linux-maps.h): Include.
	(gdb_regex.h): Remove the include.
	(enum filterflags, struct smaps_vmflags, read_mapping, decode_vmflags)
	(mapping_is_anonymous_p, dump_mapping_p): Moved to nat/linux-maps.c.
	(linux_find_memory_region_ftype): Moved typedef to nat/linux-maps.h.
	(linux_find_memory_regions_full): Moved definition to nat/linux-maps.c.
	* nat/linux-maps.c: Include ctype.h, target/target-utils.h, gdb_regex.h
	and target/target.h.
	(struct smaps_vmflags, read_mapping, decode_vmflags)
	(mapping_is_anonymous_p, dump_mapping_p): Move from linux-tdep.c.
	(linux_find_memory_regions_full): Move from linux-tdep.c.
	* nat/linux-maps.h (read_mapping): New declaration.
	(linux_find_memory_region_ftype, enum filterflags): Moved from
	linux-tdep.c.
	(linux_find_memory_regions_full): New declaration.
	* target.c (target/target-utils.h): Include.
	(read_alloc_pread_ftype): Moved typedef to target/target-utils.h.
	(read_alloc, read_stralloc_func_ftype, read_stralloc): Moved
	definitions to target/target-utils.c.
	* target.h (target_fileio_read_stralloc): Move it to target/target.h.
	* target/target-utils.c (read_alloc, read_stralloc): Move definitions
	from target.c.
	* target/target-utils.h (read_alloc_pread_ftype): New typedef.
	(read_alloc): New declaration.
	(read_stralloc_func_ftype): New typedef.
	(read_stralloc): New declaration.
	* target/target.h (target_fileio_read_stralloc): Move it from target.h.

gdb/gdbserver/ChangeLog
2015-06-14  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* target.c: Include target/target-utils.h and fcntl.h.
	(target_fileio_read_stralloc_1_pread, target_fileio_read_stralloc_1)
	(target_fileio_read_stralloc): New functions.
---
 gdb/gdbserver/target.c    |   36 +++
 gdb/linux-tdep.c          |  499 ---------------------------------------------
 gdb/nat/linux-maps.c      |  473 +++++++++++++++++++++++++++++++++++++++++++
 gdb/nat/linux-maps.h      |   42 ++++
 gdb/target.c              |   91 --------
 gdb/target.h              |   10 -
 gdb/target/target-utils.c |   79 +++++++
 gdb/target/target-utils.h |   12 +
 gdb/target/target.h       |   11 +
 9 files changed, 656 insertions(+), 597 deletions(-)

diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index 14999e6..5525b1f 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -20,6 +20,8 @@
 
 #include "server.h"
 #include "tracepoint.h"
+#include "target/target-utils.h"
+#include <fcntl.h>
 
 struct target_ops *the_target;
 
@@ -218,3 +220,37 @@ kill_inferior (int pid)
 
   return (*the_target->kill) (pid);
 }
+
+static int
+target_fileio_read_stralloc_1_pread (int handle, gdb_byte *read_buf, int len,
+				     ULONGEST offset, int *target_errno)
+{
+  int retval = pread (handle, read_buf, len, offset);
+
+  *target_errno = errno;
+  return retval;
+}
+
+static LONGEST
+target_fileio_read_stralloc_1 (struct inferior *inf, const char *filename,
+			       gdb_byte **buf_p, int padding)
+{
+  int fd;
+  LONGEST retval;
+
+  fd = open (filename, O_RDONLY);
+  if (fd == -1)
+    return -1;
+
+  retval = read_alloc (buf_p, fd, target_fileio_read_stralloc_1_pread, padding);
+
+  close (fd);
+
+  return retval;
+}
+
+char *
+target_fileio_read_stralloc (struct inferior *inf, const char *filename)
+{
+  return read_stralloc (inf, filename, target_fileio_read_stralloc_1);
+}
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index fb59305..3bd672a 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -35,56 +35,11 @@
 #include "observer.h"
 #include "objfiles.h"
 #include "infcall.h"
+#include "nat/linux-maps.h"
 #include "gdbcmd.h"
-#include "gdb_regex.h"
 
 #include <ctype.h>
 
-/* This enum represents the values that the user can choose when
-   informing the Linux kernel about which memory mappings will be
-   dumped in a corefile.  They are described in the file
-   Documentation/filesystems/proc.txt, inside the Linux kernel
-   tree.  */
-
-enum filterflags
-  {
-    COREFILTER_ANON_PRIVATE = 1 << 0,
-    COREFILTER_ANON_SHARED = 1 << 1,
-    COREFILTER_MAPPED_PRIVATE = 1 << 2,
-    COREFILTER_MAPPED_SHARED = 1 << 3,
-    COREFILTER_ELF_HEADERS = 1 << 4,
-    COREFILTER_HUGETLB_PRIVATE = 1 << 5,
-    COREFILTER_HUGETLB_SHARED = 1 << 6,
-  };
-
-/* This struct is used to map flags found in the "VmFlags:" field (in
-   the /proc/<PID>/smaps file).  */
-
-struct smaps_vmflags
-  {
-    /* Zero if this structure has not been initialized yet.  It
-       probably means that the Linux kernel being used does not emit
-       the "VmFlags:" field on "/proc/PID/smaps".  */
-
-    unsigned int initialized_p : 1;
-
-    /* Memory mapped I/O area (VM_IO, "io").  */
-
-    unsigned int io_page : 1;
-
-    /* Area uses huge TLB pages (VM_HUGETLB, "ht").  */
-
-    unsigned int uses_huge_tlb : 1;
-
-    /* Do not include this memory region on the coredump (VM_DONTDUMP, "dd").  */
-
-    unsigned int exclude_coredump : 1;
-
-    /* Is this a MAP_SHARED mapping (VM_SHARED, "sh").  */
-
-    unsigned int shared_mapping : 1;
-  };
-
 /* Whether to take the /proc/PID/coredump_filter into account when
    generating a corefile.  */
 
@@ -395,286 +350,6 @@ linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
   return normal_pid_to_str (ptid);
 }
 
-/* Service function for corefiles and info proc.  */
-
-static void
-read_mapping (const char *line,
-	      ULONGEST *addr, ULONGEST *endaddr,
-	      const char **permissions, size_t *permissions_len,
-	      ULONGEST *offset,
-              const char **device, size_t *device_len,
-	      ULONGEST *inode,
-	      const char **filename)
-{
-  const char *p = line;
-
-  *addr = strtoulst (p, &p, 16);
-  if (*p == '-')
-    p++;
-  *endaddr = strtoulst (p, &p, 16);
-
-  p = skip_spaces_const (p);
-  *permissions = p;
-  while (*p && !isspace (*p))
-    p++;
-  *permissions_len = p - *permissions;
-
-  *offset = strtoulst (p, &p, 16);
-
-  p = skip_spaces_const (p);
-  *device = p;
-  while (*p && !isspace (*p))
-    p++;
-  *device_len = p - *device;
-
-  *inode = strtoulst (p, &p, 10);
-
-  p = skip_spaces_const (p);
-  *filename = p;
-}
-
-/* Helper function to decode the "VmFlags" field in /proc/PID/smaps.
-
-   This function was based on the documentation found on
-   <Documentation/filesystems/proc.txt>, on the Linux kernel.
-
-   Linux kernels before commit
-   834f82e2aa9a8ede94b17b656329f850c1471514 (3.10) do not have this
-   field on smaps.  */
-
-static void
-decode_vmflags (char *p, struct smaps_vmflags *v)
-{
-  char *saveptr = NULL;
-  const char *s;
-
-  v->initialized_p = 1;
-  p = skip_to_space (p);
-  p = skip_spaces (p);
-
-  for (s = strtok_r (p, " ", &saveptr);
-       s != NULL;
-       s = strtok_r (NULL, " ", &saveptr))
-    {
-      if (strcmp (s, "io") == 0)
-	v->io_page = 1;
-      else if (strcmp (s, "ht") == 0)
-	v->uses_huge_tlb = 1;
-      else if (strcmp (s, "dd") == 0)
-	v->exclude_coredump = 1;
-      else if (strcmp (s, "sh") == 0)
-	v->shared_mapping = 1;
-    }
-}
-
-/* Return 1 if the memory mapping is anonymous, 0 otherwise.
-
-   FILENAME is the name of the file present in the first line of the
-   memory mapping, in the "/proc/PID/smaps" output.  For example, if
-   the first line is:
-
-   7fd0ca877000-7fd0d0da0000 r--p 00000000 fd:02 2100770   /path/to/file
-
-   Then FILENAME will be "/path/to/file".  */
-
-static int
-mapping_is_anonymous_p (const char *filename)
-{
-  static regex_t dev_zero_regex, shmem_file_regex, file_deleted_regex;
-  static int init_regex_p = 0;
-
-  if (!init_regex_p)
-    {
-      struct cleanup *c = make_cleanup (null_cleanup, NULL);
-
-      /* Let's be pessimistic and assume there will be an error while
-	 compiling the regex'es.  */
-      init_regex_p = -1;
-
-      /* DEV_ZERO_REGEX matches "/dev/zero" filenames (with or
-	 without the "(deleted)" string in the end).  We know for
-	 sure, based on the Linux kernel code, that memory mappings
-	 whose associated filename is "/dev/zero" are guaranteed to be
-	 MAP_ANONYMOUS.  */
-      compile_rx_or_error (&dev_zero_regex, "^/dev/zero\\( (deleted)\\)\\?$",
-			   _("Could not compile regex to match /dev/zero "
-			     "filename"));
-      /* SHMEM_FILE_REGEX matches "/SYSV%08x" filenames (with or
-	 without the "(deleted)" string in the end).  These filenames
-	 refer to shared memory (shmem), and memory mappings
-	 associated with them are MAP_ANONYMOUS as well.  */
-      compile_rx_or_error (&shmem_file_regex,
-			   "^/\\?SYSV[0-9a-fA-F]\\{8\\}\\( (deleted)\\)\\?$",
-			   _("Could not compile regex to match shmem "
-			     "filenames"));
-      /* FILE_DELETED_REGEX is a heuristic we use to try to mimic the
-	 Linux kernel's 'n_link == 0' code, which is responsible to
-	 decide if it is dealing with a 'MAP_SHARED | MAP_ANONYMOUS'
-	 mapping.  In other words, if FILE_DELETED_REGEX matches, it
-	 does not necessarily mean that we are dealing with an
-	 anonymous shared mapping.  However, there is no easy way to
-	 detect this currently, so this is the best approximation we
-	 have.
-
-	 As a result, GDB will dump readonly pages of deleted
-	 executables when using the default value of coredump_filter
-	 (0x33), while the Linux kernel will not dump those pages.
-	 But we can live with that.  */
-      compile_rx_or_error (&file_deleted_regex, " (deleted)$",
-			   _("Could not compile regex to match "
-			     "'<file> (deleted)'"));
-      /* We will never release these regexes, so just discard the
-	 cleanups.  */
-      discard_cleanups (c);
-
-      /* If we reached this point, then everything succeeded.  */
-      init_regex_p = 1;
-    }
-
-  if (init_regex_p == -1)
-    {
-      const char deleted[] = " (deleted)";
-      size_t del_len = sizeof (deleted) - 1;
-      size_t filename_len = strlen (filename);
-
-      /* There was an error while compiling the regex'es above.  In
-	 order to try to give some reliable information to the caller,
-	 we just try to find the string " (deleted)" in the filename.
-	 If we managed to find it, then we assume the mapping is
-	 anonymous.  */
-      return (filename_len >= del_len
-	      && strcmp (filename + filename_len - del_len, deleted) == 0);
-    }
-
-  if (*filename == '\0'
-      || regexec (&dev_zero_regex, filename, 0, NULL, 0) == 0
-      || regexec (&shmem_file_regex, filename, 0, NULL, 0) == 0
-      || regexec (&file_deleted_regex, filename, 0, NULL, 0) == 0)
-    return 1;
-
-  return 0;
-}
-
-/* Return 0 if the memory mapping (which is related to FILTERFLAGS, V,
-   MAYBE_PRIVATE_P, and MAPPING_ANONYMOUS_P) should not be dumped, or
-   greater than 0 if it should.
-
-   In a nutshell, this is the logic that we follow in order to decide
-   if a mapping should be dumped or not.
-
-   - If the mapping is associated to a file whose name ends with
-     " (deleted)", or if the file is "/dev/zero", or if it is
-     "/SYSV%08x" (shared memory), or if there is no file associated
-     with it, or if the AnonHugePages: or the Anonymous: fields in the
-     /proc/PID/smaps have contents, then GDB considers this mapping to
-     be anonymous.  Otherwise, GDB considers this mapping to be a
-     file-backed mapping (because there will be a file associated with
-     it).
- 
-     It is worth mentioning that, from all those checks described
-     above, the most fragile is the one to see if the file name ends
-     with " (deleted)".  This does not necessarily mean that the
-     mapping is anonymous, because the deleted file associated with
-     the mapping may have been a hard link to another file, for
-     example.  The Linux kernel checks to see if "i_nlink == 0", but
-     GDB cannot easily (and normally) do this check (iff running as
-     root, it could find the mapping in /proc/PID/map_files/ and
-     determine whether there still are other hard links to the
-     inode/file).  Therefore, we made a compromise here, and we assume
-     that if the file name ends with " (deleted)", then the mapping is
-     indeed anonymous.  FWIW, this is something the Linux kernel could
-     do better: expose this information in a more direct way.
- 
-   - If we see the flag "sh" in the "VmFlags:" field (in
-     /proc/PID/smaps), then certainly the memory mapping is shared
-     (VM_SHARED).  If we have access to the VmFlags, and we don't see
-     the "sh" there, then certainly the mapping is private.  However,
-     Linux kernels before commit
-     834f82e2aa9a8ede94b17b656329f850c1471514 (3.10) do not have the
-     "VmFlags:" field; in that case, we use another heuristic: if we
-     see 'p' in the permission flags, then we assume that the mapping
-     is private, even though the presence of the 's' flag there would
-     mean VM_MAYSHARE, which means the mapping could still be private.
-     This should work OK enough, however.  */
-
-static int
-dump_mapping_p (enum filterflags filterflags, const struct smaps_vmflags *v,
-		int maybe_private_p, int mapping_anon_p, int mapping_file_p,
-		const char *filename)
-{
-  /* Initially, we trust in what we received from our caller.  This
-     value may not be very precise (i.e., it was probably gathered
-     from the permission line in the /proc/PID/smaps list, which
-     actually refers to VM_MAYSHARE, and not VM_SHARED), but it is
-     what we have until we take a look at the "VmFlags:" field
-     (assuming that the version of the Linux kernel being used
-     supports it, of course).  */
-  int private_p = maybe_private_p;
-
-  /* We always dump vDSO and vsyscall mappings, because it's likely that
-     there'll be no file to read the contents from at core load time.
-     The kernel does the same.  */
-  if (strcmp ("[vdso]", filename) == 0
-      || strcmp ("[vsyscall]", filename) == 0)
-    return 1;
-
-  if (v->initialized_p)
-    {
-      /* We never dump I/O mappings.  */
-      if (v->io_page)
-	return 0;
-
-      /* Check if we should exclude this mapping.  */
-      if (v->exclude_coredump)
-	return 0;
-
-      /* Update our notion of whether this mapping is shared or
-	 private based on a trustworthy value.  */
-      private_p = !v->shared_mapping;
-
-      /* HugeTLB checking.  */
-      if (v->uses_huge_tlb)
-	{
-	  if ((private_p && (filterflags & COREFILTER_HUGETLB_PRIVATE))
-	      || (!private_p && (filterflags & COREFILTER_HUGETLB_SHARED)))
-	    return 1;
-
-	  return 0;
-	}
-    }
-
-  if (private_p)
-    {
-      if (mapping_anon_p && mapping_file_p)
-	{
-	  /* This is a special situation.  It can happen when we see a
-	     mapping that is file-backed, but that contains anonymous
-	     pages.  */
-	  return ((filterflags & COREFILTER_ANON_PRIVATE) != 0
-		  || (filterflags & COREFILTER_MAPPED_PRIVATE) != 0);
-	}
-      else if (mapping_anon_p)
-	return (filterflags & COREFILTER_ANON_PRIVATE) != 0;
-      else
-	return (filterflags & COREFILTER_MAPPED_PRIVATE) != 0;
-    }
-  else
-    {
-      if (mapping_anon_p && mapping_file_p)
-	{
-	  /* This is a special situation.  It can happen when we see a
-	     mapping that is file-backed, but that contains anonymous
-	     pages.  */
-	  return ((filterflags & COREFILTER_ANON_SHARED) != 0
-		  || (filterflags & COREFILTER_MAPPED_SHARED) != 0);
-	}
-      else if (mapping_anon_p)
-	return (filterflags & COREFILTER_ANON_SHARED) != 0;
-      else
-	return (filterflags & COREFILTER_MAPPED_SHARED) != 0;
-    }
-}
-
 /* Implement the "info proc" command.  */
 
 static void
@@ -1098,178 +773,6 @@ linux_core_info_proc (struct gdbarch *gdbarch, const char *args,
     error (_("unable to handle request"));
 }
 
-/* Callback function for linux_find_memory_regions_full.  If it returns
-   non-zero linux_find_memory_regions_full returns immediately with that
-   value.  */
-
-typedef int linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size,
-					    ULONGEST offset, ULONGEST inode,
-					    int read, int write,
-					    int exec, int modified,
-					    const char *filename,
-					    void *data);
-
-/* List memory regions in the inferior PID matched to FILTERFLAGS for
-   a corefile.  Call FUNC with FUNC_DATA for each such region.  Return
-   immediately with the value returned by FUNC if it is non-zero.
-   *MEMORY_TO_FREE_PTR should be registered to be freed automatically if
-   called FUNC throws an exception.  MEMORY_TO_FREE_PTR can be also
-   passed as NULL if it is not used.  Return -1 if error occurs, 0 if
-   all memory regions have been processed or return the value from FUNC
-   if FUNC returns non-zero.  */
-
-static int
-linux_find_memory_regions_full (pid_t pid, enum filterflags filterflags,
-				linux_find_memory_region_ftype *func,
-				void *func_data)
-{
-  char mapsfilename[100];
-  char *data;
-
-  xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid);
-  data = target_fileio_read_stralloc (NULL, mapsfilename);
-  if (data == NULL)
-    {
-      /* Older Linux kernels did not support /proc/PID/smaps.  */
-      xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", pid);
-      data = target_fileio_read_stralloc (NULL, mapsfilename);
-    }
-
-  if (data != NULL)
-    {
-      struct cleanup *cleanup = make_cleanup (xfree, data);
-      char *line, *t;
-      int retval = 0;
-
-      line = strtok_r (data, "\n", &t);
-      while (line != NULL)
-	{
-	  ULONGEST addr, endaddr, offset, inode;
-	  const char *permissions, *device, *filename;
-	  struct smaps_vmflags v;
-	  size_t permissions_len, device_len;
-	  int read, write, exec, priv;
-	  int has_anonymous = 0;
-	  int should_dump_p = 0;
-	  int mapping_anon_p;
-	  int mapping_file_p;
-
-	  memset (&v, 0, sizeof (v));
-	  read_mapping (line, &addr, &endaddr, &permissions, &permissions_len,
-			&offset, &device, &device_len, &inode, &filename);
-	  mapping_anon_p = mapping_is_anonymous_p (filename);
-	  /* If the mapping is not anonymous, then we can consider it
-	     to be file-backed.  These two states (anonymous or
-	     file-backed) seem to be exclusive, but they can actually
-	     coexist.  For example, if a file-backed mapping has
-	     "Anonymous:" pages (see more below), then the Linux
-	     kernel will dump this mapping when the user specified
-	     that she only wants anonymous mappings in the corefile
-	     (*even* when she explicitly disabled the dumping of
-	     file-backed mappings).  */
-	  mapping_file_p = !mapping_anon_p;
-
-	  /* Decode permissions.  */
-	  read = (memchr (permissions, 'r', permissions_len) != 0);
-	  write = (memchr (permissions, 'w', permissions_len) != 0);
-	  exec = (memchr (permissions, 'x', permissions_len) != 0);
-	  /* 'private' here actually means VM_MAYSHARE, and not
-	     VM_SHARED.  In order to know if a mapping is really
-	     private or not, we must check the flag "sh" in the
-	     VmFlags field.  This is done by decode_vmflags.  However,
-	     if we are using a Linux kernel released before the commit
-	     834f82e2aa9a8ede94b17b656329f850c1471514 (3.10), we will
-	     not have the VmFlags there.  In this case, there is
-	     really no way to know if we are dealing with VM_SHARED,
-	     so we just assume that VM_MAYSHARE is enough.  */
-	  priv = memchr (permissions, 'p', permissions_len) != 0;
-
-	  /* Try to detect if region should be dumped by parsing smaps
-	     counters.  */
-	  for (line = strtok_r (NULL, "\n", &t);
-	       line != NULL && line[0] >= 'A' && line[0] <= 'Z';
-	       line = strtok_r (NULL, "\n", &t))
-	    {
-	      char keyword[64 + 1];
-
-	      if (sscanf (line, "%64s", keyword) != 1)
-		{
-		  warning (_("Error parsing {s,}maps file '%s'"), mapsfilename);
-		  break;
-		}
-
-	      if (strcmp (keyword, "Anonymous:") == 0)
-		{
-		  /* Older Linux kernels did not support the
-		     "Anonymous:" counter.  Check it here.  */
-		  has_anonymous = 1;
-		}
-	      else if (strcmp (keyword, "VmFlags:") == 0)
-		decode_vmflags (line, &v);
-
-	      if (strcmp (keyword, "AnonHugePages:") == 0
-		  || strcmp (keyword, "Anonymous:") == 0)
-		{
-		  unsigned long number;
-
-		  if (sscanf (line, "%*s%lu", &number) != 1)
-		    {
-		      warning (_("Error parsing {s,}maps file '%s' number"),
-			       mapsfilename);
-		      break;
-		    }
-		  if (number > 0)
-		    {
-		      /* Even if we are dealing with a file-backed
-			 mapping, if it contains anonymous pages we
-			 consider it to be *also* an anonymous
-			 mapping, because this is what the Linux
-			 kernel does:
-
-			 // Dump segments that have been written to.
-			 if (vma->anon_vma && FILTER(ANON_PRIVATE))
-			 	goto whole;
-
-			 Note that if the mapping is already marked as
-			 file-backed (i.e., mapping_file_p is
-			 non-zero), then this is a special case, and
-			 this mapping will be dumped either when the
-			 user wants to dump file-backed *or* anonymous
-			 mappings.  */
-		      mapping_anon_p = 1;
-		    }
-		}
-	    }
-
-	  if (has_anonymous)
-	    should_dump_p = dump_mapping_p (filterflags, &v, priv,
-					    mapping_anon_p, mapping_file_p,
-					    filename);
-	  else
-	    {
-	      /* Older Linux kernels did not support the "Anonymous:" counter.
-		 If it is missing, we can't be sure - dump all the pages.  */
-	      should_dump_p = 1;
-	    }
-
-	  /* Invoke the callback function to create the corefile segment.  */
-	  if (should_dump_p)
-	    retval = func (addr, endaddr - addr, offset, inode,
-			   read, write, exec,
-			   1, /* MODIFIED is true because we want to dump the
-				 mapping.  */
-			   filename, func_data);
-	  if (retval != 0)
-	    break;
-	}
-
-      do_cleanups (cleanup);
-      return retval;
-    }
-
-  return -1;
-}
-
 /* A structure for passing information through
    linux_find_memory_regions_full.  */
 
diff --git a/gdb/nat/linux-maps.c b/gdb/nat/linux-maps.c
index 01c8836..ef3da6a 100644
--- a/gdb/nat/linux-maps.c
+++ b/gdb/nat/linux-maps.c
@@ -18,3 +18,476 @@
 
 #include "common-defs.h"
 #include "linux-maps.h"
+#include <ctype.h>
+#include "target/target-utils.h"
+#include "gdb_regex.h"
+#include "target/target.h"
+
+/* This struct is used to map flags found in the "VmFlags:" field (in
+   the /proc/<PID>/smaps file).  */
+
+struct smaps_vmflags
+  {
+    /* Zero if this structure has not been initialized yet.  It
+       probably means that the Linux kernel being used does not emit
+       the "VmFlags:" field on "/proc/PID/smaps".  */
+
+    unsigned int initialized_p : 1;
+
+    /* Memory mapped I/O area (VM_IO, "io").  */
+
+    unsigned int io_page : 1;
+
+    /* Area uses huge TLB pages (VM_HUGETLB, "ht").  */
+
+    unsigned int uses_huge_tlb : 1;
+
+    /* Do not include this memory region on the coredump (VM_DONTDUMP, "dd").  */
+
+    unsigned int exclude_coredump : 1;
+
+    /* Is this a MAP_SHARED mapping (VM_SHARED, "sh").  */
+
+    unsigned int shared_mapping : 1;
+  };
+
+/* Service function for corefiles and info proc.  */
+
+void
+read_mapping (const char *line,
+	      ULONGEST *addr, ULONGEST *endaddr,
+	      const char **permissions, size_t *permissions_len,
+	      ULONGEST *offset,
+              const char **device, size_t *device_len,
+	      ULONGEST *inode,
+	      const char **filename)
+{
+  const char *p = line;
+
+  *addr = strtoulst (p, &p, 16);
+  if (*p == '-')
+    p++;
+  *endaddr = strtoulst (p, &p, 16);
+
+  p = skip_spaces_const (p);
+  *permissions = p;
+  while (*p && !isspace (*p))
+    p++;
+  *permissions_len = p - *permissions;
+
+  *offset = strtoulst (p, &p, 16);
+
+  p = skip_spaces_const (p);
+  *device = p;
+  while (*p && !isspace (*p))
+    p++;
+  *device_len = p - *device;
+
+  *inode = strtoulst (p, &p, 10);
+
+  p = skip_spaces_const (p);
+  *filename = p;
+}
+
+/* Helper function to decode the "VmFlags" field in /proc/PID/smaps.
+
+   This function was based on the documentation found on
+   <Documentation/filesystems/proc.txt>, on the Linux kernel.
+
+   Linux kernels before commit
+   834f82e2aa9a8ede94b17b656329f850c1471514 (3.10) do not have this
+   field on smaps.  */
+
+static void
+decode_vmflags (char *p, struct smaps_vmflags *v)
+{
+  char *saveptr = NULL;
+  const char *s;
+
+  v->initialized_p = 1;
+  p = skip_to_space (p);
+  p = skip_spaces (p);
+
+  for (s = strtok_r (p, " ", &saveptr);
+       s != NULL;
+       s = strtok_r (NULL, " ", &saveptr))
+    {
+      if (strcmp (s, "io") == 0)
+	v->io_page = 1;
+      else if (strcmp (s, "ht") == 0)
+	v->uses_huge_tlb = 1;
+      else if (strcmp (s, "dd") == 0)
+	v->exclude_coredump = 1;
+      else if (strcmp (s, "sh") == 0)
+	v->shared_mapping = 1;
+    }
+}
+
+/* Return 1 if the memory mapping is anonymous, 0 otherwise.
+
+   FILENAME is the name of the file present in the first line of the
+   memory mapping, in the "/proc/PID/smaps" output.  For example, if
+   the first line is:
+
+   7fd0ca877000-7fd0d0da0000 r--p 00000000 fd:02 2100770   /path/to/file
+
+   Then FILENAME will be "/path/to/file".  */
+
+static int
+mapping_is_anonymous_p (const char *filename)
+{
+  static regex_t dev_zero_regex, shmem_file_regex, file_deleted_regex;
+  static int init_regex_p = 0;
+
+  if (!init_regex_p)
+    {
+      struct cleanup *c = make_cleanup (null_cleanup, NULL);
+
+      /* Let's be pessimistic and assume there will be an error while
+	 compiling the regex'es.  */
+      init_regex_p = -1;
+
+      /* DEV_ZERO_REGEX matches "/dev/zero" filenames (with or
+	 without the "(deleted)" string in the end).  We know for
+	 sure, based on the Linux kernel code, that memory mappings
+	 whose associated filename is "/dev/zero" are guaranteed to be
+	 MAP_ANONYMOUS.  */
+      compile_rx_or_error (&dev_zero_regex, "^/dev/zero\\( (deleted)\\)\\?$",
+			   _("Could not compile regex to match /dev/zero "
+			     "filename"));
+      /* SHMEM_FILE_REGEX matches "/SYSV%08x" filenames (with or
+	 without the "(deleted)" string in the end).  These filenames
+	 refer to shared memory (shmem), and memory mappings
+	 associated with them are MAP_ANONYMOUS as well.  */
+      compile_rx_or_error (&shmem_file_regex,
+			   "^/\\?SYSV[0-9a-fA-F]\\{8\\}\\( (deleted)\\)\\?$",
+			   _("Could not compile regex to match shmem "
+			     "filenames"));
+      /* FILE_DELETED_REGEX is a heuristic we use to try to mimic the
+	 Linux kernel's 'n_link == 0' code, which is responsible to
+	 decide if it is dealing with a 'MAP_SHARED | MAP_ANONYMOUS'
+	 mapping.  In other words, if FILE_DELETED_REGEX matches, it
+	 does not necessarily mean that we are dealing with an
+	 anonymous shared mapping.  However, there is no easy way to
+	 detect this currently, so this is the best approximation we
+	 have.
+
+	 As a result, GDB will dump readonly pages of deleted
+	 executables when using the default value of coredump_filter
+	 (0x33), while the Linux kernel will not dump those pages.
+	 But we can live with that.  */
+      compile_rx_or_error (&file_deleted_regex, " (deleted)$",
+			   _("Could not compile regex to match "
+			     "'<file> (deleted)'"));
+      /* We will never release these regexes, so just discard the
+	 cleanups.  */
+      discard_cleanups (c);
+
+      /* If we reached this point, then everything succeeded.  */
+      init_regex_p = 1;
+    }
+
+  if (init_regex_p == -1)
+    {
+      const char deleted[] = " (deleted)";
+      size_t del_len = sizeof (deleted) - 1;
+      size_t filename_len = strlen (filename);
+
+      /* There was an error while compiling the regex'es above.  In
+	 order to try to give some reliable information to the caller,
+	 we just try to find the string " (deleted)" in the filename.
+	 If we managed to find it, then we assume the mapping is
+	 anonymous.  */
+      return (filename_len >= del_len
+	      && strcmp (filename + filename_len - del_len, deleted) == 0);
+    }
+
+  if (*filename == '\0'
+      || regexec (&dev_zero_regex, filename, 0, NULL, 0) == 0
+      || regexec (&shmem_file_regex, filename, 0, NULL, 0) == 0
+      || regexec (&file_deleted_regex, filename, 0, NULL, 0) == 0)
+    return 1;
+
+  return 0;
+}
+
+/* Return 0 if the memory mapping (which is related to FILTERFLAGS, V,
+   MAYBE_PRIVATE_P, and MAPPING_ANONYMOUS_P) should not be dumped, or
+   greater than 0 if it should.
+
+   In a nutshell, this is the logic that we follow in order to decide
+   if a mapping should be dumped or not.
+
+   - If the mapping is associated to a file whose name ends with
+     " (deleted)", or if the file is "/dev/zero", or if it is
+     "/SYSV%08x" (shared memory), or if there is no file associated
+     with it, or if the AnonHugePages: or the Anonymous: fields in the
+     /proc/PID/smaps have contents, then GDB considers this mapping to
+     be anonymous.  Otherwise, GDB considers this mapping to be a
+     file-backed mapping (because there will be a file associated with
+     it).
+ 
+     It is worth mentioning that, from all those checks described
+     above, the most fragile is the one to see if the file name ends
+     with " (deleted)".  This does not necessarily mean that the
+     mapping is anonymous, because the deleted file associated with
+     the mapping may have been a hard link to another file, for
+     example.  The Linux kernel checks to see if "i_nlink == 0", but
+     GDB cannot easily (and normally) do this check (iff running as
+     root, it could find the mapping in /proc/PID/map_files/ and
+     determine whether there still are other hard links to the
+     inode/file).  Therefore, we made a compromise here, and we assume
+     that if the file name ends with " (deleted)", then the mapping is
+     indeed anonymous.  FWIW, this is something the Linux kernel could
+     do better: expose this information in a more direct way.
+ 
+   - If we see the flag "sh" in the "VmFlags:" field (in
+     /proc/PID/smaps), then certainly the memory mapping is shared
+     (VM_SHARED).  If we have access to the VmFlags, and we don't see
+     the "sh" there, then certainly the mapping is private.  However,
+     Linux kernels before commit
+     834f82e2aa9a8ede94b17b656329f850c1471514 (3.10) do not have the
+     "VmFlags:" field; in that case, we use another heuristic: if we
+     see 'p' in the permission flags, then we assume that the mapping
+     is private, even though the presence of the 's' flag there would
+     mean VM_MAYSHARE, which means the mapping could still be private.
+     This should work OK enough, however.  */
+
+static int
+dump_mapping_p (enum filterflags filterflags, const struct smaps_vmflags *v,
+		int maybe_private_p, int mapping_anon_p, int mapping_file_p,
+		const char *filename)
+{
+  /* Initially, we trust in what we received from our caller.  This
+     value may not be very precise (i.e., it was probably gathered
+     from the permission line in the /proc/PID/smaps list, which
+     actually refers to VM_MAYSHARE, and not VM_SHARED), but it is
+     what we have until we take a look at the "VmFlags:" field
+     (assuming that the version of the Linux kernel being used
+     supports it, of course).  */
+  int private_p = maybe_private_p;
+
+  /* We always dump vDSO and vsyscall mappings, because it's likely that
+     there'll be no file to read the contents from at core load time.
+     The kernel does the same.  */
+  if (strcmp ("[vdso]", filename) == 0
+      || strcmp ("[vsyscall]", filename) == 0)
+    return 1;
+
+  if (v->initialized_p)
+    {
+      /* We never dump I/O mappings.  */
+      if (v->io_page)
+	return 0;
+
+      /* Check if we should exclude this mapping.  */
+      if (v->exclude_coredump)
+	return 0;
+
+      /* Update our notion of whether this mapping is shared or
+	 private based on a trustworthy value.  */
+      private_p = !v->shared_mapping;
+
+      /* HugeTLB checking.  */
+      if (v->uses_huge_tlb)
+	{
+	  if ((private_p && (filterflags & COREFILTER_HUGETLB_PRIVATE))
+	      || (!private_p && (filterflags & COREFILTER_HUGETLB_SHARED)))
+	    return 1;
+
+	  return 0;
+	}
+    }
+
+  if (private_p)
+    {
+      if (mapping_anon_p && mapping_file_p)
+	{
+	  /* This is a special situation.  It can happen when we see a
+	     mapping that is file-backed, but that contains anonymous
+	     pages.  */
+	  return ((filterflags & COREFILTER_ANON_PRIVATE) != 0
+		  || (filterflags & COREFILTER_MAPPED_PRIVATE) != 0);
+	}
+      else if (mapping_anon_p)
+	return (filterflags & COREFILTER_ANON_PRIVATE) != 0;
+      else
+	return (filterflags & COREFILTER_MAPPED_PRIVATE) != 0;
+    }
+  else
+    {
+      if (mapping_anon_p && mapping_file_p)
+	{
+	  /* This is a special situation.  It can happen when we see a
+	     mapping that is file-backed, but that contains anonymous
+	     pages.  */
+	  return ((filterflags & COREFILTER_ANON_SHARED) != 0
+		  || (filterflags & COREFILTER_MAPPED_SHARED) != 0);
+	}
+      else if (mapping_anon_p)
+	return (filterflags & COREFILTER_ANON_SHARED) != 0;
+      else
+	return (filterflags & COREFILTER_MAPPED_SHARED) != 0;
+    }
+}
+
+/* List memory regions in the inferior PID matched to FILTERFLAGS for
+   a corefile.  Call FUNC with FUNC_DATA for each such region.  Return
+   immediately with the value returned by FUNC if it is non-zero.
+   *MEMORY_TO_FREE_PTR should be registered to be freed automatically if
+   called FUNC throws an exception.  MEMORY_TO_FREE_PTR can be also
+   passed as NULL if it is not used.  Return -1 if error occurs, 0 if
+   all memory regions have been processed or return the value from FUNC
+   if FUNC returns non-zero.  */
+
+int
+linux_find_memory_regions_full (pid_t pid, enum filterflags filterflags,
+				linux_find_memory_region_ftype *func,
+				void *func_data)
+{
+  char mapsfilename[100];
+  char *data;
+
+  xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid);
+  data = target_fileio_read_stralloc (NULL, mapsfilename);
+  if (data == NULL)
+    {
+      /* Older Linux kernels did not support /proc/PID/smaps.  */
+      xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", pid);
+      data = target_fileio_read_stralloc (NULL, mapsfilename);
+    }
+
+  if (data != NULL)
+    {
+      struct cleanup *cleanup = make_cleanup (xfree, data);
+      char *line, *t;
+      int retval = 0;
+
+      line = strtok_r (data, "\n", &t);
+      while (line != NULL)
+	{
+	  ULONGEST addr, endaddr, offset, inode;
+	  const char *permissions, *device, *filename;
+	  struct smaps_vmflags v;
+	  size_t permissions_len, device_len;
+	  int read, write, exec, priv;
+	  int has_anonymous = 0;
+	  int should_dump_p = 0;
+	  int mapping_anon_p;
+	  int mapping_file_p;
+
+	  memset (&v, 0, sizeof (v));
+	  read_mapping (line, &addr, &endaddr, &permissions, &permissions_len,
+			&offset, &device, &device_len, &inode, &filename);
+	  mapping_anon_p = mapping_is_anonymous_p (filename);
+	  /* If the mapping is not anonymous, then we can consider it
+	     to be file-backed.  These two states (anonymous or
+	     file-backed) seem to be exclusive, but they can actually
+	     coexist.  For example, if a file-backed mapping has
+	     "Anonymous:" pages (see more below), then the Linux
+	     kernel will dump this mapping when the user specified
+	     that she only wants anonymous mappings in the corefile
+	     (*even* when she explicitly disabled the dumping of
+	     file-backed mappings).  */
+	  mapping_file_p = !mapping_anon_p;
+
+	  /* Decode permissions.  */
+	  read = (memchr (permissions, 'r', permissions_len) != 0);
+	  write = (memchr (permissions, 'w', permissions_len) != 0);
+	  exec = (memchr (permissions, 'x', permissions_len) != 0);
+	  /* 'private' here actually means VM_MAYSHARE, and not
+	     VM_SHARED.  In order to know if a mapping is really
+	     private or not, we must check the flag "sh" in the
+	     VmFlags field.  This is done by decode_vmflags.  However,
+	     if we are using a Linux kernel released before the commit
+	     834f82e2aa9a8ede94b17b656329f850c1471514 (3.10), we will
+	     not have the VmFlags there.  In this case, there is
+	     really no way to know if we are dealing with VM_SHARED,
+	     so we just assume that VM_MAYSHARE is enough.  */
+	  priv = memchr (permissions, 'p', permissions_len) != 0;
+
+	  /* Try to detect if region should be dumped by parsing smaps
+	     counters.  */
+	  for (line = strtok_r (NULL, "\n", &t);
+	       line != NULL && line[0] >= 'A' && line[0] <= 'Z';
+	       line = strtok_r (NULL, "\n", &t))
+	    {
+	      char keyword[64 + 1];
+
+	      if (sscanf (line, "%64s", keyword) != 1)
+		{
+		  warning (_("Error parsing {s,}maps file '%s'"), mapsfilename);
+		  break;
+		}
+
+	      if (strcmp (keyword, "Anonymous:") == 0)
+		{
+		  /* Older Linux kernels did not support the
+		     "Anonymous:" counter.  Check it here.  */
+		  has_anonymous = 1;
+		}
+	      else if (strcmp (keyword, "VmFlags:") == 0)
+		decode_vmflags (line, &v);
+
+	      if (strcmp (keyword, "AnonHugePages:") == 0
+		  || strcmp (keyword, "Anonymous:") == 0)
+		{
+		  unsigned long number;
+
+		  if (sscanf (line, "%*s%lu", &number) != 1)
+		    {
+		      warning (_("Error parsing {s,}maps file '%s' number"),
+			       mapsfilename);
+		      break;
+		    }
+		  if (number > 0)
+		    {
+		      /* Even if we are dealing with a file-backed
+			 mapping, if it contains anonymous pages we
+			 consider it to be *also* an anonymous
+			 mapping, because this is what the Linux
+			 kernel does:
+
+			 // Dump segments that have been written to.
+			 if (vma->anon_vma && FILTER(ANON_PRIVATE))
+			 	goto whole;
+
+			 Note that if the mapping is already marked as
+			 file-backed (i.e., mapping_file_p is
+			 non-zero), then this is a special case, and
+			 this mapping will be dumped either when the
+			 user wants to dump file-backed *or* anonymous
+			 mappings.  */
+		      mapping_anon_p = 1;
+		    }
+		}
+	    }
+
+	  if (has_anonymous)
+	    should_dump_p = dump_mapping_p (filterflags, &v, priv,
+					    mapping_anon_p, mapping_file_p,
+					    filename);
+	  else
+	    {
+	      /* Older Linux kernels did not support the "Anonymous:" counter.
+		 If it is missing, we can't be sure - dump all the pages.  */
+	      should_dump_p = 1;
+	    }
+
+	  /* Invoke the callback function to create the corefile segment.  */
+	  if (should_dump_p)
+	    retval = func (addr, endaddr - addr, offset, inode,
+			   read, write, exec,
+			   1, /* MODIFIED is true because we want to dump the
+				 mapping.  */
+			   filename, func_data);
+	  if (retval != 0)
+	    break;
+	}
+
+      do_cleanups (cleanup);
+      return retval;
+    }
+
+  return -1;
+}
diff --git a/gdb/nat/linux-maps.h b/gdb/nat/linux-maps.h
index 2cff321..7e10d65 100644
--- a/gdb/nat/linux-maps.h
+++ b/gdb/nat/linux-maps.h
@@ -19,4 +19,46 @@
 #ifndef NAT_LINUX_MAPS_H
 #define NAT_LINUX_MAPS_H
 
+extern void
+  read_mapping (const char *line,
+		ULONGEST *addr, ULONGEST *endaddr,
+		const char **permissions, size_t *permissions_len,
+		ULONGEST *offset,
+		const char **device, size_t *device_len,
+		ULONGEST *inode,
+		const char **filename);
+
+/* Callback function for linux_find_memory_regions_full.  If it returns
+   non-zero linux_find_memory_regions_full returns immediately with that
+   value.  */
+
+typedef int linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size,
+					    ULONGEST offset, ULONGEST inode,
+					    int read, int write,
+					    int exec, int modified,
+					    const char *filename,
+					    void *data);
+
+/* This enum represents the values that the user can choose when
+   informing the Linux kernel about which memory mappings will be
+   dumped in a corefile.  They are described in the file
+   Documentation/filesystems/proc.txt, inside the Linux kernel
+   tree.  */
+
+enum filterflags
+  {
+    COREFILTER_ANON_PRIVATE = 1 << 0,
+    COREFILTER_ANON_SHARED = 1 << 1,
+    COREFILTER_MAPPED_PRIVATE = 1 << 2,
+    COREFILTER_MAPPED_SHARED = 1 << 3,
+    COREFILTER_ELF_HEADERS = 1 << 4,
+    COREFILTER_HUGETLB_PRIVATE = 1 << 5,
+    COREFILTER_HUGETLB_SHARED = 1 << 6,
+  };
+
+extern int
+  linux_find_memory_regions_full (pid_t pid, enum filterflags filterflags,
+				  linux_find_memory_region_ftype *func,
+				  void *func_data);
+
 #endif /* NAT_LINUX_MAPS_H */
diff --git a/gdb/target.c b/gdb/target.c
index 2dd3116..d25cfd4 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -43,6 +43,7 @@
 #include "agent.h"
 #include "auxv.h"
 #include "target-debug.h"
+#include "target/target-utils.h"
 
 static void target_info (char *, int);
 
@@ -2973,9 +2974,6 @@ target_fileio_close_cleanup (void *opaque)
   target_fileio_close (fd, &target_errno);
 }
 
-typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len,
-				      ULONGEST offset, int *target_errno);
-
 /* Helper for target_fileio_read_alloc_1 to make it interruptible.  */
 
 static int
@@ -2996,57 +2994,6 @@ target_fileio_read_alloc_1_pread (int handle, gdb_byte *read_buf, int len,
    more information.  */
 
 static LONGEST
-read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func,
-	    int padding)
-{
-  size_t buf_alloc, buf_pos;
-  gdb_byte *buf;
-  LONGEST n;
-  int target_errno;
-
-  /* Start by reading up to 4K at a time.  The target will throttle
-     this number down if necessary.  */
-  buf_alloc = 4096;
-  buf = xmalloc (buf_alloc);
-  buf_pos = 0;
-  while (1)
-    {
-      n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding,
-		      buf_pos, &target_errno);
-      if (n <= 0)
-	{
-	  if (n < 0 || (n == 0 && buf_pos == 0))
-	    xfree (buf);
-	  else
-	    *buf_p = buf;
-	  if (n < 0)
-	    {
-	      /* An error occurred.  */
-	      return -1;
-	    }
-	  else
-	    {
-	      /* Read all there was.  */
-	      return buf_pos;
-	    }
-	}
-
-      buf_pos += n;
-
-      /* If the buffer is filling up, expand it.  */
-      if (buf_alloc < buf_pos * 2)
-	{
-	  buf_alloc *= 2;
-	  buf = xrealloc (buf, buf_alloc);
-	}
-    }
-}
-
-typedef LONGEST (read_stralloc_func_ftype) (struct inferior *inf,
-					    const char *filename,
-					    gdb_byte **buf_p, int padding);
-
-static LONGEST
 target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
 			    gdb_byte **buf_p, int padding)
 {
@@ -3073,41 +3020,7 @@ target_fileio_read_alloc (struct inferior *inf, const char *filename,
   return target_fileio_read_alloc_1 (inf, filename, buf_p, 0);
 }
 
-/* Helper for target_fileio_read_stralloc.  */
-
-static char *
-read_stralloc (struct inferior *inf, const char *filename,
-	       read_stralloc_func_ftype *func)
-{
-  gdb_byte *buffer;
-  char *bufstr;
-  LONGEST i, transferred;
-
-  transferred = func (inf, filename, &buffer, 1);
-  bufstr = (char *) buffer;
-
-  if (transferred < 0)
-    return NULL;
-
-  if (transferred == 0)
-    return xstrdup ("");
-
-  bufstr[transferred] = 0;
-
-  /* Check for embedded NUL bytes; but allow trailing NULs.  */
-  for (i = strlen (bufstr); i < transferred; i++)
-    if (bufstr[i] != 0)
-      {
-	warning (_("target file %s "
-		   "contained unexpected null characters"),
-		 filename);
-	break;
-      }
-
-  return bufstr;
-}
-
-/* See target.h.  */
+/* See target/target.h.  */
 
 char *
 target_fileio_read_stralloc (struct inferior *inf, const char *filename)
diff --git a/gdb/target.h b/gdb/target.h
index 32234f7..ae93a37 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2033,16 +2033,6 @@ extern LONGEST target_fileio_read_alloc (struct inferior *inf,
 					 const char *filename,
 					 gdb_byte **buf_p);
 
-/* Read target file FILENAME, in the filesystem as seen by INF.  If
-   INF is NULL, use the filesystem seen by the debugger (GDB or, for
-   remote targets, the remote stub).  The result is NUL-terminated and
-   returned as a string, allocated using xmalloc.  If an error occurs
-   or the transfer is unsupported, NULL is returned.  Empty objects
-   are returned as allocated but empty strings.  A warning is issued
-   if the result contains any embedded NUL bytes.  */
-extern char *target_fileio_read_stralloc (struct inferior *inf,
-					  const char *filename);
-
 
 /* Tracepoint-related operations.  */
 
diff --git a/gdb/target/target-utils.c b/gdb/target/target-utils.c
index 4e8fae7..cdfa6e6 100644
--- a/gdb/target/target-utils.c
+++ b/gdb/target/target-utils.c
@@ -19,3 +19,82 @@
 
 #include "common-defs.h"
 #include "target/target-utils.h"
+
+LONGEST
+read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func,
+	    int padding)
+{
+  size_t buf_alloc, buf_pos;
+  gdb_byte *buf;
+  LONGEST n;
+  int target_errno;
+
+  /* Start by reading up to 4K at a time.  The target will throttle
+     this number down if necessary.  */
+  buf_alloc = 4096;
+  buf = xmalloc (buf_alloc);
+  buf_pos = 0;
+  while (1)
+    {
+      n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding,
+		      buf_pos, &target_errno);
+      if (n <= 0)
+	{
+	  if (n < 0 || (n == 0 && buf_pos == 0))
+	    xfree (buf);
+	  else
+	    *buf_p = buf;
+	  if (n < 0)
+	    {
+	      /* An error occurred.  */
+	      return -1;
+	    }
+	  else
+	    {
+	      /* Read all there was.  */
+	      return buf_pos;
+	    }
+	}
+
+      buf_pos += n;
+
+      /* If the buffer is filling up, expand it.  */
+      if (buf_alloc < buf_pos * 2)
+	{
+	  buf_alloc *= 2;
+	  buf = xrealloc (buf, buf_alloc);
+	}
+    }
+}
+
+char *
+read_stralloc (struct inferior *inf, const char *filename,
+	       read_stralloc_func_ftype *func)
+{
+  gdb_byte *buffer;
+  char *bufstr;
+  LONGEST i, transferred;
+
+  transferred = func (inf, filename, &buffer, 1);
+  bufstr = (char *) buffer;
+
+  if (transferred < 0)
+    return NULL;
+
+  if (transferred == 0)
+    return xstrdup ("");
+
+  bufstr[transferred] = 0;
+
+  /* Check for embedded NUL bytes; but allow trailing NULs.  */
+  for (i = strlen (bufstr); i < transferred; i++)
+    if (bufstr[i] != 0)
+      {
+	warning (_("target file %s "
+		   "contained unexpected null characters"),
+		 filename);
+	break;
+      }
+
+  return bufstr;
+}
diff --git a/gdb/target/target-utils.h b/gdb/target/target-utils.h
index 443ffc3..e8bf52a 100644
--- a/gdb/target/target-utils.h
+++ b/gdb/target/target-utils.h
@@ -20,4 +20,16 @@
 #ifndef TARGET_TARGET_UTILS_H
 #define TARGET_TARGET_UTILS_H
 
+typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len,
+				      ULONGEST offset, int *target_errno);
+extern LONGEST read_alloc (gdb_byte **buf_p, int handle,
+			   read_alloc_pread_ftype *pread_func, int padding);
+
+struct inferior;
+typedef LONGEST (read_stralloc_func_ftype) (struct inferior *inf,
+					    const char *filename,
+					    gdb_byte **buf_p, int padding);
+extern char *read_stralloc (struct inferior *inf, const char *filename,
+			    read_stralloc_func_ftype *func);
+
 #endif /* TARGET_TARGET_UTILS_H */
diff --git a/gdb/target/target.h b/gdb/target/target.h
index 05ac758..f525bbd 100644
--- a/gdb/target/target.h
+++ b/gdb/target/target.h
@@ -72,4 +72,15 @@ extern void target_stop_and_wait (ptid_t ptid);
 
 extern void target_continue_no_signal (ptid_t ptid);
 
+/* Read target file FILENAME, in the filesystem as seen by INF.  If
+   INF is NULL, use the filesystem seen by the debugger (GDB or, for
+   remote targets, the remote stub).  The result is NUL-terminated and
+   returned as a string, allocated using xmalloc.  If an error occurs
+   or the transfer is unsupported, NULL is returned.  Empty objects
+   are returned as allocated but empty strings.  A warning is issued
+   if the result contains any embedded NUL bytes.  */
+struct inferior;
+extern char *target_fileio_read_stralloc (struct inferior *inf,
+					  const char *filename);
+
 #endif /* TARGET_COMMON_H */

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (4 preceding siblings ...)
  2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
@ 2015-06-14 19:26 ` Jan Kratochvil
  2015-06-14 19:26 ` [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

prepare code for move into gdb/common/.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00371.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Prepare linux_find_memory_regions_full & co. for move.
	* linux-tdep.c (linux_find_memory_region_ftype): Comment.
	(linux_find_memory_regions_full): Change signature and prepare
	for moving to linux-maps.
	(linux_find_memory_regions_data): Rename field 'obfd' to 'data'.
	(linux_find_memory_regions_thunk): New.
	(linux_find_memory_regions_thunk): Use 'data' field instead of 'obfd'.
	(linux_find_memory_regions_gdb): New.
	(linux_find_memory_regions): Rename argument 'obfd' to 'func_data'.
	(linux_make_mappings_corefile_notes): Use
	linux_find_memory_regions_gdb.
	* target.c (read_alloc_pread_ftype): New typedef.
	(target_fileio_read_alloc_1_pread): New function.
	(read_alloc): Refactor from target_fileio_read_alloc_1.
	(read_stralloc_func_ftype): New typedef.
	(target_fileio_read_alloc_1): New implementation. Use read_alloc.
	(read_stralloc): Refactored from target_fileio_read_stralloc.
	(target_fileio_read_stralloc): New implementation, use read_stralloc.
---
 gdb/linux-tdep.c |  121 +++++++++++++++++++++++++++++++++---------------------
 gdb/target.c     |   96 +++++++++++++++++++++++++++++--------------
 2 files changed, 138 insertions(+), 79 deletions(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index c81f71b..fb59305 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1098,6 +1098,10 @@ linux_core_info_proc (struct gdbarch *gdbarch, const char *args,
     error (_("unable to handle request"));
 }
 
+/* Callback function for linux_find_memory_regions_full.  If it returns
+   non-zero linux_find_memory_regions_full returns immediately with that
+   value.  */
+
 typedef int linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size,
 					    ULONGEST offset, ULONGEST inode,
 					    int read, int write,
@@ -1105,43 +1109,22 @@ typedef int linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size,
 					    const char *filename,
 					    void *data);
 
-/* List memory regions in the inferior for a corefile.  */
+/* List memory regions in the inferior PID matched to FILTERFLAGS for
+   a corefile.  Call FUNC with FUNC_DATA for each such region.  Return
+   immediately with the value returned by FUNC if it is non-zero.
+   *MEMORY_TO_FREE_PTR should be registered to be freed automatically if
+   called FUNC throws an exception.  MEMORY_TO_FREE_PTR can be also
+   passed as NULL if it is not used.  Return -1 if error occurs, 0 if
+   all memory regions have been processed or return the value from FUNC
+   if FUNC returns non-zero.  */
 
 static int
-linux_find_memory_regions_full (struct gdbarch *gdbarch,
+linux_find_memory_regions_full (pid_t pid, enum filterflags filterflags,
 				linux_find_memory_region_ftype *func,
-				void *obfd)
+				void *func_data)
 {
   char mapsfilename[100];
-  char coredumpfilter_name[100];
-  char *data, *coredumpfilterdata;
-  pid_t pid;
-  /* Default dump behavior of coredump_filter (0x33), according to
-     Documentation/filesystems/proc.txt from the Linux kernel
-     tree.  */
-  enum filterflags filterflags = (COREFILTER_ANON_PRIVATE
-				  | COREFILTER_ANON_SHARED
-				  | COREFILTER_ELF_HEADERS
-				  | COREFILTER_HUGETLB_PRIVATE);
-
-  /* We need to know the real target PID to access /proc.  */
-  if (current_inferior ()->fake_pid_p)
-    return 1;
-
-  pid = current_inferior ()->pid;
-
-  if (use_coredump_filter)
-    {
-      xsnprintf (coredumpfilter_name, sizeof (coredumpfilter_name),
-		 "/proc/%d/coredump_filter", pid);
-      coredumpfilterdata = target_fileio_read_stralloc (NULL,
-							coredumpfilter_name);
-      if (coredumpfilterdata != NULL)
-	{
-	  sscanf (coredumpfilterdata, "%x", &filterflags);
-	  xfree (coredumpfilterdata);
-	}
-    }
+  char *data;
 
   xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid);
   data = target_fileio_read_stralloc (NULL, mapsfilename);
@@ -1156,6 +1139,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
     {
       struct cleanup *cleanup = make_cleanup (xfree, data);
       char *line, *t;
+      int retval = 0;
 
       line = strtok_r (data, "\n", &t);
       while (line != NULL)
@@ -1270,17 +1254,20 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
 
 	  /* Invoke the callback function to create the corefile segment.  */
 	  if (should_dump_p)
-	    func (addr, endaddr - addr, offset, inode,
-		  read, write, exec, 1, /* MODIFIED is true because we
-					   want to dump the mapping.  */
-		  filename, obfd);
+	    retval = func (addr, endaddr - addr, offset, inode,
+			   read, write, exec,
+			   1, /* MODIFIED is true because we want to dump the
+				 mapping.  */
+			   filename, func_data);
+	  if (retval != 0)
+	    break;
 	}
 
       do_cleanups (cleanup);
-      return 0;
+      return retval;
     }
 
-  return 1;
+  return -1;
 }
 
 /* A structure for passing information through
@@ -1294,7 +1281,7 @@ struct linux_find_memory_regions_data
 
   /* The original datum.  */
 
-  void *obfd;
+  void *data;
 };
 
 /* A callback for linux_find_memory_regions that converts between the
@@ -1308,7 +1295,48 @@ linux_find_memory_regions_thunk (ULONGEST vaddr, ULONGEST size,
 {
   struct linux_find_memory_regions_data *data = arg;
 
-  return data->func (vaddr, size, read, write, exec, modified, data->obfd);
+  return data->func (vaddr, size, read, write, exec, modified, data->data);
+}
+
+/* Wrapper of linux_find_memory_regions_full handling FAKE_PID_P in GDB.  */
+
+static int
+linux_find_memory_regions_gdb (struct gdbarch *gdbarch,
+			       linux_find_memory_region_ftype *func,
+			       void *func_data)
+{
+  pid_t pid;
+  /* Default dump behavior of coredump_filter (0x33), according to
+     Documentation/filesystems/proc.txt from the Linux kernel
+     tree.  */
+  enum filterflags filterflags = (COREFILTER_ANON_PRIVATE
+				  | COREFILTER_ANON_SHARED
+				  | COREFILTER_ELF_HEADERS
+				  | COREFILTER_HUGETLB_PRIVATE);
+
+  /* We need to know the real target PID so
+     linux_find_memory_regions_full can access /proc.  */
+  if (current_inferior ()->fake_pid_p)
+    return -1;
+
+  pid = current_inferior ()->pid;
+
+  if (use_coredump_filter)
+    {
+      char coredumpfilter_name[100], *coredumpfilterdata;
+
+      xsnprintf (coredumpfilter_name, sizeof (coredumpfilter_name),
+		 "/proc/%d/coredump_filter", pid);
+      coredumpfilterdata = target_fileio_read_stralloc (NULL,
+							coredumpfilter_name);
+      if (coredumpfilterdata != NULL)
+	{
+	  sscanf (coredumpfilterdata, "%x", &filterflags);
+	  xfree (coredumpfilterdata);
+	}
+    }
+
+  return linux_find_memory_regions_full (pid, filterflags, func, func_data);
 }
 
 /* A variant of linux_find_memory_regions_full that is suitable as the
@@ -1316,16 +1344,15 @@ linux_find_memory_regions_thunk (ULONGEST vaddr, ULONGEST size,
 
 static int
 linux_find_memory_regions (struct gdbarch *gdbarch,
-			   find_memory_region_ftype func, void *obfd)
+			   find_memory_region_ftype func, void *func_data)
 {
   struct linux_find_memory_regions_data data;
 
   data.func = func;
-  data.obfd = obfd;
+  data.data = func_data;
 
-  return linux_find_memory_regions_full (gdbarch,
-					 linux_find_memory_regions_thunk,
-					 &data);
+  return linux_find_memory_regions_gdb (gdbarch,
+					linux_find_memory_regions_thunk, &data);
 }
 
 /* Determine which signal stopped execution.  */
@@ -1507,8 +1534,8 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
   pack_long (buf, long_type, 1);
   obstack_grow (&data_obstack, buf, TYPE_LENGTH (long_type));
 
-  linux_find_memory_regions_full (gdbarch, linux_make_mappings_callback,
-				  &mapping_data);
+  linux_find_memory_regions_gdb (gdbarch, linux_make_mappings_callback,
+				 &mapping_data);
 
   if (mapping_data.file_count != 0)
     {
diff --git a/gdb/target.c b/gdb/target.c
index 4e2d005..2dd3116 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2973,6 +2973,20 @@ target_fileio_close_cleanup (void *opaque)
   target_fileio_close (fd, &target_errno);
 }
 
+typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len,
+				      ULONGEST offset, int *target_errno);
+
+/* Helper for target_fileio_read_alloc_1 to make it interruptible.  */
+
+static int
+target_fileio_read_alloc_1_pread (int handle, gdb_byte *read_buf, int len,
+				  ULONGEST offset, int *target_errno)
+{
+  QUIT;
+
+  return target_fileio_pread (handle, read_buf, len, offset, target_errno);
+}
+
 /* Read target file FILENAME, in the filesystem as seen by INF.  If
    INF is NULL, use the filesystem seen by the debugger (GDB or, for
    remote targets, the remote stub).  Store the result in *BUF_P and
@@ -2982,23 +2996,14 @@ target_fileio_close_cleanup (void *opaque)
    more information.  */
 
 static LONGEST
-target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
-			    gdb_byte **buf_p, int padding)
+read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func,
+	    int padding)
 {
-  struct cleanup *close_cleanup;
   size_t buf_alloc, buf_pos;
   gdb_byte *buf;
   LONGEST n;
-  int fd;
   int target_errno;
 
-  fd = target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700,
-			   &target_errno);
-  if (fd == -1)
-    return -1;
-
-  close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd);
-
   /* Start by reading up to 4K at a time.  The target will throttle
      this number down if necessary.  */
   buf_alloc = 4096;
@@ -3006,25 +3011,24 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
   buf_pos = 0;
   while (1)
     {
-      n = target_fileio_pread (fd, &buf[buf_pos],
-			       buf_alloc - buf_pos - padding, buf_pos,
-			       &target_errno);
-      if (n < 0)
+      n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding,
+		      buf_pos, &target_errno);
+      if (n <= 0)
 	{
-	  /* An error occurred.  */
-	  do_cleanups (close_cleanup);
-	  xfree (buf);
-	  return -1;
-	}
-      else if (n == 0)
-	{
-	  /* Read all there was.  */
-	  do_cleanups (close_cleanup);
-	  if (buf_pos == 0)
+	  if (n < 0 || (n == 0 && buf_pos == 0))
 	    xfree (buf);
 	  else
 	    *buf_p = buf;
-	  return buf_pos;
+	  if (n < 0)
+	    {
+	      /* An error occurred.  */
+	      return -1;
+	    }
+	  else
+	    {
+	      /* Read all there was.  */
+	      return buf_pos;
+	    }
 	}
 
       buf_pos += n;
@@ -3035,11 +3039,31 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
 	  buf_alloc *= 2;
 	  buf = xrealloc (buf, buf_alloc);
 	}
-
-      QUIT;
     }
 }
 
+typedef LONGEST (read_stralloc_func_ftype) (struct inferior *inf,
+					    const char *filename,
+					    gdb_byte **buf_p, int padding);
+
+static LONGEST
+target_fileio_read_alloc_1 (struct inferior *inf, const char *filename,
+			    gdb_byte **buf_p, int padding)
+{
+  struct cleanup *close_cleanup;
+  int fd, target_errno;
+  LONGEST retval;
+
+  fd = target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700, &target_errno);
+  if (fd == -1)
+    return -1;
+
+  close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd);
+  retval = read_alloc (buf_p, fd, target_fileio_read_alloc_1_pread, padding);
+  do_cleanups (close_cleanup);
+  return retval;
+}
+
 /* See target.h.  */
 
 LONGEST
@@ -3049,16 +3073,17 @@ target_fileio_read_alloc (struct inferior *inf, const char *filename,
   return target_fileio_read_alloc_1 (inf, filename, buf_p, 0);
 }
 
-/* See target.h.  */
+/* Helper for target_fileio_read_stralloc.  */
 
-char *
-target_fileio_read_stralloc (struct inferior *inf, const char *filename)
+static char *
+read_stralloc (struct inferior *inf, const char *filename,
+	       read_stralloc_func_ftype *func)
 {
   gdb_byte *buffer;
   char *bufstr;
   LONGEST i, transferred;
 
-  transferred = target_fileio_read_alloc_1 (inf, filename, &buffer, 1);
+  transferred = func (inf, filename, &buffer, 1);
   bufstr = (char *) buffer;
 
   if (transferred < 0)
@@ -3082,6 +3107,13 @@ target_fileio_read_stralloc (struct inferior *inf, const char *filename)
   return bufstr;
 }
 
+/* See target.h.  */
+
+char *
+target_fileio_read_stralloc (struct inferior *inf, const char *filename)
+{
+  return read_stralloc (inf, filename, target_fileio_read_alloc_1);
+}
 
 static int
 default_region_ok_for_hw_watchpoint (struct target_ops *self,

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 09/10] Validate symbol file using build-id
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (6 preceding siblings ...)
  2015-06-14 19:26 ` [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
@ 2015-06-14 19:27 ` Jan Kratochvil
  2015-06-21 10:16   ` [PATCH v8 " Jan Kratochvil
  2015-06-14 19:27 ` [PATCH v7 10/10] Tests for validate " Jan Kratochvil
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

consumer part of the "build-id" attribute.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00424.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Validate symbol file using build-id.
	* NEWS (Changes since GDB 7.9): Add 'set solib-build-id-force'
	and 'show solib-build-id-force'.  Add build-id attribute.
	* solib-darwin.c (_initialize_darwin_solib): Assign validate value.
	* solib-dsbt.c (_initialize_dsbt_solib): Ditto.
	* solib-frv.c (_initialize_frv_solib): Ditto.
	* solib-spu.c (set_spu_solib_ops): Ditto.
	* solib-svr4.c: Include rsp-low.h.
	(NOTE_GNU_BUILD_ID_NAME): New define.
	(svr4_validate): New function.
	(svr4_copy_library_list): Duplicate field build_id.
	(library_list_start_library): Parse 'build-id' attribute.
	(svr4_library_attributes): Add 'build-id' attribute.
	(_initialize_svr4_solib): Assign validate value.
	* solib-target.c (solib.h): Include.
	(_initialize_solib_target): Assign validate value.
	* solib.c (solib_build_id_force, show_solib_build_id_force): New.
	(solib_map_sections): Use ops->validate.
	(clear_so): Free build_id.
	(default_solib_validate): New function.
	(_initialize_solib): Add "solib-build-id-force".
	* solib.h (default_solib_validate): New declaration.
	* solist.h (struct so_list): New fields 'build_idsz' and 'build_id'.
	(target_so_ops): New field 'validate'.

gdb/doc/ChangeLog
2014-03-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Files): Add 'set solib-build-id-force'
	and 'show solib-build-id-force'.
---
 gdb/NEWS            |   12 +++++++
 gdb/doc/gdb.texinfo |   38 +++++++++++++++++++++
 gdb/solib-darwin.c  |    1 +
 gdb/solib-dsbt.c    |    1 +
 gdb/solib-frv.c     |    1 +
 gdb/solib-spu.c     |    1 +
 gdb/solib-svr4.c    |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/solib-target.c  |    2 +
 gdb/solib.c         |   62 ++++++++++++++++++++++++++++++++++-
 gdb/solib.h         |    4 ++
 gdb/solist.h        |   21 ++++++++++++
 11 files changed, 233 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 85688c7..8f35dca 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -151,6 +151,12 @@ set debug linux-namespaces
 show debug linux-namespaces
   Control display of debugging info regarding Linux namespaces.
 
+set solib-build-id-force (on|off)
+show solib-build-id-force
+  Inferior shared library and symbol file may contain unique build-id.
+  If both build-ids are present but they do not match then this setting
+  enables (on) or disables (off) loading of such symbol file.
+
 * The command 'thread apply all' can now support new option '-ascending'
   to call its specified command for all threads in ascending order.
 
@@ -225,6 +231,12 @@ fork-events and vfork-events features in qSupported
 * GDB now supports access to vector registers on S/390 GNU/Linux
   targets.
 
+* New features in the GDB remote stub, GDBserver
+
+  ** library-list-svr4 contains also optional attribute 'build-id' for
+     each library.  GDB does not load library with build-id that
+     does not match such attribute.
+
 * Removed command line options
 
 -xdb  HP-UX XDB compatibility mode.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 10bc6e2..061abef 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17900,6 +17900,44 @@ libraries that were loaded by explicit user requests are not
 discarded.
 @end table
 
+@table @code
+@kindex set solib-build-id-force
+@cindex override @value{GDBN} build-id check
+@item set solib-build-id-force @var{mode}
+Setting to override @value{GDBN} build-id check.
+
+Inferior shared libraries and symbol files may contain unique build-id.
+By default @value{GDBN} will ignore symbol files with non-matching build-id
+while printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) and will be
+  ignored; or use 'set solib-build-id-force'.
+@end smallexample
+
+Turning on this setting would load such symbol file while still printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) but it is
+  being loaded due to 'set solib-build-id-force'.
+@end smallexample
+
+If remote build-id is present but it does not match local build-id (or local
+build-id is not present) then this setting enables (@var{mode} is @code{on}) or
+disables (@var{mode} is @code{off}) loading of such symbol file.  On systems
+where build-id is not present in the remote system this setting has no effect.
+The default value is @code{off}.
+
+Loading non-matching symbol file may confuse debugging including breakage
+of backtrace output.
+
+@kindex show solib-build-id-force
+@item show solib-build-id-force
+Display the current mode of build-id check override.
+@end table
+
 Sometimes you may wish that @value{GDBN} stops and gives you control
 when any of shared library events happen.  The best way to do this is
 to use @code{catch load} and @code{catch unload} (@pxref{Set
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index f96841f..9309c35 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -634,4 +634,5 @@ _initialize_darwin_solib (void)
   darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
   darwin_so_ops.lookup_lib_global_symbol = darwin_lookup_lib_symbol;
   darwin_so_ops.bfd_open = darwin_bfd_open;
+  darwin_so_ops.validate = default_solib_validate;
 }
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 7da5833..9fe6533 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -1080,6 +1080,7 @@ _initialize_dsbt_solib (void)
   dsbt_so_ops.open_symbol_file_object = open_symbol_file_object;
   dsbt_so_ops.in_dynsym_resolve_code = dsbt_in_dynsym_resolve_code;
   dsbt_so_ops.bfd_open = solib_bfd_open;
+  dsbt_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-dsbt", class_maintenance,
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index f7ef38b..b768146 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -1183,6 +1183,7 @@ _initialize_frv_solib (void)
   frv_so_ops.open_symbol_file_object = open_symbol_file_object;
   frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
   frv_so_ops.bfd_open = solib_bfd_open;
+  frv_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index 44fbf91..d162884 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -519,6 +519,7 @@ set_spu_solib_ops (struct gdbarch *gdbarch)
       spu_so_ops.current_sos = spu_current_sos;
       spu_so_ops.bfd_open = spu_bfd_open;
       spu_so_ops.lookup_lib_global_symbol = spu_lookup_lib_symbol;
+      spu_so_ops.validate = default_solib_validate;
     }
 
   set_solib_ops (gdbarch, &spu_so_ops);
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 909dfb7..881b8f3 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -45,6 +45,9 @@
 #include "auxv.h"
 #include "gdb_bfd.h"
 #include "probe.h"
+#include "rsp-low.h"
+
+#define NOTE_GNU_BUILD_ID_NAME  ".note.gnu.build-id"
 
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static int svr4_have_link_map_offsets (void);
@@ -970,6 +973,64 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
   return (name_lm >= vaddr && name_lm < vaddr + size);
 }
 
+/* Validate SO by comparing build-id from the associated bfd and
+   corresponding build-id from target memory.  */
+
+static char *
+svr4_validate (const struct so_list *const so)
+{
+  bfd_byte *local_id;
+  size_t local_idsz;
+
+  gdb_assert (so != NULL);
+
+  /* Target doesn't support reporting the build ID or the remote shared library
+     does not have build ID.  */
+  if (so->build_id == NULL)
+    return NULL;
+
+  /* Build ID may be present in the local file, just GDB is unable to retrieve
+     it.  As it has been reported by gdbserver it is not FSF gdbserver.  */
+  if (so->abfd == NULL
+      || !bfd_check_format (so->abfd, bfd_object)
+      || bfd_get_flavour (so->abfd) != bfd_target_elf_flavour)
+    return NULL;
+
+  /* GDB has verified the local file really does not contain the build ID.  */
+  if (elf_tdata (so->abfd)->build_id == NULL)
+    {
+      char *remote_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+
+      return xstrprintf (_("remote build ID is %s "
+			   "but local file does not have build ID"),
+			 remote_hex);
+    }
+
+  local_id = elf_tdata (so->abfd)->build_id->data;
+  local_idsz = elf_tdata (so->abfd)->build_id->size;
+
+  if (so->build_idsz != local_idsz
+      || memcmp (so->build_id, local_id, so->build_idsz) != 0)
+    {
+      char *remote_hex, *local_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+      local_hex = alloca (local_idsz * 2 + 1);
+      bin2hex (local_id, local_hex, local_idsz);
+
+      return xstrprintf (_("remote build ID %s "
+			   "does not match local build ID %s"),
+			 remote_hex, local_hex);
+    }
+
+  /* Both build IDs are present and they match.  */
+  return NULL;
+}
+
 /* Implement the "open_symbol_file_object" target_so_ops method.
 
    If no open symbol file, attempt to locate and open the main symbol
@@ -1108,6 +1169,12 @@ svr4_copy_library_list (struct so_list *src)
       newobj->lm_info = xmalloc (sizeof (struct lm_info));
       memcpy (newobj->lm_info, src->lm_info, sizeof (struct lm_info));
 
+      if (newobj->build_id != NULL)
+	{
+	  newobj->build_id = xmalloc (src->build_idsz);
+	  memcpy (newobj->build_id, src->build_id, src->build_idsz);
+	}
+
       newobj->next = NULL;
       *link = newobj;
       link = &newobj->next;
@@ -1135,6 +1202,9 @@ library_list_start_library (struct gdb_xml_parser *parser,
   ULONGEST *lmp = xml_find_attribute (attributes, "lm")->value;
   ULONGEST *l_addrp = xml_find_attribute (attributes, "l_addr")->value;
   ULONGEST *l_ldp = xml_find_attribute (attributes, "l_ld")->value;
+  const struct gdb_xml_value *const att_build_id
+    = xml_find_attribute (attributes, "build-id");
+  const char *const hex_build_id = att_build_id ? att_build_id->value : NULL;
   struct so_list *new_elem;
 
   new_elem = XCNEW (struct so_list);
@@ -1146,6 +1216,25 @@ library_list_start_library (struct gdb_xml_parser *parser,
   strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
   new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
   strcpy (new_elem->so_original_name, new_elem->so_name);
+  if (hex_build_id != NULL)
+    {
+      const size_t hex_build_id_len = strlen (hex_build_id);
+
+      if (hex_build_id_len > 0 && (hex_build_id_len & 1U) == 0)
+	{
+	  const size_t build_idsz = hex_build_id_len / 2;
+
+	  new_elem->build_id = xmalloc (build_idsz);
+	  new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id,
+					  build_idsz);
+	  if (new_elem->build_idsz != build_idsz)
+	    {
+	      xfree (new_elem->build_id);
+	      new_elem->build_id = NULL;
+	      new_elem->build_idsz = 0;
+	    }
+	}
+    }
 
   *list->tailp = new_elem;
   list->tailp = &new_elem->next;
@@ -1180,6 +1269,7 @@ static const struct gdb_xml_attribute svr4_library_attributes[] =
   { "lm", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_addr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_ld", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
+  { "build-id", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -3258,4 +3348,5 @@ _initialize_svr4_solib (void)
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
   svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
   svr4_so_ops.handle_event = svr4_handle_solib_event;
+  svr4_so_ops.validate = svr4_validate;
 }
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index f14363a..13cbd26 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "vec.h"
 #include "solib-target.h"
+#include "solib.h"
 
 /* Private data for each loaded library.  */
 struct lm_info
@@ -506,6 +507,7 @@ _initialize_solib_target (void)
   solib_target_so_ops.in_dynsym_resolve_code
     = solib_target_in_dynsym_resolve_code;
   solib_target_so_ops.bfd_open = solib_bfd_open;
+  solib_target_so_ops.validate = default_solib_validate;
 
   /* Set current_target_so_ops to solib_target_so_ops if not already
      set.  */
diff --git a/gdb/solib.c b/gdb/solib.c
index 0010c2f..4bd47d0 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -523,6 +523,20 @@ solib_bfd_open (char *pathname)
   return abfd;
 }
 
+/* Boolean for command 'set solib-build-id-force'.  */
+static int solib_build_id_force = 0;
+
+/* Implement 'show solib-build-id-force'.  */
+
+static void
+show_solib_build_id_force (struct ui_file *file, int from_tty,
+			   struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Loading of shared libraries "
+			    "with non-matching build-id is %s.\n"),
+		    value);
+}
+
 /* Given a pointer to one of the shared objects in our list of mapped
    objects, use the recorded name to open a bfd descriptor for the
    object, build a section table, relocate all the section addresses
@@ -539,7 +553,7 @@ static int
 solib_map_sections (struct so_list *so)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-  char *filename;
+  char *filename, *validate_error;
   struct target_section *p;
   struct cleanup *old_chain;
   bfd *abfd;
@@ -555,6 +569,27 @@ solib_map_sections (struct so_list *so)
   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
   so->abfd = abfd;
 
+  gdb_assert (ops->validate != NULL);
+
+  validate_error = ops->validate (so);
+  if (validate_error != NULL)
+    {
+      if (!solib_build_id_force)
+	{
+	  warning (_("Shared object \"%s\" could not be validated (%s) and "
+	             "will be ignored; or use 'set solib-build-id-force'."),
+		   so->so_name, validate_error);
+	  xfree (validate_error);
+	  gdb_bfd_unref (so->abfd);
+	  so->abfd = NULL;
+	  return 0;
+	}
+      warning (_("Shared object \"%s\" could not be validated (%s) "
+		 "but it is being loaded due to 'set solib-build-id-force'."),
+	       so->so_name, validate_error);
+      xfree (validate_error);
+    }
+
   /* Copy the full path name into so_name, allowing symbol_file_add
      to find it later.  This also affects the =library-loaded GDB/MI
      event, and in particular the part of that notification providing
@@ -631,6 +666,9 @@ clear_so (struct so_list *so)
      of the symbol file.  */
   strcpy (so->so_name, so->so_original_name);
 
+  xfree (so->build_id);
+  so->build_id = NULL;
+
   /* Do the same for target-specific data.  */
   if (ops->clear_so != NULL)
     ops->clear_so (so);
@@ -1662,6 +1700,14 @@ remove_user_added_objfile (struct objfile *objfile)
     }
 }
 
+/* Default implementation does not perform any validation.  */
+
+char *
+default_solib_validate (const struct so_list *const so)
+{
+  return NULL; /* No validation.  */
+}
+
 extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
 
 void
@@ -1719,4 +1765,18 @@ PATH and LD_LIBRARY_PATH."),
 				     reload_shared_libraries,
 				     show_solib_search_path,
 				     &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("solib-build-id-force", class_support,
+			   &solib_build_id_force, _("\
+Set loading of shared libraries with non-matching build-id."), _("\
+Show loading of shared libraries with non-matching build-id."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (on) or disables (off) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+			   NULL,
+			   show_solib_build_id_force,
+			   &setlist, &showlist);
+
 }
diff --git a/gdb/solib.h b/gdb/solib.h
index 336971d..c3bf529 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -98,4 +98,8 @@ extern void update_solib_breakpoints (void);
 
 extern void handle_solib_event (void);
 
+/* Default validation always returns 1.  */
+
+extern char *default_solib_validate (const struct so_list *so);
+
 #endif /* SOLIB_H */
diff --git a/gdb/solist.h b/gdb/solist.h
index 7021f5c..f0d8653 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -75,6 +75,22 @@ struct so_list
        There may not be just one (e.g. if two segments are relocated
        differently); but this is only used for "info sharedlibrary".  */
     CORE_ADDR addr_low, addr_high;
+
+    /* Build id in raw format, contains verbatim contents of
+       .note.gnu.build-id including note header.  This is actual
+       BUILD_ID which comes either from the remote target via qXfer
+       packet or via reading target memory.  Therefore, it may differ
+       from the build-id of the associated bfd.  In a normal
+       scenario, this so would soon lose its abfd due to failed
+       validation.
+       Reading target memory should be done by following execution view
+       of the binary (following program headers in the case of ELF).
+       Computing address from the linking view (following ELF section
+       headers) may give incorrect build-id memory address despite the
+       symbols still match.
+       Such an example is a prelinked vs.  unprelinked i386 ELF file.  */
+    size_t build_idsz;
+    gdb_byte *build_id;
   };
 
 struct target_so_ops
@@ -168,6 +184,11 @@ struct target_so_ops
        NULL, in which case no specific preprocessing is necessary
        for this target.  */
     void (*handle_event) (void);
+
+    /* Return NULL if SO does match target SO it is supposed to
+       represent.  Otherwise return string describing why it does not match.
+       Caller has to free the string.  */
+    char *(*validate) (const struct so_list *so);
   };
 
 /* Free the memory associated with a (so_list *).  */

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 10/10] Tests for validate symbol file using build-id
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (7 preceding siblings ...)
  2015-06-14 19:27 ` [PATCH v7 09/10] Validate symbol file using build-id Jan Kratochvil
@ 2015-06-14 19:27 ` Jan Kratochvil
  2015-07-08 14:44   ` Pedro Alves
  2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
  2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

new testcase.

There was no explicit approval by Tom Tromey in the series a year ago.


Jan


gdb/testsuite/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com

	Tests for validate symbol file using build-id.
	* gdb.base/solib-mismatch-lib.c: New file.
	* gdb.base/solib-mismatch-libmod.c: New file.
	* gdb.base/solib-mismatch.c: New file.
	* gdb.base/solib-mismatch.exp: New file.
---
 gdb/testsuite/gdb.base/solib-mismatch-lib.c    |   29 ++++
 gdb/testsuite/gdb.base/solib-mismatch-libmod.c |   29 ++++
 gdb/testsuite/gdb.base/solib-mismatch.c        |   56 +++++++++
 gdb/testsuite/gdb.base/solib-mismatch.exp      |  156 ++++++++++++++++++++++++
 4 files changed, 270 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-lib.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch-libmod.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.c
 create mode 100644 gdb/testsuite/gdb.base/solib-mismatch.exp

diff --git a/gdb/testsuite/gdb.base/solib-mismatch-lib.c b/gdb/testsuite/gdb.base/solib-mismatch-lib.c
new file mode 100644
index 0000000..b22863a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch-lib.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+int _bar = 42;
+
+int bar(void)
+{
+  return _bar + 21;
+}
+
+int foo(void)
+{
+  return _bar;
+}
diff --git a/gdb/testsuite/gdb.base/solib-mismatch-libmod.c b/gdb/testsuite/gdb.base/solib-mismatch-libmod.c
new file mode 100644
index 0000000..9c3f37e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch-libmod.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+int _bar = 21;
+
+int bar(void)
+{
+  return 42 - _bar;
+}
+
+int foo(void)
+{
+  return 24 + bar();
+}
diff --git a/gdb/testsuite/gdb.base/solib-mismatch.c b/gdb/testsuite/gdb.base/solib-mismatch.c
new file mode 100644
index 0000000..0979c81
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch.c
@@ -0,0 +1,56 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+
+/* The following defines must correspond to solib-mismatch.exp .  */
+
+/* DIRNAME and LIB must be defined at compile time.  */
+#ifndef DIRNAME
+#error DIRNAME not defined
+#endif
+#ifndef LIB
+#error LIB not defined
+#endif
+
+int main (int argc, char *argv[])
+{
+  void *h;
+  int (*foo) (void);
+
+  if (chdir (DIRNAME) != 0)
+    {
+      printf ("ERROR - Could not cd to %s\n", DIRNAME);
+      return 1;
+    }
+
+  h = dlopen (LIB, RTLD_NOW);
+
+  if (h == NULL)
+    {
+      printf ("ERROR - could not open lib %s\n", LIB);
+      return 1;
+    }
+  foo = dlsym (h, "foo"); /* set breakpoint 1 here */
+  dlclose (h);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/solib-mismatch.exp b/gdb/testsuite/gdb.base/solib-mismatch.exp
new file mode 100644
index 0000000..4983429
--- /dev/null
+++ b/gdb/testsuite/gdb.base/solib-mismatch.exp
@@ -0,0 +1,156 @@
+# Copyright 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+standard_testfile
+set executable $testfile
+
+if ![is_remote target] {
+  untested "only gdbserver supports build-id reporting"
+  return -1
+}
+if [is_remote host] {
+  untested "only local host is currently supported"
+  return -1
+}
+
+# Test overview:
+#  generate two shared objects. One that will be used by the process
+#  and another, modified, that will be found by gdb. Gdb should
+#  detect the mismatch and refuse to use mismatched shared object.
+
+if { [get_compiler_info] } {
+  untested "get_compiler_info failed."
+  return -1
+}
+
+# First version of the object, to be loaded by ld.
+set srclibfilerun ${testfile}-lib.c
+
+# Modified version of the object to be loaded by gdb
+# Code in -libmod.c is tuned so it gives a mismatch but
+# leaves .dynamic at the same point.
+set srclibfilegdb ${testfile}-libmod.c
+
+# So file name:
+set binlibfilebase lib${testfile}.so
+
+# Setup run directory (where program is run from)
+#   It contains executable and '-lib' version of the library.
+set binlibfiledirrun [standard_output_file ${testfile}_wd]
+set binlibfilerun ${binlibfiledirrun}/${binlibfilebase}
+
+# Second solib version is in current directory, '-libmod' version.
+set binlibfiledirgdb [standard_output_file ""]
+set binlibfilegdb ${binlibfiledirgdb}/${binlibfilebase}
+
+# Executable
+set srcfile ${testfile}.c
+set executable ${testfile}
+
+file delete -force -- "${binlibfiledirrun}"
+file mkdir "${binlibfiledirrun}"
+
+set exec_opts {}
+
+if { ![istarget "*-*-nto-*"] } {
+  lappend exec_opts "shlib_load"
+}
+
+lappend exec_opts "additional_flags=-DDIRNAME\=\"${binlibfiledirrun}\" -DLIB\=\"./${binlibfilebase}\""
+lappend exec_opts "debug"
+
+if { [build_executable $testfile.exp $executable $srcfile $exec_opts] != 0 } {
+  return -1
+}
+
+if { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilerun}" "${binlibfilerun}" [list debug ldflags=-Wl,--build-id]] != ""
+     || [gdb_gnu_strip_debug "${binlibfilerun}"]
+     || [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfilegdb}" "${binlibfilegdb}" [list debug ldflags=-Wl,--build-id]] != "" } {
+  untested "compilation failed."
+  return -1
+}
+
+proc solib_matching_test { solibfile symsloaded } {
+  global gdb_prompt
+  global testfile
+  global executable
+  global srcdir
+  global subdir
+  global binlibfiledirrun
+  global binlibfiledirgdb
+  global srcfile
+
+  clean_restart ${binlibfiledirrun}/${executable}
+
+  gdb_test_no_output "set solib-search-path \"${binlibfiledirgdb}\"" ""
+  if { [gdb_test "cd ${binlibfiledirgdb}" "" ""] != 0 } {
+    untested "cd ${binlibfiledirgdb}"
+    return -1
+  }
+
+  # Do not auto load shared libraries, the test needs to have control
+  # over when the relevant output gets printed.
+  gdb_test_no_output "set auto-solib-add off" ""
+
+  if ![runto "${srcfile}:[gdb_get_line_number "set breakpoint 1 here"]"] {
+    return -1
+  }
+
+  gdb_test "sharedlibrary" "" ""
+
+  set nocrlf "\[^\r\n\]*"
+  set expected_header "From${nocrlf}To${nocrlf}Syms${nocrlf}Read${nocrlf}Shared${nocrlf}"
+  set expected_line "${symsloaded}${nocrlf}${solibfile}"
+
+  gdb_test "info sharedlibrary ${solibfile}" \
+    "${expected_header}\r\n.*${expected_line}.*" \
+    "Symbols for ${solibfile} loaded: expected '${symsloaded}'"
+
+  return 0
+}
+
+# Copy binary to working dir so it pulls in the library from that dir
+# (by the virtue of $ORIGIN).
+file copy -force "${binlibfiledirgdb}/${executable}" \
+		 "${binlibfiledirrun}/${executable}"
+
+# Test unstripped, .dynamic matching
+with_test_prefix "test unstripped, .dynamic matching" {
+  solib_matching_test "${binlibfilebase}" "No"
+}
+
+# Keep original so for debugging purposes
+file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig"
+set objcopy_program [transform objcopy]
+set result [catch "exec $objcopy_program --only-keep-debug ${binlibfilegdb}"]
+if {$result != 0} {
+  untested "test --only-keep-debug (objcopy)"
+}
+
+# Test --only-keep-debug, .dynamic matching so
+with_test_prefix "test --only-keep-debug" {
+  solib_matching_test "${binlibfilebase}" "No"
+}
+
+# Keep previous so for debugging puroses
+file copy -force "${binlibfilegdb}" "${binlibfilegdb}-orig1"
+
+# Copy loaded so over the one gdb will find
+file copy -force "${binlibfilerun}" "${binlibfilegdb}"
+
+# Now test it does not mis-invalidate matching libraries
+with_test_prefix "test matching libraries" {
+  solib_matching_test "${binlibfilebase}" "Yes"
+}

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v7 08/10] gdbserver build-id attribute generator
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (8 preceding siblings ...)
  2015-06-14 19:27 ` [PATCH v7 10/10] Tests for validate " Jan Kratochvil
@ 2015-06-14 19:27 ` Jan Kratochvil
  2015-07-08 14:41   ` Pedro Alves
  2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-14 19:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

producer part of the new "build-id" XML attribute.

Probably approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00423.html
Although there were minor changes due to trunk updates.


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	gdbserver build-id attribute generator.
	* features/library-list-svr4.dtd (library-list-svr4): New
	'build-id' attribute.

gdb/doc/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	gdbserver build-id attribute generator.
	* gdb.texinfo (Library List Format for SVR4 Targets): Add
	'build-id' in description, example, new attribute in dtd.

gdb/gdbserver/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	gdbserver build-id attribute generator.
	* linux-low.c (nat/linux-maps.h, search.h, rsp-low.h): Include.
	(ElfXX_Ehdr, ElfXX_Phdr, ElfXX_Nhdr): New.
	(ELFXX_FLD, ELFXX_SIZEOF, ELFXX_ROUNDUP, BUILD_ID_INVALID): New.
	(find_phdr): New.
	(get_dynamic): Use find_pdhr to traverse program headers.
	(struct mapping_entry, mapping_entry_s, free_mapping_entry_vec)
	(compare_mapping_entry_range, struct find_memory_region_callback_data)
	(read_build_id, find_memory_region_callback, lrfind_mapping_entry)
	(get_hex_build_id): New.
	(linux_qxfer_libraries_svr4): Add optional build-id attribute
	to reply XML document.
---
 gdb/doc/gdb.texinfo                |   17 +-
 gdb/features/library-list-svr4.dtd |   13 +
 gdb/gdbserver/linux-low.c          |  398 +++++++++++++++++++++++++++++++++---
 3 files changed, 379 insertions(+), 49 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index faca83e..10bc6e2 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -39325,6 +39325,8 @@ memory address.  It is a displacement of absolute memory address against
 address the file was prelinked to during the library load.
 @item
 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
+@item
+@code{build-id}, hex encoded @code{NT_GNU_BUILD_ID} note, if it exists.
 @end itemize
 
 Additionally the single @code{main-lm} attribute specifies address of
@@ -39342,7 +39344,7 @@ looks like this:
   <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
            l_ld="0xe4eefc"/>
   <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
-           l_ld="0x152350"/>
+           l_ld="0x152350" build-id="9afccf7cc41e6293476223fe72480854"/>
 </library-list-svr>
 @end smallexample
 
@@ -39351,13 +39353,14 @@ The format of an SVR4 library list is described by this DTD:
 @smallexample
 <!-- library-list-svr4: Root element with versioning -->
 <!ELEMENT library-list-svr4  (library)*>
-<!ATTLIST library-list-svr4  version CDATA   #FIXED  "1.0">
-<!ATTLIST library-list-svr4  main-lm CDATA   #IMPLIED>
+<!ATTLIST library-list-svr4  version  CDATA   #FIXED  "1.0">
+<!ATTLIST library-list-svr4  main-lm  CDATA   #IMPLIED>
 <!ELEMENT library            EMPTY>
-<!ATTLIST library            name    CDATA   #REQUIRED>
-<!ATTLIST library            lm      CDATA   #REQUIRED>
-<!ATTLIST library            l_addr  CDATA   #REQUIRED>
-<!ATTLIST library            l_ld    CDATA   #REQUIRED>
+<!ATTLIST library            name     CDATA   #REQUIRED>
+<!ATTLIST library            lm       CDATA   #REQUIRED>
+<!ATTLIST library            l_addr   CDATA   #REQUIRED>
+<!ATTLIST library            l_ld     CDATA   #REQUIRED>
+<!ATTLIST library            build-id CDATA   #IMPLIED>
 @end smallexample
 
 @node Memory Map Format
diff --git a/gdb/features/library-list-svr4.dtd b/gdb/features/library-list-svr4.dtd
index 082945d..5741f03 100644
--- a/gdb/features/library-list-svr4.dtd
+++ b/gdb/features/library-list-svr4.dtd
@@ -6,11 +6,12 @@
 
 <!-- library-list-svr4: Root element with versioning -->
 <!ELEMENT library-list-svr4  (library)*>
-<!ATTLIST library-list-svr4  version CDATA   #FIXED  "1.0">
-<!ATTLIST library-list-svr4  main-lm CDATA   #IMPLIED>
+<!ATTLIST library-list-svr4  version  CDATA   #FIXED  "1.0">
+<!ATTLIST library-list-svr4  main-lm  CDATA   #IMPLIED>
 
 <!ELEMENT library            EMPTY>
-<!ATTLIST library            name    CDATA   #REQUIRED>
-<!ATTLIST library            lm      CDATA   #REQUIRED>
-<!ATTLIST library            l_addr  CDATA   #REQUIRED>
-<!ATTLIST library            l_ld    CDATA   #REQUIRED>
+<!ATTLIST library            name     CDATA   #REQUIRED>
+<!ATTLIST library            lm       CDATA   #REQUIRED>
+<!ATTLIST library            l_addr   CDATA   #REQUIRED>
+<!ATTLIST library            l_ld     CDATA   #REQUIRED>
+<!ATTLIST library            build-id CDATA   #IMPLIED>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 3774d17..40921fd 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -21,6 +21,7 @@
 #include "nat/linux-osdata.h"
 #include "agent.h"
 #include "tdesc.h"
+#include "nat/linux-maps.h"
 
 #include "nat/linux-nat.h"
 #include "nat/linux-waitpid.h"
@@ -42,9 +43,11 @@
 #include <sys/stat.h>
 #include <sys/vfs.h>
 #include <sys/uio.h>
+#include <search.h>
 #include "filestuff.h"
 #include "tracepoint.h"
 #include "hostio.h"
+#include "rsp-low.h"
 #ifndef ELFMAG0
 /* Don't include <linux/elf.h> here.  If it got included by gdb_proc_service.h
    then ELFMAG0 will have been defined.  If it didn't get included by
@@ -181,6 +184,31 @@ lwp_stop_reason (struct lwp_info *lwp)
   return lwp->stop_reason;
 }
 
+typedef union ElfXX_Ehdr
+{
+  Elf32_Ehdr _32;
+  Elf64_Ehdr _64;
+} ElfXX_Ehdr;
+
+typedef union ElfXX_Phdr
+{
+  Elf32_Phdr _32;
+  Elf64_Phdr _64;
+} ElfXX_Phdr;
+
+typedef union ElfXX_Nhdr
+{
+  Elf32_Nhdr _32;
+  Elf64_Nhdr _64;
+} ElfXX_Nhdr;
+
+#define ELFXX_FLD(elf64, hdr, fld) ((elf64) ? (hdr)._64.fld : (hdr)._32.fld)
+#define ELFXX_SIZEOF(elf64, hdr) ((elf64) ? sizeof ((hdr)._64) \
+					  : sizeof ((hdr)._32))
+/* Round up to next 4 byte boundary.  */
+#define ELFXX_ROUNDUP_4(elf64, what) (((what) + 3) & ~(ULONGEST) 3)
+#define BUILD_ID_INVALID "?"
+
 /* A list of all unknown processes which receive stop signals.  Some
    other process will presumably claim each of these as forked
    children momentarily.  */
@@ -6006,15 +6034,38 @@ get_phdr_phnum_from_proc_auxv (const int pid, const int is_elf64,
   return 0;
 }
 
+/* Linearly traverse pheaders and look for P_TYPE pheader.  */
+
+static const void *
+find_phdr (const int is_elf64, const void *const phdr_begin,
+	   const void *const phdr_end, const ULONGEST p_type)
+{
+#define PHDR_NEXT(hdrp) ((const void *) ((const gdb_byte *) (hdrp) + \
+			 ELFXX_SIZEOF (is_elf64, *hdrp)))
+
+  const ElfXX_Phdr *phdr = phdr_begin;
+
+  while (PHDR_NEXT (phdr) <= phdr_end)
+    {
+      if (ELFXX_FLD (is_elf64, *phdr, p_type) == p_type)
+	return phdr;
+      phdr = PHDR_NEXT (phdr);
+    }
+
+  return NULL;
+#undef PHDR_NEXT
+}
+
 /* Return &_DYNAMIC (via PT_DYNAMIC) in the inferior, or 0 if not present.  */
 
 static CORE_ADDR
 get_dynamic (const int pid, const int is_elf64)
 {
   CORE_ADDR phdr_memaddr, relocation;
-  int num_phdr, i;
+  int num_phdr;
   unsigned char *phdr_buf;
-  const int phdr_size = is_elf64 ? sizeof (Elf64_Phdr) : sizeof (Elf32_Phdr);
+  const ElfXX_Phdr *phdr;
+  const int phdr_size = ELFXX_SIZEOF (is_elf64, *phdr);
 
   if (get_phdr_phnum_from_proc_auxv (pid, is_elf64, &phdr_memaddr, &num_phdr))
     return 0;
@@ -6028,22 +6079,10 @@ get_dynamic (const int pid, const int is_elf64)
   /* Compute relocation: it is expected to be 0 for "regular" executables,
      non-zero for PIE ones.  */
   relocation = -1;
-  for (i = 0; relocation == -1 && i < num_phdr; i++)
-    if (is_elf64)
-      {
-	Elf64_Phdr *const p = (Elf64_Phdr *) (phdr_buf + i * phdr_size);
-
-	if (p->p_type == PT_PHDR)
-	  relocation = phdr_memaddr - p->p_vaddr;
-      }
-    else
-      {
-	Elf32_Phdr *const p = (Elf32_Phdr *) (phdr_buf + i * phdr_size);
-
-	if (p->p_type == PT_PHDR)
-	  relocation = phdr_memaddr - p->p_vaddr;
-      }
-
+  phdr = find_phdr (is_elf64, phdr_buf, phdr_buf + num_phdr * phdr_size,
+		    PT_PHDR);
+  if (phdr != NULL)
+    relocation = phdr_memaddr - ELFXX_FLD (is_elf64, *phdr, p_vaddr);
   if (relocation == -1)
     {
       /* PT_PHDR is optional, but necessary for PIE in general.  Fortunately
@@ -6059,23 +6098,11 @@ get_dynamic (const int pid, const int is_elf64)
       return 0;
     }
 
-  for (i = 0; i < num_phdr; i++)
-    {
-      if (is_elf64)
-	{
-	  Elf64_Phdr *const p = (Elf64_Phdr *) (phdr_buf + i * phdr_size);
+  phdr = find_phdr (is_elf64, phdr_buf, phdr_buf + num_phdr * phdr_size,
+		    PT_DYNAMIC);
 
-	  if (p->p_type == PT_DYNAMIC)
-	    return p->p_vaddr + relocation;
-	}
-      else
-	{
-	  Elf32_Phdr *const p = (Elf32_Phdr *) (phdr_buf + i * phdr_size);
-
-	  if (p->p_type == PT_DYNAMIC)
-	    return p->p_vaddr + relocation;
-	}
-    }
+  if (phdr != NULL)
+    return ELFXX_FLD (is_elf64, *phdr, p_vaddr) + relocation;
 
   return 0;
 }
@@ -6215,6 +6242,278 @@ struct link_map_offsets
     int l_prev_offset;
   };
 
+
+/* Structure for holding a mapping.  Only mapping
+   containing l_ld can have hex_build_id set.  */
+
+struct mapping_entry
+{
+  /* Fields are populated from linux_find_memory_region parameters.  */
+
+  ULONGEST vaddr;
+  ULONGEST size;
+  ULONGEST offset;
+  ULONGEST inode;
+
+  /* Hex encoded string allocated using xmalloc, and
+     needs to be freed.  It can be NULL.  */
+
+  char *hex_build_id;
+};
+
+typedef struct mapping_entry mapping_entry_s;
+
+DEF_VEC_O(mapping_entry_s);
+
+/* Free vector of mapping_entry_s objects.  */
+
+static void
+free_mapping_entry_vec (VEC (mapping_entry_s) *lst)
+{
+  int ix;
+  mapping_entry_s *p;
+
+  for (ix = 0; VEC_iterate (mapping_entry_s, lst, ix, p); ++ix)
+    xfree (p->hex_build_id);
+
+  VEC_free (mapping_entry_s, lst);
+}
+
+/* Used for finding a mapping containing the given
+   l_ld passed in K.  */
+
+static int
+compare_mapping_entry_range (const void *const k, const void *const b)
+{
+  const ULONGEST key = *(const CORE_ADDR *) k;
+  const mapping_entry_s *const p = b;
+
+  if (key < p->vaddr)
+    return -1;
+
+  if (key < p->vaddr + p->size)
+    return 0;
+
+  return 1;
+}
+
+struct find_memory_region_callback_data
+{
+  unsigned is_elf64;
+
+  /* Return.  Must be freed with free_mapping_entry_vec.  */
+  VEC (mapping_entry_s) *list;
+};
+
+/* Read build-id from PT_NOTE.
+   Argument LOAD_ADDR represents run time virtual address corresponding to
+   the beginning of the first loadable segment.  L_ADDR is displacement
+   as supplied by the dynamic linker.  */
+
+static void
+read_build_id (struct find_memory_region_callback_data *const p,
+	       mapping_entry_s *const bil, const CORE_ADDR load_addr,
+	       const CORE_ADDR l_addr)
+{
+  const int is_elf64 = p->is_elf64;
+  ElfXX_Ehdr ehdr;
+
+  if (linux_read_memory (load_addr, (unsigned char *) &ehdr,
+			 ELFXX_SIZEOF (is_elf64, ehdr)) == 0
+      && ELFXX_FLD (is_elf64, ehdr, e_ident[EI_MAG0]) == ELFMAG0
+      && ELFXX_FLD (is_elf64, ehdr, e_ident[EI_MAG1]) == ELFMAG1
+      && ELFXX_FLD (is_elf64, ehdr, e_ident[EI_MAG2]) == ELFMAG2
+      && ELFXX_FLD (is_elf64, ehdr, e_ident[EI_MAG3]) == ELFMAG3)
+    {
+      const ElfXX_Phdr *phdr;
+      void *phdr_buf;
+      const unsigned e_phentsize = ELFXX_FLD (is_elf64, ehdr, e_phentsize);
+
+      if (ELFXX_FLD (is_elf64, ehdr, e_phnum) >= 100
+	  || e_phentsize != ELFXX_SIZEOF (is_elf64, *phdr))
+	{
+	  /* Basic sanity check failed.  */
+	  warning (_("Could not identify program header at %s."),
+		   paddress (load_addr));
+	  return;
+	}
+
+      phdr_buf = alloca (ELFXX_FLD (is_elf64, ehdr, e_phnum) * e_phentsize);
+
+      if (linux_read_memory (load_addr + ELFXX_FLD (is_elf64, ehdr, e_phoff),
+			     phdr_buf,
+			     ELFXX_FLD (is_elf64, ehdr, e_phnum) * e_phentsize)
+	  != 0)
+	{
+	  warning (_("Could not read program header at %s."),
+		   paddress (load_addr));
+	  return;
+	}
+
+      phdr = phdr_buf;
+
+      for (;;)
+	{
+	  gdb_byte *pt_note;
+	  const gdb_byte *pt_end;
+	  const ElfXX_Nhdr *nhdr;
+	  CORE_ADDR note_addr;
+
+	  phdr = find_phdr (p->is_elf64, phdr, (gdb_byte *) phdr_buf
+			    + ELFXX_FLD (is_elf64, ehdr, e_phnum) * e_phentsize,
+			    PT_NOTE);
+	  if (phdr == NULL)
+	    break;
+	  pt_note = xmalloc (ELFXX_FLD (is_elf64, *phdr, p_memsz));
+	  note_addr = ELFXX_FLD (is_elf64, *phdr, p_vaddr) + l_addr;
+	  if (linux_read_memory (note_addr, pt_note,
+				 ELFXX_FLD (is_elf64, *phdr, p_memsz)) != 0)
+	    {
+	      xfree (pt_note);
+	      warning (_("Could not read note at address 0x%s"),
+		       paddress (note_addr));
+	      break;
+	    }
+
+	  pt_end = pt_note + ELFXX_FLD (is_elf64, *phdr, p_memsz);
+	  nhdr = (void *) pt_note;
+	  while ((const gdb_byte *) nhdr < pt_end)
+	    {
+	      const size_t namesz
+		= ELFXX_ROUNDUP_4 (is_elf64, ELFXX_FLD (is_elf64, *nhdr,
+							n_namesz));
+	      const size_t descsz
+		= ELFXX_ROUNDUP_4 (is_elf64, ELFXX_FLD (is_elf64, *nhdr,
+							n_descsz));
+	      const size_t note_sz = (ELFXX_SIZEOF (is_elf64, *nhdr) + namesz
+				      + descsz);
+
+	      if (((const gdb_byte *) nhdr + note_sz) > pt_end || note_sz == 0
+		  || descsz == 0)
+		{
+		  warning (_("Malformed PT_NOTE at address 0x%s\n"),
+			   paddress (note_addr + (gdb_byte *) nhdr - pt_note));
+		  break;
+		}
+	      if (ELFXX_FLD (is_elf64, *nhdr, n_type) == NT_GNU_BUILD_ID
+		  && ELFXX_FLD (is_elf64, *nhdr, n_namesz) == 4)
+		{
+		  const char gnu[4] = "GNU\0";
+		  const char *const pname
+		    = (char *) nhdr + ELFXX_SIZEOF (is_elf64, *nhdr);
+
+		  if (memcmp (pname, gnu, 4) == 0)
+		    {
+		      const size_t n_descsz = ELFXX_FLD (is_elf64, *nhdr,
+							 n_descsz);
+
+		      bil->hex_build_id = xmalloc (n_descsz * 2 + 1);
+		      bin2hex ((const gdb_byte *) pname + namesz,
+			       bil->hex_build_id, n_descsz);
+		      xfree (pt_note);
+		      return;
+		    }
+		}
+	      nhdr = (void *) ((gdb_byte *) nhdr + note_sz);
+	    }
+	  xfree (pt_note);
+	}
+    }
+}
+
+static linux_find_memory_region_ftype find_memory_region_callback;
+
+/* Add mapping_entry.  See linux_find_memory_ftype for the parameters
+   description.  */
+
+static int
+find_memory_region_callback (ULONGEST vaddr, ULONGEST size, ULONGEST offset,
+			     ULONGEST inode, int read, int write, int exec,
+			     int modified, const char *filename, void *data)
+{
+  if (inode != 0)
+    {
+      struct find_memory_region_callback_data *const p = data;
+      mapping_entry_s bil;
+
+      bil.vaddr = vaddr;
+      bil.size = size;
+      bil.offset = offset;
+      bil.inode = inode;
+      bil.hex_build_id = NULL;
+
+      VEC_safe_push (mapping_entry_s, p->list, &bil);
+    }
+
+  /* Continue the traversal.  */
+  return 0;
+}
+
+/* Linear reverse find starting from RBEGIN towards REND looking for
+   the lowest vaddr mapping of the same inode and zero offset.  */
+
+static mapping_entry_s *
+lrfind_mapping_entry (mapping_entry_s *const rbegin,
+		      const mapping_entry_s *const rend)
+{
+  mapping_entry_s *p;
+
+  for (p = rbegin - 1; p >= rend; --p)
+    if (p->offset == 0 && p->inode == rbegin->inode)
+      return p;
+
+  return NULL;
+}
+
+/* Get build-id for the given L_LD, where L_LD corresponds to
+   link_map.l_ld as specified by the dynamic linker.
+   DATA must point to already filled list of mapping_entry elements.
+
+   If build-id had not been read, read it and cache in corresponding
+   list element.
+
+   Return build_id as stored in the list element corresponding
+   to L_LD.
+
+   NULL may be returned if build-id could not be fetched.
+
+   Returned string must not be freed explicitly.  */
+
+static const char *
+get_hex_build_id (const CORE_ADDR l_addr, const CORE_ADDR l_ld,
+		  struct find_memory_region_callback_data *const data)
+{
+  mapping_entry_s *bil;
+
+  bil = bsearch (&l_ld, VEC_address (mapping_entry_s, data->list),
+		 VEC_length (mapping_entry_s, data->list),
+		 sizeof (mapping_entry_s), compare_mapping_entry_range);
+
+  if (bil == NULL)
+    return NULL;
+
+  if (bil->hex_build_id == NULL)
+    {
+      mapping_entry_s *bil_min;
+
+      bil_min = lrfind_mapping_entry (bil, VEC_address (mapping_entry_s,
+							data->list));
+      if (bil_min != NULL)
+	read_build_id (data, bil, bil_min->vaddr, l_addr);
+      else
+	{
+	  /* Do not try to find hex_build_id again.  */
+	  bil->hex_build_id = xstrdup (BUILD_ID_INVALID);
+	  warning (_("Could not determine load address; mapping entry with "
+		     "offset 0 corresponding to l_ld = 0x%s could not be "
+		     "found; build-id can not be used."),
+		   paddress (l_ld));
+	}
+    }
+
+  return bil->hex_build_id;
+}
+
 /* Construct qXfer:libraries-svr4:read reply.  */
 
 static int
@@ -6227,6 +6526,15 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
   struct process_info_private *const priv = current_process ()->priv;
   char filename[PATH_MAX];
   int pid, is_elf64;
+  struct find_memory_region_callback_data data;
+  
+  /* COREFILTER_ANON_PRIVATE and COREFILTER_ANON_SHARED do not have an
+     associated file so it is not expected it could have an ELF header.  */ 
+  const enum filterflags filterflags = (COREFILTER_MAPPED_PRIVATE
+					| COREFILTER_MAPPED_SHARED
+					| COREFILTER_ELF_HEADERS
+					| COREFILTER_HUGETLB_PRIVATE
+					| COREFILTER_HUGETLB_SHARED);
 
   static const struct link_map_offsets lmo_32bit_offsets =
     {
@@ -6269,6 +6577,14 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
   lmo = is_elf64 ? &lmo_64bit_offsets : &lmo_32bit_offsets;
   ptr_size = is_elf64 ? 8 : 4;
 
+  data.is_elf64 = is_elf64;
+  data.list = NULL;
+  VEC_reserve (mapping_entry_s, data.list, 16);
+  if (linux_find_memory_regions_full (pid, filterflags,
+				      find_memory_region_callback, &data)
+      < 0)
+    warning (_("Finding memory regions failed"));
+
   while (annex[0] != '\0')
     {
       const char *sep;
@@ -6375,6 +6691,7 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
 	      /* 6x the size for xml_escape_text below.  */
 	      size_t len = 6 * strlen ((char *) libname);
 	      char *name;
+	      const char *hex_enc_build_id = NULL;
 
 	      if (!header_done)
 		{
@@ -6383,7 +6700,11 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
 		  header_done = 1;
 		}
 
-	      while (allocated < p - document + len + 200)
+	      hex_enc_build_id = get_hex_build_id (l_addr, l_ld, &data);
+
+	      while (allocated < (p - document + len + 200
+				  + (hex_enc_build_id != NULL
+				     ? strlen (hex_enc_build_id) : 0)))
 		{
 		  /* Expand to guarantee sufficient storage.  */
 		  uintptr_t document_len = p - document;
@@ -6395,9 +6716,13 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
 
 	      name = xml_escape_text ((char *) libname);
 	      p += sprintf (p, "<library name=\"%s\" lm=\"0x%lx\" "
-			    "l_addr=\"0x%lx\" l_ld=\"0x%lx\"/>",
+			    "l_addr=\"0x%lx\" l_ld=\"0x%lx\"",
 			    name, (unsigned long) lm_addr,
 			    (unsigned long) l_addr, (unsigned long) l_ld);
+	      if (hex_enc_build_id != NULL
+		  && strcmp (hex_enc_build_id, BUILD_ID_INVALID) != 0)
+		p += sprintf (p, " build-id=\"%s\"", hex_enc_build_id);
+	      p += sprintf (p, "/>");
 	      free (name);
 	    }
 	}
@@ -6424,6 +6749,7 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
 
   memcpy (readbuf, document + offset, len);
   xfree (document);
+  free_mapping_entry_vec (data.list);
 
   return len;
 }

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 01/10] Move utility functions to common/
  2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
@ 2015-06-15 13:22   ` Joel Brobecker
  2015-06-15 15:07     ` [commit] " Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Joel Brobecker @ 2015-06-15 13:22 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Aleksandar Ristovski

> gdb/ChangeLog
> 2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
> 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Move utility functions to common/.
> 	* cli/cli-utils.c (skip_spaces, skip_spaces_const, skip_to_space_const):
> 	Move defs to common/common-utils.c.
> 	* cli/cli-utils.h (skip_spaces, skip_spaces_const, skip_to_space)
> 	(skip_to_space_const): Move decls to common/common-utils.h.
> 	* common/common-defs.h: Move include of common-types.h before
> 	common-utils.h.
> 	* common/common-utils.c: Include host-defs.h and ctype.h.
> 	(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
> 	from utils.c.
> 	(skip_spaces, skip_spaces_const, skip_to_space_const): Move from
> 	cli/cli-utils.c.
> 	* common/common-utils.h (strtoulst): Move decl from utils.h.
> 	(skip_spaces, skip_spaces_const, skip_to_space, skip_to_space_const):
> 	Move from cli/cli-utils.h.
> 	* common/host-defs.h: Include limits.h.
> 	(TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved from defs.h.
> 	(skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
> 	* defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
> 	common/common-utils.h.
> 	* utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int)
> 	(strtoulst): Move to common/common-utils.c.
> 	* utils.h (strtoulst): Moved decl to common/common-utils.h.

This one looks pretty straightfoward and useful, so OK.

I *think* from reading through the patch that some of the functions
being moved don't have documentation. This is not for this patch,
but if you wouldn't mind, would you use this opportunity to  add
that documentation as a followup patch? If you don't have the time,
then no problem, but do let me know so I can go in and do that.

Thanks,
-- 
Joel

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 02/10] Merge multiple hex conversions
  2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
@ 2015-06-15 13:33   ` Joel Brobecker
  2015-06-15 15:09     ` [commit] " Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Joel Brobecker @ 2015-06-15 13:33 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Aleksandar Ristovski

> gdb/gdbserver/ChangeLog
> 2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
> 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Merge multiple hex conversions.
> 	* gdbreplay.c (tohex): Rename to 'fromhex'.
> 	(logchar): Use fromhex.

I hesitated on this one, since I was wondering why we have two
implementations of fromhex, one there, and one in rsp-low.c.
I'm guessing it's because this on in gdbreplay has a call to
"exit" (!!!). But, in the end, it seems to me that this patch
is already an improvement over the previous situation, and I'm not
really sure of the reasons behind the current implementation,
so we can leave this as is for now. (FTAOD: this is OK).

> gdb/ChangeLog
> 2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
> 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Merge multiple hex conversions.
> 	* monitor.c: Include rsp-low.h.
> 	(fromhex): Remove definition.

OK.


-- 
Joel

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags
  2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
@ 2015-06-15 13:34   ` Joel Brobecker
  2015-06-15 15:12     ` [commit] " Jan Kratochvil
  2015-07-08 14:38   ` Pedro Alves
  1 sibling, 1 reply; 44+ messages in thread
From: Joel Brobecker @ 2015-06-15 13:34 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Aleksandar Ristovski

> gdb/ChangeLog
> 2015-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* linux-tdep.c (enum filterflags): Make it from anonymous enum.
> 	(dump_mapping_p): Use it for parameter filterflags.
> 	(linux_find_memory_regions_full): Use it for variable filterflags.

Would be OK with me, pending comments from Sergio.

-- 
Joel

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [commit] [PATCH v7 01/10] Move utility functions to common/
  2015-06-15 13:22   ` Joel Brobecker
@ 2015-06-15 15:07     ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-15 15:07 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Aleksandar Ristovski

On Mon, 15 Jun 2015 15:22:50 +0200, Joel Brobecker wrote:
> This one looks pretty straightfoward and useful, so OK.

There were some discussions whether it should be checked in even without the
further patches but I have therefore checked it in:
	03aef70fecec83e109c65337a59600ad36def6bf


> I *think* from reading through the patch that some of the functions
> being moved don't have documentation. This is not for this patch,
> but if you wouldn't mind, would you use this opportunity to  add
> that documentation as a followup patch? If you don't have the time,
> then no problem, but do let me know so I can go in and do that.

I can but not sure now, it could be assigned by Pedro.


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [commit] [PATCH v7 02/10] Merge multiple hex conversions
  2015-06-15 13:33   ` Joel Brobecker
@ 2015-06-15 15:09     ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-15 15:09 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Aleksandar Ristovski

On Mon, 15 Jun 2015 15:33:10 +0200, Joel Brobecker wrote:
> > gdb/ChangeLog
> > 2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
> > 	    Jan Kratochvil  <jan.kratochvil@redhat.com>
> > 
> > 	Merge multiple hex conversions.
> > 	* monitor.c: Include rsp-low.h.
> > 	(fromhex): Remove definition.
> 
> OK.

Checked in:
	909c2cdaa78f5c33ce61a3b47e86f831025d0a02


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [commit] [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags
  2015-06-15 13:34   ` Joel Brobecker
@ 2015-06-15 15:12     ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-15 15:12 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Aleksandar Ristovski

On Mon, 15 Jun 2015 15:34:06 +0200, Joel Brobecker wrote:
> > gdb/ChangeLog
> > 2015-06-07  Jan Kratochvil  <jan.kratochvil@redhat.com>
> > 
> > 	* linux-tdep.c (enum filterflags): Make it from anonymous enum.
> > 	(dump_mapping_p): Use it for parameter filterflags.
> > 	(linux_find_memory_regions_full): Use it for variable filterflags.
> 
> Would be OK with me,

Checked in:
	31b7833d205031b52996982f5da025d60c6e052f


> pending comments from Sergio.

Sergio already expressed his agreement:
	https://sourceware.org/ml/gdb-patches/2015-06/msg00107.html


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-14 19:27 ` [PATCH v7 09/10] Validate symbol file using build-id Jan Kratochvil
@ 2015-06-21 10:16   ` Jan Kratochvil
  2015-06-22 12:55     ` Aleksandar Ristovski
  2015-06-22 22:25     ` Doug Evans
  0 siblings, 2 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-21 10:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

Hi,

updated for:
	commit c74f7d1c6c5a968330208757f476c67a4bb66643
	Author: Jon Turney <jon.turney@dronecode.org.uk>
	Date:   Tue Apr 7 20:49:08 2015 +0100
	    Allow gdb to find debug symbols file by build-id for PE file format also


Jan

[-- Attachment #2: Type: message/rfc822, Size: 18272 bytes --]

From: Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: [PATCH 1/2] Validate symbol file using build-id
Date: Sun, 21 Jun 2015 11:51:52 +0200

Hi,

consumer part of the "build-id" attribute.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00424.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Validate symbol file using build-id.
	* NEWS (Changes since GDB 7.9): Add 'set solib-build-id-force'
	and 'show solib-build-id-force'.  Add build-id attribute.
	* solib-darwin.c (_initialize_darwin_solib): Assign validate value.
	* solib-dsbt.c (_initialize_dsbt_solib): Ditto.
	* solib-frv.c (_initialize_frv_solib): Ditto.
	* solib-spu.c (set_spu_solib_ops): Ditto.
	* solib-svr4.c: Include rsp-low.h.
	(NOTE_GNU_BUILD_ID_NAME): New define.
	(svr4_validate): New function.
	(svr4_copy_library_list): Duplicate field build_id.
	(library_list_start_library): Parse 'build-id' attribute.
	(svr4_library_attributes): Add 'build-id' attribute.
	(_initialize_svr4_solib): Assign validate value.
	* solib-target.c (solib.h): Include.
	(_initialize_solib_target): Assign validate value.
	* solib.c (solib_build_id_force, show_solib_build_id_force): New.
	(solib_map_sections): Use ops->validate.
	(clear_so): Free build_id.
	(default_solib_validate): New function.
	(_initialize_solib): Add "solib-build-id-force".
	* solib.h (default_solib_validate): New declaration.
	* solist.h (struct so_list): New fields 'build_idsz' and 'build_id'.
	(target_so_ops): New field 'validate'.

gdb/doc/ChangeLog
2014-03-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Files): Add 'set solib-build-id-force'
	and 'show solib-build-id-force'.
---
 gdb/NEWS            | 12 +++++++
 gdb/doc/gdb.texinfo | 38 ++++++++++++++++++++++
 gdb/solib-darwin.c  |  1 +
 gdb/solib-dsbt.c    |  1 +
 gdb/solib-frv.c     |  1 +
 gdb/solib-spu.c     |  1 +
 gdb/solib-svr4.c    | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/solib-target.c  |  2 ++
 gdb/solib.c         | 62 +++++++++++++++++++++++++++++++++++-
 gdb/solib.h         |  4 +++
 gdb/solist.h        | 21 +++++++++++++
 11 files changed, 232 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 3ec5851..8cbe1fc 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -159,6 +159,12 @@ set debug linux-namespaces
 show debug linux-namespaces
   Control display of debugging info regarding Linux namespaces.
 
+set solib-build-id-force (on|off)
+show solib-build-id-force
+  Inferior shared library and symbol file may contain unique build-id.
+  If both build-ids are present but they do not match then this setting
+  enables (on) or disables (off) loading of such symbol file.
+
 * The command 'thread apply all' can now support new option '-ascending'
   to call its specified command for all threads in ascending order.
 
@@ -233,6 +239,12 @@ fork-events and vfork-events features in qSupported
 * GDB now supports access to vector registers on S/390 GNU/Linux
   targets.
 
+* New features in the GDB remote stub, GDBserver
+
+  ** library-list-svr4 contains also optional attribute 'build-id' for
+     each library.  GDB does not load library with build-id that
+     does not match such attribute.
+
 * Removed command line options
 
 -xdb  HP-UX XDB compatibility mode.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1460b7f..f7e4405 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17912,6 +17912,44 @@ libraries that were loaded by explicit user requests are not
 discarded.
 @end table
 
+@table @code
+@kindex set solib-build-id-force
+@cindex override @value{GDBN} build-id check
+@item set solib-build-id-force @var{mode}
+Setting to override @value{GDBN} build-id check.
+
+Inferior shared libraries and symbol files may contain unique build-id.
+By default @value{GDBN} will ignore symbol files with non-matching build-id
+while printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) and will be
+  ignored; or use 'set solib-build-id-force'.
+@end smallexample
+
+Turning on this setting would load such symbol file while still printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) but it is
+  being loaded due to 'set solib-build-id-force'.
+@end smallexample
+
+If remote build-id is present but it does not match local build-id (or local
+build-id is not present) then this setting enables (@var{mode} is @code{on}) or
+disables (@var{mode} is @code{off}) loading of such symbol file.  On systems
+where build-id is not present in the remote system this setting has no effect.
+The default value is @code{off}.
+
+Loading non-matching symbol file may confuse debugging including breakage
+of backtrace output.
+
+@kindex show solib-build-id-force
+@item show solib-build-id-force
+Display the current mode of build-id check override.
+@end table
+
 Sometimes you may wish that @value{GDBN} stops and gives you control
 when any of shared library events happen.  The best way to do this is
 to use @code{catch load} and @code{catch unload} (@pxref{Set
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index f96841f..9309c35 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -634,4 +634,5 @@ _initialize_darwin_solib (void)
   darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
   darwin_so_ops.lookup_lib_global_symbol = darwin_lookup_lib_symbol;
   darwin_so_ops.bfd_open = darwin_bfd_open;
+  darwin_so_ops.validate = default_solib_validate;
 }
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 7da5833..9fe6533 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -1080,6 +1080,7 @@ _initialize_dsbt_solib (void)
   dsbt_so_ops.open_symbol_file_object = open_symbol_file_object;
   dsbt_so_ops.in_dynsym_resolve_code = dsbt_in_dynsym_resolve_code;
   dsbt_so_ops.bfd_open = solib_bfd_open;
+  dsbt_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-dsbt", class_maintenance,
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index f7ef38b..b768146 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -1183,6 +1183,7 @@ _initialize_frv_solib (void)
   frv_so_ops.open_symbol_file_object = open_symbol_file_object;
   frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
   frv_so_ops.bfd_open = solib_bfd_open;
+  frv_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index 44fbf91..d162884 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -519,6 +519,7 @@ set_spu_solib_ops (struct gdbarch *gdbarch)
       spu_so_ops.current_sos = spu_current_sos;
       spu_so_ops.bfd_open = spu_bfd_open;
       spu_so_ops.lookup_lib_global_symbol = spu_lookup_lib_symbol;
+      spu_so_ops.validate = default_solib_validate;
     }
 
   set_solib_ops (gdbarch, &spu_so_ops);
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 909dfb7..b434c1f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -45,6 +45,9 @@
 #include "auxv.h"
 #include "gdb_bfd.h"
 #include "probe.h"
+#include "rsp-low.h"
+
+#define NOTE_GNU_BUILD_ID_NAME  ".note.gnu.build-id"
 
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static int svr4_have_link_map_offsets (void);
@@ -970,6 +973,63 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
   return (name_lm >= vaddr && name_lm < vaddr + size);
 }
 
+/* Validate SO by comparing build-id from the associated bfd and
+   corresponding build-id from target memory.  */
+
+static char *
+svr4_validate (const struct so_list *const so)
+{
+  const bfd_byte *local_id;
+  size_t local_idsz;
+
+  gdb_assert (so != NULL);
+
+  /* Target doesn't support reporting the build ID or the remote shared library
+     does not have build ID.  */
+  if (so->build_id == NULL)
+    return NULL;
+
+  /* Build ID may be present in the local file, just GDB is unable to retrieve
+     it.  As it has been reported by gdbserver it is not FSF gdbserver.  */
+  if (so->abfd == NULL
+      || !bfd_check_format (so->abfd, bfd_object))
+    return NULL;
+
+  /* GDB has verified the local file really does not contain the build ID.  */
+  if (so->abfd->build_id == NULL)
+    {
+      char *remote_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+
+      return xstrprintf (_("remote build ID is %s "
+			   "but local file does not have build ID"),
+			 remote_hex);
+    }
+
+  local_id = so->abfd->build_id->data;
+  local_idsz = so->abfd->build_id->size;
+
+  if (so->build_idsz != local_idsz
+      || memcmp (so->build_id, local_id, so->build_idsz) != 0)
+    {
+      char *remote_hex, *local_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+      local_hex = alloca (local_idsz * 2 + 1);
+      bin2hex (local_id, local_hex, local_idsz);
+
+      return xstrprintf (_("remote build ID %s "
+			   "does not match local build ID %s"),
+			 remote_hex, local_hex);
+    }
+
+  /* Both build IDs are present and they match.  */
+  return NULL;
+}
+
 /* Implement the "open_symbol_file_object" target_so_ops method.
 
    If no open symbol file, attempt to locate and open the main symbol
@@ -1108,6 +1168,12 @@ svr4_copy_library_list (struct so_list *src)
       newobj->lm_info = xmalloc (sizeof (struct lm_info));
       memcpy (newobj->lm_info, src->lm_info, sizeof (struct lm_info));
 
+      if (newobj->build_id != NULL)
+	{
+	  newobj->build_id = xmalloc (src->build_idsz);
+	  memcpy (newobj->build_id, src->build_id, src->build_idsz);
+	}
+
       newobj->next = NULL;
       *link = newobj;
       link = &newobj->next;
@@ -1135,6 +1201,9 @@ library_list_start_library (struct gdb_xml_parser *parser,
   ULONGEST *lmp = xml_find_attribute (attributes, "lm")->value;
   ULONGEST *l_addrp = xml_find_attribute (attributes, "l_addr")->value;
   ULONGEST *l_ldp = xml_find_attribute (attributes, "l_ld")->value;
+  const struct gdb_xml_value *const att_build_id
+    = xml_find_attribute (attributes, "build-id");
+  const char *const hex_build_id = att_build_id ? att_build_id->value : NULL;
   struct so_list *new_elem;
 
   new_elem = XCNEW (struct so_list);
@@ -1146,6 +1215,25 @@ library_list_start_library (struct gdb_xml_parser *parser,
   strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
   new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
   strcpy (new_elem->so_original_name, new_elem->so_name);
+  if (hex_build_id != NULL)
+    {
+      const size_t hex_build_id_len = strlen (hex_build_id);
+
+      if (hex_build_id_len > 0 && (hex_build_id_len & 1U) == 0)
+	{
+	  const size_t build_idsz = hex_build_id_len / 2;
+
+	  new_elem->build_id = xmalloc (build_idsz);
+	  new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id,
+					  build_idsz);
+	  if (new_elem->build_idsz != build_idsz)
+	    {
+	      xfree (new_elem->build_id);
+	      new_elem->build_id = NULL;
+	      new_elem->build_idsz = 0;
+	    }
+	}
+    }
 
   *list->tailp = new_elem;
   list->tailp = &new_elem->next;
@@ -1180,6 +1268,7 @@ static const struct gdb_xml_attribute svr4_library_attributes[] =
   { "lm", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_addr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_ld", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
+  { "build-id", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -3258,4 +3347,5 @@ _initialize_svr4_solib (void)
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
   svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
   svr4_so_ops.handle_event = svr4_handle_solib_event;
+  svr4_so_ops.validate = svr4_validate;
 }
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index f14363a..13cbd26 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "vec.h"
 #include "solib-target.h"
+#include "solib.h"
 
 /* Private data for each loaded library.  */
 struct lm_info
@@ -506,6 +507,7 @@ _initialize_solib_target (void)
   solib_target_so_ops.in_dynsym_resolve_code
     = solib_target_in_dynsym_resolve_code;
   solib_target_so_ops.bfd_open = solib_bfd_open;
+  solib_target_so_ops.validate = default_solib_validate;
 
   /* Set current_target_so_ops to solib_target_so_ops if not already
      set.  */
diff --git a/gdb/solib.c b/gdb/solib.c
index 0010c2f..4bd47d0 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -523,6 +523,20 @@ solib_bfd_open (char *pathname)
   return abfd;
 }
 
+/* Boolean for command 'set solib-build-id-force'.  */
+static int solib_build_id_force = 0;
+
+/* Implement 'show solib-build-id-force'.  */
+
+static void
+show_solib_build_id_force (struct ui_file *file, int from_tty,
+			   struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Loading of shared libraries "
+			    "with non-matching build-id is %s.\n"),
+		    value);
+}
+
 /* Given a pointer to one of the shared objects in our list of mapped
    objects, use the recorded name to open a bfd descriptor for the
    object, build a section table, relocate all the section addresses
@@ -539,7 +553,7 @@ static int
 solib_map_sections (struct so_list *so)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-  char *filename;
+  char *filename, *validate_error;
   struct target_section *p;
   struct cleanup *old_chain;
   bfd *abfd;
@@ -555,6 +569,27 @@ solib_map_sections (struct so_list *so)
   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
   so->abfd = abfd;
 
+  gdb_assert (ops->validate != NULL);
+
+  validate_error = ops->validate (so);
+  if (validate_error != NULL)
+    {
+      if (!solib_build_id_force)
+	{
+	  warning (_("Shared object \"%s\" could not be validated (%s) and "
+	             "will be ignored; or use 'set solib-build-id-force'."),
+		   so->so_name, validate_error);
+	  xfree (validate_error);
+	  gdb_bfd_unref (so->abfd);
+	  so->abfd = NULL;
+	  return 0;
+	}
+      warning (_("Shared object \"%s\" could not be validated (%s) "
+		 "but it is being loaded due to 'set solib-build-id-force'."),
+	       so->so_name, validate_error);
+      xfree (validate_error);
+    }
+
   /* Copy the full path name into so_name, allowing symbol_file_add
      to find it later.  This also affects the =library-loaded GDB/MI
      event, and in particular the part of that notification providing
@@ -631,6 +666,9 @@ clear_so (struct so_list *so)
      of the symbol file.  */
   strcpy (so->so_name, so->so_original_name);
 
+  xfree (so->build_id);
+  so->build_id = NULL;
+
   /* Do the same for target-specific data.  */
   if (ops->clear_so != NULL)
     ops->clear_so (so);
@@ -1662,6 +1700,14 @@ remove_user_added_objfile (struct objfile *objfile)
     }
 }
 
+/* Default implementation does not perform any validation.  */
+
+char *
+default_solib_validate (const struct so_list *const so)
+{
+  return NULL; /* No validation.  */
+}
+
 extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
 
 void
@@ -1719,4 +1765,18 @@ PATH and LD_LIBRARY_PATH."),
 				     reload_shared_libraries,
 				     show_solib_search_path,
 				     &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("solib-build-id-force", class_support,
+			   &solib_build_id_force, _("\
+Set loading of shared libraries with non-matching build-id."), _("\
+Show loading of shared libraries with non-matching build-id."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (on) or disables (off) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+			   NULL,
+			   show_solib_build_id_force,
+			   &setlist, &showlist);
+
 }
diff --git a/gdb/solib.h b/gdb/solib.h
index 336971d..c3bf529 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -98,4 +98,8 @@ extern void update_solib_breakpoints (void);
 
 extern void handle_solib_event (void);
 
+/* Default validation always returns 1.  */
+
+extern char *default_solib_validate (const struct so_list *so);
+
 #endif /* SOLIB_H */
diff --git a/gdb/solist.h b/gdb/solist.h
index 7021f5c..f0d8653 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -75,6 +75,22 @@ struct so_list
        There may not be just one (e.g. if two segments are relocated
        differently); but this is only used for "info sharedlibrary".  */
     CORE_ADDR addr_low, addr_high;
+
+    /* Build id in raw format, contains verbatim contents of
+       .note.gnu.build-id including note header.  This is actual
+       BUILD_ID which comes either from the remote target via qXfer
+       packet or via reading target memory.  Therefore, it may differ
+       from the build-id of the associated bfd.  In a normal
+       scenario, this so would soon lose its abfd due to failed
+       validation.
+       Reading target memory should be done by following execution view
+       of the binary (following program headers in the case of ELF).
+       Computing address from the linking view (following ELF section
+       headers) may give incorrect build-id memory address despite the
+       symbols still match.
+       Such an example is a prelinked vs.  unprelinked i386 ELF file.  */
+    size_t build_idsz;
+    gdb_byte *build_id;
   };
 
 struct target_so_ops
@@ -168,6 +184,11 @@ struct target_so_ops
        NULL, in which case no specific preprocessing is necessary
        for this target.  */
     void (*handle_event) (void);
+
+    /* Return NULL if SO does match target SO it is supposed to
+       represent.  Otherwise return string describing why it does not match.
+       Caller has to free the string.  */
+    char *(*validate) (const struct so_list *so);
   };
 
 /* Free the memory associated with a (so_list *).  */
-- 
2.1.0

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-21 10:16   ` [PATCH v8 " Jan Kratochvil
@ 2015-06-22 12:55     ` Aleksandar Ristovski
  2015-06-22 20:37       ` Jan Kratochvil
  2015-06-22 22:25     ` Doug Evans
  1 sibling, 1 reply; 44+ messages in thread
From: Aleksandar Ristovski @ 2015-06-22 12:55 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches

FWIW, looks good to me.

Minor thing: it seems you did not put space before the comment block, but
in the practice most of such blocks are separated by an empty line from
the previous.
Example: 
...
}
+/* Boolean for command 'set solib-build-id-force'.  */
...


Thanks,

Aleksandar Ristovski
QNX Software Systems

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-22 12:55     ` Aleksandar Ristovski
@ 2015-06-22 20:37       ` Jan Kratochvil
  2015-06-22 20:41         ` Aleksandar Ristovski
  0 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-22 20:37 UTC (permalink / raw)
  To: Aleksandar Ristovski; +Cc: gdb-patches

On Mon, 22 Jun 2015 14:55:14 +0200, Aleksandar Ristovski wrote:
> Minor thing: it seems you did not put space before the comment block, but
> in the practice most of such blocks are separated by an empty line from
> the previous.
> Example: 
> ...
> }
> +/* Boolean for command 'set solib-build-id-force'.  */
> ...

I guess it is some mail reading problem.  The patch is:

1: }\n
2: \n
3:+/* Boolean for command 'set solib-build-id-force'.  */\n
4:+static int solib_build_id_force = 0;\n
5:+\n
6:+/* Implement 'show solib-build-id-force'.  */\n
7:+\n
8:+static void\n

I believe you ask about the empty line 2 - but that one is there.

The missing empty line between lines 3 and 4 and the present empty line 7 are
conforming to:
	https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-22 20:37       ` Jan Kratochvil
@ 2015-06-22 20:41         ` Aleksandar Ristovski
  0 siblings, 0 replies; 44+ messages in thread
From: Aleksandar Ristovski @ 2015-06-22 20:41 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On 2015-06-22, 4:37 PM, "Jan Kratochvil" <jan.kratochvil@redhat.com> wrote:

>On Mon, 22 Jun 2015 14:55:14 +0200, Aleksandar Ristovski wrote:
>> Minor thing: it seems you did not put space before the comment block,
>>but
>> in the practice most of such blocks are separated by an empty line from
>> the previous.
>> Example: 
>> ...
>> }
>> +/* Boolean for command 'set solib-build-id-force'.  */
>> ...
>
>I guess it is some mail reading problem.  The patch is:
>
>1: }\n
>2: \n

^^^^^^^^
This one appeared to be missing when I viewed the patch, apparently due to
the viewer.

Thanks,

Aleksandar

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-21 10:16   ` [PATCH v8 " Jan Kratochvil
  2015-06-22 12:55     ` Aleksandar Ristovski
@ 2015-06-22 22:25     ` Doug Evans
  2015-06-23 20:47       ` Jan Kratochvil
  2015-06-27 21:05       ` [PATCH v8 " Jan Kratochvil
  1 sibling, 2 replies; 44+ messages in thread
From: Doug Evans @ 2015-06-22 22:25 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Aleksandar Ristovski

On Sun, Jun 21, 2015 at 5:16 AM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Hi,
>
> updated for:
>         commit c74f7d1c6c5a968330208757f476c67a4bb66643
>         Author: Jon Turney <jon.turney@dronecode.org.uk>
>         Date:   Tue Apr 7 20:49:08 2015 +0100
>             Allow gdb to find debug symbols file by build-id for PE file format also
>
>
> Jan
>
>
> ---------- Forwarded message ----------
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> To:
> Cc:
> Date: Sun, 21 Jun 2015 11:51:52 +0200
> Subject: [PATCH 1/2] Validate symbol file using build-id
> Hi,
>
> consumer part of the "build-id" attribute.
>
> Approved by:
>         https://sourceware.org/ml/gdb-patches/2014-05/msg00424.html
>
>
> Jan
>
>
> gdb/ChangeLog
> 2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
>             Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         Validate symbol file using build-id.
>         * NEWS (Changes since GDB 7.9): Add 'set solib-build-id-force'
>         and 'show solib-build-id-force'.  Add build-id attribute.
>         * solib-darwin.c (_initialize_darwin_solib): Assign validate value.
>         * solib-dsbt.c (_initialize_dsbt_solib): Ditto.
>         * solib-frv.c (_initialize_frv_solib): Ditto.
>         * solib-spu.c (set_spu_solib_ops): Ditto.
>         * solib-svr4.c: Include rsp-low.h.
>         (NOTE_GNU_BUILD_ID_NAME): New define.
>         (svr4_validate): New function.
>         (svr4_copy_library_list): Duplicate field build_id.
>         (library_list_start_library): Parse 'build-id' attribute.
>         (svr4_library_attributes): Add 'build-id' attribute.
>         (_initialize_svr4_solib): Assign validate value.
>         * solib-target.c (solib.h): Include.
>         (_initialize_solib_target): Assign validate value.
>         * solib.c (solib_build_id_force, show_solib_build_id_force): New.
>         (solib_map_sections): Use ops->validate.
>         (clear_so): Free build_id.
>         (default_solib_validate): New function.
>         (_initialize_solib): Add "solib-build-id-force".
>         * solib.h (default_solib_validate): New declaration.
>         * solist.h (struct so_list): New fields 'build_idsz' and 'build_id'.
>         (target_so_ops): New field 'validate'.
>
> gdb/doc/ChangeLog
> 2014-03-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * gdb.texinfo (Files): Add 'set solib-build-id-force'
>         and 'show solib-build-id-force'.

IIUC this applies to symbol files (the main program) too, right?

If so, having solib in the option name is confusing.

set build-id-force
or
set require-build-id-match
or some such would be clearer.

> diff --git a/gdb/NEWS b/gdb/NEWS
> index 3ec5851..8cbe1fc 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -159,6 +159,12 @@ set debug linux-namespaces
>  show debug linux-namespaces
>    Control display of debugging info regarding Linux namespaces.
>
> +set solib-build-id-force (on|off)
> +show solib-build-id-force
> +  Inferior shared library and symbol file may contain unique build-id.
> +  If both build-ids are present but they do not match then this setting
> +  enables (on) or disables (off) loading of such symbol file.
> +
>  * The command 'thread apply all' can now support new option '-ascending'
>    to call its specified command for all threads in ascending order.
>
> @@ -233,6 +239,12 @@ fork-events and vfork-events features in qSupported
>  * GDB now supports access to vector registers on S/390 GNU/Linux
>    targets.
>
> +* New features in the GDB remote stub, GDBserver
> +
> +  ** library-list-svr4 contains also optional attribute 'build-id' for
> +     each library.  GDB does not load library with build-id that
> +     does not match such attribute.
> +
>  * Removed command line options
>
>  -xdb  HP-UX XDB compatibility mode.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 1460b7f..f7e4405 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -17912,6 +17912,44 @@ libraries that were loaded by explicit user requests are not
>  discarded.
>  @end table
>
> +@table @code
> +@kindex set solib-build-id-force
> +@cindex override @value{GDBN} build-id check
> +@item set solib-build-id-force @var{mode}
> +Setting to override @value{GDBN} build-id check.
> +
> +Inferior shared libraries and symbol files may contain unique build-id.
> +By default @value{GDBN} will ignore symbol files with non-matching build-id
> +while printing:
> +
> +@smallexample
> +  warning: Shared object "libfoo.so.1" could not be validated (remote
> +  build ID 2bc1745e does not match local build ID a08f8767) and will be
> +  ignored; or use 'set solib-build-id-force'.
> +@end smallexample
> +
> +Turning on this setting would load such symbol file while still printing:
> +
> +@smallexample
> +  warning: Shared object "libfoo.so.1" could not be validated (remote
> +  build ID 2bc1745e does not match local build ID a08f8767) but it is
> +  being loaded due to 'set solib-build-id-force'.
> +@end smallexample
> +
> +If remote build-id is present but it does not match local build-id (or local
> +build-id is not present) then this setting enables (@var{mode} is @code{on}) or
> +disables (@var{mode} is @code{off}) loading of such symbol file.  On systems
> +where build-id is not present in the remote system this setting has no effect.
> +The default value is @code{off}.
> +
> +Loading non-matching symbol file may confuse debugging including breakage
> +of backtrace output.
> +
> +@kindex show solib-build-id-force
> +@item show solib-build-id-force
> +Display the current mode of build-id check override.
> +@end table
> +
>  Sometimes you may wish that @value{GDBN} stops and gives you control
>  when any of shared library events happen.  The best way to do this is
>  to use @code{catch load} and @code{catch unload} (@pxref{Set
> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
> index f96841f..9309c35 100644
> --- a/gdb/solib-darwin.c
> +++ b/gdb/solib-darwin.c
> @@ -634,4 +634,5 @@ _initialize_darwin_solib (void)
>    darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
>    darwin_so_ops.lookup_lib_global_symbol = darwin_lookup_lib_symbol;
>    darwin_so_ops.bfd_open = darwin_bfd_open;
> +  darwin_so_ops.validate = default_solib_validate;
>  }
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index 7da5833..9fe6533 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -1080,6 +1080,7 @@ _initialize_dsbt_solib (void)
>    dsbt_so_ops.open_symbol_file_object = open_symbol_file_object;
>    dsbt_so_ops.in_dynsym_resolve_code = dsbt_in_dynsym_resolve_code;
>    dsbt_so_ops.bfd_open = solib_bfd_open;
> +  dsbt_so_ops.validate = default_solib_validate;
>
>    /* Debug this file's internals.  */
>    add_setshow_zuinteger_cmd ("solib-dsbt", class_maintenance,
> diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
> index f7ef38b..b768146 100644
> --- a/gdb/solib-frv.c
> +++ b/gdb/solib-frv.c
> @@ -1183,6 +1183,7 @@ _initialize_frv_solib (void)
>    frv_so_ops.open_symbol_file_object = open_symbol_file_object;
>    frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
>    frv_so_ops.bfd_open = solib_bfd_open;
> +  frv_so_ops.validate = default_solib_validate;
>
>    /* Debug this file's internals.  */
>    add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
> diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
> index 44fbf91..d162884 100644
> --- a/gdb/solib-spu.c
> +++ b/gdb/solib-spu.c
> @@ -519,6 +519,7 @@ set_spu_solib_ops (struct gdbarch *gdbarch)
>        spu_so_ops.current_sos = spu_current_sos;
>        spu_so_ops.bfd_open = spu_bfd_open;
>        spu_so_ops.lookup_lib_global_symbol = spu_lookup_lib_symbol;
> +      spu_so_ops.validate = default_solib_validate;
>      }
>
>    set_solib_ops (gdbarch, &spu_so_ops);
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 909dfb7..b434c1f 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -45,6 +45,9 @@
>  #include "auxv.h"
>  #include "gdb_bfd.h"
>  #include "probe.h"
> +#include "rsp-low.h"
> +
> +#define NOTE_GNU_BUILD_ID_NAME  ".note.gnu.build-id"
>
>  static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
>  static int svr4_have_link_map_offsets (void);
> @@ -970,6 +973,63 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
>    return (name_lm >= vaddr && name_lm < vaddr + size);
>  }
>
> +/* Validate SO by comparing build-id from the associated bfd and
> +   corresponding build-id from target memory.  */

Please document that the result is an error message or NULL for success
(including missing build id), and that the caller must free it.
I realize you say so in the docs for the "validate" "method",
but the comment here doesn't mention it is the validate method
(which would be a fine alternative to repeating all the docs
of the method).

> +
> +static char *
> +svr4_validate (const struct so_list *const so)
> +{
> +  const bfd_byte *local_id;
> +  size_t local_idsz;
> +
> +  gdb_assert (so != NULL);
> +
> +  /* Target doesn't support reporting the build ID or the remote shared library
> +     does not have build ID.  */
> +  if (so->build_id == NULL)
> +    return NULL;
> +
> +  /* Build ID may be present in the local file, just GDB is unable to retrieve
> +     it.  As it has been reported by gdbserver it is not FSF gdbserver.  */
> +  if (so->abfd == NULL
> +      || !bfd_check_format (so->abfd, bfd_object))
> +    return NULL;
> +
> +  /* GDB has verified the local file really does not contain the build ID.  */
> +  if (so->abfd->build_id == NULL)
> +    {
> +      char *remote_hex;
> +
> +      remote_hex = alloca (so->build_idsz * 2 + 1);
> +      bin2hex (so->build_id, remote_hex, so->build_idsz);
> +
> +      return xstrprintf (_("remote build ID is %s "
> +                          "but local file does not have build ID"),
> +                        remote_hex);
> +    }
> +
> +  local_id = so->abfd->build_id->data;
> +  local_idsz = so->abfd->build_id->size;
> +
> +  if (so->build_idsz != local_idsz
> +      || memcmp (so->build_id, local_id, so->build_idsz) != 0)
> +    {
> +      char *remote_hex, *local_hex;
> +
> +      remote_hex = alloca (so->build_idsz * 2 + 1);
> +      bin2hex (so->build_id, remote_hex, so->build_idsz);
> +      local_hex = alloca (local_idsz * 2 + 1);
> +      bin2hex (local_id, local_hex, local_idsz);
> +
> +      return xstrprintf (_("remote build ID %s "
> +                          "does not match local build ID %s"),
> +                        remote_hex, local_hex);
> +    }
> +
> +  /* Both build IDs are present and they match.  */
> +  return NULL;
> +}
> +
>  /* Implement the "open_symbol_file_object" target_so_ops method.
>
>     If no open symbol file, attempt to locate and open the main symbol
> @@ -1108,6 +1168,12 @@ svr4_copy_library_list (struct so_list *src)
>        newobj->lm_info = xmalloc (sizeof (struct lm_info));
>        memcpy (newobj->lm_info, src->lm_info, sizeof (struct lm_info));
>
> +      if (newobj->build_id != NULL)
> +       {
> +         newobj->build_id = xmalloc (src->build_idsz);
> +         memcpy (newobj->build_id, src->build_id, src->build_idsz);
> +       }
> +
>        newobj->next = NULL;
>        *link = newobj;
>        link = &newobj->next;
> @@ -1135,6 +1201,9 @@ library_list_start_library (struct gdb_xml_parser *parser,
>    ULONGEST *lmp = xml_find_attribute (attributes, "lm")->value;
>    ULONGEST *l_addrp = xml_find_attribute (attributes, "l_addr")->value;
>    ULONGEST *l_ldp = xml_find_attribute (attributes, "l_ld")->value;
> +  const struct gdb_xml_value *const att_build_id
> +    = xml_find_attribute (attributes, "build-id");
> +  const char *const hex_build_id = att_build_id ? att_build_id->value : NULL;
>    struct so_list *new_elem;
>
>    new_elem = XCNEW (struct so_list);
> @@ -1146,6 +1215,25 @@ library_list_start_library (struct gdb_xml_parser *parser,
>    strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
>    new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
>    strcpy (new_elem->so_original_name, new_elem->so_name);
> +  if (hex_build_id != NULL)
> +    {
> +      const size_t hex_build_id_len = strlen (hex_build_id);
> +
> +      if (hex_build_id_len > 0 && (hex_build_id_len & 1U) == 0)
> +       {
> +         const size_t build_idsz = hex_build_id_len / 2;
> +
> +         new_elem->build_id = xmalloc (build_idsz);
> +         new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id,
> +                                         build_idsz);
> +         if (new_elem->build_idsz != build_idsz)
> +           {

This happens for a malformed build id, right?
A warning would be useful here.
It'd also be nice to have a warning for an odd count.

> +             xfree (new_elem->build_id);
> +             new_elem->build_id = NULL;
> +             new_elem->build_idsz = 0;
> +           }
> +       }
> +    }
>
>    *list->tailp = new_elem;
>    list->tailp = &new_elem->next;
> @@ -1180,6 +1268,7 @@ static const struct gdb_xml_attribute svr4_library_attributes[] =
>    { "lm", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
>    { "l_addr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
>    { "l_ld", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
> +  { "build-id", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { NULL, GDB_XML_AF_NONE, NULL, NULL }
>  };
>
> @@ -3258,4 +3347,5 @@ _initialize_svr4_solib (void)
>    svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
>    svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
>    svr4_so_ops.handle_event = svr4_handle_solib_event;
> +  svr4_so_ops.validate = svr4_validate;
>  }
> diff --git a/gdb/solib-target.c b/gdb/solib-target.c
> index f14363a..13cbd26 100644
> --- a/gdb/solib-target.c
> +++ b/gdb/solib-target.c
> @@ -25,6 +25,7 @@
>  #include "target.h"
>  #include "vec.h"
>  #include "solib-target.h"
> +#include "solib.h"
>
>  /* Private data for each loaded library.  */
>  struct lm_info
> @@ -506,6 +507,7 @@ _initialize_solib_target (void)
>    solib_target_so_ops.in_dynsym_resolve_code
>      = solib_target_in_dynsym_resolve_code;
>    solib_target_so_ops.bfd_open = solib_bfd_open;
> +  solib_target_so_ops.validate = default_solib_validate;
>
>    /* Set current_target_so_ops to solib_target_so_ops if not already
>       set.  */
> diff --git a/gdb/solib.c b/gdb/solib.c
> index 0010c2f..4bd47d0 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -523,6 +523,20 @@ solib_bfd_open (char *pathname)
>    return abfd;
>  }
>
> +/* Boolean for command 'set solib-build-id-force'.  */
> +static int solib_build_id_force = 0;
> +
> +/* Implement 'show solib-build-id-force'.  */
> +
> +static void
> +show_solib_build_id_force (struct ui_file *file, int from_tty,
> +                          struct cmd_list_element *c, const char *value)
> +{
> +  fprintf_filtered (file, _("Loading of shared libraries "
> +                           "with non-matching build-id is %s.\n"),
> +                   value);
> +}
> +
>  /* Given a pointer to one of the shared objects in our list of mapped
>     objects, use the recorded name to open a bfd descriptor for the
>     object, build a section table, relocate all the section addresses
> @@ -539,7 +553,7 @@ static int
>  solib_map_sections (struct so_list *so)
>  {
>    const struct target_so_ops *ops = solib_ops (target_gdbarch ());
> -  char *filename;
> +  char *filename, *validate_error;
>    struct target_section *p;
>    struct cleanup *old_chain;
>    bfd *abfd;
> @@ -555,6 +569,27 @@ solib_map_sections (struct so_list *so)
>    /* Leave bfd open, core_xfer_memory and "info files" need it.  */
>    so->abfd = abfd;
>
> +  gdb_assert (ops->validate != NULL);
> +
> +  validate_error = ops->validate (so);
> +  if (validate_error != NULL)
> +    {
> +      if (!solib_build_id_force)
> +       {
> +         warning (_("Shared object \"%s\" could not be validated (%s) and "
> +                    "will be ignored; or use 'set solib-build-id-force'."),
> +                  so->so_name, validate_error);
> +         xfree (validate_error);
> +         gdb_bfd_unref (so->abfd);
> +         so->abfd = NULL;
> +         return 0;
> +       }
> +      warning (_("Shared object \"%s\" could not be validated (%s) "
> +                "but it is being loaded due to 'set solib-build-id-force'."),
> +              so->so_name, validate_error);
> +      xfree (validate_error);
> +    }
> +
>    /* Copy the full path name into so_name, allowing symbol_file_add
>       to find it later.  This also affects the =library-loaded GDB/MI
>       event, and in particular the part of that notification providing
> @@ -631,6 +666,9 @@ clear_so (struct so_list *so)
>       of the symbol file.  */
>    strcpy (so->so_name, so->so_original_name);
>
> +  xfree (so->build_id);
> +  so->build_id = NULL;
> +
>    /* Do the same for target-specific data.  */
>    if (ops->clear_so != NULL)
>      ops->clear_so (so);
> @@ -1662,6 +1700,14 @@ remove_user_added_objfile (struct objfile *objfile)
>      }
>  }
>
> +/* Default implementation does not perform any validation.  */
> +
> +char *
> +default_solib_validate (const struct so_list *const so)
> +{
> +  return NULL; /* No validation.  */
> +}
> +
>  extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
>
>  void
> @@ -1719,4 +1765,18 @@ PATH and LD_LIBRARY_PATH."),
>                                      reload_shared_libraries,
>                                      show_solib_search_path,
>                                      &setlist, &showlist);
> +
> +  add_setshow_boolean_cmd ("solib-build-id-force", class_support,
> +                          &solib_build_id_force, _("\
> +Set loading of shared libraries with non-matching build-id."), _("\
> +Show loading of shared libraries with non-matching build-id."), _("\
> +Inferior shared library and symbol file may contain unique build-id.\n\
> +If both build-ids are present but they do not match then this setting\n\
> +enables (on) or disables (off) loading of such symbol file.\n\
> +Loading non-matching symbol file may confuse debugging including breakage\n\
> +of backtrace output."),
> +                          NULL,
> +                          show_solib_build_id_force,
> +                          &setlist, &showlist);
> +
>  }
> diff --git a/gdb/solib.h b/gdb/solib.h
> index 336971d..c3bf529 100644
> --- a/gdb/solib.h
> +++ b/gdb/solib.h
> @@ -98,4 +98,8 @@ extern void update_solib_breakpoints (void);
>
>  extern void handle_solib_event (void);
>
> +/* Default validation always returns 1.  */
> +
> +extern char *default_solib_validate (const struct so_list *so);
> +
>  #endif /* SOLIB_H */
> diff --git a/gdb/solist.h b/gdb/solist.h
> index 7021f5c..f0d8653 100644
> --- a/gdb/solist.h
> +++ b/gdb/solist.h
> @@ -75,6 +75,22 @@ struct so_list
>         There may not be just one (e.g. if two segments are relocated
>         differently); but this is only used for "info sharedlibrary".  */
>      CORE_ADDR addr_low, addr_high;
> +
> +    /* Build id in raw format, contains verbatim contents of
> +       .note.gnu.build-id including note header.

Including the note header will be confusing to readers.
Is there a reason to include it?

OTOH, given the above call to hex2bin,
does this really include the note header?

> ... This is actual
> +       BUILD_ID which comes either from the remote target via qXfer
> +       packet or via reading target memory.  Therefore, it may differ
> +       from the build-id of the associated bfd.  In a normal
> +       scenario, this so would soon lose its abfd due to failed
> +       validation.

I can't read this last sentence.
What are you trying to say here?

> +       Reading target memory should be done by following execution view
> +       of the binary (following program headers in the case of ELF).
> +       Computing address from the linking view (following ELF section
> +       headers) may give incorrect build-id memory address despite the
> +       symbols still match.
> +       Such an example is a prelinked vs.  unprelinked i386 ELF file.  */
> +    size_t build_idsz;
> +    gdb_byte *build_id;
>    };
>
>  struct target_so_ops
> @@ -168,6 +184,11 @@ struct target_so_ops
>         NULL, in which case no specific preprocessing is necessary
>         for this target.  */
>      void (*handle_event) (void);
> +
> +    /* Return NULL if SO does match target SO it is supposed to
> +       represent.  Otherwise return string describing why it does not match.
> +       Caller has to free the string.  */
> +    char *(*validate) (const struct so_list *so);
>    };
>
>  /* Free the memory associated with a (so_list *).  */
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-22 22:25     ` Doug Evans
@ 2015-06-23 20:47       ` Jan Kratochvil
  2015-07-08 14:44         ` Pedro Alves
  2015-06-27 21:05       ` [PATCH v8 " Jan Kratochvil
  1 sibling, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-23 20:47 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, Aleksandar Ristovski

On Tue, 23 Jun 2015 00:25:52 +0200, Doug Evans wrote:
> On Sun, Jun 21, 2015 at 5:16 AM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> >         * gdb.texinfo (Files): Add 'set solib-build-id-force'
> >         and 'show solib-build-id-force'.
> 
> IIUC this applies to symbol files (the main program) too, right?

No.  That is an extension I am working on as an add-on patchset, to be posted
in a week or two.

I expected this "solib" patchset will be already approved a long time ago so
the add-on patchset will make sense.  But given this patchset is still being
reviewed and the new patchset will change some parts of this one I am curious
whether I should not rather merge the second patchset into the first one and
start the review process from scratch.


> If so, having solib in the option name is confusing.
> 
> set build-id-force
> or
> set require-build-id-match
> or some such would be clearer.

The new patchset is being cooked as the last commits without ChangeLogs at:
	https://sourceware.org/git/?p=archer.git;a=log;h=refs/heads/jankratochvil/gdbserverbuildid
Particularly:
	https://sourceware.org/git/?p=archer.git;a=commitdiff;h=79c03cbb287878d3e5fcfb8104bdd21aa712f013
	-set solib-build-id-force (on|off)
	+set build-id-force (on|off)


> > +/* Validate SO by comparing build-id from the associated bfd and
> > +   corresponding build-id from target memory.  */
> 
> Please document that the result is an error message or NULL for success
> (including missing build id), and that the caller must free it.
> I realize you say so in the docs for the "validate" "method",
> but the comment here doesn't mention it is the validate method
> (which would be a fine alternative to repeating all the docs
> of the method).

I agree; although it gets reworked in the add-on patchset anyway.
	https://sourceware.org/git/?p=archer.git;a=commitdiff;h=6d40ae1db39bdabb415a05aa909178d61cb519ed

> > +
> > +static char *
> > +svr4_validate (const struct so_list *const so)


> > @@ -1146,6 +1215,25 @@ library_list_start_library (struct gdb_xml_parser *parser,
> >    strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
> >    new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
> >    strcpy (new_elem->so_original_name, new_elem->so_name);
> > +  if (hex_build_id != NULL)
> > +    {
> > +      const size_t hex_build_id_len = strlen (hex_build_id);
> > +
> > +      if (hex_build_id_len > 0 && (hex_build_id_len & 1U) == 0)
> > +       {
> > +         const size_t build_idsz = hex_build_id_len / 2;
> > +
> > +         new_elem->build_id = xmalloc (build_idsz);
> > +         new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id,
> > +                                         build_idsz);
> > +         if (new_elem->build_idsz != build_idsz)
> > +           {
> 
> This happens for a malformed build id, right?

Yes.

> A warning would be useful here.
> It'd also be nice to have a warning for an odd count.

OK.


> > --- a/gdb/solist.h
> > +++ b/gdb/solist.h
> > @@ -75,6 +75,22 @@ struct so_list
> >         There may not be just one (e.g. if two segments are relocated
> >         differently); but this is only used for "info sharedlibrary".  */
> >      CORE_ADDR addr_low, addr_high;
> > +
> > +    /* Build id in raw format, contains verbatim contents of
> > +       .note.gnu.build-id including note header.
> 
> Including the note header will be confusing to readers.
> Is there a reason to include it?

It seems to simplify all the code.  I will recheck how the code looks if it
parses the note.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-22 22:25     ` Doug Evans
  2015-06-23 20:47       ` Jan Kratochvil
@ 2015-06-27 21:05       ` Jan Kratochvil
  2015-07-08 15:40         ` Doug Evans
  1 sibling, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-06-27 21:05 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, Aleksandar Ristovski

On Tue, 23 Jun 2015 00:25:52 +0200, Doug Evans wrote:
> On Sun, Jun 21, 2015 at 5:16 AM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> > --- a/gdb/solist.h
> > +++ b/gdb/solist.h
> > @@ -75,6 +75,22 @@ struct so_list
> >         There may not be just one (e.g. if two segments are relocated
> >         differently); but this is only used for "info sharedlibrary".  */
> >      CORE_ADDR addr_low, addr_high;
> > +
> > +    /* Build id in raw format, contains verbatim contents of
> > +       .note.gnu.build-id including note header.
> 
> Including the note header will be confusing to readers.
> Is there a reason to include it?
> 
> OTOH, given the above call to hex2bin,
> does this really include the note header?

It does not, only the comment was wrong.  Changed it to:
    /* Build id decoded from .note.gnu.build-id without note header.  This is
       actual BUILD_ID which comes either from the remote target via qXfer


> > ... This is actual
> > +       BUILD_ID which comes either from the remote target via qXfer
> > +       packet or via reading target memory.  Therefore, it may differ
> > +       from the build-id of the associated bfd.  In a normal
> > +       scenario, this so would soon lose its abfd due to failed
> > +       validation.
> 
> I can't read this last sentence.
> What are you trying to say here?

It was written by Aleksandar Ristovski and I find it OK myself.
So as an explanation the process is:

1. GDB reads/receives so->build_id from GDB server.
2. GDB opens local BFD so->abfd.
3. GDB compares so->build_id with so->abfd->build_id (by ops->validate)
4. If they differ so->abfd is freed/cleared (in solib_map_sections).

Therefore could you suggest a different comment?


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags
  2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
  2015-06-15 13:34   ` Joel Brobecker
@ 2015-07-08 14:38   ` Pedro Alves
  1 sibling, 0 replies; 44+ messages in thread
From: Pedro Alves @ 2015-07-08 14:38 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches; +Cc: Aleksandar Ristovski

On 06/14/2015 08:26 PM, Jan Kratochvil wrote:
> Hi Sergio,
> 
> this is an unrelated cleanup, bit mask ints are better to make enums as GDB
> already has support to automatically decode them:
> 
> before this patch:
> 	(gdb) p filterflags
> 	$1 = 51
> 	(gdb) p/x filterflags
> 	$2 = 0x33
> 
> after this patch:
> 	(gdb) p filterflags
> 	$1 = (COREFILTER_ANON_PRIVATE | COREFILTER_ANON_SHARED | COREFILTER_ELF_HEADERS | COREFILTER_HUGETLB_PRIVATE)
> 
> New patch, not yet reviewed before.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 05/10] Move gdb_regex* to common/
  2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* " Jan Kratochvil
@ 2015-07-08 14:39   ` Pedro Alves
  2015-07-14 20:13     ` Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Pedro Alves @ 2015-07-08 14:39 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches; +Cc: Aleksandar Ristovski

On 06/14/2015 08:26 PM, Jan Kratochvil wrote:
> Hi,
> 
> later patches need regex support also in gdbserver.
> 
> New patch, not yet reviewed before.


> diff --git a/gdb/common/gdb_regex.h b/gdb/common/gdb_regex.h
> new file mode 100644
> index 0000000..85c9c72
> --- /dev/null
> +++ b/gdb/common/gdb_regex.h
> @@ -0,0 +1,36 @@
> +/* Portable <regex.h>.
> +   Copyright (C) 2000-2015 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef COMMON_GDB_REGEX_H
> +#define COMMON_GDB_REGEX_H 1
> +
> +#ifdef USE_INCLUDED_REGEX
> +# include "xregex.h"
> +#else
> +/* Request 4.2 BSD regex functions.  */
> +# define _REGEX_RE_COMP
> +# include <regex.h>
> +#endif
> +
> +/* From utils.c.  */

This comment is no longer true.

Otherwise lgtm.

> +struct cleanup *make_regfree_cleanup (regex_t *);
> +char *get_regcomp_error (int, regex_t *);
> +struct cleanup *compile_rx_or_error (regex_t *pattern, const char *rx,
> +				     const char *message);
> +

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 08/10] gdbserver build-id attribute generator
  2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
@ 2015-07-08 14:41   ` Pedro Alves
  0 siblings, 0 replies; 44+ messages in thread
From: Pedro Alves @ 2015-07-08 14:41 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches; +Cc: Aleksandar Ristovski

On 06/14/2015 08:26 PM, Jan Kratochvil wrote:
> Hi,
> 
> producer part of the new "build-id" XML attribute.
> 
> Probably approved by:
> 	https://sourceware.org/ml/gdb-patches/2014-05/msg00423.html
> Although there were minor changes due to trunk updates.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 10/10] Tests for validate symbol file using build-id
  2015-06-14 19:27 ` [PATCH v7 10/10] Tests for validate " Jan Kratochvil
@ 2015-07-08 14:44   ` Pedro Alves
  0 siblings, 0 replies; 44+ messages in thread
From: Pedro Alves @ 2015-07-08 14:44 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches; +Cc: Aleksandar Ristovski

On 06/14/2015 08:27 PM, Jan Kratochvil wrote:
> Hi,
> 
> new testcase.
> 
> There was no explicit approval by Tom Tromey in the series a year ago.
> 

OK, but please reformat the .c files to follow the GDB coding conventions.
Space before parens, function name at first column, etc.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-23 20:47       ` Jan Kratochvil
@ 2015-07-08 14:44         ` Pedro Alves
  2015-07-12 19:09           ` Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Pedro Alves @ 2015-07-08 14:44 UTC (permalink / raw)
  To: Jan Kratochvil, Doug Evans; +Cc: gdb-patches, Aleksandar Ristovski

Jan Kratochvil wrote:

> +static char *
> +svr4_validate (const struct so_list *const so)
> +{

...

> +      return xstrprintf (_("remote build ID is %s "
> +			   "but local file does not have build ID"),
> +			 remote_hex);

Seems odd to say "remote" here.  Can't these errors trigger with native
debugging as well?

Doug Evans wrote:
> 
>> > If so, having solib in the option name is confusing.
>> > 
>> > set build-id-force
>> > or
>> > set require-build-id-match
>> > or some such would be clearer.

"build-id-force" sound odd to me.  The latter sounds OK,
as would "set build-id-validation on/off/...".

With that, and once the previous issues raised are
addressed, I think this is good to go.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-06-27 21:05       ` [PATCH v8 " Jan Kratochvil
@ 2015-07-08 15:40         ` Doug Evans
  2015-07-12 19:27           ` Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Doug Evans @ 2015-07-08 15:40 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Aleksandar Ristovski

On Sat, Jun 27, 2015 at 4:05 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Tue, 23 Jun 2015 00:25:52 +0200, Doug Evans wrote:
>> On Sun, Jun 21, 2015 at 5:16 AM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
>> > --- a/gdb/solist.h
>> > +++ b/gdb/solist.h
>> > @@ -75,6 +75,22 @@ struct so_list
>> >         There may not be just one (e.g. if two segments are relocated
>> >         differently); but this is only used for "info sharedlibrary".  */
>> >      CORE_ADDR addr_low, addr_high;
>> > +
>> > +    /* Build id in raw format, contains verbatim contents of
>> > +       .note.gnu.build-id including note header.
>>
>> Including the note header will be confusing to readers.
>> Is there a reason to include it?
>>
>> OTOH, given the above call to hex2bin,
>> does this really include the note header?
>
> It does not, only the comment was wrong.  Changed it to:
>     /* Build id decoded from .note.gnu.build-id without note header.  This is
>        actual BUILD_ID which comes either from the remote target via qXfer
>
>
>> > ... This is actual
>> > +       BUILD_ID which comes either from the remote target via qXfer
>> > +       packet or via reading target memory.  Therefore, it may differ
>> > +       from the build-id of the associated bfd.  In a normal
>> > +       scenario, this so would soon lose its abfd due to failed
>> > +       validation.
>>
>> I can't read this last sentence.
>> What are you trying to say here?
>
> It was written by Aleksandar Ristovski and I find it OK myself.
> So as an explanation the process is:
>
> 1. GDB reads/receives so->build_id from GDB server.
> 2. GDB opens local BFD so->abfd.
> 3. GDB compares so->build_id with so->abfd->build_id (by ops->validate)
> 4. If they differ so->abfd is freed/cleared (in solib_map_sections).
>
> Therefore could you suggest a different comment?

I'd be ok with just deleting the last two sentences:

This is actual
BUILD_ID which comes either from the remote target via qXfer
packet or via reading target memory.

But if you want more I'm ok with:

This is actual
BUILD_ID which comes either from the remote target via qXfer
packet or via reading target memory. Note that if there's a
mismatch with the associated bfd then so->abfd will be cleared.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-07-08 14:44         ` Pedro Alves
@ 2015-07-12 19:09           ` Jan Kratochvil
  2015-07-12 19:29             ` [PATCH v9 " Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-12 19:09 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Doug Evans, gdb-patches, Aleksandar Ristovski

On Wed, 08 Jul 2015 16:44:25 +0200, Pedro Alves wrote:
> Jan Kratochvil wrote:
> 
> > +static char *
> > +svr4_validate (const struct so_list *const so)
> > +{
> 
> ...
> 
> > +      return xstrprintf (_("remote build ID is %s "
> > +			   "but local file does not have build ID"),
> > +			 remote_hex);
> 
> Seems odd to say "remote" here.  Can't these errors trigger with native
> debugging as well?

For this patchset not yet.  The message is changed in a later patchset being
prepared where it applies also for local files.


> Doug Evans wrote:
> > 
> >> > If so, having solib in the option name is confusing.
> >> > 
> >> > set build-id-force
> >> > or
> >> > set require-build-id-match
> >> > or some such would be clearer.
> 
> "build-id-force" sound odd to me.  The latter sounds OK,
> as would "set build-id-validation on/off/...".

OK, I will change it to "set build-id-validation on/off/...".


> With that, and once the previous issues raised are
> addressed, I think this is good to go.

There patches are left without reply:
	[PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
	[PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move
	[PATCH v7 07/10] Move linux_find_memory_regions_full & co.

There particularly the [PATCH v7 06/10] contains non-mechanical (a bit)
changes.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 09/10] Validate symbol file using build-id
  2015-07-08 15:40         ` Doug Evans
@ 2015-07-12 19:27           ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-12 19:27 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches, Aleksandar Ristovski

On Wed, 08 Jul 2015 17:39:14 +0200, Doug Evans wrote:
> On Sat, Jun 27, 2015 at 4:05 PM, Jan Kratochvil
> <jan.kratochvil@redhat.com> wrote:
> >> > ... This is actual
> >> > +       BUILD_ID which comes either from the remote target via qXfer
> >> > +       packet or via reading target memory.  Therefore, it may differ
> >> > +       from the build-id of the associated bfd.  In a normal
> >> > +       scenario, this so would soon lose its abfd due to failed
> >> > +       validation.
> >>
> >> I can't read this last sentence.
> >> What are you trying to say here?
> >
> > It was written by Aleksandar Ristovski and I find it OK myself.
> > So as an explanation the process is:
> >
> > 1. GDB reads/receives so->build_id from GDB server.
> > 2. GDB opens local BFD so->abfd.
> > 3. GDB compares so->build_id with so->abfd->build_id (by ops->validate)
> > 4. If they differ so->abfd is freed/cleared (in solib_map_sections).
> >
> > Therefore could you suggest a different comment?
> 
> I'd be ok with just deleting the last two sentences:
> 
> This is actual
> BUILD_ID which comes either from the remote target via qXfer
> packet or via reading target memory.
> 
> But if you want more I'm ok with:
> 
> This is actual
> BUILD_ID which comes either from the remote target via qXfer
> packet or via reading target memory. Note that if there's a
> mismatch with the associated bfd then so->abfd will be cleared.

Used the latter one.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-12 19:09           ` Jan Kratochvil
@ 2015-07-12 19:29             ` Jan Kratochvil
  2015-07-12 19:54               ` Eli Zaretskii
  0 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-12 19:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Doug Evans, gdb-patches, Aleksandar Ristovski, Eli Zaretskii

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

On Sun, 12 Jul 2015 21:09:21 +0200, Jan Kratochvil wrote:
> On Wed, 08 Jul 2015 16:44:25 +0200, Pedro Alves wrote:
> > Doug Evans wrote:
> > > 
> > >> > If so, having solib in the option name is confusing.
> > >> > 
> > >> > set build-id-force
> > >> > or
> > >> > set require-build-id-match
> > >> > or some such would be clearer.
> > 
> > "build-id-force" sound odd to me.  The latter sounds OK,
> > as would "set build-id-validation on/off/...".
> 
> OK, I will change it to "set build-id-validation on/off/...".

It required some language changes as it reversed its on<->off meaning,
therefore Ccing Eli.


Jan

[-- Attachment #2: Type: message/rfc822, Size: 18973 bytes --]

From: Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: [PATCH] Validate symbol file using build-id
Date: Sun, 12 Jul 2015 20:59:02 +0200

Hi,

consumer part of the "build-id" attribute.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00424.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Validate symbol file using build-id.
	* NEWS (Changes since GDB 7.9): Add 'set solib-build-id-validation'
	and 'show solib-build-id-validation'.  Add build-id attribute.
	* solib-darwin.c (_initialize_darwin_solib): Assign validate value.
	* solib-dsbt.c (_initialize_dsbt_solib): Ditto.
	* solib-frv.c (_initialize_frv_solib): Ditto.
	* solib-spu.c (set_spu_solib_ops): Ditto.
	* solib-svr4.c: Include rsp-low.h.
	(NOTE_GNU_BUILD_ID_NAME): New define.
	(svr4_validate): New function.
	(svr4_copy_library_list): Duplicate field build_id.
	(library_list_start_library): Parse 'build-id' attribute.
	(svr4_library_attributes): Add 'build-id' attribute.
	(_initialize_svr4_solib): Assign validate value.
	* solib-target.c (solib.h): Include.
	(_initialize_solib_target): Assign validate value.
	* solib.c (solib_build_id_validation, show_solib_build_id_validation):
	New.
	(solib_map_sections): Use ops->validate.
	(clear_so): Free build_id.
	(default_solib_validate): New function.
	(_initialize_solib): Add "solib-build-id-validation".
	* solib.h (default_solib_validate): New declaration.
	* solist.h (struct so_list): New fields 'build_idsz' and 'build_id'.
	(target_so_ops): New field 'validate'.

gdb/doc/ChangeLog
2014-03-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Files): Add 'set solib-build-id-validation'
	and 'show solib-build-id-validation'.
---
 gdb/NEWS            |  12 ++++++
 gdb/doc/gdb.texinfo |  38 +++++++++++++++++++
 gdb/solib-darwin.c  |   1 +
 gdb/solib-dsbt.c    |   1 +
 gdb/solib-frv.c     |   1 +
 gdb/solib-spu.c     |   1 +
 gdb/solib-svr4.c    | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/solib-target.c  |   2 +
 gdb/solib.c         |  64 +++++++++++++++++++++++++++++++-
 gdb/solib.h         |   4 ++
 gdb/solist.h        |  18 +++++++++
 11 files changed, 244 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 7ce9758..b07c973 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -194,6 +194,12 @@ maint set|show btrace pt skip-pad
   Set and show whether PAD packets are skipped when computing the
   packet history.
 
+set solib-build-id-validation (on|off)
+show solib-build-id-validation
+  Inferior shared library and symbol file may contain unique build-id.
+  If both build-ids are present but they do not match then this setting
+  enables (off) or disables (on) loading of such symbol file.
+
 * The command 'thread apply all' can now support new option '-ascending'
   to call its specified command for all threads in ascending order.
 
@@ -277,6 +283,12 @@ fork-events and vfork-events features in qSupported
 * GDB now supports access to vector registers on S/390 GNU/Linux
   targets.
 
+* New features in the GDB remote stub, GDBserver
+
+  ** library-list-svr4 contains also optional attribute 'build-id' for
+     each library.  GDB does not load library with build-id that
+     does not match such attribute.
+
 * Removed command line options
 
 -xdb  HP-UX XDB compatibility mode.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 932c38d..b017a6d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17950,6 +17950,44 @@ libraries that were loaded by explicit user requests are not
 discarded.
 @end table
 
+@table @code
+@kindex set solib-build-id-validation
+@cindex override @value{GDBN} build-id check
+@item set solib-build-id-validation @var{mode}
+Setting to override @value{GDBN} build-id check.
+
+Inferior shared libraries and symbol files may contain unique build-id.
+By default @value{GDBN} will ignore symbol files with non-matching build-id
+while printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) and will be
+  ignored; or use 'set solib-build-id-validation off'.
+@end smallexample
+
+Turning off this setting would load such symbol file while still printing:
+
+@smallexample
+  warning: Shared object "libfoo.so.1" could not be validated (remote
+  build ID 2bc1745e does not match local build ID a08f8767) but it is
+  being loaded due to 'set solib-build-id-validation off'.
+@end smallexample
+
+If remote build-id is present but it does not match local build-id (or local
+build-id is not present) then this setting enables (@var{mode} is @code{off}) or
+disables (@var{mode} is @code{on}) loading of such symbol file.  On systems
+where build-id is not present in the remote system this setting has no effect.
+The default value is @code{on}.
+
+Loading non-matching symbol file may confuse debugging including breakage
+of backtrace output.
+
+@kindex show solib-build-id-validation
+@item show solib-build-id-validation
+Display the current mode of build-id check override.
+@end table
+
 Sometimes you may wish that @value{GDBN} stops and gives you control
 when any of shared library events happen.  The best way to do this is
 to use @code{catch load} and @code{catch unload} (@pxref{Set
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index f96841f..9309c35 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -634,4 +634,5 @@ _initialize_darwin_solib (void)
   darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
   darwin_so_ops.lookup_lib_global_symbol = darwin_lookup_lib_symbol;
   darwin_so_ops.bfd_open = darwin_bfd_open;
+  darwin_so_ops.validate = default_solib_validate;
 }
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 7da5833..9fe6533 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -1080,6 +1080,7 @@ _initialize_dsbt_solib (void)
   dsbt_so_ops.open_symbol_file_object = open_symbol_file_object;
   dsbt_so_ops.in_dynsym_resolve_code = dsbt_in_dynsym_resolve_code;
   dsbt_so_ops.bfd_open = solib_bfd_open;
+  dsbt_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-dsbt", class_maintenance,
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index f7ef38b..b768146 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -1183,6 +1183,7 @@ _initialize_frv_solib (void)
   frv_so_ops.open_symbol_file_object = open_symbol_file_object;
   frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
   frv_so_ops.bfd_open = solib_bfd_open;
+  frv_so_ops.validate = default_solib_validate;
 
   /* Debug this file's internals.  */
   add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index 44fbf91..d162884 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -519,6 +519,7 @@ set_spu_solib_ops (struct gdbarch *gdbarch)
       spu_so_ops.current_sos = spu_current_sos;
       spu_so_ops.bfd_open = spu_bfd_open;
       spu_so_ops.lookup_lib_global_symbol = spu_lookup_lib_symbol;
+      spu_so_ops.validate = default_solib_validate;
     }
 
   set_solib_ops (gdbarch, &spu_so_ops);
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 909dfb7..71522c6 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -45,6 +45,9 @@
 #include "auxv.h"
 #include "gdb_bfd.h"
 #include "probe.h"
+#include "rsp-low.h"
+
+#define NOTE_GNU_BUILD_ID_NAME  ".note.gnu.build-id"
 
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static int svr4_have_link_map_offsets (void);
@@ -970,6 +973,64 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
   return (name_lm >= vaddr && name_lm < vaddr + size);
 }
 
+/* Validate SO by comparing build-id from the associated bfd and
+   corresponding build-id from target memory.  Return NULL for success
+   or a string for error.  Caller must call xfree for the error string.  */
+
+static char *
+svr4_validate (const struct so_list *const so)
+{
+  const bfd_byte *local_id;
+  size_t local_idsz;
+
+  gdb_assert (so != NULL);
+
+  /* Target doesn't support reporting the build ID or the remote shared library
+     does not have build ID.  */
+  if (so->build_id == NULL)
+    return NULL;
+
+  /* Build ID may be present in the local file, just GDB is unable to retrieve
+     it.  As it has been reported by gdbserver it is not FSF gdbserver.  */
+  if (so->abfd == NULL
+      || !bfd_check_format (so->abfd, bfd_object))
+    return NULL;
+
+  /* GDB has verified the local file really does not contain the build ID.  */
+  if (so->abfd->build_id == NULL)
+    {
+      char *remote_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+
+      return xstrprintf (_("remote build ID is %s "
+			   "but local file does not have build ID"),
+			 remote_hex);
+    }
+
+  local_id = so->abfd->build_id->data;
+  local_idsz = so->abfd->build_id->size;
+
+  if (so->build_idsz != local_idsz
+      || memcmp (so->build_id, local_id, so->build_idsz) != 0)
+    {
+      char *remote_hex, *local_hex;
+
+      remote_hex = alloca (so->build_idsz * 2 + 1);
+      bin2hex (so->build_id, remote_hex, so->build_idsz);
+      local_hex = alloca (local_idsz * 2 + 1);
+      bin2hex (local_id, local_hex, local_idsz);
+
+      return xstrprintf (_("remote build ID %s "
+			   "does not match local build ID %s"),
+			 remote_hex, local_hex);
+    }
+
+  /* Both build IDs are present and they match.  */
+  return NULL;
+}
+
 /* Implement the "open_symbol_file_object" target_so_ops method.
 
    If no open symbol file, attempt to locate and open the main symbol
@@ -1108,6 +1169,12 @@ svr4_copy_library_list (struct so_list *src)
       newobj->lm_info = xmalloc (sizeof (struct lm_info));
       memcpy (newobj->lm_info, src->lm_info, sizeof (struct lm_info));
 
+      if (newobj->build_id != NULL)
+	{
+	  newobj->build_id = xmalloc (src->build_idsz);
+	  memcpy (newobj->build_id, src->build_id, src->build_idsz);
+	}
+
       newobj->next = NULL;
       *link = newobj;
       link = &newobj->next;
@@ -1135,6 +1202,9 @@ library_list_start_library (struct gdb_xml_parser *parser,
   ULONGEST *lmp = xml_find_attribute (attributes, "lm")->value;
   ULONGEST *l_addrp = xml_find_attribute (attributes, "l_addr")->value;
   ULONGEST *l_ldp = xml_find_attribute (attributes, "l_ld")->value;
+  const struct gdb_xml_value *const att_build_id
+    = xml_find_attribute (attributes, "build-id");
+  const char *const hex_build_id = att_build_id ? att_build_id->value : NULL;
   struct so_list *new_elem;
 
   new_elem = XCNEW (struct so_list);
@@ -1146,6 +1216,37 @@ library_list_start_library (struct gdb_xml_parser *parser,
   strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1);
   new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0;
   strcpy (new_elem->so_original_name, new_elem->so_name);
+  if (hex_build_id != NULL)
+    {
+      const size_t hex_build_id_len = strlen (hex_build_id);
+
+      if (hex_build_id_len == 0)
+	warning (_("Shared library \"%s\" received empty build-id "
+	           "from gdbserver"), new_elem->so_original_name);
+      else if ((hex_build_id_len & 1U) != 0)
+	warning (_("Shared library \"%s\" received odd number "
+		   "of build-id \"%s\" hex characters from gdbserver"),
+		 new_elem->so_original_name, hex_build_id);
+      else
+	{
+	  const size_t build_idsz = hex_build_id_len / 2;
+
+	  new_elem->build_id = xmalloc (build_idsz);
+	  new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id,
+					  build_idsz);
+	  if (new_elem->build_idsz != build_idsz)
+	    {
+	      warning (_("Shared library \"%s\" received invalid "
+			 "build-id \"%s\" hex character at encoded byte "
+			 "position %s (first as 0) from gdbserver"),
+		       new_elem->so_original_name, hex_build_id,
+		       pulongest (new_elem->build_idsz));
+	      xfree (new_elem->build_id);
+	      new_elem->build_id = NULL;
+	      new_elem->build_idsz = 0;
+	    }
+	}
+    }
 
   *list->tailp = new_elem;
   list->tailp = &new_elem->next;
@@ -1180,6 +1281,7 @@ static const struct gdb_xml_attribute svr4_library_attributes[] =
   { "lm", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_addr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
   { "l_ld", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
+  { "build-id", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -3258,4 +3360,5 @@ _initialize_svr4_solib (void)
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
   svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
   svr4_so_ops.handle_event = svr4_handle_solib_event;
+  svr4_so_ops.validate = svr4_validate;
 }
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index f14363a..13cbd26 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "vec.h"
 #include "solib-target.h"
+#include "solib.h"
 
 /* Private data for each loaded library.  */
 struct lm_info
@@ -506,6 +507,7 @@ _initialize_solib_target (void)
   solib_target_so_ops.in_dynsym_resolve_code
     = solib_target_in_dynsym_resolve_code;
   solib_target_so_ops.bfd_open = solib_bfd_open;
+  solib_target_so_ops.validate = default_solib_validate;
 
   /* Set current_target_so_ops to solib_target_so_ops if not already
      set.  */
diff --git a/gdb/solib.c b/gdb/solib.c
index eb933c0..2ab8b80 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -518,6 +518,20 @@ solib_bfd_open (char *pathname)
   return abfd;
 }
 
+/* Boolean for command 'set solib-build-id-validation'.  */
+static int solib_build_id_validation = 1;
+
+/* Implement 'show solib-build-id-validation'.  */
+
+static void
+show_solib_build_id_validation (struct ui_file *file, int from_tty,
+				struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Validation a build-id matches to load a shared "
+			    "library is %s.\n"),
+		    value);
+}
+
 /* Given a pointer to one of the shared objects in our list of mapped
    objects, use the recorded name to open a bfd descriptor for the
    object, build a section table, relocate all the section addresses
@@ -534,7 +548,7 @@ static int
 solib_map_sections (struct so_list *so)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-  char *filename;
+  char *filename, *validate_error;
   struct target_section *p;
   struct cleanup *old_chain;
   bfd *abfd;
@@ -550,6 +564,29 @@ solib_map_sections (struct so_list *so)
   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
   so->abfd = abfd;
 
+  gdb_assert (ops->validate != NULL);
+
+  validate_error = ops->validate (so);
+  if (validate_error != NULL)
+    {
+      if (solib_build_id_validation)
+	{
+	  warning (_("Shared object \"%s\" could not be validated (%s) and "
+	             "will be ignored; "
+		     "or use 'set solib-build-id-validation off'."),
+		   so->so_name, validate_error);
+	  xfree (validate_error);
+	  gdb_bfd_unref (so->abfd);
+	  so->abfd = NULL;
+	  return 0;
+	}
+      warning (_("Shared object \"%s\" could not be validated (%s) "
+		 "but it is being loaded due to "
+		 "'set solib-build-id-validation off'."),
+	       so->so_name, validate_error);
+      xfree (validate_error);
+    }
+
   /* Copy the full path name into so_name, allowing symbol_file_add
      to find it later.  This also affects the =library-loaded GDB/MI
      event, and in particular the part of that notification providing
@@ -626,6 +663,9 @@ clear_so (struct so_list *so)
      of the symbol file.  */
   strcpy (so->so_name, so->so_original_name);
 
+  xfree (so->build_id);
+  so->build_id = NULL;
+
   /* Do the same for target-specific data.  */
   if (ops->clear_so != NULL)
     ops->clear_so (so);
@@ -1657,6 +1697,14 @@ remove_user_added_objfile (struct objfile *objfile)
     }
 }
 
+/* Default implementation does not perform any validation.  */
+
+char *
+default_solib_validate (const struct so_list *const so)
+{
+  return NULL; /* No validation.  */
+}
+
 extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
 
 void
@@ -1714,4 +1762,18 @@ PATH and LD_LIBRARY_PATH."),
 				     reload_shared_libraries,
 				     show_solib_search_path,
 				     &setlist, &showlist);
+
+  add_setshow_boolean_cmd ("solib-build-id-validation", class_support,
+			   &solib_build_id_validation, _("\
+Set validation a build-id matches to load a shared library."), _("\
+SHow validation a build-id matches to load a shared library."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (off) or disables (on) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+			   NULL,
+			   show_solib_build_id_validation,
+			   &setlist, &showlist);
+
 }
diff --git a/gdb/solib.h b/gdb/solib.h
index 336971d..c3bf529 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -98,4 +98,8 @@ extern void update_solib_breakpoints (void);
 
 extern void handle_solib_event (void);
 
+/* Default validation always returns 1.  */
+
+extern char *default_solib_validate (const struct so_list *so);
+
 #endif /* SOLIB_H */
diff --git a/gdb/solist.h b/gdb/solist.h
index 7021f5c..e6e74af 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -75,6 +75,19 @@ struct so_list
        There may not be just one (e.g. if two segments are relocated
        differently); but this is only used for "info sharedlibrary".  */
     CORE_ADDR addr_low, addr_high;
+
+    /* Build id decoded from .note.gnu.build-id without note header.  This is
+       actual BUILD_ID which comes either from the remote target via qXfer
+       packet or via reading target memory.  Note that if there's a
+       mismatch with the associated bfd then so->abfd will be cleared.
+       Reading target memory should be done by following execution view
+       of the binary (following program headers in the case of ELF).
+       Computing address from the linking view (following ELF section
+       headers) may give incorrect build-id memory address despite the
+       symbols still match.
+       Such an example is a prelinked vs. unprelinked i386 ELF file.  */
+    size_t build_idsz;
+    gdb_byte *build_id;
   };
 
 struct target_so_ops
@@ -168,6 +181,11 @@ struct target_so_ops
        NULL, in which case no specific preprocessing is necessary
        for this target.  */
     void (*handle_event) (void);
+
+    /* Return NULL if SO does match target SO it is supposed to
+       represent.  Otherwise return string describing why it does not match.
+       Caller has to free the string.  */
+    char *(*validate) (const struct so_list *so);
   };
 
 /* Free the memory associated with a (so_list *).  */
-- 
2.1.0

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-12 19:29             ` [PATCH v9 " Jan Kratochvil
@ 2015-07-12 19:54               ` Eli Zaretskii
  2015-07-12 20:01                 ` Jan Kratochvil
  2015-07-13 10:34                 ` Pedro Alves
  0 siblings, 2 replies; 44+ messages in thread
From: Eli Zaretskii @ 2015-07-12 19:54 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: palves, dje, gdb-patches, ARistovski

> Date: Sun, 12 Jul 2015 21:29:11 +0200
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: Doug Evans <dje@google.com>, gdb-patches <gdb-patches@sourceware.org>,
>         Aleksandar Ristovski <ARistovski@qnx.com>,
>         Eli Zaretskii <eliz@gnu.org>
> 
> > > "build-id-force" sound odd to me.  The latter sounds OK,
> > > as would "set build-id-validation on/off/...".
> > 
> > OK, I will change it to "set build-id-validation on/off/...".
> 
> It required some language changes as it reversed its on<->off meaning,
> therefore Ccing Eli.

It's OK, although I wonder whether solib-validate-build-id is perhaps
a better name.

Thanks.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-12 19:54               ` Eli Zaretskii
@ 2015-07-12 20:01                 ` Jan Kratochvil
  2015-07-13  2:30                   ` Eli Zaretskii
  2015-07-13 10:34                 ` Pedro Alves
  1 sibling, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-12 20:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: palves, dje, gdb-patches, ARistovski

On Sun, 12 Jul 2015 21:54:17 +0200, Eli Zaretskii wrote:
> > > OK, I will change it to "set build-id-validation on/off/...".
> > 
> > It required some language changes as it reversed its on<->off meaning,
> > therefore Ccing Eli.
> 
> It's OK, although I wonder whether solib-validate-build-id is perhaps
> a better name.

I do not have an opinion on it so tell me if there is some settlement on
a change request.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-12 20:01                 ` Jan Kratochvil
@ 2015-07-13  2:30                   ` Eli Zaretskii
  0 siblings, 0 replies; 44+ messages in thread
From: Eli Zaretskii @ 2015-07-13  2:30 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: palves, dje, gdb-patches, ARistovski

> Date: Sun, 12 Jul 2015 22:01:08 +0200
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: palves@redhat.com, dje@google.com, gdb-patches@sourceware.org,
>         ARistovski@qnx.com
> 
> On Sun, 12 Jul 2015 21:54:17 +0200, Eli Zaretskii wrote:
> > > > OK, I will change it to "set build-id-validation on/off/...".
> > > 
> > > It required some language changes as it reversed its on<->off meaning,
> > > therefore Ccing Eli.
> > 
> > It's OK, although I wonder whether solib-validate-build-id is perhaps
> > a better name.
> 
> I do not have an opinion on it so tell me if there is some settlement on
> a change request.

It was just a thought, feel free to disregard if you are okay with the
name you suggested.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-12 19:54               ` Eli Zaretskii
  2015-07-12 20:01                 ` Jan Kratochvil
@ 2015-07-13 10:34                 ` Pedro Alves
  2015-07-13 12:38                   ` Jan Kratochvil
  1 sibling, 1 reply; 44+ messages in thread
From: Pedro Alves @ 2015-07-13 10:34 UTC (permalink / raw)
  To: Eli Zaretskii, Jan Kratochvil; +Cc: dje, gdb-patches, ARistovski

On 07/12/2015 08:54 PM, Eli Zaretskii wrote:
>> Date: Sun, 12 Jul 2015 21:29:11 +0200
>> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>> Cc: Doug Evans <dje@google.com>, gdb-patches <gdb-patches@sourceware.org>,
>>         Aleksandar Ristovski <ARistovski@qnx.com>,
>>         Eli Zaretskii <eliz@gnu.org>
>>
>>>> "build-id-force" sound odd to me.  The latter sounds OK,
>>>> as would "set build-id-validation on/off/...".
>>>
>>> OK, I will change it to "set build-id-validation on/off/...".
>>
>> It required some language changes as it reversed its on<->off meaning,
>> therefore Ccing Eli.
> 
> It's OK, although I wonder whether solib-validate-build-id is perhaps
> a better name.

As the plan is for the feature to apply to the main executable too,
it's better that "solib" isn't part of the setting name.  I agree
that "validate-build-id" sounds better than "build-id-validation".

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-13 10:34                 ` Pedro Alves
@ 2015-07-13 12:38                   ` Jan Kratochvil
  2015-07-14 16:14                     ` Doug Evans
  0 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-13 12:38 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Eli Zaretskii, dje, gdb-patches, ARistovski

On Mon, 13 Jul 2015 12:34:33 +0200, Pedro Alves wrote:
> As the plan is for the feature to apply to the main executable too,
> it's better that "solib" isn't part of the setting name.  I agree
> that "validate-build-id" sounds better than "build-id-validation".

OK, so validate-build-id or solib-validate-build-id.

Just this series being approved is still only for shlib and I do not yet have
completely finished the second series for all binaries; although 7.10 is
branched so till 7.11 there is now really enough time to have it all.

So I do not know if I should call it in this shlib-only first series as
validate-build-id or as solib-validate-build-id.


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-13 12:38                   ` Jan Kratochvil
@ 2015-07-14 16:14                     ` Doug Evans
  2015-07-15  8:21                       ` Jan Kratochvil
  0 siblings, 1 reply; 44+ messages in thread
From: Doug Evans @ 2015-07-14 16:14 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Pedro Alves, Eli Zaretskii, gdb-patches, Aleksandar Ristovski

On Mon, Jul 13, 2015 at 5:38 AM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Mon, 13 Jul 2015 12:34:33 +0200, Pedro Alves wrote:
>> As the plan is for the feature to apply to the main executable too,
>> it's better that "solib" isn't part of the setting name.  I agree
>> that "validate-build-id" sounds better than "build-id-validation".
>
> OK, so validate-build-id or solib-validate-build-id.
>
> Just this series being approved is still only for shlib and I do not yet have
> completely finished the second series for all binaries; although 7.10 is
> branched so till 7.11 there is now really enough time to have it all.
>
> So I do not know if I should call it in this shlib-only first series as
> validate-build-id or as solib-validate-build-id.

One of the important bits for me is to not add an option knowing
we're going to rename it later.

We've just branched 7.10 and I'm guessing all of this will be
present for 7.11.

So I'd be ok with just adding a simple note somewhere saying
the option only applies to solibs at the moment and will
eventually also apply to exes.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v7 05/10] Move gdb_regex* to common/
  2015-07-08 14:39   ` Pedro Alves
@ 2015-07-14 20:13     ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-14 20:13 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Aleksandar Ristovski

On Wed, 08 Jul 2015 16:39:35 +0200, Pedro Alves wrote:
> On 06/14/2015 08:26 PM, Jan Kratochvil wrote:
> > diff --git a/gdb/common/gdb_regex.h b/gdb/common/gdb_regex.h
> > new file mode 100644
> > index 0000000..85c9c72
> > --- /dev/null
> > +++ b/gdb/common/gdb_regex.h
> > @@ -0,0 +1,36 @@
> > +/* Portable <regex.h>.
> > +   Copyright (C) 2000-2015 Free Software Foundation, Inc.
> > +
> > +   This file is part of GDB.
> > +
> > +   This program is free software; you can redistribute it and/or modify
> > +   it under the terms of the GNU General Public License as published by
> > +   the Free Software Foundation; either version 3 of the License, or
> > +   (at your option) any later version.
> > +
> > +   This program is distributed in the hope that it will be useful,
> > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +   GNU General Public License for more details.
> > +
> > +   You should have received a copy of the GNU General Public License
> > +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> > +
> > +#ifndef COMMON_GDB_REGEX_H
> > +#define COMMON_GDB_REGEX_H 1
> > +
> > +#ifdef USE_INCLUDED_REGEX
> > +# include "xregex.h"
> > +#else
> > +/* Request 4.2 BSD regex functions.  */
> > +# define _REGEX_RE_COMP
> > +# include <regex.h>
> > +#endif
> > +
> > +/* From utils.c.  */
> 
> This comment is no longer true.

Updated.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-14 16:14                     ` Doug Evans
@ 2015-07-15  8:21                       ` Jan Kratochvil
  2015-07-15 14:59                         ` Doug Evans
  0 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-15  8:21 UTC (permalink / raw)
  To: Doug Evans; +Cc: Pedro Alves, Eli Zaretskii, gdb-patches, Aleksandar Ristovski

On Tue, 14 Jul 2015 18:13:26 +0200, Doug Evans wrote:
> So I'd be ok with just adding a simple note somewhere saying
> the option only applies to solibs at the moment and will
> eventually also apply to exes.

So the option is now called 'validate-build-id'.

Its description everywhere (NEWS+gdb.texinfo+'help set validate-build-id')
talks about shared library now.  Is it OK this way or should it be changed?


Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v9 09/10] Validate symbol file using build-id
  2015-07-15  8:21                       ` Jan Kratochvil
@ 2015-07-15 14:59                         ` Doug Evans
  0 siblings, 0 replies; 44+ messages in thread
From: Doug Evans @ 2015-07-15 14:59 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Pedro Alves, Eli Zaretskii, gdb-patches, Aleksandar Ristovski

On Wed, Jul 15, 2015 at 1:21 AM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Tue, 14 Jul 2015 18:13:26 +0200, Doug Evans wrote:
>> So I'd be ok with just adding a simple note somewhere saying
>> the option only applies to solibs at the moment and will
>> eventually also apply to exes.
>
> So the option is now called 'validate-build-id'.
>
> Its description everywhere (NEWS+gdb.texinfo+'help set validate-build-id')
> talks about shared library now.  Is it OK this way or should it be changed?

fine by me.  thanks!

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [commit] [PATCH v7 00/10] Validate binary before use
  2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
                   ` (9 preceding siblings ...)
  2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
@ 2015-07-15 16:36 ` Jan Kratochvil
  2015-07-15 18:33   ` [revert] " Jan Kratochvil
  10 siblings, 1 reply; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-15 16:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski

Hi,

therefore this patchset is checked in:

ddc98fbf2fd9e244a215a4d09e559180dc573a14 Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
6e5b4429db0d66e2d0b27e1bcfe4709f3dae73ed Move gdb_regex* to common/
f7af1fcd759fa126612018a5916cf808df7bb8bc Prepare linux_find_memory_regions_full & co. for move
9904185cfde13d6c6849f1f042c8e3b74974cf08 Move linux_find_memory_regions_full & co.
700ca40f6fc1addd7238f4ab57f76c095ad3c99f gdbserver build-id attribute generator
ca5268b6be265580b91ef75c1a1a9815f581ae42 Validate symbol file using build-id
0a94970d663a053c523f23ac0d71deb25a77f709 Tests for validate symbol file using build-id


Thanks,
Jan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [revert] [PATCH v7 00/10] Validate binary before use
  2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
@ 2015-07-15 18:33   ` Jan Kratochvil
  0 siblings, 0 replies; 44+ messages in thread
From: Jan Kratochvil @ 2015-07-15 18:33 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aleksandar Ristovski, Gary Benson

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

On Wed, 15 Jul 2015 17:49:59 +0200, Jan Kratochvil wrote:
> therefore this patchset is checked in:
> 
> ddc98fbf2fd9e244a215a4d09e559180dc573a14 Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
> 6e5b4429db0d66e2d0b27e1bcfe4709f3dae73ed Move gdb_regex* to common/
> f7af1fcd759fa126612018a5916cf808df7bb8bc Prepare linux_find_memory_regions_full & co. for move
> 9904185cfde13d6c6849f1f042c8e3b74974cf08 Move linux_find_memory_regions_full & co.
> 700ca40f6fc1addd7238f4ab57f76c095ad3c99f gdbserver build-id attribute generator
> ca5268b6be265580b91ef75c1a1a9815f581ae42 Validate symbol file using build-id
> 0a94970d663a053c523f23ac0d71deb25a77f709 Tests for validate symbol file using build-id

It has been reverted as it broke non-x86* builds such as s390*-linux:

linux-tdep.o: In function `linux_info_proc':
linux-tdep.c:(.text+0x110e): undefined reference to `read_mapping'
linux-tdep.o: In function `linux_find_memory_regions_gdb':
linux-tdep.c:(.text+0x2a2a): undefined reference to `linux_find_memory_regions_full'
collect2: error: ld returned 1 exit status

It is now obvious from:
        Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
        * Makefile.in (HFILES_NO_SRCDIR); Add nat/linux-maps.h,
        common/target-utils.h.
        (COMMON_OBS): Add target-utils.o.
        (linux-maps.o, target-utils.o): New.
        * target/target-utils.c: New file.
        * target/target-utils.h: New file.
        * config/i386/linux.mh (NATDEPFILES): Add linux-maps.o.
        * config/i386/linux64.mh (NATDEPFILES): Ditto.
        * nat/linux-maps.c: New file.
        * nat/linux-maps.h: New file.

I updated that config/i386/* only as a proof of concept and later forgot about
it.  As nat/linux-maps.c is used by linux-tdep.c it seems to me it should not
be in nat/ .

Anyway the fix is not obvious to me so I have just reverted it so far.


Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 1898 bytes --]

commit db1ff28b60f8886b8d7c634f1db2f939ba47a13c
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 15 20:27:32 2015 +0200

    Revert the previous 7 commits of: Validate binary before use
    
    ddc98fbf2fd9e244a215a4d09e559180dc573a14 Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
    6e5b4429db0d66e2d0b27e1bcfe4709f3dae73ed Move gdb_regex* to common/
    f7af1fcd759fa126612018a5916cf808df7bb8bc Prepare linux_find_memory_regions_full & co. for move
    9904185cfde13d6c6849f1f042c8e3b74974cf08 Move linux_find_memory_regions_full & co.
    700ca40f6fc1addd7238f4ab57f76c095ad3c99f gdbserver build-id attribute generator
    ca5268b6be265580b91ef75c1a1a9815f581ae42 Validate symbol file using build-id
    0a94970d663a053c523f23ac0d71deb25a77f709 Tests for validate symbol file using build-id
    
    gdb/ChangeLog
    2015-07-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Revert the previous 6 commits:
    	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
    	Move gdb_regex* to common/
    	Prepare linux_find_memory_regions_full & co. for move
    	Move linux_find_memory_regions_full & co.
    	gdbserver build-id attribute generator
    	Validate symbol file using build-id
    
    gdb/gdbserver/ChangeLog
    2015-07-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Revert the previous 3 commits:
    	Move gdb_regex* to common/
    	Move linux_find_memory_regions_full & co.
    	gdbserver build-id attribute generator
    
    gdb/doc/ChangeLog
    2015-07-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Revert the previous 2 commits:
    	gdbserver build-id attribute generator
    	Validate symbol file using build-id
    
    gdb/testsuite/ChangeLog
    2015-07-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Revert the previous commit:
    	Tests for validate symbol file using build-id.

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2015-07-15 18:33 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-06-14 19:25 ` [PATCH v7 01/10] Move utility functions to common/ Jan Kratochvil
2015-06-15 13:22   ` Joel Brobecker
2015-06-15 15:07     ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* " Jan Kratochvil
2015-07-08 14:39   ` Pedro Alves
2015-07-14 20:13     ` Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 07/10] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
2015-06-15 13:34   ` Joel Brobecker
2015-06-15 15:12     ` [commit] " Jan Kratochvil
2015-07-08 14:38   ` Pedro Alves
2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
2015-06-15 13:33   ` Joel Brobecker
2015-06-15 15:09     ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-06-14 19:27 ` [PATCH v7 09/10] Validate symbol file using build-id Jan Kratochvil
2015-06-21 10:16   ` [PATCH v8 " Jan Kratochvil
2015-06-22 12:55     ` Aleksandar Ristovski
2015-06-22 20:37       ` Jan Kratochvil
2015-06-22 20:41         ` Aleksandar Ristovski
2015-06-22 22:25     ` Doug Evans
2015-06-23 20:47       ` Jan Kratochvil
2015-07-08 14:44         ` Pedro Alves
2015-07-12 19:09           ` Jan Kratochvil
2015-07-12 19:29             ` [PATCH v9 " Jan Kratochvil
2015-07-12 19:54               ` Eli Zaretskii
2015-07-12 20:01                 ` Jan Kratochvil
2015-07-13  2:30                   ` Eli Zaretskii
2015-07-13 10:34                 ` Pedro Alves
2015-07-13 12:38                   ` Jan Kratochvil
2015-07-14 16:14                     ` Doug Evans
2015-07-15  8:21                       ` Jan Kratochvil
2015-07-15 14:59                         ` Doug Evans
2015-06-27 21:05       ` [PATCH v8 " Jan Kratochvil
2015-07-08 15:40         ` Doug Evans
2015-07-12 19:27           ` Jan Kratochvil
2015-06-14 19:27 ` [PATCH v7 10/10] Tests for validate " Jan Kratochvil
2015-07-08 14:44   ` Pedro Alves
2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
2015-07-08 14:41   ` Pedro Alves
2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-07-15 18:33   ` [revert] " Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).