Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH][PR symtab/32658] Fix parsing .debug_aranges section for MIPS signed addresses
@ 2025-03-07 23:57 Martin Simmons
  2025-03-08 16:39 ` Tom Tromey
  2025-03-19 16:48 ` Tom Tromey
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Simmons @ 2025-03-07 23:57 UTC (permalink / raw)
  To: gdb-patches

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);
 	}

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

end of thread, other threads:[~2025-04-03 15:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-07 23:57 [PATCH][PR symtab/32658] Fix parsing .debug_aranges section for MIPS signed addresses Martin Simmons
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox