public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Genericize addrmap handling in the DWARF index writer
@ 2022-04-12 15:41 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-12 15:41 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fa38ad7d8aa15309cfc51d4dec48108816e3fcbd

commit fa38ad7d8aa15309cfc51d4dec48108816e3fcbd
Author: Tom Tromey <tom@tromey.com>
Date:   Fri May 28 15:52:44 2021 -0600

    Genericize addrmap handling in the DWARF index writer
    
    This updates the DWARF index writing code to make the addrmap-writing
    a bit more generic.  Now, it can handle multiple maps, and it can work
    using the maps generated by the new indexer.
    
    Note that the new addrmap_index_data::using_index field will be
    deleted in a future patch, when the rest of the DWARF psymtab code is
    removed.

Diff:
---
 gdb/dwarf2/index-write.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 509dde462e3..9fe7724feea 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -412,8 +412,11 @@ typedef std::unordered_map<dwarf2_per_cu_data *, unsigned int> cu_index_map;
 /* Helper struct for building the address table.  */
 struct addrmap_index_data
 {
-  addrmap_index_data (data_buf &addr_vec_, cu_index_map &cu_index_htab_)
-    : addr_vec (addr_vec_), cu_index_htab (cu_index_htab_)
+  addrmap_index_data (data_buf &addr_vec_, cu_index_map &cu_index_htab_,
+		      bool using_index_)
+    : addr_vec (addr_vec_),
+      cu_index_htab (cu_index_htab_),
+      using_index (using_index_)
   {}
 
   data_buf &addr_vec;
@@ -421,6 +424,8 @@ struct addrmap_index_data
 
   int operator() (CORE_ADDR start_addr, void *obj);
 
+  /* True if the DWARF reader uses the new DWARF indexer.  */
+  bool using_index;
   /* True if the previous_* fields are valid.
      We can't write an entry until we see the next entry (since it is only then
      that we know the end of the entry).  */
@@ -447,7 +452,11 @@ add_address_entry (data_buf &addr_vec,
 int
 addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
 {
-  dwarf2_psymtab *pst = (dwarf2_psymtab *) obj;
+  dwarf2_per_cu_data *per_cu;
+  if (using_index)
+    per_cu = (dwarf2_per_cu_data *) obj;
+  else
+    per_cu = obj == nullptr ? nullptr : ((dwarf2_psymtab *) obj)->per_cu_data;
 
   if (previous_valid)
     add_address_entry (addr_vec,
@@ -455,9 +464,9 @@ addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
 		       previous_cu_index);
 
   previous_cu_start = start_addr;
-  if (pst != NULL)
+  if (per_cu != NULL)
     {
-      const auto it = cu_index_htab.find (pst->per_cu_data);
+      const auto it = cu_index_htab.find (per_cu);
       gdb_assert (it != cu_index_htab.cend ());
       previous_cu_index = it->second;
       previous_valid = true;
@@ -474,9 +483,10 @@ addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
 
 static void
 write_address_map (struct addrmap *addrmap, data_buf &addr_vec,
-		   cu_index_map &cu_index_htab)
+		   cu_index_map &cu_index_htab, bool using_index)
 {
-  struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
+  struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab,
+						using_index);
 
   addrmap_foreach (addrmap, addrmap_index_data);
 
@@ -1377,8 +1387,17 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
 
   /* Dump the address map.  */
   data_buf addr_vec;
-  write_address_map (per_objfile->per_bfd->partial_symtabs->psymtabs_addrmap,
-		     addr_vec, cu_index_htab);
+  if (per_objfile->per_bfd->using_index)
+    {
+      std::vector<addrmap *> addrmaps
+	= per_objfile->per_bfd->cooked_index_table->get_addrmaps ();
+      for (auto map : addrmaps)
+	write_address_map (map, addr_vec, cu_index_htab, true);
+    }
+  else
+    write_address_map (per_objfile->per_bfd->partial_symtabs->psymtabs_addrmap,
+		       addr_vec, cu_index_htab,
+		       per_objfile->per_bfd->using_index);
 
   /* Now that we've processed all symbols we can shrink their cu_indices
      lists.  */


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

only message in thread, other threads:[~2022-04-12 15:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 15:41 [binutils-gdb] Genericize addrmap handling in the DWARF index writer Tom Tromey

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