public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/3] Consistently use BFD's time
Date: Tue, 14 Jan 2020 21:10:00 -0000	[thread overview]
Message-ID: <20200114210956.25115-3-tromey@adacore.com> (raw)
In-Reply-To: <20200114210956.25115-1-tromey@adacore.com>

gdb uses the gnulib stat, while BFD does not.  This can lead to
inconsistencies between the two, because the gnulib stat adjusts for
timezones.

This patch changes gdb to use bfd_stat when examining a BFD's time.
This avoids the problem; and also opens the door to caching target
BFDs as well.

One possible downside here is that gdb must now create a BFD before
checking the cache.

gdb/ChangeLog
2020-01-14  Tom Tromey  <tromey@adacore.com>

	* gdb_bfd.c (gdb_bfd_open): Use bfd_stat.
	* symfile.c (reread_symbols): Use bfd_stat.

Change-Id: Ie937630a221cbae15809c99327b47c1cbce141c0
---
 gdb/ChangeLog |  5 +++++
 gdb/gdb_bfd.c | 49 +++++++++++++++++++++++++------------------------
 gdb/symfile.c |  5 +----
 3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index a1ee7814f32..26968396a15 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -442,8 +442,15 @@ gdb_bfd_open (const char *name, const char *target, int fd)
 	}
     }
 
+  /* We open the BFD here so that we can use BFD to get the mtime.
+     This is important because gdb uses the gnulib stat, but BFD does
+     not, and this can lead to differences on some systems.  */
+  abfd = bfd_fopen (name, target, FOPEN_RB, fd);
+  if (abfd == NULL)
+    return NULL;
+
   search.filename = name;
