public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Do not write the index cache from an index
@ 2024-01-18 20:37 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-01-18 20:37 UTC (permalink / raw)
  To: gdb-cvs

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

commit 6e53356b77887974e554ae07f9d76b83cd211700
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Dec 3 12:10:14 2023 -0700

    Do not write the index cache from an index
    
    The new .debug_names reader will work by creating a cooked index from
    .debug_names.  This patch updates cooked_index::maybe_write_index to
    avoid writing the index in this case.
    
    However, in order to do this in a clean way, the readers are changed
    so that a nullptr result from index_for_writing means "cannot be
    done", and then the error message is moved into write_dwarf_index
    (where it historically lived).

Diff:
---
 gdb/dwarf2/cooked-index.c | 7 +++++--
 gdb/dwarf2/index-write.c  | 2 ++
 gdb/dwarf2/mapped-index.h | 4 +---
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 542ec2fd69f..d63fd0ab5bc 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -704,8 +704,11 @@ void
 cooked_index::maybe_write_index (dwarf2_per_bfd *per_bfd,
 				 const index_cache_store_context &ctx)
 {
-  /* (maybe) store an index in the cache.  */
-  global_index_cache.store (m_per_bfd, ctx);
+  if (index_for_writing () != nullptr)
+    {
+      /* (maybe) store an index in the cache.  */
+      global_index_cache.store (m_per_bfd, ctx);
+    }
   m_state->set (cooked_state::CACHE_DONE);
 }
 
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 2decee62a4c..5cd550ef2d8 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1629,6 +1629,8 @@ write_dwarf_index (dwarf2_per_bfd *per_bfd, const char *dir,
   if (per_bfd->index_table == nullptr)
     error (_("No debugging symbols"));
   cooked_index *table = per_bfd->index_table->index_for_writing ();
+  if (table == nullptr)
+    error (_("Cannot use an index to create the index"));
 
   if (per_bfd->types.size () > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
diff --git a/gdb/dwarf2/mapped-index.h b/gdb/dwarf2/mapped-index.h
index df91e6402dc..86a3c59e7e4 100644
--- a/gdb/dwarf2/mapped-index.h
+++ b/gdb/dwarf2/mapped-index.h
@@ -127,9 +127,7 @@ struct mapped_index_base : public dwarf_scanner_base
 				 dwarf2_per_objfile *per_objfile) const;
 
   cooked_index *index_for_writing () override
-  {
-    error (_("Cannot use an index to create the index"));
-  }
+  { return nullptr; }
 };
 
 #endif /* GDB_DWARF2_MAPPED_INDEX_H */

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

only message in thread, other threads:[~2024-01-18 20:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 20:37 [binutils-gdb] Do not write the index cache from an index 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).