public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Check OBJF_NOT_FILENAME in DWARF index code
@ 2022-04-26 18:46 Tom Tromey
  2022-04-27  0:14 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-04-26 18:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The DWARF index code currently uses 'stat' to see if an objfile
represents a real file.  However, I think it's more correct to check
OBJF_NOT_FILENAME instead.

Regression tested on x86-64 Fedora 34.
---
 gdb/dwarf2/index-cache.c | 4 ++++
 gdb/dwarf2/index-write.c | 9 +++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
index fb827e04e59..a1f6ff59634 100644
--- a/gdb/dwarf2/index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -96,6 +96,10 @@ index_cache::store (dwarf2_per_objfile *per_objfile)
   if (!enabled ())
     return;
 
+  /* If the objfile does not correspond to an actual file, skip it.  */
+  if ((obj->flags & OBJF_NOT_FILENAME) != 0)
+    return;
+
   /* Get build id of objfile.  */
   const bfd_build_id *build_id = build_id_bfd_get (obj->obfd);
   if (build_id == nullptr)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index afe55da6c1b..3d1c78d4459 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1411,9 +1411,8 @@ write_dwarf_index (dwarf2_per_objfile *per_objfile, const char *dir,
   if (per_objfile->per_bfd->types.size () > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
-  struct stat st;
-  if (stat (objfile_name (objfile), &st) < 0)
-    perror_with_name (objfile_name (objfile));
+
+  gdb_assert ((objfile->flags & OBJF_NOT_FILENAME) == 0);
 
   const char *index_suffix = (index_kind == dw_index_kind::DEBUG_NAMES
 			      ? INDEX5_SUFFIX : INDEX4_SUFFIX);
@@ -1472,10 +1471,8 @@ save_gdb_index_command (const char *arg, int from_tty)
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      struct stat st;
-
       /* If the objfile does not correspond to an actual file, skip it.  */
-      if (stat (objfile_name (objfile), &st) < 0)
+      if ((objfile->flags & OBJF_NOT_FILENAME) != 0)
 	continue;
 
       dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Check OBJF_NOT_FILENAME in DWARF index code
  2022-04-26 18:46 [PATCH] Check OBJF_NOT_FILENAME in DWARF index code Tom Tromey
@ 2022-04-27  0:14 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2022-04-27  0:14 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2022-04-26 14:46, Tom Tromey wrote:
> The DWARF index code currently uses 'stat' to see if an objfile
> represents a real file.  However, I think it's more correct to check
> OBJF_NOT_FILENAME instead.

Makes sense to me.

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-27  0:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 18:46 [PATCH] Check OBJF_NOT_FILENAME in DWARF index code Tom Tromey
2022-04-27  0:14 ` Simon Marchi

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