public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Markus Metzger <mmetzger@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb, compile: unlink objfile stored in module
Date: Tue, 18 Oct 2022 13:25:08 +0000 (GMT)	[thread overview]
Message-ID: <20221018132508.294083858401@sourceware.org> (raw)

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

commit fb4f3f38e98599690946cc24b09ae6883a36edb0
Author: Markus Metzger <markus.t.metzger@intel.com>
Date:   Mon Apr 11 15:12:33 2022 +0200

    gdb, compile: unlink objfile stored in module
    
    When cleaning up after a compile command, we iterate over all objfiles and
    unlink the first objfile with the same name as the one we compiled.
    
    Since we already store a pointer to that objfile in the module and use it
    to get the name we're comparing against, there's no reason to iterate, at
    all.  We can simply use that objfile.
    
    This further avoids potential issues when an objfile with the same name is
    loaded into a different linker namespace.

Diff:
---
 gdb/compile/compile-object-run.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 6fcd10b29a4..af761e8782c 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -79,21 +79,18 @@ do_module_cleanup (void *arg, int registers_valid)
 	}
     }
 
+  objfile *objfile = data->module->objfile;
+  gdb_assert (objfile != nullptr);
+
   /* We have to make a copy of the name so that we can unlink the
      underlying file -- removing the objfile will cause the name to be
      freed, so we can't simply keep a reference to it.  */
-  std::string objfile_name_s = objfile_name (data->module->objfile);
-  for (objfile *objfile : current_program_space->objfiles ())
-    if ((objfile->flags & OBJF_USERLOADED) == 0
-	&& objfile_name_s == objfile_name (objfile))
-      {
-	objfile->unlink ();
-
-	/* It may be a bit too pervasive in this dummy_frame dtor callback.  */
-	clear_symtab_users (0);
-
-	break;
-      }
+  std::string objfile_name_s = objfile_name (objfile);
+
+  objfile->unlink ();
+
+  /* It may be a bit too pervasive in this dummy_frame dtor callback.  */
+  clear_symtab_users (0);
 
   /* Delete the .c file.  */
   unlink (data->module->source_file.c_str ());

                 reply	other threads:[~2022-10-18 13:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221018132508.294083858401@sourceware.org \
    --to=mmetzger@sourceware.org \
    --cc=gdb-cvs@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).