From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 1F0813858D1E for ; Tue, 30 Apr 2024 16:41:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F0813858D1E 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 1F0813858D1E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=96.47.72.81 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714495293; cv=pass; b=N3t1GEjQStpFnIrLWUakdnzOgZBaNB6FHwlEn1Yz55jWQz9Jqc5oV3e/vfZHZwb3mZEZkw2r5CISPkbNx++aEvJPEPbPvPqihDPMezBzmvFfTIQVKKvDTIvcSEBXVyNqprWLvFntwujUhmc1fdBfu8iwoiHa2HkprFCst//lv2Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714495293; c=relaxed/simple; bh=NS+gdOZeljYCYHxwPMLFTyGhyjUtJUCKuPgWX7Qstbo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=J1zALyJwbEZfzMBhrDgFMSw8wncGQbP0YwJF6rAZNBVpJ67XvPVEdNk3BKbotZ6apG512MhCLO0DMGwLCAsuykuMFpXVRZ+IdFbX+j5IB3tp4gWXWzIsdBH3BPUAEuWiiIYct/yfVMFNZbuubbRlVGLpIPfvYkXDxy8I/TbyRTs= 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 4VTQvG6tQ4z4Pl5 for ; Tue, 30 Apr 2024 16:41:30 +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 4VTQvG66Tsz4tgT for ; Tue, 30 Apr 2024 16:41:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714495290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nDC+lDmzVhTckEVB+h4oSLDGbfYmmZq4mrbBgyk/F8Y=; b=fa+O7l1dO3fMJf7Q5THNs7qXsgFGvf2pwxYctyddkKrOKK1j+YhLhg2m50tA/pbNI3JTst GI1U+5QnUhUhqUBdt2e5mkekFP8qEwBIw06RScJYAXEfk4cWeVLKSpEiQEeMcUoSwfrG1X 2Yc7k+aowMv29P5+Iw9OVEWLPKizklphYtyaaOAt1lzu5Bx75/xJ0lFS/pMxTzGbfIfjvE phj9rEdpkbOqYkOETcemFiHLADso6Il+05Lh7to4U5qpmdxA+AP9tlSYDdCQMjwBSrjk6u aoT3n7g5uRJ0AvpJyjsEVsiSFvz/CcCWgEMTyznzWtmfig6StjgxtF7akTy/UQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714495290; a=rsa-sha256; cv=none; b=V9sC3bXaZSpJSafLC15slL5tH851Q240qm6JL5yA3IvlEhUp5rcjzbOP9ZV1GJVSnLhFlz Dvv46b9RRQOAz6czgKG2oSt6ydODVXEvtC6RlCbLVvATn20ZaiHAcW1VZ3wuoapX7k+mTk vMIE6WaXqwt71AIonqDewFXlTQBfh2hSx39aYLzg/xnrFKrWEqs1/bn+XMj905pjK/hA4l Dlfq9ddSbOVlbNiGQWusj4rIVwuP+MUYT4QBey5bJeM+xFjPEiqWAMrfpJGX8Dugxg5hBX hSwcFm7M2K2RD9tRntW/hQM+wkuoZtpFHkz4aZvmz+2H0uYeLz6goL4OecPSdQ== 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=1714495290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nDC+lDmzVhTckEVB+h4oSLDGbfYmmZq4mrbBgyk/F8Y=; b=IyAsqbBkhMZqlT4WN9eYHWa1oU/2Wbq5qC5NN2aZ6Xx7EqedFNc9VOOHo0SpZJqZd60Axe 8vX4QCthWfO+LZAre03RS3d8peDeEe7S83SGglCCLG0It0fyZLw1HEk/TTXeIUOCu9U5kX D5U11kQTvAmg330MbWbRS4UAvc408+kVQ4Ro4A6AXQiqkxIy5vCCcI8Kmw0/dVFrrYAssk VsWhgdlx8XmvLCWZh+F/TYmxiw+xH1TmrzrtoYRBsdEM7DMyOoui/p1o8JxclbYLaEmfqv uTCOIiwcF8/n2SsQ3N0rN+X4mYEfxJq/WPMOMc0raHVkTTHWwJKhcu4Gg7f8Bw== Received: from [IPV6:2601:644:937f:4c50:4f5:7fc4:6856:aba3] (unknown [IPv6:2601:644:937f:4c50:4f5:7fc4:6856:aba3]) (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 4VTQvG4Lt9z1HVx for ; Tue, 30 Apr 2024 16:41:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Tue, 30 Apr 2024 09:41:29 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix AIX thread exit events not being reported and UI to show kernel thread ID. Content-Language: en-US To: gdb-patches@sourceware.org References: <20240429114024.12916-1-akamath996@gmail.com> From: John Baldwin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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/29/24 4:48 AM, Aditya Kamath1 wrote: > This is an older version of the patch. Sorry for resending this. Kindly ignore the same. I have sent the latest version in another git send-email. Please use -v (e.g. '-v 2') with a new version of n each time you use git send-email to send a new version of a patch. This makes includes the 'n' value in the e-mail subject making it easier to see which version is the latest version. > Have a nice day ahead. > > Thanks and regards, > Aditya. > > From: Aditya Vidyadhar Kamath > Date: Monday, 29 April 2024 at 5:11 PM > To: tom@tromey.com > Cc: Ulrich Weigand , gdb-patches@sourceware.org , Aditya Kamath1 , Sangamesh Mallayya > Subject: [EXTERNAL] [PATCH] Fix AIX thread exit events not being reported and UI to show kernel thread ID. > From: Aditya Vidyadhar Kamath > > In AIX when a thread exits we were not showing that a thread exit event happened > and GDB continued to keep the terminated threads. > > If we have terminated threads then the UI on info threads command will look like > (gdb) info threads > Id Target Id Frame > * 1 Thread 1 (tid 26607979, running) 0xd0611d70 in _p_nsleep () from /usr/lib/libpthreads.a(_shr_xpg5.o) > 2 Thread 258 (tid 30998799, finished) aix-thread: ptrace (52, 30998799) returned -1 (errno = 3 The process does not exist.) > > If we see the frame is not getting displayed correctly. > > The reason for the same is that in AIX we were not managing thread states. In particular we do not know > when a thread terminates. > > The reason being in sync_threadlists () the pbuf and gbuf lists remain the same though certain threads exit. > > This patch is a fix to the same. > > Also certain UI is changed. > > On a new thread born and exit the UI in AIX will be similar to Linux with both user and kernel thread information. > > [New Thread 258 (tid 32178533)] > [New Thread 515 (tid 30343651)] > [New Thread 772 (tid 33554909)] > [New Thread 1029 (tid 24969489)] > [New Thread 1286 (tid 18153945)] > [New Thread 1543 (tid 30736739)] > [Thread 258 (tid 32178533) exited] > [Thread 515 (tid 30343651) exited] > [Thread 772 (tid 33554909) exited] > [Thread 1029 (tid 24969489) exited] > [Thread 1286 (tid 18153945) exited] > [Thread 1543 (tid 30736739) exited] > > and info threads will look like > (gdb) info threads > Id Target Id Frame > * 1 Thread 1 (tid 31326579) ([running]) 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o) > --- > gdb/aix-thread.c | 91 ++++++++++++++++++++++++++++++------------------ > 1 file changed, 57 insertions(+), 34 deletions(-) > > diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c > index c70bd82bc24..5ccccf02879 100644 > --- a/gdb/aix-thread.c > +++ b/gdb/aix-thread.c > @@ -55,6 +55,7 @@ > #include > #include > #include > +#include > > #if !HAVE_DECL_GETTHRDS > extern int getthrds (pid_t, struct thrdsinfo64 *, int, tid_t *, int); > @@ -190,6 +191,9 @@ struct aix_thread_variables > /* Whether the current architecture is 64-bit. > Only valid when pd_able is true. */ > int arch64; > + > + /* Describes the number of thread born events have been reported. */ > + int threads_reported = 0; > }; > > /* Key to our per-inferior data. */ > @@ -740,11 +744,9 @@ state2str (pthdb_state_t state) > /* qsort() comparison function for sorting pd_thread structs by pthid. */ > > static int > -pcmp (const void *p1v, const void *p2v) > +pcmp (struct pd_thread p1v, struct pd_thread p2v) > { > - struct pd_thread *p1 = (struct pd_thread *) p1v; > - struct pd_thread *p2 = (struct pd_thread *) p2v; > - return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid; > + return p1v.pthid < p2v.pthid; > } > > /* ptid comparison function */ > @@ -823,7 +825,6 @@ sync_threadlists (pid_t pid) > { > int cmd, status; > int pcount, psize, pi, gcount, gi; > - struct pd_thread *pbuf; > struct thread_info **gbuf, **g, *thread; > pthdb_pthread_t pdtid; > pthread_t pthid; > @@ -831,12 +832,13 @@ sync_threadlists (pid_t pid) > process_stratum_target *proc_target = current_inferior ()->process_target (); > struct aix_thread_variables *data; > data = get_thread_data_helper_for_pid (pid); > + std::vector pbuf; > + struct pd_thread aix_pd_thread; > > /* Accumulate an array of libpthdebug threads sorted by pthread id. */ > > pcount = 0; > psize = 1; > - pbuf = XNEWVEC (struct pd_thread, psize); > > for (cmd = PTHDB_LIST_FIRST;; cmd = PTHDB_LIST_NEXT) > { > @@ -848,27 +850,36 @@ sync_threadlists (pid_t pid) > if (status != PTHDB_SUCCESS || pthid == PTHDB_INVALID_PTID) > continue; > > - if (pcount == psize) > - { > - psize *= 2; > - pbuf = (struct pd_thread *) xrealloc (pbuf, > - psize * sizeof *pbuf); > - } > - pbuf[pcount].pdtid = pdtid; > - pbuf[pcount].pthid = pthid; > + aix_pd_thread.pdtid = pdtid; > + aix_pd_thread.pthid = pthid; > + pbuf.push_back (aix_pd_thread); > pcount++; > } > > - for (pi = 0; pi < pcount; pi++) > + for (auto it = pbuf.begin (); it != pbuf.end ();) > { > - status = pthdb_pthread_tid (data->pd_session, pbuf[pi].pdtid, &tid); > + status = pthdb_pthread_tid (data->pd_session, (*it).pdtid, &tid); > if (status != PTHDB_SUCCESS) > tid = PTHDB_INVALID_TID; > - pbuf[pi].tid = tid; > - } > > - qsort (pbuf, pcount, sizeof *pbuf, pcmp); > + (*it).tid = tid; > + pthdb_state_t state; > + > + status = pthdb_pthread_state (data->pd_session, (*it).pdtid, &state); > > + /* If the thread is terminated and has not reported its existence > + or new thread event, then wait for it to report. We want users > + to know threads were added and then delete. So first add them to > + pbuf and the next time sync_threadlists is called delete them since > + data->threads_reported is guarenteed to be greater than 0. */ > + > + if (state == PST_TERM && data->threads_reported > 0) > + pbuf.erase (it); > + else > + ++it; > + } > + > + std::sort (pbuf.begin (), pbuf.end (), pcmp); > /* Accumulate an array of GDB threads sorted by pid. */ > > /* gcount is GDB thread count and pcount is pthreadlib thread count. */ > @@ -881,6 +892,7 @@ sync_threadlists (pid_t pid) > *g++ = tp; > qsort (gbuf, gcount, sizeof *gbuf, gcmp); > > + pcount = pbuf.size (); > /* Apply differences between the two arrays to GDB's thread list. */ > > for (pi = gi = 0; pi < pcount || gi < gcount;) > @@ -889,6 +901,12 @@ sync_threadlists (pid_t pid) > { > delete_thread (gbuf[gi]); > gi++; > + data->threads_reported--; > + > + /* Since main thread is reported. */ > + > + if (data->threads_reported == 0) > + data->threads_reported = 1; > } > else if (gi == gcount) > { > @@ -901,6 +919,7 @@ sync_threadlists (pid_t pid) > private_thread_info_up (priv)); > > pi++; > + data->threads_reported++; > } > else > { > @@ -913,7 +932,6 @@ sync_threadlists (pid_t pid) > tid = pbuf[pi].tid; > > cmp_result = ptid_cmp (pptid, gptid); > - > if (cmp_result == 0) > { > aix_thread_info *priv = get_aix_thread_info (gbuf[gi]); > @@ -943,6 +961,10 @@ sync_threadlists (pid_t pid) > { > delete_thread (gbuf[gi]); > gi++; > + data->threads_reported--; > + > + if (data->threads_reported == 0) > + data->threads_reported = 1; > } > } > else > @@ -954,11 +976,11 @@ sync_threadlists (pid_t pid) > priv->pdtid = pdtid; > priv->tid = tid; > pi++; > + data->threads_reported++; > } > } > } > > - xfree (pbuf); > xfree (gbuf); > } > > @@ -2084,10 +2106,17 @@ aix_thread_target::thread_alive (ptid_t ptid) > std::string > aix_thread_target::pid_to_str (ptid_t ptid) > { > - if (ptid.tid () == 0) > - return beneath ()->pid_to_str (ptid); > + thread_info *thread_info = current_inferior ()->find_thread (ptid); > + > + if (thread_info != NULL && thread_info->priv != NULL) > + { > + aix_thread_info *priv = get_aix_thread_info (thread_info); > + > + return string_printf (_("Thread %s (tid %s)"), pulongest (ptid.tid ()), > + pulongest (priv->tid)); > + } > > - return string_printf (_("Thread %s"), pulongest (ptid.tid ())); > + return beneath ()->pid_to_str (ptid); > } > > /* Return a printable representation of extra information about > @@ -2098,7 +2127,6 @@ aix_thread_target::extra_thread_info (struct thread_info *thread) > { > int status; > pthdb_pthread_t pdtid; > - pthdb_tid_t tid; > pthdb_state_t state; > pthdb_suspendstate_t suspendstate; > pthdb_detachstate_t detachstate; > @@ -2115,33 +2143,28 @@ aix_thread_target::extra_thread_info (struct thread_info *thread) > aix_thread_info *priv = get_aix_thread_info (thread); > > pdtid = priv->pdtid; > - tid = priv->tid; > - > - if (tid != PTHDB_INVALID_TID) > - /* i18n: Like "thread-identifier %d, [state] running, suspended" */ > - buf.printf (_("tid %d"), (int)tid); > > status = pthdb_pthread_state (data->pd_session, pdtid, &state); > if (status != PTHDB_SUCCESS) > state = PST_NOTSUP; > - buf.printf (", %s", state2str (state)); > + buf.printf ("[%s]", state2str (state)); > > status = pthdb_pthread_suspendstate (data->pd_session, pdtid, > &suspendstate); > if (status == PTHDB_SUCCESS && suspendstate == PSS_SUSPENDED) > /* i18n: Like "Thread-Id %d, [state] running, suspended" */ > - buf.printf (_(", suspended")); > + buf.printf (_("[suspended]")); > > status = pthdb_pthread_detachstate (data->pd_session, pdtid, > &detachstate); > if (status == PTHDB_SUCCESS && detachstate == PDS_DETACHED) > /* i18n: Like "Thread-Id %d, [state] running, detached" */ > - buf.printf (_(", detached")); > + buf.printf (_("[detached]")); > > pthdb_pthread_cancelpend (data->pd_session, pdtid, &cancelpend); > if (status == PTHDB_SUCCESS && cancelpend) > /* i18n: Like "Thread-Id %d, [state] running, cancel pending" */ > - buf.printf (_(", cancel pending")); > + buf.printf (_("[cancel pending]")); > > buf.write ("", 1); > > -- > 2.41.0 -- John Baldwin