[gdb/symtab] Fix gdb.base/fission-macro.exp with unix/-m32

Message ID 20250121101855.14719-1-tdevries@suse.de
State Committed
Headers
Series [gdb/symtab] Fix gdb.base/fission-macro.exp with unix/-m32 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply

Commit Message

Tom de Vries Jan. 21, 2025, 10:18 a.m. UTC
  When running test-case gdb.base/fission-macro.exp on openSUSE Tumbleweed
(using gcc 14) with target board unix/-m32, I get:
...
(gdb) info macro FIRST^M
Defined at /data/vries/gdb/src/gdb/testsuite/gdb.base/fission-macro.c:0^M
-DFIRST=1^M
(gdb) FAIL: $exp: \
  dwarf_version=5: dwarf_bits=32: strict_dwarf=0: info macro FIRST
...
instead of the expected:
...
(gdb) info macro FIRST^M
Defined at /data/vries/gdb/src/gdb/testsuite/gdb.base/fission-macro.c:18^M
(gdb) PASS: $exp: \
  dwarf_version=5: dwarf_bits=32: strict_dwarf=0: info macro FIRST
...

A dwarf-5 .debug_str_offsets section starts with a header consisting of:
- an initial length (4 bytes for 32-bit and 12 bytes for 64-bit),
- a 2 byte version string, and
- 2 bytes padding
so in total 8 bytes for 32-bit and 16 bytes for 64-bit.

This offset is calculated here in dwarf_decode_macros:
...
      str_offsets_base = cu->header.addr_size;
...
which is wrong for both dwarf-5 (and also happens to be wrong for dwarf-4).

Fix this by computing str_offsets_base correctly for dwarf-5, for both the
32-bit and 64-bit case.

Likewise, fix this for dwarf-4, using str_offsets_base 0.  We can only test
this with gcc-15, because gcc 14 and earlier don't have the fix for
PR debug/115066.

Tested on x86_64-linux.

Tested test-case using a current gcc trunk build, and gcc 14.

PR symtab/31897
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31897
---
 gdb/dwarf2/read.c                        | 12 +++++++++++-
 gdb/testsuite/gdb.base/fission-macro.exp |  8 ++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)


base-commit: 24f46f126f4df6d727967f4489c66bc0921b1d6e
  

Comments

Tom Tromey Jan. 21, 2025, 1:42 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Likewise, fix this for dwarf-4, using str_offsets_base 0.  We can only test
Tom> this with gcc-15, because gcc 14 and earlier don't have the fix for
Tom> PR debug/115066.

Tom> Tested on x86_64-linux.

Tom> Tested test-case using a current gcc trunk build, and gcc 14.

Tom> PR symtab/31897
Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31897

Ok
Approved-By: Tom Tromey <tom@tromey.com>

I wonder if this fixes any of the PRs in the macros component.

Tom
  
Tom de Vries Jan. 21, 2025, 2:27 p.m. UTC | #2
On 1/21/25 14:42, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> Likewise, fix this for dwarf-4, using str_offsets_base 0.  We can only test
> Tom> this with gcc-15, because gcc 14 and earlier don't have the fix for
> Tom> PR debug/115066.
> 
> Tom> Tested on x86_64-linux.
> 
> Tom> Tested test-case using a current gcc trunk build, and gcc 14.
> 
> Tom> PR symtab/31897
> Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31897
> 
> Ok
> Approved-By: Tom Tromey <tom@tromey.com>
> 
> I wonder if this fixes any of the PRs in the macros component.

Hi Tom,

thanks for the review.

I searched for macros component and -gsplit-dwarf, and only came up with 
this PR ( https://sourceware.org/bugzilla/show_bug.cgi?id=31750 ) which 
is with clang.

I was about to ping this patch ( 
https://sourceware.org/pipermail/gdb-patches/2024-May/209307.html ) 
which should fix that PR.

Thanks,
- Tom
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4503977d62b..9e3d13c9875 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20832,7 +20832,17 @@  dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
       str_offsets_section = &cu->dwo_unit->dwo_file
 			       ->sections.str_offsets;
       str_section = &cu->dwo_unit->dwo_file->sections.str;
-      str_offsets_base = cu->header.addr_size;
+      if (cu->header.version <= 4)
+	str_offsets_base = 0;
+      else
+	{
+	  bfd *abfd = str_offsets_section->get_bfd_owner ();
+	  unsigned int bytes_read = 0;
+	  read_initial_length (abfd, str_offsets_section->buffer, &bytes_read,
+			       false);
+	  const bool is_dwarf64 = bytes_read != 4;
+	  str_offsets_base = is_dwarf64 ? 16 : 8;
+	}
     }
   else
     {
diff --git a/gdb/testsuite/gdb.base/fission-macro.exp b/gdb/testsuite/gdb.base/fission-macro.exp
index 705e3dd0c4b..9e5d5c0a0d5 100644
--- a/gdb/testsuite/gdb.base/fission-macro.exp
+++ b/gdb/testsuite/gdb.base/fission-macro.exp
@@ -66,8 +66,12 @@  proc do_tests { dwarf_version dwarf_bits strict_dwarf } {
     gdb_test "info macro FOURTH" "#define FOURTH 4"
 }
 
-foreach_with_prefix dwarf_version {5} {
-    foreach_with_prefix dwarf_bits {32} {
+foreach_with_prefix dwarf_version {4 5} {
+    if { $dwarf_version == 4 && [gcc_major_version] < 15 } {
+	# Gcc does not contain fix for PR debug/115066.
+	continue
+    }
+    foreach_with_prefix dwarf_bits {32 64} {
 	foreach_with_prefix strict_dwarf {0 1} {
 	    do_tests $dwarf_version $dwarf_bits $strict_dwarf
 	}