From patchwork Tue Mar 5 18:43:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31721 Received: (qmail 5913 invoked by alias); 5 Mar 2019 18:43:51 -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 5819 invoked by uid 89); 5 Mar 2019 18:43:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=hitherto, fp, H*MI:sk:2019030 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:49 +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 6E59F30EBE75 for ; Tue, 5 Mar 2019 18:43:48 +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 010545D782 for ; Tue, 5 Mar 2019 18:43:47 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/4] Make "checkpoint" not rely on inferior_ptid Date: Tue, 5 Mar 2019 18:43:37 +0000 Message-Id: <20190305184340.26768-2-palves@redhat.com> In-Reply-To: <20190305184340.26768-1-palves@redhat.com> References: <20190305184340.26768-1-palves@redhat.com> Don't rely on "inferior_ptid" deep within add_fork. In the multi-target branch, I'm forcing inferior_ptid to null_ptid early in infrun event handling to make sure we inadvertently rely on the current thread/target when we shouldn't, and that caught some bad or unnecessary assumptions throughout. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linux-fork.c (new_fork): New, split out of ... (add_fork): ... this. Return void. Move "first fork" special case from here, to ... (checkpoint_command): ... here. * linux-linux.h (add_fork): Return void. --- gdb/linux-fork.c | 44 ++++++++++++++++++++++++++++---------------- gdb/linux-fork.h | 2 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index b1b390c5c6..a748deaa3a 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -76,29 +76,30 @@ find_last_fork (void) return last; } -/* Add a fork to the internal fork list. */ +/* Allocate a new fork. */ -struct fork_info * -add_fork (pid_t pid) +static struct fork_info * +new_fork (pid_t pid) { struct fork_info *fp; - if (fork_list == NULL && pid != inferior_ptid.pid ()) - { - /* Special case -- if this is the first fork in the list - (the list is hitherto empty), and if this new fork is - NOT the current inferior_ptid, then add inferior_ptid - first, as a special zeroeth fork id. */ - highest_fork_num = -1; - add_fork (inferior_ptid.pid ()); /* safe recursion */ - } - fp = XCNEW (struct fork_info); fp->ptid = ptid_t (pid, pid, 0); - fp->num = ++highest_fork_num; + return fp; +} + +/* Add a new fork to the internal fork list. */ + +void +add_fork (pid_t pid) +{ + struct fork_info *fp = new_fork (pid); if (fork_list == NULL) - fork_list = fp; + { + fork_list = fp; + highest_fork_num = 0; + } else { struct fork_info *last = find_last_fork (); @@ -106,7 +107,7 @@ add_fork (pid_t pid) last->next = fp; } - return fp; + fp->num = ++highest_fork_num; } static void @@ -760,6 +761,17 @@ checkpoint_command (const char *args, int from_tty) if (!fp) error (_("Failed to find new fork")); + + if (fork_list->next == NULL) + { + /* Special case -- if this is the first fork in the list (the + list was hitherto empty), then add inferior_ptid first, as a + special zeroeth fork id. */ + fork_info *first = new_fork (inferior_ptid.pid ()); + first->next = fork_list; + fork_list = first; + } + fork_save_infrun_state (fp, 1); fp->parent_ptid = last_target_ptid; } diff --git a/gdb/linux-fork.h b/gdb/linux-fork.h index e6f130438c..f918bcb3d9 100644 --- a/gdb/linux-fork.h +++ b/gdb/linux-fork.h @@ -21,7 +21,7 @@ #define LINUX_FORK_H struct fork_info; -extern struct fork_info *add_fork (pid_t); +extern void add_fork (pid_t); extern struct fork_info *find_fork_pid (pid_t); extern void linux_fork_killall (void); extern void linux_fork_mourn_inferior (void);