public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/symtab] Workaround PR gas/31115
Date: Wed,  6 Mar 2024 16:53:15 +0100	[thread overview]
Message-ID: <20240306155315.22240-1-tdevries@suse.de> (raw)

On arm-linux, with gas 2.40, I run into:
...
(gdb) x /i main+8^M
   0x4e1 <main+7>:      vrhadd.u16      d14, d14, d31^M
(gdb) FAIL: gdb.arch/pr25124.exp: disassemble thumb instruction (1st try)
...

This is a regression due to PR gas/31115, which makes gas produce a low_pc
with the thumb bit set (0x4d8 & 0x1):
...
 <1><24>: Abbrev Number: 2 (DW_TAG_subprogram)
    <25>   DW_AT_name        : main
    <29>   DW_AT_external    : 1
    <29>   DW_AT_type        : <0x2f>
    <2a>   DW_AT_low_pc      : 0x4d9
    <2e>   DW_AT_high_pc     : 12
...

The regression was introduced in 2.39, and is also present in 2.40 and 2.41,
and hasn't been fixed yet.

Work around this in read_func_scope, by using gdbarch_addr_bits_remove on
low_pc and high_pc.

Tested on arm-linux and x86_64-linux.

PR tdep/31453
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31453
---
 gdb/dwarf2/cu.c   |  1 +
 gdb/dwarf2/cu.h   |  1 +
 gdb/dwarf2/read.c | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index ae46dd2a9b2..62c0a8a3ede 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -42,6 +42,7 @@ dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu,
     producer_is_clang (false),
     producer_is_gas_lt_2_38 (false),
     producer_is_gas_2_39 (false),
+    producer_is_gas_ge_2_40 (false),
     processing_has_namespace_info (false)
 {
 }
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index ad89228ef8d..58e89960aad 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -263,6 +263,7 @@ struct dwarf2_cu
   bool producer_is_clang : 1;
   bool producer_is_gas_lt_2_38 : 1;
   bool producer_is_gas_2_39 : 1;
+  bool producer_is_gas_ge_2_40 : 1;
 
   /* When true, the file that we're processing is known to have
      debugging info for C++ namespaces.  GCC 3.3.x did not produce
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 486be7e4921..34985898b6a 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -148,6 +148,7 @@ static int dwarf2_loclist_block_index;
 static int ada_block_index;
 
 static bool producer_is_gas_lt_2_38 (struct dwarf2_cu *cu);
+static bool producer_is_gas_ge_2_39 (struct dwarf2_cu *cu);
 
 /* Size of .debug_loclists section header for 32-bit DWARF format.  */
 #define LOCLIST_HEADER_SIZE32 12
@@ -9974,6 +9975,15 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   lowpc = per_objfile->relocate (unrel_low);
   highpc = per_objfile->relocate (unrel_high);
 
+  if (gdbarch_bfd_arch_info (gdbarch)->arch == bfd_arch_arm
+      && producer_is_gas_ge_2_39 (cu))
+    {
+      /* Gas version 2.39 produces DWARF for a Thumb subprogram with a low_pc
+	 attribute with the thumb bit set (PR gas/31115).  Work around this.  */
+      lowpc = gdbarch_addr_bits_remove (gdbarch, lowpc);
+      highpc = gdbarch_addr_bits_remove (gdbarch, highpc);
+    }
+
   /* If we have any template arguments, then we must allocate a
      different sort of symbol.  */
   for (child_die = die->child; child_die; child_die = child_die->sibling)
@@ -11326,6 +11336,7 @@ check_producer (struct dwarf2_cu *cu)
     {
       cu->producer_is_gas_lt_2_38 = major < 2 || (major == 2 && minor < 38);
       cu->producer_is_gas_2_39 = major == 2 && minor == 39;
+      cu->producer_is_gas_ge_2_40 = major > 2 || (major == 2 && minor >= 40);
     }
   else
     {
@@ -11380,6 +11391,17 @@ producer_is_gas_2_39 (struct dwarf2_cu *cu)
   return cu->producer_is_gas_2_39;
 }
 
+/* Return true if CU is produced by GAS 2.39 or later.  */
+
+static bool
+producer_is_gas_ge_2_39 (struct dwarf2_cu *cu)
+{
+  if (!cu->checked_producer)
+    check_producer (cu);
+
+  return cu->producer_is_gas_2_39 || cu->producer_is_gas_ge_2_40;
+}
+
 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
    If that attribute is not available, return the appropriate
    default.  */

base-commit: 164cc86b81de7ab25682a234b978134d08fb3009
-- 
2.35.3


             reply	other threads:[~2024-03-06 15:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 15:53 Tom de Vries [this message]
2024-03-07 19:07 ` Tom Tromey
2024-03-07 21:09   ` Tom de Vries
2024-03-19  9:39     ` Tom de Vries
2024-03-19 10:48       ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240306155315.22240-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).