]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Merge GCC producer parsers. Allow digits in identifiers.
authorMark Wielaard <mjw@redhat.com>
Sun, 25 Jan 2015 10:20:39 +0000 (11:20 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 29 Jan 2015 12:39:01 +0000 (13:39 +0100)
Both dwarf2read.c (checkproducer) and utils.c (producer_is_gcc_ge_4)
implemented a GCC producer parser that tried to extract the major and minor
version of GCC. Merge them into one GCC producer parser used by both. Also
allow digits in the identifier after "GNU " such as used by GCC5 like:
"GNU C11 5.0.0 20150123 (experimental) -mtune=generic -march=x86-64 -gdwarf-5"

gdb/ChangeLog:

* dwarf2read.c (checkproducer): Call producer_is_gcc.
* utils.c (producer_is_gcc_ge_4): Likewise.
(producer_is_gcc): New function.
* utils.h (producer_is_gcc): New declaration.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/utils.c
gdb/utils.h

index d97aa03699302d3d2c7cc45489c95758c92463d0..f36936401f71d47ff202ef934d90d60670ebd5c0 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-25  Mark Wielaard  <mjw@redhat.com>
+
+       * dwarf2read.c (checkproducer): Call producer_is_gcc.
+       * utils.c (producer_is_gcc_ge_4): Likewise.
+       (producer_is_gcc): New function.
+       * utils.h (producer_is_gcc): New declaration.
+
 2015-01-29  Joel Brobecker  <brobecker@adacore.com>
 
        * gdbtypes.h (struct dynamic_prop): New PROP_ADDR_OFFSET enum
index ccbaeded62ec78b521de46d396ffe557b2396279..89b8dfe8d302c880d01a06ab9c86adb543606ec7 100644 (file)
@@ -12266,7 +12266,7 @@ static void
 check_producer (struct dwarf2_cu *cu)
 {
   const char *cs;
-  int major, minor, release;
+  int major, minor;
 
   if (cu->producer == NULL)
     {
@@ -12279,22 +12279,10 @@ check_producer (struct dwarf2_cu *cu)
         combination.  gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
         interpreted incorrectly by GDB now - GCC PR debug/48229.  */
     }
-  else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0)
+  else if ((major = producer_is_gcc (cu->producer, &minor)) > 0)
     {
-      /* Skip any identifier after "GNU " - such as "C++" or "Java".  */
-
-      cs = &cu->producer[strlen ("GNU ")];
-      while (*cs && !isdigit (*cs))
-       cs++;
-      if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
-       {
-         /* Not recognized as GCC.  */
-       }
-      else
-       {
-         cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
-         cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
-       }
+      cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
+      cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
     }
   else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
     cu->producer_is_icc = 1;
index a9a30826d603323e45574c4304cc09f82765da2e..909476bce2e467f7d129a5f0dd8f3a4d5c4392b8 100644 (file)
@@ -3258,36 +3258,8 @@ make_bpstat_clear_actions_cleanup (void)
 int
 producer_is_gcc_ge_4 (const char *producer)
 {
-  const char *cs;
   int major, minor;
-
-  if (producer == NULL)
-    {
-      /* For unknown compilers expect their behavior is not compliant.  For GCC
-        this case can also happen for -gdwarf-4 type units supported since
-        gcc-4.5.  */
-
-      return -1;
-    }
-
-  /* Skip any identifier after "GNU " - such as "C++" or "Java".  */
-
-  if (strncmp (producer, "GNU ", strlen ("GNU ")) != 0)
-    {
-      /* For non-GCC compilers expect their behavior is not compliant.  */
-
-      return -1;
-    }
-  cs = &producer[strlen ("GNU ")];
-  while (*cs && !isdigit (*cs))
-    cs++;
-  if (sscanf (cs, "%d.%d", &major, &minor) != 2)
-    {
-      /* Not recognized as GCC.  */
-
-      return -1;
-    }
-
+  major = producer_is_gcc (producer, &minor);
   if (major < 4)
     return -1;
   if (major > 4)
@@ -3295,6 +3267,36 @@ producer_is_gcc_ge_4 (const char *producer)
   return minor;
 }
 
+/* Returns the major version number if the given PRODUCER string is GCC and
+   sets the MINOR version.  Returns -1 if the given PRODUCER is NULL or it
+   isn't GCC.  */
+int
+producer_is_gcc (const char *producer, int *minor)
+{
+  const char *cs;
+  int major;
+
+  if (producer != NULL && strncmp (producer, "GNU ", strlen ("GNU ")) == 0)
+    {
+      /* Skip any identifier after "GNU " - such as "C11" "C++" or "Java".
+        A full producer string might look like:
+        "GNU C 4.7.2"
+        "GNU Fortran 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic ..."
+        "GNU C++14 5.0.0 20150123 (experimental)"
+      */
+      cs = &producer[strlen ("GNU ")];
+      while (*cs && !isspace (*cs))
+        cs++;
+      if (*cs && isspace (*cs))
+        cs++;
+      if (sscanf (cs, "%d.%d", &major, minor) == 2)
+       return major;
+    }
+
+  /* Not recognized as GCC.  */
+  return -1;
+}
+
 /* Helper for make_cleanup_free_char_ptr_vec.  */
 
 static void
index e58260c6c57cb10efd6125b41563ffa948cf5e99..6724d7ce8da40df66da4ca17c82f740b6d549cd3 100644 (file)
@@ -302,6 +302,7 @@ extern pid_t wait_to_die_with_timeout (pid_t pid, int *status, int timeout);
 #endif
 
 extern int producer_is_gcc_ge_4 (const char *producer);
+extern int producer_is_gcc (const char *producer, int *minor);
 
 extern int myread (int, char *, int);