public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Handle missing aranges with debug_names
@ 2021-02-02 16:06 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-02-02 16:06 UTC (permalink / raw)
  To: gdb-patches

Hi,

When running test-case gdb.dwarf2/template-specification-full-name.exp with
target board cc-with-debug-names, we get:
...
(gdb) print apply<int>^M
$1 = {void (void)} 0x4004a7 <apply<int>()>^M
Warning: the current language does not match this frame.^M
(gdb) FAIL: gdb.dwarf2/template-specification-full-name.exp: print apply<int>
...

The current language is supposed to be set to c++, but that fails because we
fail to find the CU corresponding to the pc in main.

This is due to the fact that the dwarf test-case does not provide a
.debug_aranges section for the CU containing main.

Fix this conservatively by:
- skipping the .debug_aranges section if missing CUs are detected, and
- skipping the .debug_names section if the .debug_aranges reading failed.

Tested on x86_64-linux with target board cc-with-debug-names.

Any comments?

Thanks,
- Tom

[gdb/symtab] Handle missing aranges with debug_names

gdb/ChangeLog:

2021-02-02  Tom de Vries  <tdevries@suse.de>

	PR symtab/27298
	* dwarf2/read.c (create_addrmap_from_aranges): Detect and handle
	missing and duplicate CUs.
	(dwarf2_read_debug_names): Handle failure to read .debug_ranges.

gdb/testsuite/ChangeLog:

2021-02-02  Tom de Vries  <tdevries@suse.de>

	PR symtab/27298
	* lib/gdb.exp (gdb_load_no_complaints): Make complaints detection
	more specific.

---
 gdb/dwarf2/read.c         | 32 ++++++++++++++++++++++++++++++++
 gdb/testsuite/lib/gdb.exp |  4 ++--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 872b4e7bcf2..625d25a4e26 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -82,6 +82,7 @@
 #include <fcntl.h>
 #include <algorithm>
 #include <unordered_map>
+#include <unordered_set>
 #include "gdbsupport/selftest.h"
 #include "rust-lang.h"
 #include "gdbsupport/pathstuff.h"
@@ -2870,6 +2871,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 		     dwarf2_per_cu_data *,
 		     gdb::hash_enum<sect_offset>>
     debug_info_offset_to_per_cu;
+  std::unordered_set<sect_offset, gdb::hash_enum<sect_offset>> cus;
   for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
     {
       const auto insertpair
@@ -2881,6 +2883,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 		   objfile_name (objfile), sect_offset_str (per_cu->sect_off));
 	  return;
 	}
+      cus.emplace (per_cu->sect_off);
     }
 
   section->read (objfile);
@@ -2942,6 +2945,19 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	}
       dwarf2_per_cu_data *const per_cu = per_cu_it->second;
 
+      auto cu_it = cus.find (sect_offset (debug_info_offset));
+      if (cu_it == cus.end ())
+	{
+	  warning (_("Section .debug_aranges in %s entry at offset %s:"
+		     " duplicate debug_info_offset %s,"
+		     " ignoring .debug_aranges."),
+		   objfile_name (objfile),
+		   plongest (entry_addr - section->buffer),
+		   pulongest (debug_info_offset));
+	  return;
+	}
+      cus.erase (cu_it);
+
       const uint8_t address_size = *addr++;
       if (address_size < 1 || address_size > 8)
 	{
@@ -3012,6 +3028,13 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	}
     }
 
+  if (!cus.empty ())
+    {
+      warning (_("Section .debug_aranges does not contain entries"
+		 " for all CUs, ignoring .debug_aranges."));
+      return;
+    }
+
   objfile->partial_symtabs->psymtabs_addrmap
     = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ());
 }
@@ -5424,6 +5447,15 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
     }
 
   create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
+  if (objfile->partial_symtabs->psymtabs_addrmap == nullptr)
+    {
+      warning (_("Could not read '.debug_aranges' section;"
+		 " skipping .debug_names."));
+      /* Clear to prevent asserts.  */
+      per_objfile->per_bfd->all_comp_units.clear ();
+      per_objfile->per_bfd->all_type_units.clear ();
+      return false;
+    }
 
   per_bfd->debug_names_table = std::move (map);
   per_bfd->using_index = 1;
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 53ac9f1408c..dbbf239dab9 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5124,8 +5124,8 @@ proc gdb_load_no_complaints { arg } {
     gdb_load $arg
 
     # Verify that there were no complaints.
-    set re "^Reading symbols from \[^\r\n\]*\r\n$gdb_prompt $"
-    gdb_assert {[regexp $re $gdb_file_cmd_msg]} "No complaints"
+    set re "\r\nDuring symbol reading: "
+    gdb_assert {![regexp $re $gdb_file_cmd_msg]} "No complaints"
 
     # Restore saved setting of complaints.
     gdb_test_no_output "set complaints $save" ""

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-02 16:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 16:06 [PATCH][gdb/symtab] Handle missing aranges with debug_names Tom de Vries

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).