From patchwork Tue Mar 5 18:43:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31724 Received: (qmail 6530 invoked by alias); 5 Mar 2019 18:43:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6439 invoked by uid 89); 5 Mar 2019 18:43:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=numbered X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Mar 2019 18:43:53 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 146CBC057EC3 for ; Tue, 5 Mar 2019 18:43:52 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 786F65D732 for ; Tue, 5 Mar 2019 18:43:50 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 4/4] Eliminate fork_info::clobber_regs Date: Tue, 5 Mar 2019 18:43:40 +0000 Message-Id: <20190305184340.26768-5-palves@redhat.com> In-Reply-To: <20190305184340.26768-1-palves@redhat.com> References: <20190305184340.26768-1-palves@redhat.com> All fork_save_infrun_state callers pass '1' as CLOBBER_REGS nowadays. The larger hunk in fork_save_infrun_state is just a reindentation. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linux-fork.c (fork_info::clobber_regs): Delete. (fork_load_infrun_state): Remove reference to 'clobber_regs'. (fork_save_infrun_state): Remove 'clobber_regs' parameter. Update comment. Adjust. (scoped_switch_fork_info::scoped_switch_fork_info) (checkpoint_command, linux_fork_context): Adjust fork_save_infrun_state calls. --- gdb/linux-fork.c | 79 +++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 4bc454ba6d..51e8fddbc2 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -77,9 +77,6 @@ struct fork_info CORE_ADDR pc = 0; - /* True if we should restore saved regs. */ - int clobber_regs = 0; - /* Set of open file descriptors' offsets. */ off_t *filepos = nullptr; @@ -223,7 +220,7 @@ fork_load_infrun_state (struct fork_info *fp) linux_nat_switch_fork (fp->ptid); - if (fp->savedregs && fp->clobber_regs) + if (fp->savedregs) get_current_regcache ()->restore (fp->savedregs); registers_changed (); @@ -245,11 +242,10 @@ fork_load_infrun_state (struct fork_info *fp) } } -/* Save infrun state for the fork PTID. - Exported for use by linux child_follow_fork. */ +/* Save infrun state for the fork FP. */ static void -fork_save_infrun_state (struct fork_info *fp, int clobber_regs) +fork_save_infrun_state (struct fork_info *fp) { char path[PATH_MAX]; struct dirent *de; @@ -260,44 +256,39 @@ fork_save_infrun_state (struct fork_info *fp, int clobber_regs) fp->savedregs = new readonly_detached_regcache (*get_current_regcache ()); fp->pc = regcache_read_pc (get_current_regcache ()); - fp->clobber_regs = clobber_regs; - if (clobber_regs) + /* Now save the 'state' (file position) of all open file descriptors. + Unfortunately fork does not take care of that for us... */ + snprintf (path, PATH_MAX, "/proc/%ld/fd", (long) fp->ptid.pid ()); + if ((d = opendir (path)) != NULL) { - /* Now save the 'state' (file position) of all open file descriptors. - Unfortunately fork does not take care of that for us... */ - snprintf (path, PATH_MAX, "/proc/%ld/fd", - (long) fp->ptid.pid ()); - if ((d = opendir (path)) != NULL) + long tmp; + + fp->maxfd = 0; + while ((de = readdir (d)) != NULL) { - long tmp; - - fp->maxfd = 0; - while ((de = readdir (d)) != NULL) - { - /* Count open file descriptors (actually find highest - numbered). */ - tmp = strtol (&de->d_name[0], NULL, 10); - if (fp->maxfd < tmp) - fp->maxfd = tmp; - } - /* Allocate array of file positions. */ - fp->filepos = XRESIZEVEC (off_t, fp->filepos, fp->maxfd + 1); - - /* Initialize to -1 (invalid). */ - for (tmp = 0; tmp <= fp->maxfd; tmp++) - fp->filepos[tmp] = -1; - - /* Now find actual file positions. */ - rewinddir (d); - while ((de = readdir (d)) != NULL) - if (isdigit (de->d_name[0])) - { - tmp = strtol (&de->d_name[0], NULL, 10); - fp->filepos[tmp] = call_lseek (tmp, 0, SEEK_CUR); - } - closedir (d); + /* Count open file descriptors (actually find highest + numbered). */ + tmp = strtol (&de->d_name[0], NULL, 10); + if (fp->maxfd < tmp) + fp->maxfd = tmp; } + /* Allocate array of file positions. */ + fp->filepos = XRESIZEVEC (off_t, fp->filepos, fp->maxfd + 1); + + /* Initialize to -1 (invalid). */ + for (tmp = 0; tmp <= fp->maxfd; tmp++) + fp->filepos[tmp] = -1; + + /* Now find actual file positions. */ + rewinddir (d); + while ((de = readdir (d)) != NULL) + if (isdigit (de->d_name[0])) + { + tmp = strtol (&de->d_name[0], NULL, 10); + fp->filepos[tmp] = call_lseek (tmp, 0, SEEK_CUR); + } + closedir (d); } } @@ -421,7 +412,7 @@ public: gdb_assert (m_oldfp != nullptr); newfp = find_fork_ptid (pptid); gdb_assert (newfp != nullptr); - fork_save_infrun_state (m_oldfp, 1); + fork_save_infrun_state (m_oldfp); remove_breakpoints (); fork_load_infrun_state (newfp); insert_breakpoints (); @@ -718,7 +709,7 @@ checkpoint_command (const char *args, int from_tty) fork_list.emplace_front (inferior_ptid.pid ()); } - fork_save_infrun_state (fp, 1); + fork_save_infrun_state (fp); fp->parent_ptid = last_target_ptid; } @@ -733,7 +724,7 @@ linux_fork_context (struct fork_info *newfp, int from_tty) oldfp = find_fork_ptid (inferior_ptid); gdb_assert (oldfp != NULL); - fork_save_infrun_state (oldfp, 1); + fork_save_infrun_state (oldfp); remove_breakpoints (); fork_load_infrun_state (newfp); insert_breakpoints ();