Bug 31209 - [gdb, delete checkpoint] inferior.c:406: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
Summary: [gdb, delete checkpoint] inferior.c:406: internal-error: find_inferior_pid: A...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-03 14:16 UTC by Tom de Vries
Modified: 2024-01-10 10:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2024-01-03 14:16:07 UTC
I played around with checkpoints on a hello world exec, and ran into an assertion failure:
...
$ gdb -q -batch a.out -ex "set trace-commands on" -x gdb.in
+start
Temporary breakpoint 1 at 0x4101b0: file hello.c, line 6.

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at hello.c:6
6         printf ("hello\n");
+checkpoint
+next
hello
8         return 0;
+restart 1
Switching to Thread 0xfffff7ffed80 (LWP 1325214)
#0  main () at hello.c:6
6         printf ("hello\n");
+delete checkpoint 0
/home/vries/gdb/src/gdb/inferior.c:406: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x57f597 gdb_internal_backtrace_1
        /home/vries/gdb/src/gdb/bt-utils.c:122
0x57f65b _Z22gdb_internal_backtracev
        /home/vries/gdb/src/gdb/bt-utils.c:168
0xb7c463 internal_vproblem
        /home/vries/gdb/src/gdb/utils.c:396
0xb7c87f _Z15internal_verrorPKciS0_St9__va_list
        /home/vries/gdb/src/gdb/utils.c:476
0xdbfcff _Z18internal_error_locPKciS0_z
        /home/vries/gdb/src/gdbsupport/errors.cc:58
0x804863 _Z17find_inferior_pidP22process_stratum_targeti
        /home/vries/gdb/src/gdb/inferior.c:406
0x804917 _Z18find_inferior_ptidP22process_stratum_target6ptid_t
        /home/vries/gdb/src/gdb/inferior.c:420
0x9269bf _ZN22process_stratum_target11find_threadE6ptid_t
        /home/vries/gdb/src/gdb/process-stratum-target.c:191
0x85756b delete_checkpoint_command
        /home/vries/gdb/src/gdb/linux-fork.c:544
0x5d288b do_simple_func
        /home/vries/gdb/src/gdb/cli/cli-decode.c:95
0x5d7c1b _Z8cmd_funcP16cmd_list_elementPKci
        /home/vries/gdb/src/gdb/cli/cli-decode.c:2735
0xadf8df _Z15execute_commandPKci
        /home/vries/gdb/src/gdb/top.c:575
0x763493 _Z15command_handlerPKc
        /home/vries/gdb/src/gdb/event-top.c:566
0xadef97 _Z17read_command_fileP8_IO_FILE
        /home/vries/gdb/src/gdb/top.c:342
0x5e66cf _Z16script_from_fileP8_IO_FILEPKc
        /home/vries/gdb/src/gdb/cli/cli-script.c:1642
0x5c9cc3 source_script_from_stream
        /home/vries/gdb/src/gdb/cli/cli-cmds.c:730
0x5c9ddf source_script_with_search
        /home/vries/gdb/src/gdb/cli/cli-cmds.c:775
0x5c9e4b _Z13source_scriptPKci
        /home/vries/gdb/src/gdb/cli/cli-cmds.c:784
0x893ea3 catch_command_errors
        /home/vries/gdb/src/gdb/main.c:514
0x894083 execute_cmdargs
        /home/vries/gdb/src/gdb/main.c:610
0x8956c3 captured_main_1
        /home/vries/gdb/src/gdb/main.c:1312
0x895883 captured_main
        /home/vries/gdb/src/gdb/main.c:1333
0x89590b _Z8gdb_mainP18captured_main_args
        /home/vries/gdb/src/gdb/main.c:1362
0x4239b3 main
        /home/vries/gdb/src/gdb/gdb.c:39
...
Comment 1 Tom de Vries 2024-01-03 14:17:07 UTC
FWIW, command file:
...
$ cat gdb.in
start
checkpoint
next
restart 1
delete checkpoint 0
...
Comment 2 Tom de Vries 2024-01-03 14:30:33 UTC
Fixed by:
...
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 1430ff89fa7..8156b51897b 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -537,6 +537,9 @@ Please switch to another checkpoint before deleting the current one"));
 
   delete_fork (ptid);
 
+  if (pptid == null_ptid)
+    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
...
Comment 4 Sourceware Commits 2024-01-10 10:27:13 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=83094d3de44846071cc2e3e42366ea782b3e4027

commit 83094d3de44846071cc2e3e42366ea782b3e4027
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jan 10 11:27:34 2024 +0100

    [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 <kevinb@redhat.com>
    
    PR gdb/31209
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31209
Comment 5 Tom de Vries 2024-01-10 10:28:49 UTC
Fixed.