From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id STCFHMYIjl+ERwAAWB0awg (envelope-from ) for ; Mon, 19 Oct 2020 17:44:38 -0400 Received: by simark.ca (Postfix, from userid 112) id 6037E1EFBF; Mon, 19 Oct 2020 17:44:38 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D09E31EFBB for ; Mon, 19 Oct 2020 17:44:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 211DD388EC1E; Mon, 19 Oct 2020 21:44:36 +0000 (GMT) Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.111]) by sourceware.org (Postfix) with ESMTPS id 99B413844046 for ; Mon, 19 Oct 2020 21:44:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99B413844046 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 339C95B10E for ; Mon, 19 Oct 2020 16:44:33 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id UcxFkUxAUBD8bUcxFkRu9A; Mon, 19 Oct 2020 16:44:33 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oaezbPalEgjv5hkUYxFzS+n4T5ik83ublqGItDQD12E=; b=nznDfmo+rHwS80pbyjXBxipN/e oHEcN2c6J9xZ3fy9AotzVIYstXDEtMybBdKTBAD+vY8C2sdakpCIurZBFCKOvyLX31NWvTxI7jW/r 4MzaEAzYQdGAKKDrs2H/FcQyT; Received: from 75-166-102-113.hlrn.qwest.net ([75.166.102.113]:45712 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kUcxE-004Oci-Uc; Mon, 19 Oct 2020 15:44:33 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH v2 03/16] Change exec_close to be a method on program_space Date: Mon, 19 Oct 2020 15:44:16 -0600 Message-Id: <20201019214429.13815-4-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20201019214429.13815-1-tom@tromey.com> References: <20201019214429.13815-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.102.113 X-Source-L: No X-Exim-ID: 1kUcxE-004Oci-Uc X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-102-113.hlrn.qwest.net (bapiya.Home) [75.166.102.113]:45712 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" exec_close uses the current program space, so it seemed cleaner to change it to be a method on program_space. This patch makes this change. gdb/ChangeLog 2020-10-19 Tom Tromey * progspace.c (program_space::exec_close): New method, from exec_close in exec.c. * exec.c (exec_close): Move to progspace.c. (exec_target::close, exec_file_attach): Update. * progspace.h (struct program_space) : Declare method. --- gdb/ChangeLog | 9 +++++++++ gdb/exec.c | 29 +++-------------------------- gdb/exec.h | 2 -- gdb/progspace.c | 20 ++++++++++++++++++++ gdb/progspace.h | 3 +++ 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 98b7fbbe5a4..96164ddfd02 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -148,29 +148,6 @@ exec_target_open (const char *args, int from_tty) exec_file_attach (args, from_tty); } -/* Close and clear exec_bfd. If we end up with no target sections to - read memory from, this unpushes the exec_ops target. */ - -void -exec_close (void) -{ - if (exec_bfd) - { - bfd *abfd = exec_bfd; - - gdb_bfd_unref (abfd); - - /* Removing target sections may close the exec_ops target. - Clear exec_bfd before doing so to prevent recursion. */ - exec_bfd = NULL; - exec_bfd_mtime = 0; - - remove_target_sections (&exec_bfd); - - current_program_space->exec_filename.reset (nullptr); - } -} - /* This is the target_close implementation. Clears all target sections and closes all executable bfds from all program spaces. */ @@ -183,7 +160,7 @@ exec_target::close () { set_current_program_space (ss); current_target_sections->clear (); - exec_close (); + ss->exec_close (); } } @@ -396,7 +373,7 @@ exec_file_attach (const char *filename, int from_tty) gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (exec_bfd); /* Remove any previous exec file. */ - exec_close (); + current_program_space->exec_close (); /* Now open and digest the file the user requested, if any. */ @@ -497,7 +474,7 @@ exec_file_attach (const char *filename, int from_tty) { /* Make sure to close exec_bfd, or else "run" might try to use it. */ - exec_close (); + current_program_space->exec_close (); error (_("\"%ps\": not in executable format: %s"), styled_string (file_name_style.style (), scratch_pathname), gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); diff --git a/gdb/exec.h b/gdb/exec.h index b2f51509bcf..f98dd83da21 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -117,8 +117,6 @@ extern void add_target_sections_of_objfile (struct objfile *objfile); extern void print_section_info (target_section_table *table, bfd *abfd); -extern void exec_close (void); - /* Helper function that attempts to open the symbol file at EXEC_FILE_HOST. If successful, it proceeds to add the symbol file as the main symbol file. diff --git a/gdb/progspace.c b/gdb/progspace.c index 76001234255..8a15c402c28 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -223,6 +223,26 @@ program_space::solibs () const return next_adapter (this->so_list); } +/* See progspace.h. */ + +void +program_space::exec_close () +{ + if (ebfd) + { + gdb_bfd_unref (ebfd); + + /* Removing target sections may close the exec_ops target. + Clear exec_bfd before doing so to prevent recursion. */ + ebfd = NULL; + ebfd_mtime = 0; + + remove_target_sections (&ebfd); + + exec_filename.reset (nullptr); + } +} + /* Copies program space SRC to DEST. Copies the main executable file, and the main symbol file. Returns DEST. */ diff --git a/gdb/progspace.h b/gdb/progspace.h index 3acce50b32f..6dcec9c96f7 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -272,6 +272,9 @@ struct program_space for (so_list *so : pspace->solibs ()) { ... } */ next_adapter solibs () const; + /* Close and clear exec_bfd. If we end up with no target sections + to read memory from, this unpushes the exec_ops target. */ + void exec_close (); /* Unique ID number. */ int num = 0; -- 2.17.2