From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 17013384AB75 for ; Mon, 22 Apr 2024 15:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17013384AB75 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 17013384AB75 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=148.163.156.1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713800992; cv=pass; b=KXWaourQPAUcuE4GLeehr8lpwZdFSfBfW48EninT1Ul5VEmRtn6o8HewxmorDuJ0ueJXmJdwkh2MvNBdenlMqPuMDfIFKkDlScgTmeSztUaL6z3cOQOSpITKoQQo9DxJI5C+9ZdHQEma6kdl8derdAvMqa0O7NKjZRzg/1jnGF4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713800992; c=relaxed/simple; bh=mypFjVZDvQd9S5QLFLddbPcsEAs+T+bTDLFMUMZIFQw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=G/DmUM6eQkZ0A869qRT+G6nuX8hF7mfN7x/GNCZn/mVRWIWa/gUwD+Q/h/DLZd65j+xtS3tuEJFJp5N5acd2rEKRzauWqmh0Ly4bQfQHcUNgYPeYQ50dsvs/RD7uGT8PmChkFairIaOcSMgO5j5bARI4bMa6SWoJTd4hBhY9JZA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43MEO3xw013183; Mon, 22 Apr 2024 14:33:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-type : mime-version; s=pp1; bh=JPps2BNgN0KFAbx4xVEHzpPk2XAghVLEGx0sDhtl7gw=; b=MM0CWAd/m+iiWZBFIXZsKYBvuGraJCV/yMLs+909Z4gcgR9gM3iSo+wPuDPcv7nE6Ihf j2Ma7N5ljEnEjGWsA9qhP978g2NatDEPn5Yss7Lz6mGI8ZG0CpyaUbsHjhDQze3bnD/G mMFhpO4PdY2s+YRKSOXGjJV9a1oiQ8WFziZrl1zWmUr59ncGOG4ATz6J041zj46+sRbi uOfkcvCw636OWXDZxbKzjZ56PqySceL17JLas3/IbgtOCohR8iCKtKkESzxjZbvYzmq+ 1PYIkMrfwo4YGCOv91OV2PIX0KGT9R5KFbm7VnSMPLT5Kc4Qd4CI3qPJBL2773d+1cZS tQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xns0t03nn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Apr 2024 14:33:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kXvrsiRKHZ6cXbRKpXHhe7lD26prGxWp3P7yZdsQVsWCcZarpNRY0DSQxT1ACdYq/wzBxZZRYwNflnCdQPmrtBeKDH4Bnn5O2WV8qG0DYkt6IlGaJ9fJPfP1DoNg6DuXjjTd0ivdREh4teZlHir7Qno9wDnlOpaJlkIEJo0SV/L4qESiCOavZI0JqXLmp5OinVHQyqBvI0OKfY3uDErEp8fvlDhpsTCc56fnHFeDctctqplXbLLoIHyXaHQvXEm5MKw01ABpBunZZkY0d1Qa7Wq7sAkf0r6/UVnbCwdBntGFo42gszxD1oNzlloRJWR+UgB0vW82gMrp3hN+3sDytg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JPps2BNgN0KFAbx4xVEHzpPk2XAghVLEGx0sDhtl7gw=; b=kSspoUSOQugBaAZipeTZIKaA/KD7USRJjbDUpbdE+U2S3c6Ssa9eYLNtSwIRv4vmOPPTdzcKeZQNHdlLk4c9b3pmaJz+rftc4q4PDnrUWoc/44Tfi8z411tKxLl39sTuSiBxRkqgwYf/I2c1qZkqwEkNZrzpND3dscM/9w1JJUbvMo1fIHPhugdkESP3bc9ENEXFBsi4+sQ5FJXMi+qTzPM5gXujwZ5FLDCcZVwj7hDJtQinEwymZx91aJLf1rxS+Kne5WEAX7JzXH4YW99Mv5slSjlWueiB+jjFblDyp2a3PaXdYGP/kyZxYWh8nGNGQfZKTx+VvCcx8keiH6v0pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ibm.com; dmarc=pass action=none header.from=ibm.com; dkim=pass header.d=ibm.com; arc=none Received: from CH2PR15MB3544.namprd15.prod.outlook.com (2603:10b6:610:5::26) by BLAPR15MB3938.namprd15.prod.outlook.com (2603:10b6:208:272::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 14:33:40 +0000 Received: from CH2PR15MB3544.namprd15.prod.outlook.com ([fe80::86ba:f8f8:c478:6919]) by CH2PR15MB3544.namprd15.prod.outlook.com ([fe80::86ba:f8f8:c478:6919%3]) with mapi id 15.20.7472.044; Mon, 22 Apr 2024 14:33:40 +0000 From: Aditya Kamath1 To: Aditya Kamath1 via Gdb-patches , Ulrich Weigand , Tom Tromey , John Baldwin CC: Sangamesh Mallayya Subject: [Patch v2] Fix AIX thread exit events not being reported and UI to show kernel thread ID. Thread-Topic: [Patch v2] Fix AIX thread exit events not being reported and UI to show kernel thread ID. Thread-Index: AQHalMASL5ooYn4+bk6YTQPjhBpXfw== Date: Mon, 22 Apr 2024 14:33:40 +0000 Message-ID: Accept-Language: en-IN, en-US Content-Language: en-IN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH2PR15MB3544:EE_|BLAPR15MB3938:EE_ x-ms-office365-filtering-correlation-id: fe449e4f-488d-4637-bbcf-08dc62d93467 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: =?Windows-1252?Q?Paqc+u/x+LvLOGwWbB3iJmQV0AbGjjAIB+BGNb85xyqSZ+3oQB+/R3Zt?= =?Windows-1252?Q?5JhOTtdZHQWKM7b0Zee+w1lQwt4/4WNFmzDZHOFYPl7BZmUJKkVMOWaS?= =?Windows-1252?Q?LG27nuDaS+TgPPJDxoD860rn9/znZcYmgReY01UdVpMxvaI9smk75etY?= =?Windows-1252?Q?faPDjssqJ8zscqSXEWKRCVFCMlZyIRSA2f/gcghvAeor6nOCvinQn6w7?= =?Windows-1252?Q?PMbq6s1ZKoCqfOfB9DCl14+v99hAoXNT7XwyTJuBMET8gZRBu6lJgsDL?= =?Windows-1252?Q?8XdAUFqhqZ8yF3e5/lv5y18O6ewkf2/8UeSRnOIIddy2RZb0Suk+cfMW?= =?Windows-1252?Q?SX21//ooaV1pWceSdkIy4XBi/BqW1FQGX88CmWP9MAR9j9eCX6kUsXyA?= =?Windows-1252?Q?5ofz9OcDX08FDKsSCr1LJMxXVku6y4UKSsaWk+mp2zLyI8RiNHd+k33G?= =?Windows-1252?Q?Kpn00W5/t1YJDyKOjQ67WXC15hIgXbm71SztLKfj9lNR3Icrawh3zecK?= =?Windows-1252?Q?Xp/031dAMyyWJRlen0dbKWfPGyci3Q0/mSzlHJgVxIJv8vz2f8W4wtgW?= =?Windows-1252?Q?vmMd4yTJ4C4up5dy5lM5h8HXUGQRP/n7ELRCeGX0YwJcYJDuyeIEzZbV?= =?Windows-1252?Q?38tcCQdyNIJEWua94rUjKrBmBbrPfSqQt4fMU0ie1j6iXlQDGkghA08N?= =?Windows-1252?Q?T8shn+v6tKQWwLT2cqGayzXccDKfQWN5upDanTkjxQVfWOuYcZJ5O7PH?= =?Windows-1252?Q?BWJU0LwcsItHjyxHWBG5LRNbJmle/fpFY+yxOjX01LGlPy5ydivU3YlS?= =?Windows-1252?Q?8Ghr8YcbhOqFk0AiUq/sYO+YgSkcTylXWxxjdNXSMrb0oFcxe9aRcsfE?= =?Windows-1252?Q?YkyWER8vfadHsf1LSOHiYfL+7rtMkAN97nhGq/S6bSnQS3MPpSsc2V3z?= =?Windows-1252?Q?fRfGCGZIkRPKErMfELjTlTKG23KpQlfQuKtpoOXjjql8UqBb3/OH8kWK?= =?Windows-1252?Q?5vwZYBCMvw4jrkk31V2BpXJ21Mcb9FiH0edyPfu7izBpVe0IlWU18RAV?= =?Windows-1252?Q?hm+3NKwWVpZTDHtV1E4OgGn7qOYqLoBg27W1MoUUrL8OUEfXKQI8BUt2?= =?Windows-1252?Q?esZqWWkb0VTXpwV2q94xcZSqsjXwUTGUHb3kigH64WlYCqRXl/TjQBf8?= =?Windows-1252?Q?N9QrCWX9x/AtkBbWColzGBwbURFePjCKBH9UD6zaFSMZkJSdDhim7eFr?= =?Windows-1252?Q?vwI6cRa9kt3x2YBu3OtJi0c6JXKD39iV12OJ2PEepHAYiy/ViLmepX6P?= =?Windows-1252?Q?o8V+nTzOUHeLUe5xUxOYe+6dqYOgsYJ3//soVBIcV+/TJGuNOxGYhCmq?= =?Windows-1252?Q?MGoNzKUfRGYqpTXLNz7gwGMYrSIIm8gagvzhLv/VAzMEsdvpBCnBUU9l?= =?Windows-1252?Q?NYHF+jQ2H0aCa//PY9M3NA=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR15MB3544.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?Windows-1252?Q?mBUU3FQbpHOtLKB+wsnLMX8VlGB0etqEuAnxFFGqpasWJCDyEdV7dRoL?= =?Windows-1252?Q?bvdW/HL99e/fs3ctrOHYMgfiy3aRK1EZeanVRjSTOZofsyHqTZUjV7WY?= =?Windows-1252?Q?gHhx2y3AFDbN8nn9nCrNN3aH228fSURzTUlNinaaAeiVS8JbUipIx3SH?= =?Windows-1252?Q?RIgoFn1DF7ZEg+qcjllp1fJm9Ijd2M0XJMD/mQZq6wtFK5y8guTSsFAM?= =?Windows-1252?Q?DB0gN6M9ca+T6wexz9P2hAQ/JppPMWizE+ipWAMb7bnfzYlytAaNJeIN?= =?Windows-1252?Q?w490YfVvMYMKr908r9wa/O8WC+/scVhJT9/mnCDGg8wrfdQLP3rmfj0P?= =?Windows-1252?Q?AtDYaX4FXe4mnz+oDr+NqETy4BU+kWtiVbh8hvhl8LoQxc4dtU5QDe3V?= =?Windows-1252?Q?8aEpoab3Nqtgns8z3HsLlvPyzyh/qB5Bj0Rh/mdZPomjEbCEweeC2K80?= =?Windows-1252?Q?m2jXWfaRBJU7SG2x/Ubzl+8rUCPMgzJamUfHhxAYllnZKe1qMyrLLJoz?= =?Windows-1252?Q?HZQiV4J76dWiDQl5ysZbHR6zl789bW2HyqXeiw2JpYqYSbE48LTMkCXC?= =?Windows-1252?Q?UQUJccUEtOaLu27yblu+GKw101T5+e9p/9wQENucVHv9shc+g97jrzzj?= =?Windows-1252?Q?xzF5+fpry7dd29eaxnYPzgsHAtOJ52oALfT6ZBjtJ8rqwxBAqpHHrJTR?= =?Windows-1252?Q?/PALYepTMMrPK7rqbMsqzrm1OLpQUruDwaXD7PxxWq2/kOoYi3DoXgjl?= =?Windows-1252?Q?6u1i1RCPIaSicMMCdzlSrzp6FUSZX3fhg0TKrutLA1ezQtFLbc8vi4qx?= =?Windows-1252?Q?8YKJD+6eqrDqzKmqmG9OQ2NmMak8Z/1MpLTC8CEgoGEWHg4ujtNyXmq4?= =?Windows-1252?Q?e9Q+HnOikMhoCC027OtuZzVgG3BK+oJ83uVmiFH1p4z25OwuxpxXX/Ko?= =?Windows-1252?Q?WBt7JikHTqW9Dn4rToMQOT3sUpaQtNrVraz43Chq9vuMEf6VXbtlGKni?= =?Windows-1252?Q?bubezQT1z6TLxDbhl3pLnbD9AupjzLlr5bjn6w5p6BDo+2yo9qh+CWep?= =?Windows-1252?Q?+12Mql+NAX3vF2hqmghcwv9ZJ1uIF6zl7VedpsfKv84vGdqTObkwvn2R?= =?Windows-1252?Q?e6MX2VMR94aXv37cwUZXkbtTMYWZeqUVa/d6dsrWLv5Bvvf61G01YBmm?= =?Windows-1252?Q?u5n8nATZ4HIRRNZaTAEumJ3QezpEwzN4TWaeRR1KuUeGusnE7+G5lfbJ?= =?Windows-1252?Q?Y8yZXMluoC0UdDF0VqWAtKk093rLQST5Kc84h4UvRVAMYTJvpNsYLQr/?= =?Windows-1252?Q?xvLUpRR4SrNFzbjG5W+p9A0q+TRdPe1uaBkqvPtrZLhhAuJB5AmjDTXe?= =?Windows-1252?Q?NYi44E19YJGa4UVJnOpnLEKteVwvhRlMRZMCLM4pU+4UF56S561a8Rmy?= =?Windows-1252?Q?Jte456/RFK0ElDTKi2UyhDRb2VKhqN8E4/Q4F/BVuSzxrWdy2aCHcXHK?= =?Windows-1252?Q?46ikrd1S5FCjfh46gMBvj0sg+4C7IIE5N0LZxLX85xRhZ81nee01jaDn?= =?Windows-1252?Q?FIiIH8XWMIfXk9VGJ46CCtEcNgFFIVYTcEUYsR2ZNevUdDudzBEkZIxB?= =?Windows-1252?Q?yTHf0ytyXO8OJKdPoB7svWEI1Pdo+zUvH0wh089HPiSYHc83YomckZdM?= =?Windows-1252?Q?ltBN860tV3wyUJ2BzQf5hI8Fc83dyxtE3F5qXQ4KYsDOWSh7eQcGelLx?= =?Windows-1252?Q?yx5BE43LStvLiw+UDXMn+gxyHNAezDLCzTobN+cv77s4iGnzxnC6B4z6?= =?Windows-1252?Q?afVJ6Q=3D=3D?= Content-Type: multipart/alternative; boundary="_000_CH2PR15MB3544D487D375AAD3455FEC7AD6122CH2PR15MB3544namp_" X-OriginatorOrg: ibm.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR15MB3544.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe449e4f-488d-4637-bbcf-08dc62d93467 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Apr 2024 14:33:40.6081 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: fcf67057-50c9-4ad4-98f3-ffca64add9e9 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3VSlmhxs5SaUsrE40wqLo/zuUHbQhPyA6OddD8JPnBwy8xbvPKaJPptNaqTvnqFLKkheemAiPKXdLOfx7dmdeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR15MB3938 X-Proofpoint-ORIG-GUID: FQUQkrxkvqSOYuCpVreu-J_lllefPTO6 X-Proofpoint-GUID: FQUQkrxkvqSOYuCpVreu-J_lllefPTO6 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-22_09,2024-04-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 malwarescore=0 phishscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404220063 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,TXREP,T_SPF_TEMPERROR 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: --_000_CH2PR15MB3544D487D375AAD3455FEC7AD6122CH2PR15MB3544namp_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Respected John, Tom, Ulrich, and community members, Hi, Thank you for the comments in the previous version of the patch. >Next time can you please send the patch inline as a separate e-mail? You = can use a cover >letter for the contents of this mail. It is just easier to review in that= case. >One thing I think I'm not fully understanding: does a thread never get rem= oved from the >pth list once it has exited? That is, is it on that list forever? If so,= I think >you could simplify this quite a bit to remove the qsort and the gcount and= associated >list, etc. Instead, I would keep track of exited threads whose exit has b= een reported >via a new std::unordered_set<> class member in the target to avoid reporti= ng duplicate >events and then do something like: Please see the patch pasted below this email. Thank you for this John. This= makes it easy for us to maintain and keep track. I have done a small clean-up of aix-thread.c to keep things simple. Yes, a thread was never getting removed from pbuf. It was in it forever. Output after applying this patch:- Reading symbols from //gdb_tests/continue-pending-status_exit_test... (gdb) r Starting program: /gdb_tests/continue-pending-status_exit_test More threads Hello World Hello World Hello World Hello World Hello World Hello World [New Thread 258 (tid 19136989)] [Thread 258 (tid 19136989) exited] [New Thread 515 (tid 19464469)] [Thread 515 (tid 19464469) exited] [New Thread 772 (tid 34144651)] [Thread 772 (tid 34144651) exited] [New Thread 1029 (tid 25690595)] [Thread 1029 (tid 25690595) exited] [New Thread 1286 (tid 18547171)] [Thread 1286 (tid 18547171) exited] [New Thread 1543 (tid 32637297)] [Thread 1543 (tid 32637297) exited] Thread 1 received signal SIGINT, Interrupt. 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o) (gdb) info thread q Id Target Id Frame * 1 Thread 1 (tid 31916313) ([running]) 0xd0611d70 in _p_nsleep () from = /usr/lib/libpthread.a(_shr_xpg5.o) (gdb) q Kindly let me know if this version is okay. >> So, consider program 1 pasted below this email. >Is there some existing gdb test case that is fixed by this patch? If >not then I think it would be better if the patch came with a new test. Sure Tom. I will create another patch for this and send it soon. For now I will attach the test program below. Also, I have update the comments and removed the old ones. >>I am planning to use >>=93status =3D pthdb_pthread_state (data->pd_session, pdtid, &state);=94 >> >>And if the state is PST_TERM then I want to remove the thread vector >>from the pbuf list and make sure pcount is also reduced. >>This can fix the issue. >>This makes sense to me. Thanks Ulrich. So as John suggested we will making use of unordered set and= keeping track of exited threads using the state PST_TERM. Have a nice day ahead. Thanks and regards, Aditya. The patch:- # cat patches/0001-Fix-AIX-thread-exit-events-not-being-reported-and-UI.pat= ch =46rom ae736fe495c279d42e65f936bce0f9dab5ec703b Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Aditya.Kamath1@ibm.com Date: Mon, 22 Apr 2024 09:16:56 -0500 Subject: [PATCH] Fix AIX thread exit events not being reported and UI to sh= ow kernel thread ID. In AIX when a thread exits we were not showing that a thread exit event hap= pened 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 =3D 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 b= oth 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 | 217 ++++++++++++----------------------------------- 1 file changed, 52 insertions(+), 165 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index c70bd82bc24..73839243213 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 exit events reported. */ + std::unordered_set exited_threads; }; /* Key to our per-inferior data. */ @@ -737,47 +741,6 @@ state2str (pthdb_state_t state) } } -/* qsort() comparison function for sorting pd_thread structs by pthid. */ - -static int -pcmp (const void *p1v, const void *p2v) -{ - struct pd_thread *p1 =3D (struct pd_thread *) p1v; - struct pd_thread *p2 =3D (struct pd_thread *) p2v; - return p1->pthid < p2->pthid ? -1 : p1->pthid > p2->pthid; -} - -/* ptid comparison function */ - -static int -ptid_cmp (ptid_t ptid1, ptid_t ptid2) -{ - if (ptid1.pid () < ptid2.pid ()) - return -1; - else if (ptid1.pid () > ptid2.pid ()) - return 1; - else if (ptid1.tid () < ptid2.tid ()) - return -1; - else if (ptid1.tid () > ptid2.tid ()) - return 1; - else if (ptid1.lwp () < ptid2.lwp ()) - return -1; - else if (ptid1.lwp () > ptid2.lwp ()) - return 1; - else - return 0; -} - -/* qsort() comparison function for sorting thread_info structs by pid. */ - -static int -gcmp (const void *t1v, const void *t2v) -{ - struct thread_info *t1 =3D *(struct thread_info **) t1v; - struct thread_info *t2 =3D *(struct thread_info **) t2v; - return ptid_cmp (t1->ptid, t2->ptid); -} - /* Search through the list of all kernel threads for the thread that has stopped on a SIGTRAP signal, and return its TID. Return 0 if none found. */ @@ -822,22 +785,16 @@ static void 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; pthdb_tid_t tid; process_stratum_target *proc_target =3D current_inferior ()->process_tar= get (); struct aix_thread_variables *data; data =3D get_thread_data_helper_for_pid (pid); + pthdb_state_t state; /* Accumulate an array of libpthdebug threads sorted by pthread id. */ - pcount =3D 0; - psize =3D 1; - pbuf =3D XNEWVEC (struct pd_thread, psize); - for (cmd =3D PTHDB_LIST_FIRST;; cmd =3D PTHDB_LIST_NEXT) { status =3D pthdb_pthread (data->pd_session, &pdtid, cmd); @@ -848,118 +805,44 @@ sync_threadlists (pid_t pid) if (status !=3D PTHDB_SUCCESS || pthid =3D=3D PTHDB_INVALID_PTID) continue; - if (pcount =3D=3D psize) + ptid_t ptid (pid, 0, pthid); + status =3D pthdb_pthread_state (data->pd_session, pdtid, &state); + if (state =3D=3D PST_TERM) { - psize *=3D 2; - pbuf =3D (struct pd_thread *) xrealloc (pbuf, - psize * sizeof *pbuf); + if (data->exited_threads.count (pdtid) !=3D 0) + continue; } - pbuf[pcount].pdtid =3D pdtid; - pbuf[pcount].pthid =3D pthid; - pcount++; - } - - for (pi =3D 0; pi < pcount; pi++) - { - status =3D pthdb_pthread_tid (data->pd_session, pbuf[pi].pdtid, &tid= ); - if (status !=3D PTHDB_SUCCESS) - tid =3D PTHDB_INVALID_TID; - pbuf[pi].tid =3D tid; - } - - qsort (pbuf, pcount, sizeof *pbuf, pcmp); - - /* Accumulate an array of GDB threads sorted by pid. */ - - /* gcount is GDB thread count and pcount is pthreadlib thread count. */ - - gcount =3D 0; - for (thread_info *tp : all_threads (proc_target, ptid_t (pid))) - gcount++; - g =3D gbuf =3D XNEWVEC (struct thread_info *, gcount); - for (thread_info *tp : all_threads (proc_target, ptid_t (pid))) - *g++ =3D tp; - qsort (gbuf, gcount, sizeof *gbuf, gcmp); - /* Apply differences between the two arrays to GDB's thread list. */ - - for (pi =3D gi =3D 0; pi < pcount || gi < gcount;) - { - if (pi =3D=3D pcount) - { - delete_thread (gbuf[gi]); - gi++; - } - else if (gi =3D=3D gcount) + /* If this thread has never been reported to GDB, add it. */ + if (!in_thread_list (proc_target, ptid)) { aix_thread_info *priv =3D new aix_thread_info; - priv->pdtid =3D pbuf[pi].pdtid; - priv->tid =3D pbuf[pi].tid; - - thread =3D add_thread_with_info (proc_target, - ptid_t (pid, 0, pbuf[pi].pthid), - private_thread_info_up (priv)); - - pi++; - } - else - { - ptid_t pptid, gptid; - int cmp_result; - - pptid =3D ptid_t (pid, 0, pbuf[pi].pthid); - gptid =3D gbuf[gi]->ptid; - pdtid =3D pbuf[pi].pdtid; - tid =3D pbuf[pi].tid; - - cmp_result =3D ptid_cmp (pptid, gptid); - - if (cmp_result =3D=3D 0) - { - aix_thread_info *priv =3D get_aix_thread_info (gbuf[gi]); - - priv->pdtid =3D pdtid; - priv->tid =3D tid; - pi++; - gi++; - } - else if (cmp_result > 0) + /* init priv */ + priv->pdtid =3D pdtid; + status =3D pthdb_pthread_tid (data->pd_session, pdtid, &tid); + priv->tid =3D tid; + /* Check if this is the main thread. If it is, then change + its ptid and add its private data. */ + if (get_signaled_thread (pid) =3D=3D tid + && in_thread_list (proc_target, ptid_t (pid))) { - /* This is to make the main process thread now look - like a thread. */ - - if (gptid.is_pid ()) - { - thread_info *tp =3D proc_target->find_thread (gptid); - thread_change_ptid (proc_target, gptid, pptid); - aix_thread_info *priv =3D new aix_thread_info; - priv->pdtid =3D pbuf[pi].pdtid; - priv->tid =3D pbuf[pi].tid; - tp->priv.reset (priv); - gi++; - pi++; - } - else - { - delete_thread (gbuf[gi]); - gi++; - } + thread_info *tp =3D proc_target->find_thread (ptid_t (pid)); + thread_change_ptid (proc_target, ptid_t (pid), ptid); + tp->priv.reset (priv); } else - { - thread =3D add_thread (proc_target, pptid); + add_thread_with_info (proc_target, ptid, + private_thread_info_up (priv)); + } - aix_thread_info *priv =3D new aix_thread_info; - thread->priv.reset (priv); - priv->pdtid =3D pdtid; - priv->tid =3D tid; - pi++; - } + if (state =3D=3D PST_TERM) + { + thread_info *thr =3D proc_target->find_thread (ptid); + gdb_assert (thr !=3D nullptr); + delete_thread (thr); + data->exited_threads.insert (pdtid); } } - - xfree (pbuf); - xfree (gbuf); } /* Iterate_over_threads() callback for locating a thread, using @@ -2084,10 +1967,17 @@ aix_thread_target::thread_alive (ptid_t ptid) std::string aix_thread_target::pid_to_str (ptid_t ptid) { - if (ptid.tid () =3D=3D 0) - return beneath ()->pid_to_str (ptid); + thread_info *thread_info =3D current_inferior ()->find_thread (ptid); + + if (thread_info !=3D NULL && thread_info->priv !=3D NULL) + { + aix_thread_info *priv =3D 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 +1988,6 @@ aix_thread_target::extra_thread_info (struct thread_i= nfo *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 +2004,31 @@ aix_thread_target::extra_thread_info (struct thread= _info *thread) aix_thread_info *priv =3D get_aix_thread_info (thread); pdtid =3D priv->pdtid; - tid =3D priv->tid; - - if (tid !=3D PTHDB_INVALID_TID) - /* i18n: Like "thread-identifier %d, [state] running, suspended" */ - buf.printf (_("tid %d"), (int)tid); status =3D pthdb_pthread_state (data->pd_session, pdtid, &state); + + /* Output should look like Thread %d (tid %d) ([state]). */ + /* Example:- Thread 1 (tid 34144587) ([running]). */ + /* where state can be running, idle, sleeping, finished, + suspended, detached, cancel pending, ready or unknown. */ + if (status !=3D PTHDB_SUCCESS) state =3D PST_NOTSUP; - buf.printf (", %s", state2str (state)); + buf.printf ("[%s]", state2str (state)); status =3D pthdb_pthread_suspendstate (data->pd_session, pdtid, &suspendstate); if (status =3D=3D PTHDB_SUCCESS && suspendstate =3D=3D PSS_SUSPENDED) - /* i18n: Like "Thread-Id %d, [state] running, suspended" */ - buf.printf (_(", suspended")); + buf.printf (_("[suspended]")); status =3D pthdb_pthread_detachstate (data->pd_session, pdtid, &detachstate); if (status =3D=3D PTHDB_SUCCESS && detachstate =3D=3D 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 =3D=3D 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 Test Program 1:- #include #include #include #include #include pthread_barrier_t barrier; #define NUM_THREADS 3 void * thread_function (void *arg) { /* This ensures that the breakpoint is only hit after both threads are created, so the test can always switch to the non-event thread when the breakpoint triggers. */ // pthread_barrier_wait (&barrier); printf ("Hello World \n"); /* break here */ } int main (void) { int i; alarm (300); pthread_barrier_init (&barrier, NULL, NUM_THREADS); for (i =3D 0; i < NUM_THREADS; i++) { pthread_t thread; int res; res =3D pthread_create (&thread, NULL, thread_function, NULL); assert (res =3D=3D 0); } printf ("More threads \n"); for (i =3D 0; i < NUM_THREADS; i++) { pthread_t thread; int res; res =3D pthread_create (&thread, NULL, thread_function, NULL); assert (res =3D=3D 0); } while (1) sleep (1); return 0; } --_000_CH2PR15MB3544D487D375AAD3455FEC7AD6122CH2PR15MB3544namp_--