From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id H0bYNpdqKGdNESUAWB0awg (envelope-from ) for ; Mon, 04 Nov 2024 01:32:55 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lT/eLSJh; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C1CBB1E5DD; Mon, 4 Nov 2024 01:32:55 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,URIBL_BLOCKED,URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B37F51E5DB for ; Mon, 4 Nov 2024 01:32:54 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32DA03858410 for ; Mon, 4 Nov 2024 06:32:54 +0000 (GMT) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id A4B953858D29 for ; Mon, 4 Nov 2024 06:32:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4B953858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A4B953858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730701955; cv=none; b=I/x+jdHMCCvDgnlZ0QUje4oNPSjw23V2mBLHXjLoF6Dus7+xCzOiwCxrxSjlVmz6f05v3HiUlWXhqICORgo2yAToEteeFVW5ZsibBtp0mDWVA3TwZPkawCIOkqJ+J9o7LWnSBIxuB4focGb/GTG29tTUT7V5aSJK7+vnGHUgrsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730701955; c=relaxed/simple; bh=FsPvF4Dc/e/xlltg12KDfaLFXZ7isBzRLcjzenGvqTI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Tvzf7TSbKDbhGOq6RQ4f/HKU+d0tMGJ4dhHSlmo/QQtyrXqw0zytZCcp5F27VCyV5I13ky/XSxZq7Wkm5YnjWJkD8ZMwQQV1wb65nPt3kd01UtSKJQAxtNu9gJpRmvpjTQHDu+jrgNhIRVICRM5RMMBeZC2sFKnZHNKMwkjBMwM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-207115e3056so35146875ad.2 for ; Sun, 03 Nov 2024 22:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730701949; x=1731306749; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CTdN43DnBfnSk0rMDO8byj8Mfo2Ns01DRHEMtHCKgTU=; b=lT/eLSJhW+GsZ0o3lunJd/RnD6MBFBCyvT4kmaHxCMZBj84iDMIhnMx9M+3RIhz6zV cwJx/WxGfRZuXlaG5RKimZV/mC4Ou2E8vkhkYU2ehMHVERYNxPY9DhPbo2nbK7vz7h5+ yGVEu/lSQFGsLAKQKnDN53MRPL6rwcsAmJu+8mE6rOtGMA+MYyySa657bH6jHl0C1rsZ 5m6ox49r4DMP8BbsPWqWMXceKfp4+x2jDwKkk4grdO70xfYs1l6sCI/wYcXyZ9o0KkNE hkZ/QZpFJcuzNiUxq3lP+P5UJus/9wgzi4hEuoRLR0faqpGC4h8/CjEtT0OF9d81xzhc C8rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730701949; x=1731306749; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CTdN43DnBfnSk0rMDO8byj8Mfo2Ns01DRHEMtHCKgTU=; b=L2g35p234uNNu7frUfe3gQo175/+0blrW0pj7CzIGMFPU1lpwgxlG5O5Q23DkNc9ab XZ2IXM4K8a25bgchJKOC4BYk9iLP0mHDiiIt3wn3WRhplbjB/RWPGvCCIXI+QGO5/Lgv vbX5ibVPrP8CC3KL8+VVad/BhmM0k+SuuYdFAGgByT5R2jOhD+vGqyuFkLTFPw7hTbiZ 43PzWNHii50MqifhvATo9u4u9zPRaU5THABuQOtohlzgxQWEtva4NeeKWzjpSb2CNOJU dbB8LRW3ZyKCCVQTM4FYoX6w5n0nTvPUjUxrfeILubzUAogaKU21+2wk6Dw3j4OdJS26 w0Fg== X-Gm-Message-State: AOJu0YyKG3GPf3mUfvx5ojfOJ3nUz07+zVreK3s2XRkUuW0mG/6LrzeJ au/UdXDIoVzXEhnAVE5cwdHZuDzIMoSMJGQTuIHV9T0UTS+vPGyi X-Google-Smtp-Source: AGHT+IEaP7PAy1zB2pmZ1X520nDX/bVd4g4bKn4OIlZMmM2tt85xirsTMt0yA8653bRaee2pE8Hh+Q== X-Received: by 2002:a17:902:ccc6:b0:20c:fb47:5c1c with SMTP id d9443c01a7336-210c68917e5mr427575975ad.14.1730701949281; Sun, 03 Nov 2024 22:32:29 -0800 (PST) Received: from localhost.localdomain ([122.171.18.182]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057d41c2sm54964705ad.254.2024.11.03.22.32.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 03 Nov 2024 22:32:28 -0800 (PST) From: Aditya Vidyadhar Kamath To: ulrich.weigand@de.ibm.com Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com, Aditya Vidyadhar Kamath Subject: [PATCH v2] Fix AIX core dump while main thread exits. Date: Mon, 4 Nov 2024 12:02:16 +0530 Message-Id: <20241104063215.3482-1-akamath996@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Aditya Vidyadhar Kamath Consider the test case: void *thread_main(void *) { std::cout << getpid() << std::endl; sleep(20); return nullptr; } int main(void) { pthread_t thread; pthread_create(&thread, nullptr, thread_main, nullptr); pthread_join(thread, nullptr); return 0; } This program creates a thread via main that sleeps for 20 seconds. When we debug this with gdb we get, Reading symbols from ./test... (gdb) b main Breakpoint 1 at 0x10000934: file test.c, line 11. (gdb) r Starting program: /read_only_gdb/binutils-gdb/gdb/test Breakpoint 1, main () at test.c:11 11 pthread_create(&thread, nullptr, thread_main, nullptr); (gdb) c Continuing. 15335884 [New Thread 258 (tid 31130079)] Thread 2 received signal SIGINT, Interrupt. [Switching to Thread 258 (tid 31130079)] 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o) (gdb) thread 1 [Switching to thread 1 (Thread 1 (tid 25493845))] (gdb) c Continuing. [Thread 1 (tid 25493845) exited] [Thread 258 (tid 31130079) exited] inferior.c:405: internal-error: find_inferior_pid: Assertion `pid != 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- There are two bugs here. One is the core dump. The other is the main thread information not captured. So, while I was debugging the first part the reason, the reason I figured out was the last for loop in sync_threadlists (). Once both my threads exit we delete them as below: for (struct thread_info *it : all_threads ()) { if (in_queue_threads.count (priv->pdtid) == 0 && in_thread_list (proc_target, it->ptid) && pid == it->ptid.pid ()) { delete_thread (it); data->exited_threads.insert (priv->pdtid); But once these two threads are deleted, all_threads () has one more thread whose tid and pid are 0. gdb) c Continuing. In for loop 8782296 is pid, 19857879 is tid [Thread 1 (tid 19857879) exited] In for loop 8782296 is pid, 30933401 is tid [Thread 258 (tid 30933401) exited] In for loop 0 is pid, 0 is tid [Inferior 1 (process 8782296) exited normally] (gdb) q I used a printf in the for loop mentioned above for explaination. You see the loop enters the third time with 0 as pid. The reason being though the threads are removed but not deleted since they are not deletable (). Hence we use all_threads_safe () iterator instead. The second part to the bug is the lack of information of the main thread. Andrew was right here (https://sourceware.org/pipermail/gdb-patches/2024-September/211875.html) Thank you Andrew. The thread has loaded but then ptrace () call when we tried to fetch_regs_kernel_thread failed. This returned EPERM as errno. if (!ptrace32 (PTT_READ_GPRS, tid, (uintptr_t) gprs32, 0, NULL)) memset (gprs32, 0, sizeof (gprs32)); Hence all registers were set to 0 and we did not get the required infromation. This issue will be fixed within the AIX ptrace call. --- gdb/aix-thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 9e6952b974f..4a050cdff10 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -854,7 +854,7 @@ sync_threadlists (pid_t pid) thread exits and gets into a PST_UNKNOWN state. So this thread will not run in the above for loop. Therefore the below for loop is to manually delete such threads. */ - for (struct thread_info *it : all_threads ()) + for (struct thread_info *it : all_threads_safe ()) { aix_thread_info *priv = get_aix_thread_info (it); if (in_queue_threads.count (priv->pdtid) == 0 -- 2.41.0