public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lancelot.six@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <lsix@lancelotsix.com>, Lancelot SIX <lancelot.six@amd.com>
Subject: [PATCH 3/3] gdb/corelow.c: do not try to reopen a file if open failed once
Date: Wed, 31 May 2023 17:04:06 +0100	[thread overview]
Message-ID: <20230531160406.3932028-4-lancelot.six@amd.com> (raw)
In-Reply-To: <20230531160406.3932028-1-lancelot.six@amd.com>

In the current implementation, core_target::build_file_mappings will try
to locate and open files which were mapped in the process for which the
core dump was produced.  If the file cannot be found or cannot be
opened, GDB will re-try to open it once for each time it was mapped in
the process's address space.

This patch makes it so GDB recognizes that it has already failed to open
a given file once and does not re-try the process for each mapping.
---
 gdb/corelow.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/gdb/corelow.c b/gdb/corelow.c
index ce68f91132e..b831a90792c 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -233,6 +233,16 @@ core_target::build_file_mappings ()
 	   weed out non-file-backed mappings.  */
 	gdb_assert (filename != nullptr);
 
+	if (unavailable_paths.find (filename) != unavailable_paths.end ())
+	  {
+	    /* We have already seen some mapping for FILENAME but failed to
+	       find/open the file.  There is no point in trying the same
+	       thing again so just record that the range [start, end) is
+	       unavailable.  */
+	    m_core_unavailable_mappings.emplace_back (start, end - start);
+	    return;
+	  }
+
 	struct bfd *bfd = bfd_map[filename];
 	if (bfd == nullptr)
 	  {
@@ -250,11 +260,10 @@ core_target::build_file_mappings ()
 	    if (expanded_fname == nullptr)
 	      {
 		m_core_unavailable_mappings.emplace_back (start, end - start);
-		/* Print just one warning per path.  */
-		if (unavailable_paths.insert (filename).second)
-		  warning (_("Can't open file %s during file-backed mapping "
-			     "note processing"),
-			   filename);
+		unavailable_paths.insert (filename);
+		warning (_("Can't open file %s during file-backed mapping "
+			   "note processing"),
+			 filename);
 		return;
 	      }
 
@@ -264,10 +273,10 @@ core_target::build_file_mappings ()
 	    if (bfd == nullptr || !bfd_check_format (bfd, bfd_object))
 	      {
 		m_core_unavailable_mappings.emplace_back (start, end - start);
-		if (unavailable_paths.insert (filename).second)
-		  warning (_("Can't open file %s which was expanded to %s "
-			     "during file-backed mapping note processing"),
-			   filename, expanded_fname.get ());
+		unavailable_paths.insert (filename);
+		warning (_("Can't open file %s which was expanded to %s "
+			   "during file-backed mapping note processing"),
+			 filename, expanded_fname.get ());
 
 		if (bfd != nullptr)
 		  {
-- 
2.34.1


  parent reply	other threads:[~2023-05-31 16:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 16:04 [PATCH 0/3] Fix use-after-free in gdb/corelow.c + cleanups Lancelot SIX
2023-05-31 16:04 ` [PATCH 1/3] gdb/corelow.c: fix use-after-free in build_file_mappings Lancelot SIX
2023-05-31 18:30   ` John Baldwin
2023-06-01  9:57     ` Andrew Burgess
2023-06-01 10:45       ` [PATCH v2 " Lancelot SIX
2023-06-01 17:05         ` John Baldwin
2023-06-07 14:54         ` Andrew Burgess
2023-06-08 13:22           ` Lancelot SIX
2023-05-31 16:04 ` [PATCH 2/3] gdb/corelow.c: avoid repeated warnings " Lancelot SIX
2023-06-01  9:50   ` Andrew Burgess
2023-05-31 16:04 ` Lancelot SIX [this message]
2023-06-01 10:04   ` [PATCH 3/3] gdb/corelow.c: do not try to reopen a file if open failed once Andrew Burgess
2023-05-31 18:32 ` [PATCH 0/3] Fix use-after-free in gdb/corelow.c + cleanups John Baldwin

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=20230531160406.3932028-4-lancelot.six@amd.com \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    /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).