* [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors
@ 2024-06-26 1:55 Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 1/4] " Kevin Buettner
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-06-26 1:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Kevin Buettner
This series fixes some problems with the current checkpoint code. The
first patch makes the checkpoint code inferior aware, fixing a number
of bugs. The second and third patches are largely cosmetic - they
make changes to checkpoint related output.
The v2 series incorporates Pedro's suggestions regarding the
numbering of checkpoint ids. See the first patch for details. The
tests have been revised to account for these changes and new tests
have been added as well.
The v3 series splits out a cosmetic change from the first patch. It
capitalizes the output of a successful checkpoint command. This was
prompted by the Linaro regression tester, which, due to the
capitalization change, found two regressions in
gdb.base/kill-during-detach.exp. (I had made a mistake during my own
testing causing this to not be caught.)
This v4 series addresses Pedro's concerns from his review of the v3
series. It also adds a NEWS entry and updates the GDB manual with
regard to checkpoint identifiers.
Kevin Buettner (4):
Make linux checkpoints work with multiple inferiors
Capitalize output of successful checkpoint command
Print only process ptids from linux-fork.c
Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple
inferiors
gdb/NEWS | 2 +
gdb/doc/gdb.texinfo | 23 +-
gdb/linux-fork.c | 557 +++++++++-----
gdb/linux-fork.h | 15 +-
gdb/linux-nat.c | 18 +-
gdb/testsuite/gdb.base/checkpoint.exp | 26 +-
gdb/testsuite/gdb.base/kill-during-detach.exp | 2 +-
gdb/testsuite/gdb.multi/checkpoint-multi.exp | 689 ++++++++++++++++++
8 files changed, 1134 insertions(+), 198 deletions(-)
create mode 100644 gdb/testsuite/gdb.multi/checkpoint-multi.exp
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 1/4] Make linux checkpoints work with multiple inferiors
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
@ 2024-06-26 1:55 ` Kevin Buettner
2024-10-23 20:10 ` Pedro Alves
2024-06-26 1:55 ` [PATCH v4 2/4] Capitalize output of successful checkpoint command Kevin Buettner
` (5 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Kevin Buettner @ 2024-06-26 1:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Kevin Buettner
The current linux checkpoint code, most of which may be found in
linux-fork.c, is quite broken when attempting to use more than
one inferior. Running GDB will show internal errors when starting
two inferiors, placing a checkpoint in one, then switching to
the other and doing one of the following commands, "restart",
"detach", "kill", or continue (to program exit). Test cases
for two of those scenarios may be found in this bug:
https://sourceware.org/bugzilla/show_bug.cgi?id=31065
I've tested for each of the scenarios and many more in the new
test case, gdb.multi/checkpoint-multi.exp.
I started off with the goal of fixing just those problems, and was
mostly successful with a much smaller patch, but doing "info
checkpoints" with more than one inferior didn't work correctly due to
some of the inferiors being in the wrong program space. That led me
to making the linux-fork code fully inferior-aware.
Prior to this commit, the list of forks was being maintained in a
global named named 'fork_list'. I turned this into a per-inferior
data structure. There was also global named 'highest_fork_num' which
is also now part of the per-inferior struct. A registry key named
'checkpoint_inferior_data_key' along with function
'get_checkpoint_inferior_data' is used to access the per-inferior
data. This new function, get_checkpoint_inferior_data, is only
called by the new functions 'fork_list', 'reset_highest_fork_num',
and increment_highest_fork_num, each of which is passed a pointer to
the inferior. Most occurrences referring to the (previously) global
'fork_list' have been replaced by 'fork_list (inf)'. In some
functions, where the 'fork_list' is referenced multiple times, a local
named 'fork_list' is declared and initialized instead, like this:
auto &fork_list = ::fork_list (inf);
The constructor for 'struct fork_info' has gained an additional
parameter. In addition to passing the pid of the new fork, we now
also pass the fork identifier, fork_num, to the constructor. This
integer is shown to the user in the "info checkpoints" command and
is provided by the user, perhaps in conjunction with the inferior
number, in commands which manipulate checkpoints, e.g. 'restart' and
'delete checkpoint'.
When checkpoints are used in only one inferior, this commit will
present information to the user and will accept checkpoint identifiers
to commands in much the same way as the code did before this commit.
Per Pedro Alves's recommendations, the "info checkpoints" command
has been changed somewhat. "info checkpoints" used to display
"(main process)" for the first process in the checkpoint list.
This is no longer done because it does not provide useful information.
It also used to display "<running>", presumably when in non-stop
mode. I've changed this to print a state flag 'R'. Additionally,
a state flag 'A' is used to indicate the active checkpoint for
each inferior. For the active inferior a '*' is also printed
preceding the checkpoint identifier. Here's what things look(ed)
like before and after for just one inferior:
Before:
(gdb) info checkpoints
* 0 Thread 0x7ffff7cd3740 (LWP 84201) (main process) at 0x40114a, file hello.c, line 28
1 process 84205 at 0x401199, file hello.c, line 51
2 process 84206 at 0x4011a3, file hello.c, line 53
After:
(gdb) info checkpoints
* 0 A process 84159 at 0x40114a, file hello.c, line 28
1 process 84162 at 0x401199, file hello.c, line 51
2 process 84163 at 0x4011a3, file hello.c, line 53
(The Thread versus process distinction is handled by another
patch - the "After" example assumes that patch is applied too.)
When there are multiple inferiors, the "info checkpoints" output looks
like this:
(gdb) info checkpoints
1.0 process 84159 at 0x40114a, file hello.c, line 28
* 1.1 A process 84162 at 0x401199, file hello.c, line 51
1.2 process 84163 at 0x4011a3, file hello.c, line 53
2.0 A process 84223 at 0x40116f, file hangout.c, line 35
2.1 process 84224 at 0x40115c, file hangout.c, line 31
2.2 process 84225 at 0x401166, file hangout.c, line 33
3.0 A process 84226 at 0x401218, file goodbye.c, line 46
3.1 process 84229 at 0x40124e, file goodbye.c, line 61
A new function named 'parse_checkpoint_id' has been added. As its
name suggests, it's responsible for parsing a string representing a
checkpoint identifier. These identifiers may be either a decimal
number representing the checkpoint number in the current inferior or
two decimal numbers separated by '.', in which case the first is the
inferior number and the second is the checkpoint number in that
inferior. It is called by delete_checkpoint_command,
detach_checkpoint_command, info_checkpoints_command, and
restart_command. Calls to 'parse_checkpoint_id' replace calls to
'parse_and_eval_long', plus error checking and error reporting code
near the calls to 'parse_and_eval_long'. As such, error checking and
reporting has been consolidated into a single function and the
messages output are more uniform, though this has necessitated changes
to the existing test case gdb.base/checkpoint.exp.
The functions 'find_fork_ptid' and 'find_fork_pid' used to return a
pointer to a fork_info struct. They now return a pair consisting of
the pointer to a fork_info struct in addition to a pointer to the
inferior containing that checkpoint.
'find_fork_id' returns a a pointer to a fork_info struct just as
it did before, but it's now gained a new parameter, 'inf', which
is the inferior in which to look.
info_checkpoints_command used to simply iterate over the list of
forks (checkpoints), printing each one out. It now needs to iterate
over all inferiors and, for those which have checkpoints, it needs
to iterate over the list of checkpoints in that inferior. As noted
earlier, the format of the output has been changed so that checkpoint
identifers incorporating an inferior number may be printed.
linux_fork_context, called by restart_command, now contains code to
switch inferiors when the fork being restarted is in an inferior which
is different from the current one. The scoped_switch_fork_info class
now also contains code for switching inferiors in both the constructor
and destructor.
gdb/linux-nat.c has a few changes. All but one of them are related
to passing the inferior to one of the linux-fork functions. But
one of the tests in linux_nat_target::detach has also changed in
a non-obvious way. In attempting to determine whether to call
linux_fork_detach(), that code used to do:
if (pid == inferior_ptid.pid () && forks_exist_p ())
It's been simplified to:
if (forks_exist_p (inf))
I had added the 'pid == inferior_ptid.pid ()' condition in late 2023
while working on a detach bug. It was kind of a hack to prevent
calling linux_fork_detach() when in a different inferior. That's no
longer needed since the call to forks_exist_p does this directly -
i.e. it is now inferior-aware.
Finally, the header file 'linux-fork.h' has been updated to reflect
the fact that add_fork, linux_fork_killall, linux_fork_detach, and
forks_exist_p all now require that a pointer to an inferior be passed
to these functions. Additionally (as mentioned earlier),
find_fork_pid now returns std::pair<fork_info *, inferior *> instead
'of fork_info *'.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31065
---
gdb/linux-fork.c | 524 +++++++++-----
gdb/linux-fork.h | 15 +-
gdb/linux-nat.c | 18 +-
gdb/testsuite/gdb.base/checkpoint.exp | 24 +-
gdb/testsuite/gdb.multi/checkpoint-multi.exp | 689 +++++++++++++++++++
5 files changed, 1084 insertions(+), 186 deletions(-)
create mode 100644 gdb/testsuite/gdb.multi/checkpoint-multi.exp
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 319a13fd480..833778bf9f7 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -29,6 +29,7 @@
#include "linux-nat.h"
#include "gdbthread.h"
#include "source.h"
+#include "progspace-and-thread.h"
#include "nat/gdb_ptrace.h"
#include "gdbsupport/gdb_wait.h"
@@ -39,10 +40,11 @@
#include <list>
/* Fork list data structure: */
+
struct fork_info
{
- explicit fork_info (pid_t pid)
- : ptid (pid, pid)
+ explicit fork_info (pid_t pid, int fork_num)
+ : ptid (pid, pid), num (fork_num)
{
}
@@ -70,7 +72,7 @@ struct fork_info
ptid_t parent_ptid = null_ptid;
/* Convenient handle (GDB fork id). */
- int num = 0;
+ int num;
/* Convenient for info fork, saves having to actually switch
contexts. */
@@ -84,115 +86,264 @@ struct fork_info
int maxfd = 0;
};
-static std::list<fork_info> fork_list;
-static int highest_fork_num;
+/* Per-inferior checkpoint data. */
+
+struct checkpoint_inferior_data
+{
+ /* List of forks (checkpoints) in particular inferior. Once a
+ checkpoint has been created, fork_list will contain at least two
+ items, the first in the list will be the original (or, if not
+ original, then the oldest) fork. */
+ std::list<fork_info> fork_list;
+
+ /* Most recently assigned fork number; when 0, no checkpoints have
+ been created yet. */
+ int highest_fork_num = 0;
+};
+
+/* Per-inferior data key. */
+
+static const registry<inferior>::key<checkpoint_inferior_data>
+ checkpoint_inferior_data_key;
+
+/* Fetch per-inferior checkpoint data. It always returns a valid pointer
+ to a checkpoint_inferior_info struct. */
+
+static struct checkpoint_inferior_data *
+get_checkpoint_inferior_data (struct inferior *inf)
+{
+ struct checkpoint_inferior_data *data;
+
+ data = checkpoint_inferior_data_key.get (inf);
+ if (data == nullptr)
+ data = checkpoint_inferior_data_key.emplace (inf);
+
+ return data;
+}
+
+/* Return a reference to the per-inferior fork list. */
+
+static std::list<fork_info> &
+fork_list (inferior *inf)
+{
+ return get_checkpoint_inferior_data (inf)->fork_list;
+}
+
+/* Increment the highest fork number for inferior INF, returning
+ the new value. */
+
+static int
+increment_highest_fork_num (inferior *inf)
+{
+ return ++get_checkpoint_inferior_data (inf)->highest_fork_num;
+}
+
+/* Reset the highest fork number for inferior INF. */
+
+static void
+reset_highest_fork_num (inferior *inf)
+{
+ get_checkpoint_inferior_data (inf)->highest_fork_num = 0;
+}
+
+/* Predicate which returns true when more than one inferior contains
+ a checkpoint, false otherwise. */
+
+static bool
+forks_exist_in_multiple_inferiors_p ()
+{
+ int count = 0;
+ for (inferior *inf : all_inferiors (linux_target))
+ {
+ if (forks_exist_p (inf))
+ count++;
+ if (count > 1)
+ return true;
+ }
+ return false;
+}
/* Fork list methods: */
-int
-forks_exist_p (void)
+/* Predicate which returns true if checkpoint(s) exist in the inferior
+ INF, false otherwise. */
+
+bool
+forks_exist_p (inferior *inf)
{
- return !fork_list.empty ();
+ /* Avoid allocating checkpoint_inferior_data storage by checking
+ to see if such storage exists prior to calling fork_list.
+ If we just call fork_list alone, then that call will create
+ this storage, even for inferiors which don't need it. */
+ return (checkpoint_inferior_data_key.get (inf) != nullptr
+ && !fork_list (inf).empty ());
}
-/* Return the last fork in the list. */
+/* Return the last fork in the list for inferior INF. */
static struct fork_info *
-find_last_fork (void)
+find_last_fork (inferior *inf)
{
+ auto &fork_list = ::fork_list (inf);
+
if (fork_list.empty ())
return NULL;
return &fork_list.back ();
}
-/* Return true iff there's one fork in the list. */
+/* Return true iff there's one fork in the list for inferior INF. */
static bool
-one_fork_p ()
+one_fork_p (inferior *inf)
{
- return fork_list.size () == 1;
+ return fork_list (inf).size () == 1;
}
/* Add a new fork to the internal fork list. */
void
-add_fork (pid_t pid)
+add_fork (pid_t pid, inferior *inf)
{
- fork_list.emplace_back (pid);
-
- if (one_fork_p ())
- highest_fork_num = 0;
-
- fork_info *fp = &fork_list.back ();
- fp->num = ++highest_fork_num;
+ fork_list (inf).emplace_back (pid, increment_highest_fork_num (inf));
}
+/* Delete a fork for PTID in inferior INF. When the last fork is
+ deleted, HIGHEST_FORK_NUM for the given inferior is reset to 0.
+ The fork list may also be made to be empty when only one fork
+ remains. */
+
static void
-delete_fork (ptid_t ptid)
+delete_fork (ptid_t ptid, inferior *inf)
{
linux_target->low_forget_process (ptid.pid ());
+ auto &fork_list = ::fork_list (inf);
for (auto it = fork_list.begin (); it != fork_list.end (); ++it)
if (it->ptid == ptid)
{
fork_list.erase (it);
+ if (fork_list.empty ())
+ reset_highest_fork_num (inf);
+
/* Special case: if there is now only one process in the list,
and if it is (hopefully!) the current inferior_ptid, then
remove it, leaving the list empty -- we're now down to the
default case of debugging a single process. */
- if (one_fork_p () && fork_list.front ().ptid == inferior_ptid)
+ if (one_fork_p (inf) && fork_list.front ().ptid == inferior_ptid)
{
/* Last fork -- delete from list and handle as solo
process (should be a safe recursion). */
- delete_fork (inferior_ptid);
+ delete_fork (inferior_ptid, inf);
}
return;
}
}
-/* Find a fork_info by matching PTID. */
-static struct fork_info *
+/* Find a fork_info and inferior by matching PTID. */
+
+static std::pair<fork_info *, inferior *>
find_fork_ptid (ptid_t ptid)
{
- for (fork_info &fi : fork_list)
- if (fi.ptid == ptid)
- return &fi;
+ for (inferior *inf : all_inferiors (linux_target))
+ {
+ for (fork_info &fi : fork_list (inf))
+ if (fi.ptid == ptid)
+ return { &fi, inf };
+ }
- return NULL;
+ return { nullptr, nullptr };
}
-/* Find a fork_info by matching ID. */
-static struct fork_info *
-find_fork_id (int num)
+/* Find a fork_info by matching NUM in inferior INF. */
+
+static fork_info *
+find_fork_id (inferior *inf, int num)
{
- for (fork_info &fi : fork_list)
+ for (fork_info &fi : fork_list (inf))
if (fi.num == num)
return &fi;
- return NULL;
+ return nullptr;
}
-/* Find a fork_info by matching pid. */
-extern struct fork_info *
+/* Find a fork_info and inferior by matching pid. */
+
+extern std::pair<fork_info *, inferior *>
find_fork_pid (pid_t pid)
{
- for (fork_info &fi : fork_list)
- if (pid == fi.ptid.pid ())
- return &fi;
+ for (inferior *inf : all_inferiors (linux_target))
+ {
+ for (fork_info &fi : fork_list (inf))
+ if (pid == fi.ptid.pid ())
+ return { &fi, inf };
+ }
- return NULL;
+ return { nullptr, nullptr };
}
-static ptid_t
-fork_id_to_ptid (int num)
+/* Parse a command argument representing a checkpoint id. This
+ can take one of two forms:
+
+ Num
+
+ -or-
+
+ Inf.Num
+
+ where Num is a non-negative decimal integer and Inf, if present, is
+ a positive decimal integer.
+
+ Return a pair with a pointer to the fork_info struct and pointer
+ to the inferior. This function will throw an error if there's
+ a problem with the parsing or if either the inferior or checkpoint
+ id does not exist. */
+
+static std::pair<fork_info *, inferior *>
+parse_checkpoint_id (const char *ckptstr)
{
- struct fork_info *fork = find_fork_id (num);
- if (fork)
- return fork->ptid;
+ const char *number = ckptstr;
+ const char *p1;
+ struct inferior *inf;
+
+ const char *dot = strchr (number, '.');
+
+ if (dot != nullptr)
+ {
+ /* Parse number to the left of the dot. */
+ int inf_num;
+
+ p1 = number;
+ inf_num = get_number_trailer (&p1, '.');
+ if (inf_num <= 0)
+ error (_("Inferior number must be a positive integer"));
+
+ inf = find_inferior_id (inf_num);
+ if (inf == NULL)
+ error (_("No inferior number '%d'"), inf_num);
+
+ p1 = dot + 1;
+ }
else
- return ptid_t (-1);
+ {
+ inf = current_inferior ();
+ p1 = number;
+ }
+
+ int fork_num = get_number_trailer (&p1, 0);
+ if (fork_num < 0)
+ error (_("Checkpoint number must be a non-negative integer"));
+
+ if (!forks_exist_p (inf))
+ error (_("Inferior %d has no checkpoints"), inf->num);
+
+ fork_info *fork_ptr = find_fork_id (inf, fork_num);
+ if (fork_ptr == nullptr)
+ error (_("Invalid checkpoint number %d for inferior %d"),
+ fork_num, inf->num);
+
+ return { fork_ptr, inf };
}
/* Fork list <-> gdb interface. */
@@ -297,7 +448,7 @@ fork_save_infrun_state (struct fork_info *fp)
/* Kill 'em all, let God sort 'em out... */
void
-linux_fork_killall (void)
+linux_fork_killall (inferior *inf)
{
/* Walk list and kill every pid. No need to treat the
current inferior_ptid as special (we do not return a
@@ -305,6 +456,7 @@ linux_fork_killall (void)
or a parent, so may get a SIGCHLD from a previously
killed child. Wait them all out. */
+ auto &fork_list = ::fork_list (inf);
for (fork_info &fi : fork_list)
{
pid_t pid = fi.ptid.pid ();
@@ -323,6 +475,7 @@ linux_fork_killall (void)
/* Clear list, prepare to start fresh. */
fork_list.clear ();
+ reset_highest_fork_num (inf);
}
/* The current inferior_ptid has exited, but there are other viable
@@ -330,10 +483,11 @@ linux_fork_killall (void)
first available. */
void
-linux_fork_mourn_inferior (void)
+linux_fork_mourn_inferior ()
{
struct fork_info *last;
int status;
+ inferior *inf = current_inferior ();
/* Wait just one more time to collect the inferior's exit status.
Do not check whether this succeeds though, since we may be
@@ -342,23 +496,23 @@ linux_fork_mourn_inferior (void)
waitpid (inferior_ptid.pid (), &status, 0);
/* OK, presumably inferior_ptid is the one who has exited.
- We need to delete that one from the fork_list, and switch
+ We need to delete that one from the fork list, and switch
to the next available fork. */
- delete_fork (inferior_ptid);
+ delete_fork (inferior_ptid, inf);
/* There should still be a fork - if there's only one left,
delete_fork won't remove it, because we haven't updated
inferior_ptid yet. */
- gdb_assert (!fork_list.empty ());
+ gdb_assert (!fork_list (inf).empty ());
- last = find_last_fork ();
+ last = find_last_fork (inf);
fork_load_infrun_state (last);
gdb_printf (_("[Switching to %s]\n"),
target_pid_to_str (inferior_ptid).c_str ());
/* If there's only one fork, switch back to non-fork mode. */
- if (one_fork_p ())
- delete_fork (inferior_ptid);
+ if (one_fork_p (inf))
+ delete_fork (inferior_ptid, inf);
}
/* The current inferior_ptid is being detached, but there are other
@@ -366,13 +520,13 @@ linux_fork_mourn_inferior (void)
the first available. */
void
-linux_fork_detach (int from_tty, lwp_info *lp)
+linux_fork_detach (int from_tty, lwp_info *lp, inferior *inf)
{
gdb_assert (lp != nullptr);
gdb_assert (lp->ptid == inferior_ptid);
/* OK, inferior_ptid is the one we are detaching from. We need to
- delete it from the fork_list, and switch to the next available
+ delete it from the fork list, and switch to the next available
fork. But before doing the detach, do make sure that the lwp
hasn't exited or been terminated first. */
@@ -385,11 +539,12 @@ linux_fork_detach (int from_tty, lwp_info *lp)
target_pid_to_str (inferior_ptid).c_str ());
}
- delete_fork (inferior_ptid);
+ delete_fork (inferior_ptid, inf);
/* There should still be a fork - if there's only one left,
delete_fork won't remove it, because we haven't updated
inferior_ptid yet. */
+ auto &fork_list = ::fork_list (inf);
gdb_assert (!fork_list.empty ());
fork_load_infrun_state (&fork_list.front ());
@@ -399,8 +554,8 @@ linux_fork_detach (int from_tty, lwp_info *lp)
target_pid_to_str (inferior_ptid).c_str ());
/* If there's only one fork, switch back to non-fork mode. */
- if (one_fork_p ())
- delete_fork (inferior_ptid);
+ if (one_fork_p (inf))
+ delete_fork (inferior_ptid, inf);
}
/* Temporarily switch to the infrun state stored on the fork_info
@@ -413,19 +568,26 @@ class scoped_switch_fork_info
/* Switch to the infrun state held on the fork_info identified by
PPTID. If PPTID is the current inferior then no switch is done. */
explicit scoped_switch_fork_info (ptid_t pptid)
- : m_oldfp (nullptr)
+ : m_oldfp (nullptr), m_oldinf (nullptr)
{
if (pptid != inferior_ptid)
{
- struct fork_info *newfp = nullptr;
-
/* Switch to pptid. */
- m_oldfp = find_fork_ptid (inferior_ptid);
+ auto [oldfp, oldinf] = find_fork_ptid (inferior_ptid);
+ m_oldfp = oldfp;
gdb_assert (m_oldfp != nullptr);
- newfp = find_fork_ptid (pptid);
+ auto [newfp, newinf] = find_fork_ptid (pptid);
gdb_assert (newfp != nullptr);
fork_save_infrun_state (m_oldfp);
remove_breakpoints ();
+
+ if (oldinf != newinf)
+ {
+ thread_info *tp = any_thread_of_inferior (newinf);
+ switch_to_thread (tp);
+ m_oldinf = oldinf;
+ }
+
fork_load_infrun_state (newfp);
insert_breakpoints ();
}
@@ -435,12 +597,17 @@ class scoped_switch_fork_info
didn't need to switch states, then nothing is done here either. */
~scoped_switch_fork_info ()
{
- if (m_oldfp != nullptr)
+ if (m_oldinf != nullptr || m_oldfp != nullptr)
{
/* Switch back to inferior_ptid. */
try
{
remove_breakpoints ();
+ if (m_oldinf != nullptr)
+ {
+ thread_info *tp = any_thread_of_inferior (m_oldinf);
+ switch_to_thread (tp);
+ }
fork_load_infrun_state (m_oldfp);
insert_breakpoints ();
}
@@ -472,8 +639,16 @@ class scoped_switch_fork_info
we were already in the desired state, and nothing needs to be
restored. */
struct fork_info *m_oldfp;
+
+ /* When switching to a different fork, this is the inferior for the
+ fork that we're switching from, and to which we'll switch back once
+ end-of-scope is reached. It may also be nullptr if no switching
+ is required. */
+ inferior *m_oldinf;
};
+/* Call waitpid() by making an inferior function call. */
+
static int
inferior_call_waitpid (ptid_t pptid, int pid)
{
@@ -514,30 +689,25 @@ static void
delete_checkpoint_command (const char *args, int from_tty)
{
ptid_t ptid, pptid;
- struct fork_info *fi;
if (!args || !*args)
error (_("Requires argument (checkpoint id to delete)"));
- ptid = fork_id_to_ptid (parse_and_eval_long (args));
- if (ptid == minus_one_ptid)
- error (_("No such checkpoint id, %s"), args);
+ auto [fi, inf] = parse_checkpoint_id (args);
+ ptid = fi->ptid;
+ gdb_assert (fi != nullptr);
+ pptid = fi->parent_ptid;
- if (ptid == inferior_ptid)
- error (_("\
-Please switch to another checkpoint before deleting the current one"));
+ if (ptid.pid () == inf->pid)
+ error (_("Cannot delete active checkpoint"));
if (ptrace (PTRACE_KILL, ptid.pid (), 0, 0))
error (_("Unable to kill pid %s"), target_pid_to_str (ptid).c_str ());
- fi = find_fork_ptid (ptid);
- gdb_assert (fi);
- pptid = fi->parent_ptid;
-
if (from_tty)
gdb_printf (_("Killed %s\n"), target_pid_to_str (ptid).c_str ());
- delete_fork (ptid);
+ delete_fork (ptid, inf);
if (pptid == null_ptid)
{
@@ -555,7 +725,7 @@ Please switch to another checkpoint before deleting the current one"));
If fi->parent_ptid is a part of lwp and it is stopped, waitpid the
ptid. */
thread_info *parent = linux_target->find_thread (pptid);
- if ((parent == NULL && find_fork_ptid (pptid))
+ if ((parent == NULL && find_fork_ptid (pptid).first != nullptr)
|| (parent != NULL && parent->state == THREAD_STOPPED))
{
if (inferior_call_waitpid (pptid, ptid.pid ()))
@@ -572,9 +742,8 @@ detach_checkpoint_command (const char *args, int from_tty)
if (!args || !*args)
error (_("Requires argument (checkpoint id to detach)"));
- ptid = fork_id_to_ptid (parse_and_eval_long (args));
- if (ptid == minus_one_ptid)
- error (_("No such checkpoint id, %s"), args);
+ auto [fi, inf] = parse_checkpoint_id (args);
+ ptid = fi->ptid;
if (ptid == inferior_ptid)
error (_("\
@@ -586,7 +755,7 @@ Please switch to another checkpoint before detaching the current one"));
if (from_tty)
gdb_printf (_("Detached %s\n"), target_pid_to_str (ptid).c_str ());
- delete_fork (ptid);
+ delete_fork (ptid, current_inferior ());
}
/* Print information about currently known checkpoints. */
@@ -595,72 +764,96 @@ static void
info_checkpoints_command (const char *arg, int from_tty)
{
struct gdbarch *gdbarch = get_current_arch ();
- int requested = -1;
+ struct inferior *cur_inf = current_inferior ();
+ inferior *req_inf = nullptr;
+ fork_info *req_fi = nullptr;
bool printed = false;
if (arg && *arg)
- requested = (int) parse_and_eval_long (arg);
+ std::tie (req_fi, req_inf) = parse_checkpoint_id (arg);
- for (const fork_info &fi : fork_list)
+ /* Figure out whether to print the inferior number in the
+ checkpoint list. */
+ bool print_inf = (!forks_exist_p (current_inferior ())
+ || forks_exist_in_multiple_inferiors_p ());
+
+ for (inferior *inf : all_inferiors (linux_target))
{
- if (requested > 0 && fi.num != requested)
+ if (req_inf != nullptr && req_inf != inf)
continue;
- printed = true;
-
- bool is_current = fi.ptid == inferior_ptid;
- if (is_current)
- gdb_printf ("* ");
- else
- gdb_printf (" ");
- gdb_printf ("%d %s", fi.num, target_pid_to_str (fi.ptid).c_str ());
- if (fi.num == 0)
- gdb_printf (_(" (main process)"));
-
- if (is_current && inferior_thread ()->state == THREAD_RUNNING)
- {
- gdb_printf (_(" <running>\n"));
- continue;
- }
+ scoped_restore_current_pspace_and_thread restore_pspace_thread;
+ switch_to_program_space_and_thread (inf->pspace);
- gdb_printf (_(" at "));
- ULONGEST pc
- = (is_current
- ? regcache_read_pc (get_thread_regcache (inferior_thread ()))
- : fi.pc);
- gdb_puts (paddress (gdbarch, pc));
-
- symtab_and_line sal = find_pc_line (pc, 0);
- if (sal.symtab)
- gdb_printf (_(", file %s"),
- symtab_to_filename_for_display (sal.symtab));
- if (sal.line)
- gdb_printf (_(", line %d"), sal.line);
- if (!sal.symtab && !sal.line)
+ for (const fork_info &fi : fork_list (inf))
{
- struct bound_minimal_symbol msym;
-
- msym = lookup_minimal_symbol_by_pc (pc);
- if (msym.minsym)
- gdb_printf (", <%s>", msym.minsym->linkage_name ());
+ if (req_fi != nullptr && req_fi != &fi)
+ continue;
+ printed = true;
+
+ thread_info *t = any_thread_of_inferior (inf);
+ bool is_current = fi.ptid.pid () == inf->pid;
+ if (is_current && cur_inf == inf)
+ gdb_printf ("*");
+ else
+ gdb_printf (" ");
+
+ if (print_inf)
+ gdb_printf ("%3d.%-2d", inf->num, fi.num);
+ else
+ gdb_printf ("%3d ", fi.num);
+
+ /* Print out state associated with current checkpoint. */
+ if (is_current)
+ {
+ gdb_printf ("A");
+ if (t->state == THREAD_RUNNING)
+ gdb_printf ("R");
+ else
+ gdb_printf (" ");
+ gdb_printf (" ");
+ }
+ else
+ gdb_printf (" ");
+
+ gdb_printf ("%s", target_pid_to_str (fi.ptid).c_str ());
+
+ gdb_printf (_(" at "));
+ ULONGEST pc
+ = (is_current
+ ? regcache_read_pc (get_thread_regcache (t))
+ : fi.pc);
+ gdb_puts (paddress (gdbarch, pc));
+
+ symtab_and_line sal = find_pc_line (pc, 0);
+ if (sal.symtab)
+ gdb_printf (_(", file %s"),
+ symtab_to_filename_for_display (sal.symtab));
+ if (sal.line)
+ gdb_printf (_(", line %d"), sal.line);
+ if (!sal.symtab && !sal.line)
+ {
+ struct bound_minimal_symbol msym;
+
+ msym = lookup_minimal_symbol_by_pc (pc);
+ if (msym.minsym)
+ gdb_printf (", <%s>", msym.minsym->linkage_name ());
+ }
+
+ gdb_putc ('\n');
}
-
- gdb_putc ('\n');
}
if (!printed)
{
- if (requested > 0)
- gdb_printf (_("No checkpoint number %d.\n"), requested);
- else
- gdb_printf (_("No checkpoints.\n"));
+ gdb_printf (_("No checkpoints.\n"));
}
}
/* The PID of the process we're checkpointing. */
static int checkpointing_pid = 0;
-int
+bool
linux_fork_checkpointing_p (int pid)
{
return (checkpointing_pid == pid);
@@ -690,17 +883,16 @@ checkpoint_command (const char *args, int from_tty)
struct target_waitstatus last_target_waitstatus;
ptid_t last_target_ptid;
struct value *fork_fn = NULL, *ret;
- struct fork_info *fp;
pid_t retpid;
- if (!target_has_execution ())
+ if (!target_has_execution ())
error (_("The program is not being run."));
/* Ensure that the inferior is not multithreaded. */
update_thread_list ();
if (inf_has_multiple_threads ())
error (_("checkpoint: can't checkpoint multiple threads."));
-
+
/* Make the inferior fork, record its (and gdb's) state. */
if (lookup_minimal_symbol ("fork", NULL, NULL).minsym != NULL)
@@ -728,14 +920,21 @@ checkpoint_command (const char *args, int from_tty)
retpid = value_as_long (ret);
get_last_target_status (nullptr, &last_target_ptid, &last_target_waitstatus);
- fp = find_fork_pid (retpid);
+ auto [fp, inf] = find_fork_pid (retpid);
+
+ if (!fp)
+ error (_("Failed to find new fork"));
if (from_tty)
{
int parent_pid;
- gdb_printf (_("checkpoint %d: fork returned pid %ld.\n"),
- fp != NULL ? fp->num : -1, (long) retpid);
+ gdb_printf (_("checkpoint %s: fork returned pid %ld.\n"),
+ (forks_exist_in_multiple_inferiors_p ()
+ ? string_printf ("%d.%d", inf->num, fp->num).c_str ()
+ : string_printf ("%d", fp->num).c_str ()),
+ (long) retpid);
+
if (info_verbose)
{
parent_pid = last_target_ptid.lwp ();
@@ -746,15 +945,12 @@ checkpoint_command (const char *args, int from_tty)
}
}
- if (!fp)
- error (_("Failed to find new fork"));
-
- if (one_fork_p ())
+ if (one_fork_p (inf))
{
/* 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_list.emplace_front (inferior_ptid.pid ());
+ list was hitherto empty), then add inferior_ptid as a special
+ zeroeth fork id. */
+ fork_list (inf).emplace_front (inferior_ptid.pid (), 0);
}
fork_save_infrun_state (fp);
@@ -762,40 +958,48 @@ checkpoint_command (const char *args, int from_tty)
}
static void
-linux_fork_context (struct fork_info *newfp, int from_tty)
+linux_fork_context (struct fork_info *newfp, int from_tty, inferior *newinf)
{
- /* Now we attempt to switch processes. */
- struct fork_info *oldfp;
+ bool inferior_changed = false;
+ /* Now we attempt to switch processes. */
gdb_assert (newfp != NULL);
- oldfp = find_fork_ptid (inferior_ptid);
- gdb_assert (oldfp != NULL);
+ if (newinf != current_inferior ())
+ {
+ thread_info *tp = any_thread_of_inferior (newinf);
+ switch_to_thread (tp);
+ inferior_changed = true;
+ }
- fork_save_infrun_state (oldfp);
- remove_breakpoints ();
- fork_load_infrun_state (newfp);
- insert_breakpoints ();
+ auto [oldfp, oldinf] = find_fork_ptid (inferior_ptid);
+ gdb_assert (oldfp != NULL);
- gdb_printf (_("Switching to %s\n"),
- target_pid_to_str (inferior_ptid).c_str ());
+ if (oldfp != newfp)
+ {
+ fork_save_infrun_state (oldfp);
+ remove_breakpoints ();
+ fork_load_infrun_state (newfp);
+ insert_breakpoints ();
+ if (!inferior_changed)
+ gdb_printf (_("Switching to %s\n"),
+ target_pid_to_str (inferior_ptid).c_str ());
+ }
- print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
+ notify_user_selected_context_changed
+ (inferior_changed ? (USER_SELECTED_INFERIOR | USER_SELECTED_FRAME)
+ : USER_SELECTED_FRAME);
}
/* Switch inferior process (checkpoint) context, by checkpoint id. */
static void
restart_command (const char *args, int from_tty)
{
- struct fork_info *fp;
-
if (!args || !*args)
error (_("Requires argument (checkpoint id to restart)"));
- if ((fp = find_fork_id (parse_and_eval_long (args))) == NULL)
- error (_("Not found: checkpoint id %s"), args);
-
- linux_fork_context (fp, from_tty);
+ auto [fp, inf] = parse_checkpoint_id (args);
+ linux_fork_context (fp, from_tty, inf);
}
void _initialize_linux_fork ();
diff --git a/gdb/linux-fork.h b/gdb/linux-fork.h
index c553aaf0740..0ed47eda15f 100644
--- a/gdb/linux-fork.h
+++ b/gdb/linux-fork.h
@@ -22,12 +22,13 @@
struct fork_info;
struct lwp_info;
-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);
-extern void linux_fork_detach (int, lwp_info *);
-extern int forks_exist_p (void);
-extern int linux_fork_checkpointing_p (int);
+class inferior;
+extern void add_fork (pid_t, inferior *inf);
+extern std::pair<fork_info *, inferior *> find_fork_pid (pid_t);
+extern void linux_fork_killall (inferior *inf);
+extern void linux_fork_mourn_inferior ();
+extern void linux_fork_detach (int, lwp_info *, inferior *inf);
+extern bool forks_exist_p (inferior *inf);
+extern bool linux_fork_checkpointing_p (int);
#endif /* LINUX_FORK_H */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 3f252370c7b..5b2cc8f2fb8 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1558,13 +1558,13 @@ linux_nat_target::detach (inferior *inf, int from_tty)
gdb_assert (num_lwps (pid) == 1
|| (target_is_non_stop_p () && num_lwps (pid) == 0));
- if (pid == inferior_ptid.pid () && forks_exist_p ())
+ if (forks_exist_p (inf))
{
/* Multi-fork case. The current inferior_ptid is being detached
from, but there are other viable forks to debug. Detach from
the current fork, and context-switch to the first
available. */
- linux_fork_detach (from_tty, find_lwp_pid (ptid_t (pid)));
+ linux_fork_detach (from_tty, find_lwp_pid (ptid_t (pid)), inf);
}
else
{
@@ -2082,8 +2082,12 @@ linux_handle_extended_wait (struct lwp_info *lp, int status)
detach_breakpoints (ptid_t (new_pid, new_pid));
/* Retain child fork in ptrace (stopped) state. */
- if (!find_fork_pid (new_pid))
- add_fork (new_pid);
+ if (find_fork_pid (new_pid).first == nullptr)
+ {
+ struct inferior *inf = find_inferior_ptid (linux_target,
+ lp->ptid);
+ add_fork (new_pid, inf);
+ }
/* Report as spurious, so that infrun doesn't want to follow
this fork. We're actually doing an infcall in
@@ -3729,8 +3733,8 @@ linux_nat_target::kill ()
parent will be sleeping if this is a vfork. */
iterate_over_lwps (pid_ptid, kill_unfollowed_child_callback);
- if (forks_exist_p ())
- linux_fork_killall ();
+ if (forks_exist_p (current_inferior ()))
+ linux_fork_killall (current_inferior ());
else
{
/* Stop all threads before killing them, since ptrace requires
@@ -3761,7 +3765,7 @@ linux_nat_target::mourn_inferior ()
close_proc_mem_file (pid);
- if (! forks_exist_p ())
+ if (! forks_exist_p (current_inferior ()))
/* Normal case, no other forks available. */
inf_ptrace_target::mourn_inferior ();
else
diff --git a/gdb/testsuite/gdb.base/checkpoint.exp b/gdb/testsuite/gdb.base/checkpoint.exp
index f87f528e167..b9a1e3161db 100644
--- a/gdb/testsuite/gdb.base/checkpoint.exp
+++ b/gdb/testsuite/gdb.base/checkpoint.exp
@@ -274,17 +274,17 @@ gdb_test "kill" "" "kill all one" \
# and confirm that all are gone
#
-gdb_test "restart 0" "Not found.*" "no more checkpoint 0"
-gdb_test "restart 1" "Not found.*" "no more checkpoint 1"
-gdb_test "restart 2" "Not found.*" "no more checkpoint 2"
-gdb_test "restart 3" "Not found.*" "no more checkpoint 3"
-gdb_test "restart 4" "Not found.*" "no more checkpoint 4"
-gdb_test "restart 5" "Not found.*" "no more checkpoint 5"
-gdb_test "restart 6" "Not found.*" "no more checkpoint 6"
-gdb_test "restart 7" "Not found.*" "no more checkpoint 7"
-gdb_test "restart 8" "Not found.*" "no more checkpoint 8"
-gdb_test "restart 9" "Not found.*" "no more checkpoint 9"
-gdb_test "restart 10" "Not found.*" "no more checkpoint 10"
+gdb_test "restart 0" "has no checkpoints" "no more checkpoint 0"
+gdb_test "restart 1" "has no checkpoints" "no more checkpoint 1"
+gdb_test "restart 2" "has no checkpoints" "no more checkpoint 2"
+gdb_test "restart 3" "has no checkpoints" "no more checkpoint 3"
+gdb_test "restart 4" "has no checkpoints" "no more checkpoint 4"
+gdb_test "restart 5" "has no checkpoints" "no more checkpoint 5"
+gdb_test "restart 6" "has no checkpoints" "no more checkpoint 6"
+gdb_test "restart 7" "has no checkpoints" "no more checkpoint 7"
+gdb_test "restart 8" "has no checkpoints" "no more checkpoint 8"
+gdb_test "restart 9" "has no checkpoints" "no more checkpoint 9"
+gdb_test "restart 10" "has no checkpoints" "no more checkpoint 10"
#
# Now let's try setting a large number of checkpoints (>600)
@@ -309,7 +309,7 @@ gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints"
set count 0
set msg "info checkpoints with at least 600 checkpoints"
gdb_test_multiple "info checkpoints" $msg {
- -re " $decimal process \[^\r\]*\r\n" {
+ -re " $decimal A? *process \[^\r\]*\r\n" {
incr count
exp_continue
}
diff --git a/gdb/testsuite/gdb.multi/checkpoint-multi.exp b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
new file mode 100644
index 00000000000..ec999c078c8
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
@@ -0,0 +1,689 @@
+# Copyright 2009-2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file tests various scenarios involving multiple inferiors
+# and the checkpoint command.
+
+# Checkpoint support works only on Linux.
+require {istarget "*-*-linux*"}
+
+# Checkpoint support is implemented for the (Linux) native target.
+require gdb_protocol_is_native
+
+set proc_re "(?:process $::decimal|Thread $::hex \\(LWP $::decimal\\))"
+set ckpt_re "checkpoint"
+set main_proc "\\(main process\\)"
+set hello_c "hello\\.c"
+set goodbye_c "goodbye\\.c"
+set hangout_c "hangout\\.c"
+
+set testfile "checkpoint-multi"
+
+set exec1 "hello"
+set srcfile1 ${exec1}.c
+set binfile1 [standard_output_file ${exec1}]
+
+set exec2 "goodbye"
+set srcfile2 ${exec2}.c
+set binfile2 [standard_output_file ${exec2}]
+
+set exec3 "hangout"
+set srcfile3 ${exec3}.c
+set binfile3 [standard_output_file ${exec3}]
+
+if { [build_executable ${testfile}.exp ${exec1} "${srcfile1}" {debug}] == -1 } {
+ return -1
+}
+
+if { [build_executable ${testfile}.exp ${exec2} "${srcfile2}" {debug}] == -1 } {
+ return -1
+}
+
+if { [build_executable ${testfile}.exp ${exec3} "${srcfile3}" {debug}] == -1 } {
+ return -1
+}
+
+# Start two inferiors, place a checkpoint on inferior 2, but switch
+# back to inferior 1.
+proc start_2_inferiors_checkpoint_on_inf_2 {} {
+ clean_restart $::exec1
+
+ # Start inferior 1.
+ if {[gdb_start_cmd] < 0} {
+ fail "start first inferior"
+ } else {
+ gdb_test "" "main.*" "start first inferior"
+ }
+
+ # Add a new inferior and exec into it.
+ gdb_test "add-inferior -exec $::binfile2" \
+ "Added inferior 2.*" \
+ "add inferior 2 with -exec $::exec2"
+
+ # Check that we have multiple inferiors.
+ gdb_test "info inferiors" \
+ "Executable.*$::exec1.*$::exec2.*"
+
+ # Switch to inferior 2.
+ gdb_test "inferior 2" \
+ "Switching to inferior 2.*$::exec2.*"
+
+ # Start inferior 2:
+ if {[gdb_start_cmd] < 0} {
+ fail "start second inferior"
+ } else {
+ gdb_test "" "main.*" "start second inferior"
+ }
+
+ # Set a checkpoint in inferior 2
+ gdb_test "checkpoint" "$::ckpt_re 1: fork returned pid $::decimal.*"
+
+ # Step one line in inferior 2.
+ gdb_test "step" "glob = 46;"
+
+ # Switch back to inferior 1.
+ gdb_test "inferior 1" "Switching to inferior 1.*$::exec1.*"
+}
+
+# Start two inferiors, place a checkpoint on inferior 2, but switch
+# back to inferior 1. This is like the one above, except that it
+# swaps the executables loaded into inferior 1 and inferior 2. This
+# is important for being able to test "continue to exit". (Because...
+# hello.c has an infinite loop, but goodbye.c doesn't. In order to
+# test "continue to exit", we need to continue in an executable which
+# will actually exit.)
+
+proc start_2_inferiors_checkpoint_on_inf_2_alt {} {
+ clean_restart $::exec2
+
+ # Start inferior 1.
+ if {[gdb_start_cmd] < 0} {
+ fail "start first inferior"
+ } else {
+ gdb_test "" "main.*" "start first inferior"
+ }
+
+ # Add a new inferior and exec exec1 into it.
+ gdb_test "add-inferior -exec $::binfile1" \
+ "Added inferior 2.*" \
+ "add inferior 2 with -exec $::exec1"
+
+ # Check that we have two inferiors.
+ gdb_test "info inferiors" \
+ "Executable.*$::exec2.*$::exec1.*"
+
+ # Switch to inferior 2.
+ gdb_test "inferior 2" \
+ "Switching to inferior 2.*$::exec1.*"
+
+ # Start inferior 2:
+ if {[gdb_start_cmd] < 0} {
+ fail "start second inferior"
+ } else {
+ gdb_test "" "main.*" "start second inferior"
+ }
+
+ # Set a checkpoint in inferior 2
+ gdb_test "checkpoint" "$::ckpt_re 1: fork returned pid $::decimal.*"
+
+ # next one line in inferior 2.
+ gdb_test "next" "bar\\(\\).*"
+
+ # Switch back to inferior 1.
+ gdb_test "inferior 1" "Switching to inferior 1.*$::exec2.*"
+}
+
+with_test_prefix "check detach on non-checkpointed inferior" {
+ start_2_inferiors_checkpoint_on_inf_2
+ gdb_test "detach" "Detaching from program.*$::exec1.*Inferior 1.*detached.*"
+}
+
+with_test_prefix "check kill on non-checkpointed inferior" {
+ start_2_inferiors_checkpoint_on_inf_2
+ gdb_test "kill" "" "kill non-checkpointed inferior" \
+ "Kill the program being debugged.*y or n. $" "y"
+}
+
+with_test_prefix "check restart 0 on non-checkpointed inferior" {
+ start_2_inferiors_checkpoint_on_inf_2
+ gdb_test "restart 0" "Inferior 1 has no checkpoints"
+ gdb_test "restart 2.0" "Switching to inferior 2.*?goodbye.*?#0 +mailand .*?glob = 46;.*"
+}
+
+with_test_prefix "check restart 1 on non-checkpointed inferior" {
+ start_2_inferiors_checkpoint_on_inf_2
+ gdb_test "restart 1" "Inferior 1 has no checkpoints"
+ gdb_test "restart 2.1" "Switching to inferior 2.*?goodbye.*?#0 +main .*?mailand\\(\\);.*"
+}
+
+with_test_prefix "check continue to exit on non-checkpointed inferior" {
+ start_2_inferiors_checkpoint_on_inf_2_alt
+ gdb_test "continue" "Inferior 1.*? exited normally.*"
+}
+
+with_test_prefix "two inferiors with checkpoints" {
+ start_2_inferiors_checkpoint_on_inf_2
+ with_test_prefix "one checkpoint" {
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 2.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+ with_test_prefix "two checkpoints" {
+ gdb_test "checkpoint" "$ckpt_re 1\\.1: fork returned pid $::decimal.*" \
+ "checkpoint in inferior 1"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ "\\* 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ # Note: No switching is done here since checkpoint 0 is the active one.
+ gdb_test "restart 0" "main.*?$hello_c.*?alarm \\(240\\);"
+
+ gdb_test "restart 2.0" \
+ "\\\[Switching to inferior 2.*?mailand.*?glob = 46;.*"
+ gdb_test "next" "\}"
+
+ with_test_prefix "restart 1" {
+ gdb_test "restart 1" "^Switching to $proc_re.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "info checkpoints twice in a row" {
+ # Doing "info_checkpoints" twice in a row might seem pointless,
+ # but during work on making the checkpoint code inferior aware,
+ # there was a point at which doing it twice in a row did not
+ # produce the same output.
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "restart 0" {
+ # Switch back to checkpoint 0; again, there should be no
+ # "Switching to inferior" message.
+ gdb_test "restart 0" \
+ "^Switching to $proc_re.*?#0 mailand \\(\\) at.*?$goodbye_c.*\}"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ # Try switching to invalid checkpoints:
+ with_test_prefix "invalid checkpoints" {
+ gdb_test "restart 3" "Invalid checkpoint number 3 for inferior 2"
+ gdb_test "restart 2" "Invalid checkpoint number 2 for inferior 2"
+ gdb_test "restart -1" "Checkpoint number must be a non-negative integer"
+ gdb_test "restart 2.3" "Invalid checkpoint number 3 for inferior 2"
+ gdb_test "restart 3.0" "No inferior number '3'"
+ gdb_test "restart 1.2" "Invalid checkpoint number 2 for inferior 1"
+ gdb_test "restart 1.3" "Invalid checkpoint number 3 for inferior 1"
+ gdb_test "restart 1.-1" "Checkpoint number must be a non-negative integer"
+ gdb_test "restart -1.0" "Inferior number must be a positive integer"
+ }
+
+ with_test_prefix "restart 1.1" {
+ # Switch to checkpoint 1.1; this time, we should see a "Switching to
+ # inferior" message.
+ gdb_test "restart 1.1" \
+ "\\\[Switching to inferior 1.*?main.*?$hello_c.*?alarm \\(240\\);"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "restart 2.1" {
+ gdb_test "restart 2.1" \
+ "Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "second checkpoint in inferior 2" {
+ gdb_test "checkpoint" "$ckpt_re 2\\.2: fork returned pid $::decimal.*"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "third checkpoint in inferior 2" {
+ gdb_test "checkpoint" "$ckpt_re 2.3: fork returned pid $::decimal.*"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.3 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "continue to exit in checkpoint 2.1" {
+ gdb_test "continue" \
+ "Inferior 2 \\(process $decimal\\) exited normally.*?Switching to $proc_re.*?"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.3 A $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "continue to exit in checkpoint 2.3" {
+ gdb_test "continue" \
+ "Inferior 2 \\(process $decimal\\) exited normally.*?Switching to process $decimal.*?"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "continue to exit in checkpoint 2.2" {
+ gdb_test "continue" \
+ "Inferior 2 \\(process $decimal\\) exited normally.*?Switching to process $decimal.*?"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?"]
+ }
+
+ with_test_prefix "new checkpoints in inferior 2" {
+ gdb_test "checkpoint" "$ckpt_re 2.1: fork returned pid $::decimal.*" \
+ "checkpoint 2.1"
+
+ gdb_test "checkpoint" "$ckpt_re 2.2: fork returned pid $::decimal.*" \
+ "checkpoint 2.2"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "delete checkpoint 2.0" {
+ gdb_test "delete checkpoint 2.0" \
+ "Cannot delete active checkpoint" \
+ "failed attempt to delete active checkpoint 2.0"
+
+ gdb_test "restart 2.1" \
+ "^Switching to process.*?#0 mailand \\(\\) at.*?$goodbye_c.*\}"
+
+ gdb_test "delete checkpoint 2.0" \
+ "Killed process $::decimal"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "delete checkpoint 2.2" {
+ gdb_test "delete checkpoint 2.2" \
+ "Killed process $::decimal"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?"]
+ }
+
+ with_test_prefix "new checkpoint in inferior 2" {
+ gdb_test "checkpoint" "$ckpt_re 2.1: fork returned pid $::decimal.*"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "switch to inferior 1" {
+ gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 $proc_re at $::hex, file.*?$hello_c.*?" \
+ "\\* 1\\.1 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "kill inferior 1" {
+ gdb_test "kill" "\\\[Inferior 1 \\(process $::decimal\\) killed\\\]" \
+ "kill inferior 1" \
+ "Kill the program being debugged.*y or n. $" "y"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "start inferior 1 again" {
+ gdb_test "checkpoint" "The program is not being run\\." \
+ "checkpoint in non-running inferior"
+
+ gdb_test "start" "Starting program.*?hello.*?alarm \\(240\\);"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+
+ with_test_prefix "checkpoint 1.1" {
+ gdb_test "checkpoint" "$ckpt_re 1.1: fork returned pid $::decimal.*" \
+ "second checkpoint in inferior 1"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ "\\* 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+ }
+}
+
+with_test_prefix "three inferiors with checkpoints" {
+ start_2_inferiors_checkpoint_on_inf_2
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?"]
+
+ with_test_prefix "add third inferior" {
+ # Add a third inferior and exec into it.
+ gdb_test "add-inferior -exec $::binfile3" \
+ "Added inferior 3.*" \
+ "add inferior 3 with -exec $::exec3"
+
+ # Check that we have three inferiors.
+ gdb_test "info inferiors" \
+ "Executable.*?\\* 1 .*?$::exec1.*? 2 .*?$::exec2.*? 3 .*?$::exec3.*?" \
+ "check for three inferiors"
+
+ # Switch to inferior 3.
+ gdb_test "inferior 3" \
+ "Switching to inferior 3.*$::exec3.*"
+
+ # Start inferior 2:
+ if {[gdb_start_cmd] < 0} {
+ fail "start third inferior"
+ } else {
+ gdb_test "" "main.*" "start third inferior"
+ }
+
+ gdb_test "checkpoint" "$ckpt_re 3\\.1: fork returned pid $::decimal.*"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "make checkpoint in inferior 1" {
+ gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
+
+ gdb_test "checkpoint" "$ckpt_re 1\\.1: fork returned pid $::decimal.*"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ "\\* 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "restart 2.1" {
+ gdb_test "restart 2.1" \
+ "Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "next and make new checkpoint" {
+ gdb_test "next" "foo\\(glob\\);"
+ gdb_test "checkpoint" "$ckpt_re 2\\.2: fork returned pid $::decimal.*"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "switch to inferior 3 for upcoming kill" {
+ gdb_test "inferior 3" "Switching to inferior 3.*?alarm \\(30\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "kill inferior 3" {
+ gdb_test "kill" "\\\[Inferior 3 \\(process $::decimal\\) killed\\\]" \
+ "kill inferior 3" \
+ "Kill the program being debugged.*y or n. $" "y"
+
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.0 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" ]
+ }
+
+ with_test_prefix "delete checkpoint 2.0" {
+ gdb_test "delete checkpoint 0" \
+ "Inferior 3 has no checkpoints"
+ gdb_test "delete checkpoint 2.0" \
+ "Killed process $::decimal"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 $proc_re at $::hex, file.*?$goodbye_c.*?" ]
+ }
+
+ with_test_prefix "restart 2.2" {
+ gdb_test "restart 2.2" \
+ "Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*foo\\(glob\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" ]
+ }
+
+ with_test_prefix "switch to non-running inferior 3" {
+ gdb_test "inferior 3" "\\\[Switching to inferior 3 \\\[<null>\\\] \\(.*?$::exec3\\)\\\]"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" ]
+ }
+
+ with_test_prefix "restart inferior 3 and make new checkpoints" {
+ gdb_test "start" "Starting program.*?hangout.*?alarm \\(30\\);"
+ gdb_test "checkpoint" \
+ "$ckpt_re 3\\.1: fork returned pid $::decimal.*" \
+ "checkpoint 3.1"
+ gdb_test "checkpoint" \
+ "$ckpt_re 3\\.2: fork returned pid $::decimal.*" \
+ "checkpoint 3.2"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.1 $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "delete checkpoint 3.1" {
+ gdb_test "delete checkpoint 1" \
+ "Killed process $::decimal"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "attempt to delete active checkpoint in non-current inferior" {
+ # Switch to inferior 1, add another checkpoint - so that there
+ # are three of them in inferior 1 - then switch back to
+ # inferior 3 and delete active checkpoint in inferior 1.
+ # Then, switch to inferior 1 and attempt to add another
+ # checkpoint. During development, a "Cannot access memory at
+ # address ..." message was seen. This was a bug - there were
+ # several problems - but one of them was that the checkpoint in
+ # question was an "active" checkpoint. The fix was to
+ # disallow this case.
+ gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
+ gdb_test "checkpoint" "$ckpt_re 1\\.2: fork returned pid $::decimal.*"
+ gdb_test "inferior 3" "Switching to inferior 3.*?alarm \\(30\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.1 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.2 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+
+ # Check that deleting active checkpoints in other (non-current)
+ # inferiors is disallowed.
+ gdb_test "delete checkpoint 1.0" \
+ "Cannot delete active checkpoint"
+ }
+
+ with_test_prefix "delete non-active checkpoint in non-current inferior" {
+ # But deleting non-active checkpoints, even in other inferiors,
+ # should work.
+ gdb_test "delete checkpoint 1.1" \
+ "Killed process $::decimal"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ " 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.2 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ "\\* 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "switch to inferior 1" {
+ gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ "\\* 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.2 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "checkpoint 1.3" {
+ gdb_test "checkpoint" "$ckpt_re 1\\.3: fork returned pid $::decimal.*" \
+ "third checkpoint in inferior 1"
+ gdb_test "info checkpoints" \
+ [multi_line \
+ "\\* 1\\.0 A $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.2 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 1\\.3 $proc_re at $::hex, file.*?$hello_c.*?" \
+ " 2\\.1 $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 2\\.2 A $proc_re at $::hex, file.*?$goodbye_c.*?" \
+ " 3\\.0 A $proc_re at $::hex, file.*?$hangout_c.*?" \
+ " 3\\.2 $proc_re at $::hex, file.*?$hangout_c.*?"]
+ }
+
+ with_test_prefix "attempt to remove active but not current inferior" {
+ gdb_test "x/i \$pc" "=> $::hex <main.*"
+ gdb_test "remove-inferior 3" \
+ "warning: Can not remove active inferior 3\."
+ }
+}
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 2/4] Capitalize output of successful checkpoint command
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 1/4] " Kevin Buettner
@ 2024-06-26 1:55 ` Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 3/4] Print only process ptids from linux-fork.c Kevin Buettner
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-06-26 1:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Kevin Buettner
This commit causes the output of a "checkpoint" command to be
changed from:
checkpoint N: fork returned pid DDDD
to:
Checkpoint N: fork returned pid DDDD
This change was made to bring the output of the "checkpoint" command in
line with that of other commands, e.g.:
(gdb) break main
Breakpoint 1 at ...
(gdb) catch exec
Catchpoint 2 (exec)
(gdb) add-inferior
[New inferior 2]
Added inferior 2
The tests gdb.base/checkpoint.exp, gdb.base/kill-during-detach.exp,
and gdb.multi/checkpoint-multi.exp have been updated to accept the new
(capitalized) output from the "checkpoint" command.
---
gdb/linux-fork.c | 2 +-
gdb/testsuite/gdb.base/checkpoint.exp | 2 +-
gdb/testsuite/gdb.base/kill-during-detach.exp | 2 +-
gdb/testsuite/gdb.multi/checkpoint-multi.exp | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 833778bf9f7..4905d4ffd88 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -929,7 +929,7 @@ checkpoint_command (const char *args, int from_tty)
{
int parent_pid;
- gdb_printf (_("checkpoint %s: fork returned pid %ld.\n"),
+ gdb_printf (_("Checkpoint %s: fork returned pid %ld.\n"),
(forks_exist_in_multiple_inferiors_p ()
? string_printf ("%d.%d", inf->num, fp->num).c_str ()
: string_printf ("%d", fp->num).c_str ()),
diff --git a/gdb/testsuite/gdb.base/checkpoint.exp b/gdb/testsuite/gdb.base/checkpoint.exp
index b9a1e3161db..0662fe1c654 100644
--- a/gdb/testsuite/gdb.base/checkpoint.exp
+++ b/gdb/testsuite/gdb.base/checkpoint.exp
@@ -345,7 +345,7 @@ with_test_prefix "delete checkpoint 0" {
clean_restart $binfile
runto_main
- gdb_test "checkpoint" "checkpoint 1: fork returned pid $decimal\\."
+ gdb_test "checkpoint" "Checkpoint 1: fork returned pid $decimal\\."
gdb_test "restart 1" "Switching to .*"
gdb_test "delete checkpoint 0" "Killed process $decimal"
gdb_test "info checkpoints" [string_to_regexp "No checkpoints."]
diff --git a/gdb/testsuite/gdb.base/kill-during-detach.exp b/gdb/testsuite/gdb.base/kill-during-detach.exp
index 68292cc3c51..d9ab8ee5383 100644
--- a/gdb/testsuite/gdb.base/kill-during-detach.exp
+++ b/gdb/testsuite/gdb.base/kill-during-detach.exp
@@ -93,7 +93,7 @@ proc run_test { exit_p checkpoint_p } {
# Set the checkpoint.
gdb_test "checkpoint" \
- "checkpoint 1: fork returned pid $::decimal\\."
+ "Checkpoint 1: fork returned pid $::decimal\\."
}
# Must get the PID before we resume the inferior.
diff --git a/gdb/testsuite/gdb.multi/checkpoint-multi.exp b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
index ec999c078c8..a8f0190747b 100644
--- a/gdb/testsuite/gdb.multi/checkpoint-multi.exp
+++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
@@ -23,7 +23,7 @@ require {istarget "*-*-linux*"}
require gdb_protocol_is_native
set proc_re "(?:process $::decimal|Thread $::hex \\(LWP $::decimal\\))"
-set ckpt_re "checkpoint"
+set ckpt_re "Checkpoint"
set main_proc "\\(main process\\)"
set hello_c "hello\\.c"
set goodbye_c "goodbye\\.c"
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 3/4] Print only process ptids from linux-fork.c
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 1/4] " Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 2/4] Capitalize output of successful checkpoint command Kevin Buettner
@ 2024-06-26 1:55 ` Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors Kevin Buettner
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-06-26 1:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Kevin Buettner
This commit causes a "process ptid" to be passed to all calls
of target_pid_to_str in linux-fork.c. A "process ptid" is one
in which only the pid component is set to a non-zero value;
both the lwp and tid components are zero.
The reason for doing this is that pids associated with checkpoints can
never be a thread due to the fact that checkpoints (which are
implemented by forking a process) can only (reasonably) work with
single-threaded processes.
Without this commit, many of the "info checkpoints" commands
in gdb.multi/checkpoint-multi.exp will incorrectly show some
of the checkpoints as threads. E.g...
* 1.0 A Thread 0x7ffff7cd3740 (LWP 128534) at 0x401199, file hello.c, line 51
1.2 process 128546 at 0x401199, file hello.c, line 51
1.3 process 128547 at 0x401199, file hello.c, line 51
2.1 process 128538 at 0x401258, file goodbye.c, line 62
2.2 A Thread 0x7ffff7cd3740 (LWP 128542) at 0x401258, file goodbye.c, line 62
3.0 A Thread 0x7ffff7cd3740 (LWP 128543) at 0x40115c, file hangout.c, line 31
3.2 process 128545 at 0x40115c, file hangout.c, line 31
With this commit in place, the output looks like this instead:
* 1.0 A process 129961 at 0x401199, file hello.c, line 51
1.2 process 129974 at 0x401199, file hello.c, line 51
1.3 process 129975 at 0x401199, file hello.c, line 51
2.1 process 129965 at 0x401258, file goodbye.c, line 62
2.2 A process 129969 at 0x401258, file goodbye.c, line 62
3.0 A process 129970 at 0x40115c, file hangout.c, line 31
3.2 process 129972 at 0x40115c, file hangout.c, line 31
(For brevity, I've removed the directory elements in each of the paths
above.)
I tried fixing this problem in another way, by not initializing the
LWP component in the fork_info constructor. This leaves the LWP
component as 0, making the ptid in question a process ptid. However,
when I tried this, I saw asserts in add_initial_lwp, which is called
by add_lwp, which, in turn, is called by linux_nat_switch_fork(),
which is clearly needed by the linux-fork code. So... trying to
avoid setting the LWP component to a non-zero value doesn't work.
The testcase, gdb.multi/checkpoint-multi.exp, has been updated to
reflect the fact that only "process" should now appear in output
from "info checkpoints".
---
gdb/linux-fork.c | 37 ++++++++++++++------
gdb/testsuite/gdb.multi/checkpoint-multi.exp | 2 +-
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 4905d4ffd88..501e8c332cb 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -445,6 +445,17 @@ fork_save_infrun_state (struct fork_info *fp)
}
}
+/* Given a ptid, return a "process ptid" in which only the pid member
+ is present. This is used in calls to target_pid_to_str() to ensure
+ that only process ptids are printed by this file. */
+
+static inline ptid_t
+proc_ptid (ptid_t ptid)
+{
+ ptid_t process_ptid (ptid.pid ());
+ return process_ptid;
+}
+
/* Kill 'em all, let God sort 'em out... */
void
@@ -508,7 +519,7 @@ linux_fork_mourn_inferior ()
last = find_last_fork (inf);
fork_load_infrun_state (last);
gdb_printf (_("[Switching to %s]\n"),
- target_pid_to_str (inferior_ptid).c_str ());
+ target_pid_to_str (proc_ptid (inferior_ptid)).c_str ());
/* If there's only one fork, switch back to non-fork mode. */
if (one_fork_p (inf))
@@ -536,7 +547,7 @@ linux_fork_detach (int from_tty, lwp_info *lp, inferior *inf)
{
if (ptrace (PTRACE_DETACH, inferior_ptid.pid (), 0, 0))
error (_("Unable to detach %s"),
- target_pid_to_str (inferior_ptid).c_str ());
+ target_pid_to_str (proc_ptid (inferior_ptid)).c_str ());
}
delete_fork (inferior_ptid, inf);
@@ -551,7 +562,7 @@ linux_fork_detach (int from_tty, lwp_info *lp, inferior *inf)
if (from_tty)
gdb_printf (_("[Switching to %s]\n"),
- target_pid_to_str (inferior_ptid).c_str ());
+ target_pid_to_str (proc_ptid (inferior_ptid)).c_str ());
/* If there's only one fork, switch back to non-fork mode. */
if (one_fork_p (inf))
@@ -626,7 +637,7 @@ class scoped_switch_fork_info
catch (const gdb_exception &ex)
{
warning (_("Couldn't restore checkpoint state in %s: %s"),
- target_pid_to_str (m_oldfp->ptid).c_str (),
+ target_pid_to_str (proc_ptid (m_oldfp->ptid)).c_str (),
ex.what ());
}
}
@@ -702,10 +713,12 @@ delete_checkpoint_command (const char *args, int from_tty)
error (_("Cannot delete active checkpoint"));
if (ptrace (PTRACE_KILL, ptid.pid (), 0, 0))
- error (_("Unable to kill pid %s"), target_pid_to_str (ptid).c_str ());
+ error (_("Unable to kill pid %s"),
+ target_pid_to_str (proc_ptid (ptid)).c_str ());
if (from_tty)
- gdb_printf (_("Killed %s\n"), target_pid_to_str (ptid).c_str ());
+ gdb_printf (_("Killed %s\n"),
+ target_pid_to_str (proc_ptid (ptid)).c_str ());
delete_fork (ptid, inf);
@@ -730,7 +743,7 @@ delete_checkpoint_command (const char *args, int from_tty)
{
if (inferior_call_waitpid (pptid, ptid.pid ()))
warning (_("Unable to wait pid %s"),
- target_pid_to_str (ptid).c_str ());
+ target_pid_to_str (proc_ptid (ptid)).c_str ());
}
}
@@ -750,10 +763,12 @@ detach_checkpoint_command (const char *args, int from_tty)
Please switch to another checkpoint before detaching the current one"));
if (ptrace (PTRACE_DETACH, ptid.pid (), 0, 0))
- error (_("Unable to detach %s"), target_pid_to_str (ptid).c_str ());
+ error (_("Unable to detach %s"),
+ target_pid_to_str (proc_ptid (ptid)).c_str ());
if (from_tty)
- gdb_printf (_("Detached %s\n"), target_pid_to_str (ptid).c_str ());
+ gdb_printf (_("Detached %s\n"),
+ target_pid_to_str (proc_ptid (ptid)).c_str ());
delete_fork (ptid, current_inferior ());
}
@@ -816,7 +831,7 @@ info_checkpoints_command (const char *arg, int from_tty)
else
gdb_printf (" ");
- gdb_printf ("%s", target_pid_to_str (fi.ptid).c_str ());
+ gdb_printf ("%s", target_pid_to_str (proc_ptid (fi.ptid)).c_str ());
gdb_printf (_(" at "));
ULONGEST pc
@@ -983,7 +998,7 @@ linux_fork_context (struct fork_info *newfp, int from_tty, inferior *newinf)
insert_breakpoints ();
if (!inferior_changed)
gdb_printf (_("Switching to %s\n"),
- target_pid_to_str (inferior_ptid).c_str ());
+ target_pid_to_str (proc_ptid (inferior_ptid)).c_str ());
}
notify_user_selected_context_changed
diff --git a/gdb/testsuite/gdb.multi/checkpoint-multi.exp b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
index a8f0190747b..6d4b70e1adb 100644
--- a/gdb/testsuite/gdb.multi/checkpoint-multi.exp
+++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
@@ -22,7 +22,7 @@ require {istarget "*-*-linux*"}
# Checkpoint support is implemented for the (Linux) native target.
require gdb_protocol_is_native
-set proc_re "(?:process $::decimal|Thread $::hex \\(LWP $::decimal\\))"
+set proc_re "(?:process $::decimal)"
set ckpt_re "Checkpoint"
set main_proc "\\(main process\\)"
set hello_c "hello\\.c"
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
` (2 preceding siblings ...)
2024-06-26 1:55 ` [PATCH v4 3/4] Print only process ptids from linux-fork.c Kevin Buettner
@ 2024-06-26 1:55 ` Kevin Buettner
2024-06-26 12:25 ` Eli Zaretskii
2024-09-07 18:12 ` [PATCH v4 0/4] Make linux checkpoints work with " Kevin Buettner
` (2 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Kevin Buettner @ 2024-06-26 1:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves, Kevin Buettner
---
gdb/NEWS | 2 ++
gdb/doc/gdb.texinfo | 23 ++++++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 47677cb773a..380a204e5a2 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -13,6 +13,8 @@
This may cause breakage when using an incompatible libc, like uclibc or
newlib, or an older glibc.
+* Linux checkpoint code has been updated to work with multiple inferiors.
+
*** Changes in GDB 15
* The MPX commands "show/set mpx bound" have been deprecated, as Intel
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 86cd420832a..01d90ec0934 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4316,18 +4316,39 @@ listed:
@table @code
@item Checkpoint ID
+@item Status
@item Process ID
@item Code Address
@item Source line, or label
@end table
+Checkpoint IDs will be displayed as either a non-negative integer or
+in the form @var{I}.@var{N}, where @var{I} is the inferior number, a
+positive integer, as shown by the command @code{info inferiors}, and
+@var{N}, a non-negative integer, is the checkpoint number for that
+inferior. The single non-negative integer form is used when
+checkpoint(s) have been placed for a single inferior. The
+@var{I}.@var{N} form is used when checkpoints have been created for
+multiple inferiors.
+
+Status information consists of the letters @code{A} and @code{R}.
+@code{A} indicates an active processes in the checkpoint list; this is
+one which @value{GDBN} is currently debugging. @code{R} indicates a
+running process; this status letter can only appear when @value{GDBN}
+is running in non-stop mode. If neither @code{A} or @code{R} are present,
+this indicates a checkpoint which can be switched to using the
+@code{restart} command or deleted using the @code{delete checkpoint}
+command.
+
@kindex restart @var{checkpoint-id}
@item restart @var{checkpoint-id}
Restore the program state that was saved as checkpoint number
@var{checkpoint-id}. All program variables, registers, stack frames
etc.@: will be returned to the values that they had when the checkpoint
was saved. In essence, gdb will ``wind back the clock'' to the point
-in time when the checkpoint was saved.
+in time when the checkpoint was saved. The checkpoint number
+@var{checkpoint-id} is specified in the same form as that output by the
+@code{info checkpoints} command.
Note that breakpoints, @value{GDBN} variables, command history etc.
are not affected by restoring a checkpoint. In general, a checkpoint
--
2.45.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors
2024-06-26 1:55 ` [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors Kevin Buettner
@ 2024-06-26 12:25 ` Eli Zaretskii
0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-06-26 12:25 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches, pedro
> From: Kevin Buettner <kevinb@redhat.com>
> Cc: Pedro Alves <pedro@palves.net>,
> Kevin Buettner <kevinb@redhat.com>
> Date: Tue, 25 Jun 2024 18:55:55 -0700
>
> ---
> gdb/NEWS | 2 ++
> gdb/doc/gdb.texinfo | 23 ++++++++++++++++++++++-
> 2 files changed, 24 insertions(+), 1 deletion(-)
This is okay, thanks.
Approved-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
` (3 preceding siblings ...)
2024-06-26 1:55 ` [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors Kevin Buettner
@ 2024-09-07 18:12 ` Kevin Buettner
2024-09-30 3:39 ` Kevin Buettner
2024-10-21 18:21 ` Kevin Buettner
6 siblings, 0 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-09-07 18:12 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
Ping.
On Tue, 25 Jun 2024 18:55:51 -0700
Kevin Buettner <kevinb@redhat.com> wrote:
> This series fixes some problems with the current checkpoint code. The
> first patch makes the checkpoint code inferior aware, fixing a number
> of bugs. The second and third patches are largely cosmetic - they
> make changes to checkpoint related output.
>
> The v2 series incorporates Pedro's suggestions regarding the
> numbering of checkpoint ids. See the first patch for details. The
> tests have been revised to account for these changes and new tests
> have been added as well.
>
> The v3 series splits out a cosmetic change from the first patch. It
> capitalizes the output of a successful checkpoint command. This was
> prompted by the Linaro regression tester, which, due to the
> capitalization change, found two regressions in
> gdb.base/kill-during-detach.exp. (I had made a mistake during my own
> testing causing this to not be caught.)
>
> This v4 series addresses Pedro's concerns from his review of the v3
> series. It also adds a NEWS entry and updates the GDB manual with
> regard to checkpoint identifiers.
>
> Kevin Buettner (4):
> Make linux checkpoints work with multiple inferiors
> Capitalize output of successful checkpoint command
> Print only process ptids from linux-fork.c
> Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple
> inferiors
>
> gdb/NEWS | 2 +
> gdb/doc/gdb.texinfo | 23 +-
> gdb/linux-fork.c | 557 +++++++++-----
> gdb/linux-fork.h | 15 +-
> gdb/linux-nat.c | 18 +-
> gdb/testsuite/gdb.base/checkpoint.exp | 26 +-
> gdb/testsuite/gdb.base/kill-during-detach.exp | 2 +-
> gdb/testsuite/gdb.multi/checkpoint-multi.exp | 689 ++++++++++++++++++
> 8 files changed, 1134 insertions(+), 198 deletions(-)
> create mode 100644 gdb/testsuite/gdb.multi/checkpoint-multi.exp
>
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
` (4 preceding siblings ...)
2024-09-07 18:12 ` [PATCH v4 0/4] Make linux checkpoints work with " Kevin Buettner
@ 2024-09-30 3:39 ` Kevin Buettner
2024-10-21 18:21 ` Kevin Buettner
6 siblings, 0 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-09-30 3:39 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
Ping.
On Tue, 25 Jun 2024 18:55:51 -0700
Kevin Buettner <kevinb@redhat.com> wrote:
> This series fixes some problems with the current checkpoint code. The
> first patch makes the checkpoint code inferior aware, fixing a number
> of bugs. The second and third patches are largely cosmetic - they
> make changes to checkpoint related output.
>
> The v2 series incorporates Pedro's suggestions regarding the
> numbering of checkpoint ids. See the first patch for details. The
> tests have been revised to account for these changes and new tests
> have been added as well.
>
> The v3 series splits out a cosmetic change from the first patch. It
> capitalizes the output of a successful checkpoint command. This was
> prompted by the Linaro regression tester, which, due to the
> capitalization change, found two regressions in
> gdb.base/kill-during-detach.exp. (I had made a mistake during my own
> testing causing this to not be caught.)
>
> This v4 series addresses Pedro's concerns from his review of the v3
> series. It also adds a NEWS entry and updates the GDB manual with
> regard to checkpoint identifiers.
>
> Kevin Buettner (4):
> Make linux checkpoints work with multiple inferiors
> Capitalize output of successful checkpoint command
> Print only process ptids from linux-fork.c
> Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple
> inferiors
>
> gdb/NEWS | 2 +
> gdb/doc/gdb.texinfo | 23 +-
> gdb/linux-fork.c | 557 +++++++++-----
> gdb/linux-fork.h | 15 +-
> gdb/linux-nat.c | 18 +-
> gdb/testsuite/gdb.base/checkpoint.exp | 26 +-
> gdb/testsuite/gdb.base/kill-during-detach.exp | 2 +-
> gdb/testsuite/gdb.multi/checkpoint-multi.exp | 689 ++++++++++++++++++
> 8 files changed, 1134 insertions(+), 198 deletions(-)
> create mode 100644 gdb/testsuite/gdb.multi/checkpoint-multi.exp
>
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
` (5 preceding siblings ...)
2024-09-30 3:39 ` Kevin Buettner
@ 2024-10-21 18:21 ` Kevin Buettner
6 siblings, 0 replies; 12+ messages in thread
From: Kevin Buettner @ 2024-10-21 18:21 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
Ping.
On Tue, 25 Jun 2024 18:55:51 -0700
Kevin Buettner <kevinb@redhat.com> wrote:
> This series fixes some problems with the current checkpoint code. The
> first patch makes the checkpoint code inferior aware, fixing a number
> of bugs. The second and third patches are largely cosmetic - they
> make changes to checkpoint related output.
>
> The v2 series incorporates Pedro's suggestions regarding the
> numbering of checkpoint ids. See the first patch for details. The
> tests have been revised to account for these changes and new tests
> have been added as well.
>
> The v3 series splits out a cosmetic change from the first patch. It
> capitalizes the output of a successful checkpoint command. This was
> prompted by the Linaro regression tester, which, due to the
> capitalization change, found two regressions in
> gdb.base/kill-during-detach.exp. (I had made a mistake during my own
> testing causing this to not be caught.)
>
> This v4 series addresses Pedro's concerns from his review of the v3
> series. It also adds a NEWS entry and updates the GDB manual with
> regard to checkpoint identifiers.
>
> Kevin Buettner (4):
> Make linux checkpoints work with multiple inferiors
> Capitalize output of successful checkpoint command
> Print only process ptids from linux-fork.c
> Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple
> inferiors
>
> gdb/NEWS | 2 +
> gdb/doc/gdb.texinfo | 23 +-
> gdb/linux-fork.c | 557 +++++++++-----
> gdb/linux-fork.h | 15 +-
> gdb/linux-nat.c | 18 +-
> gdb/testsuite/gdb.base/checkpoint.exp | 26 +-
> gdb/testsuite/gdb.base/kill-during-detach.exp | 2 +-
> gdb/testsuite/gdb.multi/checkpoint-multi.exp | 689 ++++++++++++++++++
> 8 files changed, 1134 insertions(+), 198 deletions(-)
> create mode 100644 gdb/testsuite/gdb.multi/checkpoint-multi.exp
>
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/4] Make linux checkpoints work with multiple inferiors
2024-06-26 1:55 ` [PATCH v4 1/4] " Kevin Buettner
@ 2024-10-23 20:10 ` Pedro Alves
2024-10-31 3:04 ` Kevin Buettner
0 siblings, 1 reply; 12+ messages in thread
From: Pedro Alves @ 2024-10-23 20:10 UTC (permalink / raw)
To: Kevin Buettner, gdb-patches
Hi Kevin!
Trying v4 before looking at the code, I saw one behavior that
surprised me. That is when you have two inferiors, and checkpoints
in only one inferior. Like so:
(gdb) info checkpoints
No checkpoints.
(gdb) checkpoint
Checkpoint 1: fork returned pid 66326.
(gdb) info checkpoints
* 0 A process 66173 at 0x555555555258, file threads.c, line 53
1 process 66326 at 0x555555555258, file threads.c, line 53
(gdb) add-inferior
[New inferior 2]
Added inferior 2 on connection 1 (native)
Now in the following command, I was expecting to see 1.0 and 1.1
as checkpoint numbers, since we now have two inferiors, but we only
get the 0 and 1:
(gdb) info checkpoints
* 0 A process 66173 at 0x555555555258, file threads.c, line 53
1 process 66326 at 0x555555555258, file threads.c, line 53
If I switch to inferior 2, and then list checkpoints, I do get
the fully-qualified checkpoint ids:
(gdb) info inferiors
Num Description Connection Executable
* 1 process 66173 1 (native) /net/cascais.nfs/brno/pedro/gdb/tests/threads
2 <null> 1 (native)
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) info checkpoints
1.0 A process 66173 at 0x55555258, file threads.c, line 53
1.1 process 66326 at 0x55555258, file threads.c, line 53
I was expecting to see the same output when inferior 1 is the
one selected. Again, going back to inferior 1:
(gdb) inferior 1
[Switching to inferior 1 [process 66173] (/net/cascais.nfs/brno/pedro/gdb/tests/threads)]
[Switching to thread 1.1 (Thread 0x7ffff7f93740 (LWP 66173))]
#0 main () at threads.c:53
53 int main() {
(gdb) info checkpoints
* 0 A process 66173 at 0x555555555258, file threads.c, line 53
1 process 66326 at 0x555555555258, file threads.c, line 53
(gdb)
Now that I look at the code, I see that the predicate used to
determine whether to show the inferior number is checking if
there are multiple inferiors with checkpoints, so it seems
intentional. But FYI, coming at this with a lot of context
from previous discussion swapped out, I found it confusing.
On the "R" state, thinking some more (since our last discussion),
I wonder if we really need it. In "info threads", we show that
the thread is running in the "frame" column, like:
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7ffff7f8e740 (LWP 439463) "infloop" (running)
^^^^^^^^^
Maybe we should just reuse the frame-printing code from "info threads".
I tried to reproduce the "R" state here locally, and saw that
it's broken, for trying to fetch registers of a running thread:
(gdb) start
...
(gdb) checkpoint
...
(gdb) info checkpoints
* 0 A process 439463 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
(gdb) c&
Continuing.
(gdb) info checkpoints
* 0 AR process 439463 at Couldn't get registers: No such process.
BTW, the documentation patch says that you can only see the "R" state
in non-stop mode:
+one which @value{GDBN} is currently debugging. @code{R} indicates a
+running process; this status letter can only appear when @value{GDBN}
+is running in non-stop mode.
But that's not correct. You can also use the "c&" command in
all-stop mode.
I noticed this because I wanted to try what it say here:
If neither @code{A} or @code{R} are present,
+this indicates a checkpoint which can be switched to using the
+@code{restart} command or deleted using the @code{delete checkpoint}
+command.
... specifically, I wanted to try switching to a checkpoint in the "R"
state, check that GDB behaves properly.
Other than the issues above, this all LGTM. Some trivial typos
pointed out below.
Pedro Alves
On 2024-06-26 02:55, Kevin Buettner wrote:
> The functions 'find_fork_ptid' and 'find_fork_pid' used to return a
> pointer to a fork_info struct. They now return a pair consisting of
> the pointer to a fork_info struct in addition to a pointer to the
> inferior containing that checkpoint.
>
> 'find_fork_id' returns a a pointer to a fork_info struct just as
Typo, double "a a".
> it did before, but it's now gained a new parameter, 'inf', which
> is the inferior in which to look.
>
> info_checkpoints_command used to simply iterate over the list of
> forks (checkpoints), printing each one out. It now needs to iterate
> over all inferiors and, for those which have checkpoints, it needs
> to iterate over the list of checkpoints in that inferior. As noted
> earlier, the format of the output has been changed so that checkpoint
> identifers incorporating an inferior number may be printed.
identifers -> identifiers
>
> linux_fork_context, called by restart_command, now contains code to
> switch inferiors when the fork being restarted is in an inferior which
> is different from the current one. The scoped_switch_fork_info class
> now also contains code for switching inferiors in both the constructor
> and destructor.
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/4] Make linux checkpoints work with multiple inferiors
2024-10-23 20:10 ` Pedro Alves
@ 2024-10-31 3:04 ` Kevin Buettner
2024-11-11 18:40 ` Pedro Alves
0 siblings, 1 reply; 12+ messages in thread
From: Kevin Buettner @ 2024-10-31 3:04 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Wed, 23 Oct 2024 21:10:53 +0100
Pedro Alves <pedro@palves.net> wrote:
> Trying v4 before looking at the code, I saw one behavior that
> surprised me. That is when you have two inferiors, and checkpoints
> in only one inferior. Like so:
>
> (gdb) info checkpoints
> No checkpoints.
> (gdb) checkpoint
> Checkpoint 1: fork returned pid 66326.
> (gdb) info checkpoints
> * 0 A process 66173 at 0x555555555258, file threads.c, line 53
> 1 process 66326 at 0x555555555258, file threads.c, line 53
> (gdb) add-inferior
> [New inferior 2]
> Added inferior 2 on connection 1 (native)
>
> Now in the following command, I was expecting to see 1.0 and 1.1
> as checkpoint numbers, since we now have two inferiors, but we only
> get the 0 and 1:
>
> (gdb) info checkpoints
> * 0 A process 66173 at 0x555555555258, file threads.c, line 53
> 1 process 66326 at 0x555555555258, file threads.c, line 53
>
>
> If I switch to inferior 2, and then list checkpoints, I do get
> the fully-qualified checkpoint ids:
>
> (gdb) info inferiors
> Num Description Connection Executable
> * 1 process 66173 1 (native) /net/cascais.nfs/brno/pedro/gdb/tests/threads
> 2 <null> 1 (native)
> (gdb) inferior 2
> [Switching to inferior 2 [<null>] (<noexec>)]
> (gdb) info checkpoints
> 1.0 A process 66173 at 0x55555258, file threads.c, line 53
> 1.1 process 66326 at 0x55555258, file threads.c, line 53
>
> I was expecting to see the same output when inferior 1 is the
> one selected. Again, going back to inferior 1:
>
> (gdb) inferior 1
> [Switching to inferior 1 [process 66173] (/net/cascais.nfs/brno/pedro/gdb/tests/threads)]
> [Switching to thread 1.1 (Thread 0x7ffff7f93740 (LWP 66173))]
> #0 main () at threads.c:53
> 53 int main() {
> (gdb) info checkpoints
> * 0 A process 66173 at 0x555555555258, file threads.c, line 53
> 1 process 66326 at 0x555555555258, file threads.c, line 53
> (gdb)
>
> Now that I look at the code, I see that the predicate used to
> determine whether to show the inferior number is checking if
> there are multiple inferiors with checkpoints, so it seems
> intentional. But FYI, coming at this with a lot of context
> from previous discussion swapped out, I found it confusing.
As you say, it was intentional, but it's easy enough to change it
to always print fully-qualified ids when there are multiple inferiors.
I'll make that change (and will update the test case).
> On the "R" state, thinking some more (since our last discussion),
> I wonder if we really need it. In "info threads", we show that
> the thread is running in the "frame" column, like:
>
> (gdb) info threads
> Id Target Id Frame
> * 1 Thread 0x7ffff7f8e740 (LWP 439463) "infloop" (running)
> ^^^^^^^^^
>
> Maybe we should just reuse the frame-printing code from "info threads".
The current linux-fork.c code prints <running>. In the v1 series, I
had used '*' and '+' as the first character to indicate the active
forks, with '*' also indicating the active inferior. You recommended
that I instead use a state character "A" and dispense with the '+'
indicators. Well, since we have one state character, why not another,
hence "R". (It makes the output more compact.) If we change "R" to
"(running)", the state character "A" seems a little odd to me; why not
say "(active)" or, instead, use a compact method of indicating active
forks as I did in my v1 patch.
But perhaps this is needless bike-shedding. If you really want it to
be "(running)", I'll change it. But do give some thought about whether
the state character "A" still makes sense.
> I tried to reproduce the "R" state here locally, and saw that
> it's broken, for trying to fetch registers of a running thread:
>
> (gdb) start
> ...
> (gdb) checkpoint
> ...
> (gdb) info checkpoints
> * 0 A process 439463 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
> 1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
> (gdb) c&
> Continuing.
> (gdb) info checkpoints
> * 0 AR process 439463 at Couldn't get registers: No such process.
>
>
> BTW, the documentation patch says that you can only see the "R" state
> in non-stop mode:
>
> +one which @value{GDBN} is currently debugging. @code{R} indicates a
> +running process; this status letter can only appear when @value{GDBN}
> +is running in non-stop mode.
>
> But that's not correct. You can also use the "c&" command in
> all-stop mode.
>
> I noticed this because I wanted to try what it say here:
>
> If neither @code{A} or @code{R} are present,
> +this indicates a checkpoint which can be switched to using the
> +@code{restart} command or deleted using the @code{delete checkpoint}
> +command.
>
> ... specifically, I wanted to try switching to a checkpoint in the "R"
> state, check that GDB behaves properly.
I'll look into the various problems that you mention above and will
also look at adding some more tests. (I'll fix the nits for the v5
series too.)
Kevin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/4] Make linux checkpoints work with multiple inferiors
2024-10-31 3:04 ` Kevin Buettner
@ 2024-11-11 18:40 ` Pedro Alves
0 siblings, 0 replies; 12+ messages in thread
From: Pedro Alves @ 2024-11-11 18:40 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches
Hi Kevin,
On 2024-10-31 03:04, Kevin Buettner wrote:
> On Wed, 23 Oct 2024 21:10:53 +0100
> Pedro Alves <pedro@palves.net> wrote:
>> Now that I look at the code, I see that the predicate used to
>> determine whether to show the inferior number is checking if
>> there are multiple inferiors with checkpoints, so it seems
>> intentional. But FYI, coming at this with a lot of context
>> from previous discussion swapped out, I found it confusing.
>
> As you say, it was intentional, but it's easy enough to change it
> to always print fully-qualified ids when there are multiple inferiors.
> I'll make that change (and will update the test case).
>
Thanks!
>> On the "R" state, thinking some more (since our last discussion),
>> I wonder if we really need it. In "info threads", we show that
>> the thread is running in the "frame" column, like:
>>
>> (gdb) info threads
>> Id Target Id Frame
>> * 1 Thread 0x7ffff7f8e740 (LWP 439463) "infloop" (running)
>> ^^^^^^^^^
>>
>> Maybe we should just reuse the frame-printing code from "info threads".
>
> The current linux-fork.c code prints <running>. In the v1 series, I
> had used '*' and '+' as the first character to indicate the active
> forks, with '*' also indicating the active inferior. You recommended
> that I instead use a state character "A" and dispense with the '+'
> indicators. Well, since we have one state character, why not another,
> hence "R". (It makes the output more compact.) If we change "R" to
> "(running)", the state character "A" seems a little odd to me; why not
> say "(active)" or, instead, use a compact method of indicating active
> forks as I did in my v1 patch.
The '*' and '+' in the same column compact form was really confusing to me
when I tried using this in an earlier version. I really think it makes
sense to keep it in a separate column.
We shouldn't put "(active)" in the "frame" column (I mean, the column that is equivalent
to the "Frame" column in "info threads"), as an active fork has a real frame to print,
of course.
Putting "(active)" where "A" is being put looks like too much wasted space to me:
* 1.0 (active) process 439463 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
1.1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
2.0 process 439463 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
2.1 (active) process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
In downstream rocgdb (for AMDGPU), we have a new "info lanes" command with a "State" column, and one of the
states is A (for active), which is I guess why "A" and state column looked so obvious to me. E.g.:
(gdb) info lanes
Id State Target Id Frame
* 0 A AMDGPU Lane 1:1:1:1/0 (0,0,0)[0,0,0] bit_extract_kernel (C_d=0x7fffe3a00000, A_d=0x7fffe8400000, N=1000000)
at /home/pedro/rocm/bit_extract/bit_extract.cpp:62
1 A AMDGPU Lane 1:1:1:1/1 (0,0,0)[1,0,0] bit_extract_kernel (C_d=0x7fffe3a00000, A_d=0x7fffe8400000, N=1000000)
at /home/pedro/rocm/bit_extract/bit_extract.cpp:62
...
>
> But perhaps this is needless bike-shedding. If you really want it to
> be "(running)", I'll change it.
Well, you have to change _something_. If the fork is running, then there is no frame to print, so
if you don't print (running), what else could you print, other than leaving it blank, like:
* 1.0 A process 439463
1.1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
I now think that:
* 1.0 A process 439463 (running)
1.1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
... is better than:
* 1.0 AR process 439463
1.1 process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
... because:
#1 - it's what you get with "info threads" as well, and consistency is good.
#2 - running vs not-running is not really a property of the fork wrt to checkpointing, unlike active/not-active.
> But do give some thought about whether the state character "A" still makes sense.
Yeah, if there aren't other obvious states, we could also consider other representations.
Like, make it a yes/no column? This only works nicely if we add a table header row, but we
should do that anyhow. E.g.:
Id Active Target Id Frame
* 1.0 y process 439463 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
1.1 n process 439827 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
2.0 n process 484476 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
2.1 y process 454312 at 0x7ffff7ce578a, file ../sysdeps/unix/sysv/linux/clock_nanosleep.c, line 78
This is probably the most gdb-natural output?
It's also useful/interesting to consider how all these different options would be exposed to MI.
(Why that was never done, I don't know. I find it strange, especially since we know of frontends
like ARM DDT which use checkpoints. But I think they relied on annotations instead of MI. But I
hope they moved along by now.)
Representing the "active" state in MI in the same "column" as the selected thread more obviously
doesn't work there, as the "selected" item is not normally a property of a row. E.g., for threads
listing, we get a current-thread-id="1" attribute, separate from the thread list:
(gdb) interpreter-exec mi "-thread-info"
^done,threads=[{id="1",target-id="Thread 0xf7fbf600 (LWP 255870)",name="step",frame={level="0",addr="0x08048385",func="main",args=[],file="step.c",fullname="/home/pedro/pedro/gdb/tests/step.c",line="27",arch="i386"},state="stopped",core="2"}],current-thread-id="1"
An MI "-checkpoints-info" command would most probably want to do the same, and add an active=y/n attribute.
Pedro Alves
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-11-11 18:41 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26 1:55 [PATCH v4 0/4] Make linux checkpoints work with multiple inferiors Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 1/4] " Kevin Buettner
2024-10-23 20:10 ` Pedro Alves
2024-10-31 3:04 ` Kevin Buettner
2024-11-11 18:40 ` Pedro Alves
2024-06-26 1:55 ` [PATCH v4 2/4] Capitalize output of successful checkpoint command Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 3/4] Print only process ptids from linux-fork.c Kevin Buettner
2024-06-26 1:55 ` [PATCH v4 4/4] Linux checkpoints: Update NEWS and gdb.texinfo regarding multiple inferiors Kevin Buettner
2024-06-26 12:25 ` Eli Zaretskii
2024-09-07 18:12 ` [PATCH v4 0/4] Make linux checkpoints work with " Kevin Buettner
2024-09-30 3:39 ` Kevin Buettner
2024-10-21 18:21 ` Kevin Buettner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox