[09/11,gdb/macros] Fix gdb.base/fission-macro.exp with clang

Message ID 20240521154415.9543-9-tdevries@suse.de
State New
Headers
Series [01/11,gdb/testsuite] Add gdb.base/fission-macro.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries May 21, 2024, 3:44 p.m. UTC
  When running test-case gdb.base/fission-macro.exp with clang, we run into:
...
(gdb) info macro FIFTH^M
Defined at $build/gdb/testsuite/<bad macro file number 2>:18^M
  included at $src/gdb/testsuite/gdb.base/fission-macro.c:21^M
(gdb) FAIL: gdb.base/fission-macro.exp: dwarf_version=4: dwarf_bits=32: \
  strict_dwarf=0: info macro FIFTH
...

This is caused by the fact that the .debug_macros.dwo section refers to the
.debug_line.dwo section, but the .debug_line section is used instead.

Fix this by making sure the .debug_line.dwo section is used.

PR macros/31750
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31750
---
 gdb/dwarf2/read.c                        | 16 ++++++++++++++++
 gdb/testsuite/gdb.base/fission-macro.exp |  6 ++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6a489502f8b..b742f38c303 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -21224,6 +21224,7 @@  dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
   struct dwarf2_section_info *section;
   const char *section_name;
 
+  line_header_up lh_up;
   if (cu->dwo_unit != nullptr)
     {
       if (section_is_gnu)
@@ -21236,6 +21237,21 @@  dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
 	  section = &cu->dwo_unit->dwo_file->sections.macinfo;
 	  section_name = ".debug_macinfo.dwo";
 	}
+
+      {
+	struct dwarf2_section_info *line_section;
+
+	line_section = &cu->dwo_unit->dwo_file->sections.line;
+	line_section->read (per_objfile->objfile);
+	if (line_section->buffer == NULL)
+	  {
+	    complaint (_("missing .debug_line.dwo section"));
+	    return;
+	  }
+	lh_up = dwarf_decode_line_header ((sect_offset)0, 0, per_objfile,
+					  line_section, &cu->header, nullptr);
+	lh = lh_up.get ();
+      }
     }
   else
     {
diff --git a/gdb/testsuite/gdb.base/fission-macro.exp b/gdb/testsuite/gdb.base/fission-macro.exp
index 5474baf21d5..de1ce7d3823 100644
--- a/gdb/testsuite/gdb.base/fission-macro.exp
+++ b/gdb/testsuite/gdb.base/fission-macro.exp
@@ -13,8 +13,10 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-# Gcc 14 is the first release containing the fix for PR debug/111409.
-require {expr [gcc_major_version] >= 14}
+if { [test_compiler_info "gcc-*"] } {
+    # Gcc 14 is the first release containing the fix for PR debug/111409.
+    require {expr [gcc_major_version] >= 14}
+}
 
 standard_testfile .c -2.c .h