From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1805) id 294083858401; Tue, 18 Oct 2022 13:25:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 294083858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666099508; bh=g8orjblgYaxWDBWIcWGF6Lp6PNIECxZ/6sdMaUcmjdM=; h=From:To:Subject:Date:From; b=gLbr32op7BTCkoPDnhNnjYA8Z284Ww2FwpB7Vix+LzD+pniuIYYiDqNwbTcrHwtbv WcKeAswMTkYYxYhc3Kvxx/WqZQURFOgvjSC2+YWfK6SveBESllSE++C2gc7PxzFZhI LOHrpoSaNAqK6FjLg8Ex4bodRevmcccT5L5zarfU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Markus Metzger To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb, compile: unlink objfile stored in module X-Act-Checkin: binutils-gdb X-Git-Author: Markus Metzger X-Git-Refname: refs/heads/master X-Git-Oldrev: 2733d9d5d62c62023dc2d7a93fa5afa22f386ffd X-Git-Newrev: fb4f3f38e98599690946cc24b09ae6883a36edb0 Message-Id: <20221018132508.294083858401@sourceware.org> Date: Tue, 18 Oct 2022 13:25:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfb4f3f38e985= 99690946cc24b09ae6883a36edb0 commit fb4f3f38e98599690946cc24b09ae6883a36edb0 Author: Markus Metzger Date: Mon Apr 11 15:12:33 2022 +0200 gdb, compile: unlink objfile stored in module =20 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. =20 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. =20 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) } } =20 + objfile *objfile =3D data->module->objfile; + gdb_assert (objfile !=3D 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 =3D objfile_name (data->module->objfile); - for (objfile *objfile : current_program_space->objfiles ()) - if ((objfile->flags & OBJF_USERLOADED) =3D=3D 0 - && objfile_name_s =3D=3D 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 =3D objfile_name (objfile); + + objfile->unlink (); + + /* It may be a bit too pervasive in this dummy_frame dtor callback. */ + clear_symtab_users (0); =20 /* Delete the .c file. */ unlink (data->module->source_file.c_str ());