public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] [gdb/symtab] Add producer_is_gas
@ 2023-10-30  8:11 Tom de Vries
  2023-10-30  8:11 ` [PATCH 2/2] [gdb/symtab] Work around gas PR28629 Tom de Vries
  2023-10-31 19:30 ` [PATCH 1/2] [gdb/symtab] Add producer_is_gas Tom Tromey
  0 siblings, 2 replies; 10+ messages in thread
From: Tom de Vries @ 2023-10-30  8:11 UTC (permalink / raw)
  To: gdb-patches

Add producer_is_gas, a generic way to get the gas version from the
producer string.

Tested on x86_64-linux.
---
 gdb/dwarf2/read.c |  4 ++--
 gdb/producer.c    | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 gdb/producer.h    |  5 +++++
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ea0b2328a3e..24495bfbb89 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -11426,8 +11426,8 @@ check_producer (struct dwarf2_cu *cu)
     cu->producer_is_codewarrior = true;
   else if (producer_is_clang (cu->producer, &major, &minor))
     cu->producer_is_clang = true;
-  else if (startswith (cu->producer, "GNU AS 2.39.0"))
-    cu->producer_is_gas_2_39 = true;
+  else if (producer_is_gas (cu->producer, &major, &minor))
+    cu->producer_is_gas_2_39 = major == 2 && minor == 39;
   else
     {
       /* For other non-GCC compilers, expect their behavior is DWARF version
diff --git a/gdb/producer.c b/gdb/producer.c
index 9fcf749e3d4..903edfbabac 100644
--- a/gdb/producer.c
+++ b/gdb/producer.c
@@ -81,6 +81,45 @@ producer_is_gcc (const char *producer, int *major, int *minor)
 
 /* See producer.h.  */
 
+int
+producer_is_gas (const char *producer, int *major, int *minor)
+{
+  if (producer == nullptr)
+    {
+      /* No producer, don't know.  */
+      return 0;
+    }
+
+  /* Detect prefix.  */
+  const char prefix[] = "GNU AS ";
+  if (!startswith (producer, prefix))
+    {
+      /* Producer is not gas.  */
+      return 0;
+    }
+
+  /* Skip prefix.  */
+  const char *cs = &producer[strlen (prefix)];
+
+  /* Ensure that major/minor are not nullptrs.  */
+  int maj, min;
+  if (major == nullptr)
+    major = &maj;
+  if (minor == nullptr)
+    minor = &min;
+
+  int scanned = sscanf (cs, "%d.%d", major, minor);
+  if (scanned != 2)
+    {
+      /* Unable to scan major/minor version.  */
+      return 0;
+    }
+
+  return 1;
+}
+
+  /* See producer.h.  */
+
 bool
 producer_is_icc_ge_19 (const char *producer)
 {
@@ -251,6 +290,23 @@ Version 18.0 Beta";
     SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
     SELF_CHECK (producer_is_llvm (flang_llvm_exp));
   }
+
+  {
+    static const char gas_exp[] = "GNU AS 2.39.0";
+    int major = 0, minor = 0;
+    SELF_CHECK (!producer_is_gcc (gas_exp, &major, &minor));
+    SELF_CHECK (producer_is_gas (gas_exp, &major, &minor));
+    SELF_CHECK (major == 2 && minor == 39);
+
+    static const char gas_incomplete_exp[] = "GNU AS ";
+    SELF_CHECK (!producer_is_gas (gas_incomplete_exp, &major, &minor));
+    SELF_CHECK (!producer_is_gcc (gas_incomplete_exp, &major, &minor));
+
+    static const char gas_incomplete_exp_2[] = "GNU AS 2";
+    SELF_CHECK (!producer_is_gas (gas_incomplete_exp_2, &major, &minor));
+    SELF_CHECK (!producer_is_gcc (gas_incomplete_exp_2, &major, &minor));
+  }
+
 }
 }
 }
diff --git a/gdb/producer.h b/gdb/producer.h
index c915979b122..aac5088395a 100644
--- a/gdb/producer.h
+++ b/gdb/producer.h
@@ -30,6 +30,11 @@ extern int producer_is_gcc_ge_4 (const char *producer);
    is NULL or it isn't GCC.  */
 extern int producer_is_gcc (const char *producer, int *major, int *minor);
 
+/* Returns nonzero if the given PRODUCER string is GAS and sets the MAJOR
+   and MINOR versions when not NULL.  Returns zero if the given PRODUCER
+   is NULL or it isn't GAS.  */
+int producer_is_gas (const char *producer, int *major, int *minor);
+
 /* Check for Intel compilers >= 19.0.  */
 extern bool producer_is_icc_ge_19 (const char *producer);
 

base-commit: ca362799ee0ab2bd4d4ea4f521726fefbfbad738
-- 
2.35.3


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

end of thread, other threads:[~2023-11-06  7:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30  8:11 [PATCH 1/2] [gdb/symtab] Add producer_is_gas Tom de Vries
2023-10-30  8:11 ` [PATCH 2/2] [gdb/symtab] Work around gas PR28629 Tom de Vries
2023-10-31 19:31   ` Tom Tromey
2023-11-01  6:43     ` Tom de Vries
2023-11-02 21:04       ` Carl Love
2023-11-03 18:25         ` Tom Tromey
2023-11-05 20:14           ` Tom de Vries
2023-11-06  7:35             ` Tom de Vries
2023-10-31 19:30 ` [PATCH 1/2] [gdb/symtab] Add producer_is_gas Tom Tromey
2023-11-01  6:39   ` Tom de Vries

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).