Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Martin Simmons <qqxnjvamvxwx@dyxyl.com>
To: gdb-patches@sourceware.org
Subject: [PATCH][PR symtab/32658] Fix parsing .debug_aranges section for MIPS signed addresses
Date: Fri,  7 Mar 2025 23:57:22 +0000 (GMT)	[thread overview]
Message-ID: <20250307235722.1D4CDEE05D@localhost.localdomain> (raw)

This patch fixes https://sourceware.org/bugzilla/show_bug.cgi?id=32658 by sign
extending the addresses read from the .debug_aranges section as required for
MIPS.  I made it explicitly sign extend the addresses after they are read
(instead of using extract_signed_integer) because I don't know if the
address_size in the section will always be equal to the gdb arch_size.

I've tested the patch with the MIPS example from PR 32658 and also with a few
x86_64 binaries (where it has no effect, as expected).

diff --git a/gdb/dwarf2/aranges.c b/gdb/dwarf2/aranges.c
index 1be67852b43..a95e93aed27 100644
--- a/gdb/dwarf2/aranges.c
+++ b/gdb/dwarf2/aranges.c
@@ -59,6 +59,15 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 
   std::set<sect_offset> debug_info_offset_seen;
   const bfd_endian dwarf5_byte_order = gdbarch_byte_order (gdbarch);
+  ULONGEST sign_extend_bit = 0;
+  if (bfd_get_sign_extend_vma (abfd))
+    {
+      int arch_size = bfd_get_arch_size (abfd);
+      if (arch_size < 8 * sizeof(ULONGEST))
+	{
+	  sign_extend_bit = (ULONGEST) 1 << (arch_size - 1);
+	}
+    }
   const gdb_byte *addr = section->buffer;
   while (addr < section->buffer + section->size)
     {
@@ -187,6 +196,13 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	      /* Symbol was eliminated due to a COMDAT group.  */
 	      continue;
 	    }
+	  if (sign_extend_bit != 0)
+	    {
+	      /* Sign extend from the arch size. */
+	      start = (((start & ((sign_extend_bit << 1) - 1))
+			^ sign_extend_bit)
+		       - sign_extend_bit);
+	    }
 	  ULONGEST end = start + length;
 	  mutable_map->set_empty (start, end - 1, per_cu);
 	}

             reply	other threads:[~2025-03-07 23:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07 23:57 Martin Simmons [this message]
2025-03-08 16:39 ` Tom Tromey
2025-03-09 20:40   ` {Spam?} " Martin Simmons
2025-03-19 16:42     ` Tom Tromey
2025-03-19 16:48 ` Tom Tromey
2025-03-27 16:03   ` [PATCH v2][PR " Martin Simmons
2025-04-03 15:03     ` Tom Tromey

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=20250307235722.1D4CDEE05D@localhost.localdomain \
    --to=qqxnjvamvxwx@dyxyl.com \
    --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