From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2052.outbound.protection.outlook.com [40.107.20.52]) by sourceware.org (Postfix) with ESMTPS id 0FFA33858C66 for ; Thu, 3 Nov 2022 15:03:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FFA33858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ICqyGEQtTTC3dXBoswHS2B5bpbH0MGFhOpaHkKy2I5PZ5NA0dunOx9aFAej8Gk5TgtlRkvOdpA3RkmurHLVgiNxoenwoGY21acWiVG4pTyWPICRL0tVAVgJ5mi4rNFJz15qMbbAb7FbAJd2kyqcXnti3dAm/k7cyMoIdqsTKiJuFJEd0Y+BzXPUFdztC4ACfSQrsEotYnWhSJLVMk+XTS18G/lhUC7o29FXk0I39D2LFJROj9kfxNpwopuMgd5jtvEi4YqH+poO+t/gDVihPCe1TQldlRyF1Tp1T46+WFiHGJu/Jj/pXi1v7dYodUuf7BwHsrehq28yS6Xn0BbkQjA== ARC-Message-Signature: i=2; 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=zc31x4/lxafMoogKOPNI42oq4sJ2YY3I5zpO6o6JY3Y=; b=QT9VojOfVrNw1Lk/W+c/ZI3Q+0mcmj9bNtbOAVdFLH+vCNiWMcRzNbwiIOEoQXsA4z+lovcVnqIY6dwwaQcz5p5ZKKX3xNRQ2Zl/FMtU+2GVOKKrLrpQIh3WoR8gHXK2UDfESNCiMVEUoRdrivOmNYixt0XgxP8xyaaFB7be9ZUzEJXVAIWM90upFDIysTPdkz9C0Kdum0k/mssABdU8cWC41acRGNotTJmSO36LZPU17FIE2WsHuTYq8/ekaLExzd4yxwFKOq/Re3LyrUwpE5nWc1pTP851beuVfvNN7imRTHjQhO7J08KmNG3SoImHyoAzZ1ANbE+PXa6pOJ7SjA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zc31x4/lxafMoogKOPNI42oq4sJ2YY3I5zpO6o6JY3Y=; b=YtCsgRumdIeRpfpFEyLy6xTw70QuIQH4uWWB0TrTd+DqUguhV2YeLyhBlFb7WZRurp/PUFga/8OL5MaRqnSWXROEZNh4WDbKh1Z5JoDS+wNChWKdwPcCZ4ZTgPo7r4oPsfnzF1d3P88sA8Y27/YcnMGZv807bb1LQ2VwfVWogf8= Received: from DUZPR01CA0030.eurprd01.prod.exchangelabs.com (2603:10a6:10:46b::19) by PA4PR08MB6285.eurprd08.prod.outlook.com (2603:10a6:102:e0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Thu, 3 Nov 2022 15:03:35 +0000 Received: from DBAEUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:46b:cafe::61) by DUZPR01CA0030.outlook.office365.com (2603:10a6:10:46b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.15 via Frontend Transport; Thu, 3 Nov 2022 15:03:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT050.mail.protection.outlook.com (100.127.142.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Thu, 3 Nov 2022 15:03:35 +0000 Received: ("Tessian outbound aeae1c7b66fd:v130"); Thu, 03 Nov 2022 15:03:35 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e952dd6049b1dc9b X-CR-MTA-TID: 64aa7808 Received: from a01ee64d4ef2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 56575C17-3878-4C0B-9222-182AE37B6D27.1; Thu, 03 Nov 2022 15:03:28 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a01ee64d4ef2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 03 Nov 2022 15:03:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BIwyQHwmuwjVhWKaVCIp/tuFxU+MQNZutF9rcu6Z5nCuduLcSx2yLU07bYjKB8tpEm1lXHQ3IPFffvcGMzYPE14o5soo5O8hQAMOt8JxEoC4A2DpKaRo36d1EIZ7t7QHNWcjFv1f+Pm+e9oDeOn2BLgUNRgO0WaBlcdJ2gI3PnrMJgPu1gbSgr8Ok0Y9SNTsYMCAehLWJr4cdvy5AbN7o1dX0R5fBBhtvsEM6GlQz/2nUifuDJ0HHFo+1VrYpaLxK+bu0c2aucnHsAQWIlXmSsQ631E3GkYE4o2m8U5/b8Y8C4UKIiSl6XOvRtaR7UPqI1PhpTVbBdRagtUG148PEQ== 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=zc31x4/lxafMoogKOPNI42oq4sJ2YY3I5zpO6o6JY3Y=; b=EEK4OGjhR+9OQDZE9F+IXF/F42ji6k1TuDA66HYoHOjwAQjCXsG6bKDgTTtRJ5B9gO8V3QLR52JEscXzG74NxnP0bNVnWsf15rxry5YfW9KKy3vn4VOv2r5EH7y7nm15J09FSjG3S5PMNWeD85mTDvc6am6QUd061xlt9kvPYBoqlKOhcmMEdlkc+0KoO6DA2T+1ls9EVXUCd1JMLhsfHJYmWPsw6sWYzlcJ7OPACHrMneekbx2D2LAb8AY/cjk0ATaB4tyIXSsXc1Lj4rjOFW4xUpgdQG4Ar3Rw2JwZed0B6yke0yf8AIB69jD8rHqIj+LJqjv1bprj/5DbMn7gbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zc31x4/lxafMoogKOPNI42oq4sJ2YY3I5zpO6o6JY3Y=; b=YtCsgRumdIeRpfpFEyLy6xTw70QuIQH4uWWB0TrTd+DqUguhV2YeLyhBlFb7WZRurp/PUFga/8OL5MaRqnSWXROEZNh4WDbKh1Z5JoDS+wNChWKdwPcCZ4ZTgPo7r4oPsfnzF1d3P88sA8Y27/YcnMGZv807bb1LQ2VwfVWogf8= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AS8PR08MB7720.eurprd08.prod.outlook.com (2603:10a6:20b:508::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20; Thu, 3 Nov 2022 15:03:27 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::6ba4:2f18:7531:943b]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::6ba4:2f18:7531:943b%7]) with mapi id 15.20.5769.021; Thu, 3 Nov 2022 15:03:26 +0000 Message-ID: Date: Thu, 3 Nov 2022 15:03:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCHv2] gdb: new $_inferior_thread_count convenience variable Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <20221102143416.3307157-1-aburgess@redhat.com> <20221103144239.98993-1-aburgess@redhat.com> From: Luis Machado In-Reply-To: <20221103144239.98993-1-aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SA0PR12CA0011.namprd12.prod.outlook.com (2603:10b6:806:6f::16) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB7720:EE_|DBAEUR03FT050:EE_|PA4PR08MB6285:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e48ac83-248a-447c-0c0f-08dabdac94ff x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 6Ec1ldvXDFU/5/A1y05V4AJKPHobFT5jrINAhVGVxY4Nh9JI6vJmBQ6+YkZ1RRve7Kedj95qWLam/rIi+4rVAPAiPc9Vej4HEj4S3ZD57pzgN0XDVEdIAVLxC2lUjUW6Vly5eousKM8HP2zY++jx6D/HI+/31SjpXAbX9GQBUnmXMrmfQ8dymiD2R3bwuqraxjPmez5Tmm3B9jVxCsY5ZZOKYFnsYSkdnSuqeUXvRi0AH7fFaMF5FBR8wAVNm5gMj+AMWjR5Fd18PnYnxatTtUdccKtQscn5uXRt/rBN2ksDmt3WrIKl/Cys3gx8cfvyloKOiG0N/bE+uzfqs8Od+9s3IXAJbwmeGE4PwgNqyQ/9KAvE98b+GipSUvX2hOAhWkS2hagDRwnsCNHx9idlX6rjvFZfaYGKskYPk7O/bRUhLQhlw4fwHxeQE6p5XHMaUFlWEO66Ku4qtdX+Nsw1EKsOAsggQaxik0Wfg6yeSo/NUpgmV7yLuylb5b6ZInHugl66LhIRDYop5QuL1mbqwNDDCF5h/QEvPMuSp7YnOgRnXNfETyCKRpVIJxPezDj19xx1djwRm4145YcYwdJKgdYjiVDMpcaMMbhfOWdQev8mXoyxJbPmcFzsZqxCcKImHEA2+UbOt7qqRm9k07BdNnHFbMTkggzwYBIhRZBi0wV+aONX7BlDH4hdfDlm0BuUeHiC41Eo7FYFTg9rarlvXgP/p30nDdksFzKnwc+1qGYxP3khUkiKo6BwwaWwn4cCMQrcsVwjETKQaRPXtEVq7yXucFt2gBup87TZ5JyQyPg= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(396003)(136003)(39860400002)(366004)(451199015)(2906002)(186003)(44832011)(2616005)(478600001)(31686004)(6486002)(6506007)(66556008)(6666004)(36756003)(83380400001)(66946007)(53546011)(26005)(316002)(38100700002)(41300700001)(8936002)(31696002)(66476007)(5660300002)(6512007)(86362001)(8676002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7720 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: cf85e60c-7569-4876-0cd7-08dabdac8f4f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RazapUZvJIDCGowjyfJi7Q5TLLy7d1mN5YoTpQSAzpRbnlspJVYM56LtpZKPHpzCqnzCdlTRDFWMKaLhG1MC741vhfaO3stf5HhyXfN/oEZ18xfs/E146o/itnalWxKR2X+8S4RjiKI7XmUr6Pk07Riw1qCPeCAFsotcjh2b+l5yjyl20mcsZUxcq5QDOEoelIBJSf0cRqPwgId3aCPuvlW2/Ud0MnKFsRpTr2FydwLOD/tTI1YUE6YIm5VbYlsJyl/6mszK+02Hc4WedtCsDp07s+EgKnSlE9xQn76x9rC764rTO6z7QG/VyQBTFgDmSm3ctQFHAGpc6W4YUA+qluIVcX43wYGbtaE6GRaF6JMfdsocB57boOechlto5H0M7gPY0Yv/qMj/lQoUr6ikjN7m3i44QsJInJoDg+GHpUjcUQ4yLP91lTJaPBdDw07IM/IhyvQk9jDAJ3L5Mv/ugokKWKCS50VV2MdJ0ww39k2OqVbhyd0z97aN74DA3faQx3Jvrzzt7nPkqvhrxin854upaLl/YcfxM+wrSH7ofiaTQfLR+/WGRO4238WZzqyr54J7JZOrKZ6cmdyj5nhsSf/+cGzQdVtLl41uCDFbYdUUT83JwW/p427uMU9fut8JMh+rFZUiosHq9IMVixSmOmgZsYJ4FqYQQuogmcqLEvpLIU2PsOtGJCEqbrMKTK9ZbO/VWD6aSJIcN8Tbty3UndxrpEp4Y51f/FT+jmXZhuIb1Ev1cRxW0ui+PrbgYxZd8e4Rn4Zp8zXEnrqOPoUKnxnLjFW6I6hRrxt7ZQGlElI= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(39860400002)(396003)(136003)(451199015)(40470700004)(36840700001)(46966006)(8676002)(36756003)(53546011)(2906002)(70586007)(70206006)(47076005)(83380400001)(6666004)(40480700001)(82310400005)(316002)(31696002)(86362001)(36860700001)(40460700003)(81166007)(356005)(82740400003)(6506007)(478600001)(6512007)(26005)(2616005)(41300700001)(31686004)(8936002)(5660300002)(186003)(6486002)(336012)(44832011)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2022 15:03:35.7957 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e48ac83-248a-447c-0c0f-08dabdac94ff X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6285 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY 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 11/3/22 14:42, Andrew Burgess via Gdb-patches wrote: > Simon, Luis, thanks for your feedback. > > Changes since v1: > > 1. Rename variable to $_inferior_thread_count. > > 2. Use "live" in the docs and NEWS file to describe the threads > being counted. I do still use "non-exited" within the commit > message and comments, as this is how "live" is actually implemented > within GDB. > > 3. Updated the docs to mention that in non-stop mode the value of > $_inferior_thread_count will not be stable. > > Thanks, > Andrew > > --- > > Add a new convenience variable $_inferior_thread_count that contains > the number of live (non-exited) threads in the current inferior. This > can be used in command scripts, or breakpoint conditions, etc to > adjust the behaviour for multi-threaded inferiors. > > This value is only stable in all-stop mode. In non-stop mode, where > new threads can be started, and existing threads exit, at any time, > this convenience variable can give a different value each time it is > evaluated. > --- > gdb/NEWS | 3 +++ > gdb/doc/gdb.texinfo | 14 ++++++++++++-- > gdb/testsuite/gdb.base/default.exp | 1 + > gdb/testsuite/gdb.multi/tids.exp | 20 ++++++++++++++++++++ > gdb/thread.c | 26 ++++++++++++++++++++++++++ > gdbsupport/iterator-range.h | 4 ++++ > 6 files changed, 66 insertions(+), 2 deletions(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 8b519a648f7..8857dedb8b8 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -71,6 +71,9 @@ > For both /r and /b GDB is now better at using whitespace in order to > align the disassembled instruction text. > > +* New convenience variable $_inferior_thread_count contains the number > + of live threads in the current inferior. > + > * New commands > > maintenance set ignore-prologue-end-flag on|off > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index ea66f4ee42d..82f7fd66bf0 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -3642,8 +3642,15 @@ > @samp{$_gthread} contain, respectively, the per-inferior thread number > and the global thread number of the current thread. You may find this > useful in writing breakpoint conditional expressions, command scripts, > -and so forth. @xref{Convenience Vars,, Convenience Variables}, for > -general information on convenience variables. > +and so forth. The convenience variable @samp{$_inferior_thread_count} > +contains the number of live threads in the current inferior. > +@xref{Convenience Vars,, Convenience Variables}, for general > +information on convenience variables. > + > +When running in non-stop mode (@pxref{Non-Stop Mode}), where new > +threads can be created, and existing threads exit, at any time, > +@samp{$_inferior_thread_count} could return a different value each > +time it is evaluated. > > If @value{GDBN} detects the program is multi-threaded, it augments the > usual message about stopping at a breakpoint with the ID and name of > @@ -12655,6 +12662,9 @@ > @item $_gthread > The global number of the current thread. @xref{global thread numbers}. > > +@item $_inferior_thread_count > +The number of live threads in the current inferior. @xref{Threads}. > + > @item $_gdb_major > @itemx $_gdb_minor > @vindex $_gdb_major@r{, convenience variable} > diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp > index 29e76642830..f3e4b2867ef 100644 > --- a/gdb/testsuite/gdb.base/default.exp > +++ b/gdb/testsuite/gdb.base/default.exp > @@ -584,6 +584,7 @@ set show_conv_list \ > {$_thread = 0} \ > {$_gthread = 0} \ > {$_inferior = 1} \ > + {$_inferior_thread_count = 0} \ > {$_exception = } \ > {$_probe_argc = } \ > {$_probe_arg0 = } \ > diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp > index fb7c2a29a71..23668caf18f 100644 > --- a/gdb/testsuite/gdb.multi/tids.exp > +++ b/gdb/testsuite/gdb.multi/tids.exp > @@ -123,6 +123,8 @@ with_test_prefix "single inferior" { > info_threads "" "1" > > gdb_test "thread" "Current thread is 1 .*" > + > + gdb_test "print \$_inferior_thread_count" " = 1" > } > > # "info threads" while there are multiple inferiors should show > @@ -140,8 +142,14 @@ with_test_prefix "two inferiors" { > gdb_test "inferior 2" "Switching to inferior 2 .*" "switch to inferior 2" > gdb_test "file ${binfile}" ".*" "load file in inferior 2" > > + gdb_test "print \$_inferior_thread_count" " = 0" \ > + "no threads before we start the second inferior" > + > runto_main > > + gdb_test "print \$_inferior_thread_count" " = 1" \ > + "no other threads started yet" > + > # Now that we've added another inferior, thread IDs now show the > # inferior number. > info_threads "" "1.1 2.1" \ > @@ -153,8 +161,14 @@ with_test_prefix "two inferiors" { > gdb_breakpoint "thread_function1" > > gdb_continue_to_breakpoint "once" > + gdb_test "print \$_inferior_thread_count" " = 2" \ > + "second thread started in inferior 2" > gdb_test "inferior 1" "Switching to inferior 1 .*" > + gdb_test "print \$_inferior_thread_count" " = 1" \ > + "still only one thread in inferior 1" > gdb_continue_to_breakpoint "twice" > + gdb_test "print \$_inferior_thread_count" " = 2" \ > + "second thread started in inferior 1" > > info_threads "" "1.1 1.2 2.1 2.2" \ > "info threads again" > @@ -187,9 +201,15 @@ with_test_prefix "two inferiors" { > > gdb_test "inferior 2" "Switching to inferior 2 .*" > gdb_continue_to_breakpoint "once" > + gdb_test "print \$_inferior_thread_count" " = 3" \ > + "third thread started in inferior 2" > > gdb_test "inferior 1" "Switching to inferior 1 .*" > + gdb_test "print \$_inferior_thread_count" " = 2" \ > + "still only two threads in inferior 1" > gdb_continue_to_breakpoint "twice" > + gdb_test "print \$_inferior_thread_count" " = 3" \ > + "third thread started in inferior 1" > } > > thr_apply_info_thr "1" \ > diff --git a/gdb/thread.c b/gdb/thread.c > index 349fc01dd48..d176d1d9895 100644 > --- a/gdb/thread.c > +++ b/gdb/thread.c > @@ -2123,6 +2123,22 @@ global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var, > return thread_num_make_value_helper (gdbarch, 1); > } > > +/* Return a new value for the number of non-exited threads in the current > + inferior. If there are no threads in the current inferior return a > + value of 0. */ > + > +static struct value * > +inferior_thread_count_make_value (struct gdbarch *gdbarch, > + struct internalvar *var, void *ignore) > +{ > + int int_val = 0; > + > + if (inferior_ptid != null_ptid) > + int_val = current_inferior ()->non_exited_threads ().size (); > + > + return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val); > +} > + > /* Commands with a prefix of `thread'. */ > struct cmd_list_element *thread_cmd_list = NULL; > > @@ -2142,6 +2158,14 @@ static const struct internalvar_funcs gthread_funcs = > NULL, > }; > > +/* Implementation of `_inferior_thread_count` convenience variable. */ > + > +static const struct internalvar_funcs inferior_thread_count_funcs = > +{ > + inferior_thread_count_make_value, > + NULL, > +}; > + > void _initialize_thread (); > void > _initialize_thread () > @@ -2258,4 +2282,6 @@ When on messages about thread creation and deletion are printed."), > > create_internalvar_type_lazy ("_thread", &thread_funcs, NULL); > create_internalvar_type_lazy ("_gthread", >hread_funcs, NULL); > + create_internalvar_type_lazy ("_inferior_thread_count", > + &inferior_thread_count_funcs, NULL); > } > diff --git a/gdbsupport/iterator-range.h b/gdbsupport/iterator-range.h > index d35b03a3392..c99bdc8de07 100644 > --- a/gdbsupport/iterator-range.h > +++ b/gdbsupport/iterator-range.h > @@ -53,6 +53,10 @@ struct iterator_range > IteratorType end () const > { return m_end; } > > + /* The number of items in this iterator_range. */ > + std::size_t size () const > + { return std::distance (m_begin, m_end); } > + > private: > IteratorType m_begin, m_end; > }; LGTM.