aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2019-03-06 18:29:17 +0000
committerPedro Alves <palves@redhat.com>2019-03-06 18:29:17 +0000
commit72f31aea9e6c158f442239abedaf351465ebcb41 (patch)
tree3e1eba1360246c8281c7c01e57395cde79343e0a /gdb
parentefbecbc143f19cb308ae220fb386505f41ff4bc3 (diff)
downloadgdb-72f31aea9e6c158f442239abedaf351465ebcb41.zip
gdb-72f31aea9e6c158f442239abedaf351465ebcb41.tar.gz
gdb-72f31aea9e6c158f442239abedaf351465ebcb41.tar.bz2
Make "checkpoint" not rely on inferior_ptid
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 don't inadvertently rely on the current thread/target when we shouldn't, and that caught some bad or unnecessary assumptions throughout. gdb/ChangeLog: 2019-03-06 Pedro Alves <palves@redhat.com> * 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/linux-fork.c44
-rw-r--r--gdb/linux-fork.h2
3 files changed, 37 insertions, 17 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8866756..3aaa5ed 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-06 Pedro Alves <palves@redhat.com>
+
+ * 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.
+
2019-03-06 Andrew Burgess <andrew.burgess@embecosm.com>
* f-exp.y (direct_abs_decl): Handle TYPE*SIZE type names.
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index b1b390c..a748dea 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 e6f1304..f918bcb 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);