From 83094d3de44846071cc2e3e42366ea782b3e4027 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Wed, 10 Jan 2024 11:27:34 +0100 Subject: [PATCH] [gdb] Fix assertion failure for checkpoint delete 0 When doing "checkpoint delete 0" we run into an assertion failure: ... +delete checkpoint 0 inferior.c:406: internal-error: find_inferior_pid: Assertion `pid != 0' failed. ... Fix this by handling the "pptid == null_ptid" case in delete_checkpoint_command. Tested on x86_64-linux. Approved-By: Kevin Buettner PR gdb/31209 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31209 --- gdb/linux-fork.c | 11 +++++++++++ gdb/testsuite/gdb.base/checkpoint.exp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 659264ab712..64b83e79204 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -537,6 +537,17 @@ Please switch to another checkpoint before deleting the current one")); delete_fork (ptid); + if (pptid == null_ptid) + { + int status; + /* Wait to collect the inferior's exit status. Do not check whether + this succeeds though, since we may be dealing with a process that we + attached to. Such a process will only report its exit status to its + original parent. */ + waitpid (ptid.pid (), &status, 0); + return; + } + /* If fi->parent_ptid is not a part of lwp but it's a part of checkpoint list, waitpid the ptid. If fi->parent_ptid is a part of lwp and it is stopped, waitpid the diff --git a/gdb/testsuite/gdb.base/checkpoint.exp b/gdb/testsuite/gdb.base/checkpoint.exp index 9ba5b3e82ec..96976bb92d2 100644 --- a/gdb/testsuite/gdb.base/checkpoint.exp +++ b/gdb/testsuite/gdb.base/checkpoint.exp @@ -336,3 +336,17 @@ verbose "Timeout now $timeout sec." # # Finished: cleanup # + +# +# Now let's try to delete checkpoint 0. +# + +with_test_prefix "delete checkpoint 0" { + clean_restart $binfile + runto_main + + 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."] +}