public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/4] Simplify gdb_index writing
Date: Sat, 29 May 2021 07:54:42 -0600	[thread overview]
Message-ID: <20210529135443.1446279-4-tom@tromey.com> (raw)
In-Reply-To: <20210529135443.1446279-1-tom@tromey.com>

write_gdbindex write the CUs first, then walks the signatured type
hash table to write out the TUs.  However, now that CUs and TUs are
unified in the DWARF reader, it's simpler to handle both of these in
the same loop.

2021-05-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/index-write.c (write_one_signatured_type): Remove.
	(write_gdbindex): Write type CUs in loop.
---
 gdb/ChangeLog            |  5 +++
 gdb/dwarf2/index-write.c | 84 ++++++++++++----------------------------
 2 files changed, 29 insertions(+), 60 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 656742f2e0a..06c8e1026f0 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -600,43 +600,6 @@ struct signatured_type_index_data
   int cu_index;
 };
 
-/* A helper function that writes a single signatured_type to an
-   obstack.  */
-
-static int
-write_one_signatured_type (void **slot, void *d)
-{
-  struct signatured_type_index_data *info
-    = (struct signatured_type_index_data *) d;
-  struct signatured_type *entry = (struct signatured_type *) *slot;
-  partial_symtab *psymtab = entry->v.psymtab;
-
-  if (psymtab == nullptr)
-    {
-      /* We can end up here when processing a skeleton CU referring to a
-	 .dwo file that hasn't been found.  There's not much we can do in
-	 such a case, so skip this CU.  */
-      return 1;
-    }
-
-  write_psymbols (info->symtab, info->psyms_seen,
-		  psymtab->global_psymbols, info->cu_index,
-		  0);
-  write_psymbols (info->symtab, info->psyms_seen,
-		  psymtab->static_psymbols, info->cu_index,
-		  1);
-
-  info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
-				to_underlying (entry->sect_off));
-  info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
-				to_underlying (entry->type_offset_in_tu));
-  info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, entry->signature);
-
-  ++info->cu_index;
-
-  return 1;
-}
-
 /* Recurse into all "included" dependencies and count their symbols as
    if they appeared in this psymtab.  */
 
@@ -1420,6 +1383,9 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
   psym_index_map cu_index_htab;
   cu_index_htab.reserve (per_objfile->per_bfd->all_comp_units.size ());
 
+  /* Store out the .debug_type CUs, if any.  */
+  data_buf types_cu_list;
+
   /* The CU list is already sorted, so we don't need to do additional
      work here.  Also, the debug_types entries do not appear in
      all_comp_units, but only in their own hash table.  */
@@ -1427,54 +1393,52 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
   std::unordered_set<partial_symbol *> psyms_seen
     (psyms_seen_size (per_objfile));
   int counter = 0;
+  int types_counter = 0;
   for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
     {
       dwarf2_per_cu_data *per_cu
 	= per_objfile->per_bfd->all_comp_units[i].get ();
-      if (per_cu->is_debug_types)
-	continue;
-
       partial_symtab *psymtab = per_cu->v.psymtab;
 
+      int &this_counter = per_cu->is_debug_types ? types_counter : counter;
+
       if (psymtab != NULL)
 	{
 	  if (psymtab->user == NULL)
 	    recursively_write_psymbols (objfile, psymtab, &symtab,
-					psyms_seen, counter);
+					psyms_seen, this_counter);
 
-	  const auto insertpair = cu_index_htab.emplace (psymtab, counter);
+	  const auto insertpair = cu_index_htab.emplace (psymtab,
+							 this_counter);
 	  gdb_assert (insertpair.second);
 	}
 
       /* The all_comp_units list contains CUs read from the objfile as well as
 	 from the eventual dwz file.  We need to place the entry in the
 	 corresponding index.  */
-      data_buf &cu_list = per_cu->is_dwz ? dwz_cu_list : objfile_cu_list;
+      data_buf &cu_list = (per_cu->is_debug_types
+			   ? types_cu_list
+			   : per_cu->is_dwz ? dwz_cu_list : objfile_cu_list);
       cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
 			   to_underlying (per_cu->sect_off));
-      cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length);
-      ++counter;
+      if (per_cu->is_debug_types)
+	{
+	  signatured_type *sig_type = (signatured_type *) per_cu;
+	  cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
+			       to_underlying (sig_type->type_offset_in_tu));
+	  cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
+			       sig_type->signature);
+	}
+      else
+	cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length);
+
+      ++this_counter;
     }
 
   /* Dump the address map.  */
   data_buf addr_vec;
   write_address_map (per_objfile->per_bfd, addr_vec, cu_index_htab);
 
-  /* Write out the .debug_type entries, if any.  */
-  data_buf types_cu_list;
-  if (per_objfile->per_bfd->signatured_types)
-    {
-      signatured_type_index_data sig_data (types_cu_list,
-					   psyms_seen);
-
-      sig_data.objfile = objfile;
-      sig_data.symtab = &symtab;
-      sig_data.cu_index = (per_objfile->per_bfd->all_comp_units.size ()
-			   - per_objfile->per_bfd->tu_stats.nr_tus);
-      htab_traverse_noresize (per_objfile->per_bfd->signatured_types.get (),
-			      write_one_signatured_type, &sig_data);
-    }
-
   /* Now that we've processed all symbols we can shrink their cu_indices
      lists.  */
   uniquify_cu_indices (&symtab);
-- 
2.26.3


  parent reply	other threads:[~2021-05-29 13:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-29 13:54 [PATCH 0/4] Some small debug index writer cleanups Tom Tromey
2021-05-29 13:54 ` [PATCH 1/4] Fix oddity in write_gdbindex Tom Tromey
2021-05-29 13:54 ` [PATCH 2/4] Minor cleanup to addrmap_index_data::previous_valid Tom Tromey
2021-06-13 16:48   ` Lancelot SIX
2021-06-14 20:14     ` Tom Tromey
2021-05-29 13:54 ` Tom Tromey [this message]
2021-05-29 13:54 ` [PATCH 4/4] Simplify debug_names index writing Tom Tromey
2021-07-05 17:56 ` [PATCH 0/4] Some small debug index writer cleanups Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210529135443.1446279-4-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).