From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.93]) by sourceware.org (Postfix) with ESMTPS id A07163844027 for ; Wed, 22 Jul 2020 03:34:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A07163844027 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 cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 37C5C8471 for ; Tue, 21 Jul 2020 22:34:47 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id y5WpjIsrHhmVTy5WpjgzeY; Tue, 21 Jul 2020 22:34:47 -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=0fEcw+Tb2tqHs/AOsSp0UgPW9Pflbe1axAzvDSOAiSc=; b=iwwY0NQxzaM2IWhQDD7JF5ZRnP yAhlCcEs14knGAojX+GXy1gtSV/IkjVzKKH2zQyqcWcOglb7AK8ClF6wmR2+Vbl39WXfXpNT3BZrO iY+z8uuUcXROFw9X+HQD0Hlg5; Received: from 174-16-104-48.hlrn.qwest.net ([174.16.104.48]:44534 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 1jy5Wp-000kGI-0M; Tue, 21 Jul 2020 21:34:47 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/9] Change exec_close to be a method on program_space Date: Tue, 21 Jul 2020 21:34:37 -0600 Message-Id: <20200722033444.18522-3-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200722033444.18522-1-tom@tromey.com> References: <20200722033444.18522-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: 174.16.104.48 X-Source-L: No X-Exim-ID: 1jy5Wp-000kGI-0M X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-104-48.hlrn.qwest.net (bapiya.Home) [174.16.104.48]:44534 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3035.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, TXREP, T_SPF_TEMPERROR, URIBL_CSS, URIBL_CSS_A autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 22 Jul 2020 03:34:57 -0000 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-07-21 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 | 31 ++++--------------------------- gdb/exec.h | 2 -- gdb/progspace.c | 20 ++++++++++++++++++++ gdb/progspace.h | 3 +++ 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 8ce7a567df1..a395b58da82 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); clear_section_table (current_target_sections); - 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. */ @@ -498,7 +475,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 ()); @@ -508,7 +485,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\": can't find the file sections: %s"), styled_string (file_name_style.style (), scratch_pathname), bfd_errmsg (bfd_get_error ())); diff --git a/gdb/exec.h b/gdb/exec.h index 66fcb1624a4..daaf0d0d4a7 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -118,8 +118,6 @@ extern void add_target_sections_of_objfile (struct objfile *objfile); extern void print_section_info (struct 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 9cd83e55b75..ca32a0a1b8d 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -218,6 +218,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 afccebbc00b..777bef2e38e 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