public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, 1/2][gdb/symtab] Fix name lookup in dw2_map_matching_symbols
@ 2020-06-02 10:42 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2020-06-02 10:42 UTC (permalink / raw)
  To: gdb-patches

Hi,

In commit 9a0bacfb08 "[gdb/symtab] Handle .gdb_index in ada language mode", a
missing part of dw2_map_matching_symbols was added, containing a call to
dw2_expand_symtabs_matching_symbol.

However, the callback passed to that call has one problem: the callback has an
argument "offset_type namei", which is ignored.  Instead, match_name is passed
as argument to dw2_symtab_iter_init, where a name lookup is done, which may or
may not yield the same value as namei.

Fix this by creating a new version of dw2_symtab_iter_init that takes a
"offset_type namei" argument instead of "const char *name", and passing namei.

Tested on x86_64-linux, with native and target board cc-with-gdb-index.

Any comments?

Thanks,
- Tom

[gdb/symtab] Fix name lookup in dw2_map_matching_symbols

gdb/ChangeLog:

2020-06-02  Tom de Vries  <tdevries@suse.de>

	* dwarf2/read.c (dw2_symtab_iter_init_common): Factor out of ...
	(dw2_symtab_iter_init): ... here.  Add variant with "offset_type
	namei" instead of "const char *name" argument.
	(dw2_map_matching_symbols): Use "offset_type namei" variant of
	dw2_symtab_iter_init.

---
 gdb/dwarf2/read.c | 61 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e6566f9649..65b3b9f0a3 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3431,31 +3431,64 @@ struct dw2_symtab_iterator
   int global_seen;
 };
 
-/* Initialize the index symtab iterator ITER.  */
+/* Initialize the index symtab iterator ITER, common part.  */
 
 static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-		      dwarf2_per_objfile *per_objfile,
-		      gdb::optional<block_enum> block_index,
-		      domain_enum domain,
-		      const char *name)
+dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
+			     dwarf2_per_objfile *per_objfile,
+			     gdb::optional<block_enum> block_index,
+			     domain_enum domain)
 {
   iter->per_objfile = per_objfile;
   iter->block_index = block_index;
   iter->domain = domain;
   iter->next = 0;
   iter->global_seen = 0;
+  iter->vec = NULL;
+  iter->length = 0;
+}
 
-  mapped_index *index = per_objfile->per_bfd->index_table.get ();
+/* Initialize the index symtab iterator ITER, const char *NAME variant.  */
+
+static void
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+		      dwarf2_per_objfile *per_objfile,
+		      gdb::optional<block_enum> block_index,
+		      domain_enum domain,
+		      const char *name)
+{
+  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
 
+  mapped_index *index = per_objfile->per_bfd->index_table.get ();
   /* index is NULL if OBJF_READNOW.  */
-  if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec))
+  if (index == NULL)
+    return;
+
+  if (find_slot_in_mapped_hash (index, name, &iter->vec))
     iter->length = MAYBE_SWAP (*iter->vec);
-  else
-    {
-      iter->vec = NULL;
-      iter->length = 0;
-    }
+}
+
+/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
+
+static void
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+		      dwarf2_per_objfile *per_objfile,
+		      gdb::optional<block_enum> block_index,
+		      domain_enum domain, offset_type namei)
+{
+  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
+
+  mapped_index *index = per_objfile->per_bfd->index_table.get ();
+  /* index is NULL if OBJF_READNOW.  */
+  if (index == NULL)
+    return;
+
+  gdb_assert (!index->symbol_name_slot_invalid (namei));
+  const auto &bucket = index->symbol_table[namei];
+
+  iter->vec = (offset_type *) (index->constant_pool
+			       + MAYBE_SWAP (bucket.vec));
+  iter->length = MAYBE_SWAP (*iter->vec);
 }
 
 /* Return the next matching CU or NULL if there are no more.  */
@@ -3760,7 +3793,7 @@ dw2_map_matching_symbols
 	struct dwarf2_per_cu_data *per_cu;
 
 	dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain,
-			      match_name);
+			      namei);
 	while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
 	  dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
 					   nullptr);

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

only message in thread, other threads:[~2020-06-02 10:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 10:42 [PATCH, 1/2][gdb/symtab] Fix name lookup in dw2_map_matching_symbols 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).