From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id A941E3858D32 for ; Mon, 15 Apr 2024 17:36:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A941E3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A941E3858D32 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2610:1c1:1:606c::19:2 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713202606; cv=pass; b=XNLvJN8KKOuTWPoHoNMcMEwYElYJKBDwG10OEdRo9tgdFwvkEXpPxAKJ8wXcfOtT7VBkZmmxMoOkFw4AVSieT94OlULjGHGdf47/rLH1eWSGR8Wbk0xPmNmsAb3tk8P9i72DB4SLC+vfrVNq6rOBly/6GLh/kniM+UKqCaUllr8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713202606; c=relaxed/simple; bh=eepSy5IJOfjbDvz0c7PvG0sJ/8fw4krzDu3cZIrE2bo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Wtrs4MPt8U/vCTYta0OR7JIOPW68XTsYX8YXAjrVI4z0RYVEEc7vTrph0LkdFhxol+AjwhF9Mn760FkMHHStIY3i+X7gXHG9YN7UFAt4AzUJStGN3gDOUMRf8y3LC/tB5PCY1Uq1uXzQOLP2GqvcVR/rFilTZ/ss5VKV9zVsboY= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4VJDqv3N1dz4Gx0; Mon, 15 Apr 2024 17:36:43 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VJDqv2bj1z4Dcg; Mon, 15 Apr 2024 17:36:43 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713202603; 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=GxV4pxVcPLJGM2InPUGaUJlacA46D+NRvZC5FdSjq5Q=; b=lMzs79ggD7Wsw62spzObxfy3XJ+OqbMfmLsZg0OpSUhi8xqtL+gBMbY4P3HYo++Hs0ruVs nP+JyN7MM/Bs5PadmqizY7uoS+CKpn58aixxP9SWMoYRydoVhbFnPJZg+jUdYFk4maYQAk Jis4GoaBI12HAERi6+AOkLyq9UUgiW0V7A8o5NX4mWNGY0uJnAnRNyykIAuqy5E+l6WAKr f09bW8iKg5EIR15UeMXZiV1Md5tjmb9CAmdGfDAtFVSATxG4/aLQqFzBsbnwNaja7yB7OI 6PtPqCpXuyDn0f2u6YN/y1O/EAWBv16Zdmpm1FkXpUjIVAQzvHA+Pc5iSED6oQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713202603; a=rsa-sha256; cv=none; b=XcMSDJbU0cfTnv0tEVxnxAY5qSnx3g6punN1QjAv5fhEW8r1lAd70UIAH9buDfPL/Vg+ww n8DgVhAOuetwbGG9ZpvtS/vikmEraUDVdK8+pIXprlTN38AUY7tS5Sm3i8JU3UAFOw35Gb n890znlpxAr6p22+9uK7EjfywUICC7MEKcTg4XE8RzmVBa5Fr1VTA5aMHOuZjmdsQVye7p PHKuG10K6sgX2mdFyR2HEggIthODXEiRV/4f6U2PSkJ+LPW8RV3vVCqVoNL+y9ss8hDV2y VSYp5rYD3FUzNdUUHFjWh0Jp2OurMW7leUo0GhPy+GzCShx/8UJyZVn+2sePHw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713202603; 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=GxV4pxVcPLJGM2InPUGaUJlacA46D+NRvZC5FdSjq5Q=; b=Zck+XCpDu/mc4o66PjgP+5Vpf2GF1Fs/JLtKarqozs4cfYDh1tAlb6jKoe0KgX1ZxCgMdu Fx85rc0MmbYrqinLyXgmtyG2MH1XbPWEeUVKWTuspIMaZgnoONPEfeLaWM+gHf5I8EXjxR hcoM2P5IrNAjGCO1bHIu8NG84SZnu7Fn4n9ePi3C3WPfIBG8ODiFrgb3o3AQzQ7vfsEFPF iJA3mvSa+NN9OHKuFlDMMmdb0PXMdqWYyWWOq/e4GrvsXAk9tJn11cHHAXx11aCPz5hf1G SsyCb/HTsMPZ5cidG1UyiQeDIAz0wvTdDnMoAYmT2AId00k0qS+B02velHcMTw== Received: from [IPV6:2601:644:937f:4c50:ace4:f593:f45d:460] (unknown [IPv6:2601:644:937f:4c50:ace4:f593:f45d:460]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4VJDqt3p9dz1CQX; Mon, 15 Apr 2024 17:36:42 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Mon, 15 Apr 2024 10:36:40 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] Using all three fields of ptid and handling thread events from rs6000-aix-nat.c Content-Language: en-US To: Aditya Kamath1 , Aditya Kamath1 via Gdb-patches , Ulrich Weigand Cc: Sangamesh Mallayya References: From: John Baldwin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP 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: On 4/15/24 7:37 AM, Aditya Kamath1 wrote: > Respected community members, > > Hi, > > I am currently working on fixing a bug on handling the thread exit event in AIX and displaying the same in UI. Currently, in AIX we miss the event resulting in incorrect display of info threads. > > For example, for the program 1 pasted below this email. This is a single process creating three more threads. > > The GDB output in AIX is:- > > (gdb) b main > Breakpoint 1 at 0x10000788: file //gdb_tests/continue-pending-status_exit_test.c, line 44. > (gdb) r > Starting program: /gdb_tests/continue-pending-status_exit_test > Breakpoint 1, main () at //gdb_tests/continue-pending-status_exit_test.c:44 > 44 alarm (300); > (gdb) c > Hello World > Hello World > Hello World > [New Thread 258] > [New Thread 515] > [New Thread 772] > Thread 1 received signal SIGINT, Interrupt. > 0xd0611d70 in _p_nsleep () from /usr/lib/libpthreads.a(_shr_xpg5.o) > (gdb) info threads > Id Target Id Frame > * 1 Thread 1 (tid 26607979) (tid 26607979, running) 0xd0611d70 in _p_nsleep () from /usr/lib/libpthreads.a(_shr_xpg5.o) > 2 Thread 258 (tid 30998799) (tid 30998799, finished) aix-thread: ptrace (52, 30998799) returned -1 (errno = 3 The process does not exist.) > > The Linux output for the same is > > (gdb) b main > Breakpoint 1 at 0x10000990: file test_thread.c, line 27. > (gdb) r > Starting program: /home/buildusr/binutils-gdb/gdb/test_thread > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/lib64/libthread_db.so.1". > > Breakpoint 1, > main () at test_thread.c:27 > 27 alarm (300); > (gdb) c > Continuing. > [New Thread 0x7ffff7c7f170 (LWP 4032543)] > [New Thread 0x7ffff746f170 (LWP 4032544)] > [New Thread 0x7ffff6c5f170 (LWP 4032545)] > Hello World > Hello World > Hello World > [Thread 0x7ffff6c5f170 (LWP 4032545) exited] > [Thread 0x7ffff746f170 (LWP 4032544) exited] > [Thread 0x7ffff7c7f170 (LWP 4032543) exited] > ^C > Thread 1 "test_thread" received signal SIGINT, Interrupt. > 0x00007ffff7da5b04 in nanosleep () from /lib64/libc.so.6 > (gdb) info threads > Id Target Id Frame > * 1 Thread 0x7ffff7ff3e00 (LWP 4032541) > 0x00007ffff7da5b04 in nanosleep () from /lib64/libc.so.6 > (gdb) > > > Reason why this happened. > > In Linux, I see in the linux-nat.c /* Check if the thread has exited. */ > 2278 if (WIFEXITED (status) || WIFSIGNALED (status)) > 2279 { > > This is where it gets handled when wait () is called. > > But in AIX, in sync_threadlist () despite having the code we miss the bus. If we observe the sync_threadlists () code our pcount and gcount remain the same despite the threads exiting resulting in, we not capturing the exit. Even though pcount == gcount, in theory your ptid's should be different in pbuf[] vs gbuf[]. That said, when I added thread support to FreeBSD (albeit just using LWPs and not bothering with libthread_db), there in my 'update_thread_list' target I first call 'prune_threads' which uses the 'target::thread_alive' hook to remove any threads that are no longer active, and then call a function that does the equivalent of fetching pbuf[] and adding any threads whose ptid is not already present (see fbsd_nat.c::fbsd_add_threads). The approach of using qsort with two sets of lists and comparing the lists should be correct from what I can tell, but it is also more complex and might be harder to debug? > The debugger checks why it had to wait (), goes to pd_activate (), then to pd_update (), then to sync_threadlists () where the event of threads born are captured. > > One interesting thing here is that in Linux the print “Hello World” happens after the thread born event is captured but in AIX it happens before. Linux raises a ptrace() stop when a new thread is created. When using libthread_db I believe you should be placing a breakpoint in your thread library so that you can capture new threads in userspace before they start executing (e.g. in the internal routine in your thread library that eventually calls the thread's start routine). For FreeBSD with LWP-backed threads I ended up just adding a new ptrace event in the kernel when a new thread starts executing and use that to add threads instead. In many cases this race wouldn't matter much for users though. > Are we missing something in AIX?? One information I want to give is we do go to wait () before the print Hello world happens, but we do not call pd_activate () and even if we do [We call it on purpose skipping the if condition in wait () in aix-thread.c], the thread debug session is not successful. In the next wait () event is when we capture the new thread or add_thread () event. > > There is one more wait () event that happens after this, but here as well AIX fails to capture the thread_exit event in sync_threadlists () since the pcount and gcount are the same. I'm still not sure how we you are missing the thread exit event. Even though pcount == gcount it looks like sync_threadlists still walks the two lists using ptid_cmp so should still DTRT? -- John Baldwin