From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6F85F3858CD1 for ; Tue, 14 Nov 2023 01:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F85F3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F85F3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699925801; cv=none; b=gCuGngNvmDhjPUhSEsPplb1t1j7Ba10oidhObM5dfxz4FQIYelEnDLHSGcQvFK+8Z6sv8ZIj3BZq7C2sNi5E9x6kXJMHoHkZ2bClBW4lHPEy0nO9uVSxZfa4m9yo3a7y91CcYf4Hj8ou2ppHv/7BojD0X4fVfU1L+N1hhQt3dcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699925801; c=relaxed/simple; bh=gLyJWYkebhZpPQU0z+QZHEMvLCvDNcvi1rcjoXVEcRw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=VS8YD55RJbDbjBU+xVJ2J8lFqAIBLd6CKENhRX/kWaAQVuNR9irdqesBs4Z1BnIvPKOp1Oy3+0BeG12xriyMYYuoJvldL29IqjzSU/1fC5a802MSLdDkOOwLQus05hX8IFzxV+MAjzxDUW+JRyR/Cm9OMTGiDibY9nppuILQQ84= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699925799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VzSCxOaLMc7QAL2U71cEORF6r3u7Hx6AbE/DZHbcdcc=; b=A8BiYw5apyGxg/al/RWdgAZL3RJY/WDV6/4wIPcfsudZboF+wd7t0CZSmzfnArYmA8ZR3M i16yB/OgGoyrcUkDd+6/CTf9imiSnfW1jiuT1CoqTyoYYmxPWlVSHQ2yulgZmKflvxNdpk kYSXRpo/f8vB8tQ4gdaODIx09hHEusw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-0lmRzp0UMd20zCmgVR1ATg-1; Mon, 13 Nov 2023 20:36:37 -0500 X-MC-Unique: 0lmRzp0UMd20zCmgVR1ATg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 516AF185A785 for ; Tue, 14 Nov 2023 01:36:37 +0000 (UTC) Received: from f39-zbm-nv (unknown [10.22.8.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBE47C1596F; Tue, 14 Nov 2023 01:36:36 +0000 (UTC) Date: Mon, 13 Nov 2023 18:36:35 -0700 From: Kevin Buettner To: Andrew Burgess Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] linux-nat.c, linux-fork.c: Fix detach bug when lwp has exited/terminated Message-ID: <20231113183635.7d5a81ae@f39-zbm-nv> In-Reply-To: <87il65sywr.fsf@redhat.com> References: <20231111223046.109727-1-kevinb@redhat.com> <20231111223046.109727-2-kevinb@redhat.com> <87il65sywr.fsf@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Andrew, I'll make (or at least consider) the changes that you requested, but I see that you also asked a question. I'll answer that now... On Mon, 13 Nov 2023 10:58:12 +0000 Andrew Burgess wrote: > Kevin Buettner writes: > > + } > > + > > if (signo_p == NULL) > > { > > /* Pass on any pending signal for this LWP. */ > > @@ -1427,13 +1440,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 (forks_exist_p ()) > > + if (pid == inferior_ptid.pid () && forks_exist_p ()) > > I see how this ties to the assert in linux_fork_detach. And given the > comments and use of inferior_ptid, I can see why you added the assert. > > But I guess you added the check because some test triggered the assert. > Do you recall which test that was? I guess I'm curious what PID we are > trying to detach from when this condition triggers. I added that check and the asserts when I realized that the lwp that I was (now) passing to linux_fork_detach might not be the same as that for inferior_ptid. There was no test that I ran which demonstrated the problem. I was imagining something like this, below, using two of the executables from gdb.multi/base.exp: kev@f39-1:gdb$ ./gdb GNU gdb (GDB) 15.0.50.20231110-git [snipped start-up messages...] (gdb) file testsuite/outputs/gdb.multi/base/hello Reading symbols from testsuite/outputs/gdb.multi/base/hello... (gdb) start Temporary breakpoint 1 at 0x401199: file /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c, line 51. Starting program: /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello [snipped debuginfod stuff...] Temporary breakpoint 1, main () at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c:51 51 alarm (240); (gdb) info inferiors Num Description Connection Executable * 1 process 238425 1 (native) /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello (gdb) add-inferior -exec testsuite/outputs/gdb.multi/base/goodbye [New inferior 2] Added inferior 2 on connection 1 (native) Reading symbols from testsuite/outputs/gdb.multi/base/goodbye... (gdb) info inferiors Num Description Connection Executable * 1 process 238425 1 (native) /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello 2 1 (native) /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye (gdb) inferior 2 [Switching to inferior 2 [] (/mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye)] (gdb) start Temporary breakpoint 2 at 0x401199: -qualified main. (2 locations) Starting program: /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Thread 2.1 "goodbye" hit Temporary breakpoint 2.2, main () at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:61 61 mailand(); (gdb) checkpoint checkpoint 1: fork returned pid 238435. (gdb) info inferiors Num Description Connection Executable 1 process 238425 1 (native) /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello * 2 process 238434 1 (native) /mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/goodbye (gdb) info checkpoint * 0 Thread 0x7ffff7cd3740 (LWP 238434) (main process) at 0x0 1 process 238435 at 0x40124e, file /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c, line 61 (gdb) s mailand () at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:46 46 glob = 46; (gdb) s 47 } (gdb) s main () at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:62 62 foo(glob); (gdb) s foo (x=46) at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/goodbye.c:51 51 return x + 92; (gdb) inferior 1 [Switching to inferior 1 [process 238425] (/mesquite2/sourceware-git/f39-master/bld/gdb/testsuite/outputs/gdb.multi/base/hello)] [Switching to thread 1.1 (Thread 0x7ffff7cd3740 (LWP 238425))] #0 main () at /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/testsuite/gdb.multi/hello.c:51 51 alarm (240); (gdb) detach /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624: internal-error: lwp_lwpid_htab_add_lwp: Assertion `slot != NULL && *slot == NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x4ef132 gdb_internal_backtrace_1 /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/bt-utils.c:122 0x4ef132 _Z22gdb_internal_backtracev /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/bt-utils.c:168 0x8d9074 internal_vproblem /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/utils.c:396 0x8d92f8 _Z15internal_verrorPKciS0_P13__va_list_tag /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/utils.c:476 0xa1e431 _Z18internal_error_locPKciS0_z /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/errors.cc:58 0x6c4a41 lwp_lwpid_htab_add_lwp /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624 0x6c4a41 add_initial_lwp /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:792 0x6c7d58 add_lwp /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:806 0x6c7d58 _Z21linux_nat_switch_fork6ptid_t /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:887 0x6c28fe fork_load_infrun_state /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-fork.c:219 0x6c343b _Z17linux_fork_detachi /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-fork.c:381 0x6c8bd8 _ZN16linux_nat_target6detachEP8inferiori /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:1436 0x6d8652 _ZN16thread_db_target6detachEP8inferiori /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-thread-db.c:1385 0x85e943 _Z13target_detachP8inferiori /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/target.c:2526 0x680aed _Z14detach_commandPKci /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/infcmd.c:2863 0x5224ac _Z8cmd_funcP16cmd_list_elementPKci /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/cli/cli-decode.c:2735 0x86cd0a _Z15execute_commandPKci /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/top.c:575 0x600c4f _Z15command_handlerPKc /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:552 0x60204a _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:788 0x60149b gdb_rl_callback_handler /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:259 0x91ef44 rl_callback_read_char /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/readline/readline/callback.c:290 0x6015bd gdb_rl_callback_read_char_wrapper_noexcept /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:195 0x60173c gdb_rl_callback_read_char_wrapper /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/event-top.c:234 0x8a763f stdin_event_handler /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/ui.c:155 0xa1ed35 gdb_wait_for_event /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/event-loop.cc:716 0xa1f7f7 _Z16gdb_do_one_eventi /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdbsupport/event-loop.cc:264 0x6e92c9 start_event_loop /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:407 0x6e92c9 captured_command_loop /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:471 0x6ebba4 captured_main /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:1324 0x6ebba4 _Z8gdb_mainP18captured_main_args /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/main.c:1343 0x446ad4 main /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/gdb.c:39 --------------------- /mesquite2/sourceware-git/f39-master/bld/../../worktree-master/gdb/linux-nat.c:624: internal-error: lwp_lwpid_htab_add_lwp: Assertion `slot != NULL && *slot == NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. I see this problem both with my patch and without, so there's more to be done in to make the checkpoint support work with multiple inferiors. I would guess that the check that I added reduces by (at least) one, the number of problems that exist with the linux checkpoint code. I'll file a bug and add this to my list of things to look at. Kevin