-  if (fstat (fd, &st) < 0)
+  if (bfd_stat (abfd, &st) < 0)
     {
       /* Weird situation here.  */
       search.mtime = 0;
@@ -461,38 +468,32 @@ gdb_bfd_open (const char *name, const char *target, int fd)
 
   /* Note that this must compute the same result as hash_bfd.  */
   hash = htab_hash_string (name);
-  /* Note that we cannot use htab_find_slot_with_hash here, because
-     opening the BFD may fail; and this would violate hashtab
-     invariants.  */
-  abfd = (struct bfd *) htab_find_with_hash (gdb_bfd_cache, &search, hash);
-  if (bfd_sharing && abfd != NULL)
+
+  if (bfd_sharing)
     {
-      if (debug_bfd_cache)
-	fprintf_unfiltered (gdb_stdlog,
-			    "Reusing cached bfd %s for %s\n",
-			    host_address_to_string (abfd),
-			    bfd_get_filename (abfd));
-      close (fd);
-      return gdb_bfd_ref_ptr::new_reference (abfd);
+      slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
+      if (*slot != nullptr)
+	{
+	  bfd_close (abfd);
+	  abfd = (bfd *) *slot;
+	  if (debug_bfd_cache)
+	    fprintf_unfiltered (gdb_stdlog,
+				"Reusing cached bfd %s for %s\n",
+				host_address_to_string (abfd),
+				bfd_get_filename (abfd));
+	  close (fd);
+	  return gdb_bfd_ref_ptr::new_reference (abfd);
+	}
+      else
+	*slot = abfd;
     }
 
-  abfd = bfd_fopen (name, target, FOPEN_RB, fd);
-  if (abfd == NULL)
-    return NULL;
-
   if (debug_bfd_cache)
     fprintf_unfiltered (gdb_stdlog,
 			"Creating new bfd %s for %s\n",
 			host_address_to_string (abfd),
 			bfd_get_filename (abfd));
 
-  if (bfd_sharing)
-    {
-      slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
-      gdb_assert (!*slot);
-      *slot = abfd;
-    }
-
   /* It's important to pass the already-computed mtime here, rather
      than, say, calling gdb_bfd_ref_ptr::new_reference here.  BFD by
      default will "stat" the file each time bfd_get_mtime is called --
diff --git a/gdb/symfile.c b/gdb/symfile.c
index f7bada75f35..18995351ed3 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2456,10 +2456,7 @@ reread_symbols (void)
 	 `ar', often called a `static library' on most systems, though
 	 a `shared library' on AIX is also an archive), then you should
 	 stat on the archive name, not member name.  */
-      if (objfile->obfd->my_archive)
-	res = stat (objfile->obfd->my_archive->filename, &new_statbuf);
-      else
-	res = stat (objfile_name (objfile), &new_statbuf);
+      res = bfd_stat (objfile->obfd, &new_statbuf);
       if (res != 0)
 	{
 	  /* FIXME, should use print_sys_errmsg but it's not filtered.  */
-- 
2.21.1

  reply	other threads:[~2020-01-14 21:10 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-14 21:10 [PATCH 0/3] Fix gdb's BFD cache Tom Tromey
2020-01-14 21:10 ` Tom Tromey [this message]
2020-01-14 23:17   ` [PATCH 2/3] Consistently use BFD's time Christian Biesinger via gdb-patches
2020-01-15 17:51   ` Eli Zaretskii
2020-01-16 20:47     ` Pedro Alves
2020-01-16 21:58       ` Christian Biesinger via gdb-patches
2020-01-16 22:31         ` Pedro Alves
2020-01-17  8:48         ` Eli Zaretskii
2020-01-17 18:32           ` Tom Tromey
2020-01-17 21:03             ` Tom Tromey
2020-01-18 11:07               ` Eli Zaretskii
2020-01-20 15:52                 ` Pedro Alves
2020-01-20 15:53                   ` Pedro Alves
2020-01-20 20:50                   ` Eli Zaretskii
2020-01-20 20:58                     ` Pedro Alves
2020-01-21 15:50                       ` Pedro Alves
2020-01-21 19:38                         ` Eli Zaretskii
2020-01-21 17:56                       ` Eli Zaretskii
2020-01-23 22:05                   ` Tom Tromey
2020-06-19 17:51                   ` Tom Tromey
2020-01-17  7:57       ` Eli Zaretskii
2020-04-01 20:20       ` Tom Tromey
2020-06-18 14:14     ` Tom Tromey
2020-06-18 15:04       ` Eli Zaretskii
2020-06-18 16:00         ` Tom Tromey
2020-06-18 17:27           ` Eli Zaretskii
2020-06-18 17:32             ` Pedro Alves
2020-06-18 17:54               ` Eli Zaretskii
2020-06-19 12:02                 ` Pedro Alves
2020-06-19 12:13                   ` Eli Zaretskii
2020-06-19 17:09                   ` Tom Tromey
2020-06-19 20:24                     ` Tom Tromey
2020-06-19 23:05                       ` Pedro Alves
2020-07-21 19:39                         ` Tom Tromey
2020-07-28 19:31                         ` Tom Tromey
2020-08-13 12:15                           ` Tom de Vries
2020-08-14 23:40                             ` Joel Brobecker
2020-08-23 16:09                               ` Joel Brobecker
2020-08-23 23:32                                 ` Pedro Alves
2020-08-24 20:04                                   ` Joel Brobecker
2020-09-02 14:45                                     ` Tom Tromey
2020-09-02 14:59                                       ` Joel Brobecker
2020-06-18 17:57               ` Tom Tromey
2020-01-14 21:10 ` [PATCH 1/3] Avoid hash table corruption in gdb_bfd.c Tom Tromey
2020-01-14 22:26   ` Christian Biesinger via gdb-patches
2020-01-14 22:13 ` [PATCH 3/3] Further simplify gdb BFD caching Tom Tromey
2020-01-23 22:30   ` Tom Tromey
2020-09-02 18:45     ` 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=20200114210956.25115-3-tromey@adacore.com \
    --to=tromey@adacore.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).