From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60070.outbound.protection.outlook.com [40.107.6.70]) by sourceware.org (Postfix) with ESMTPS id B90EC385701E for ; Wed, 2 Nov 2022 15:07:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B90EC385701E 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=jNqA9uoOzYDVKX9zB5qXvBqNqsmwepKslnNci8QiLw9fv2FnRrolxN6mvb03lzQ+PO80wTt1NvPiQxmZ6REfLxR/BoFGeMuWlg7o7iTo72rhlcEx4+oScH/XyKBLTloqwctdHTtIfKzxD9Z2Qi79ipIqeLGdYeeKK+/AyjRl+WF7FuPS+lWIjLhG0gnlMYvScftwmkSaLk8DGk/5l7te+luASfgvqbxuGsqaCdGPcsX3MGWsjBGj8RgpDgNWcK03vPihH2w/sHaGUahJar5dVV9K67pmpdXt9DDLxaRZPC+404P1JUIfRrCr9JgPXG0E16wM5TgZY6FlJrp1tDkfNg== 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=Ql0pCQOS3CAeoxS7mRqc3Ab6tOYr3xmfvbzsyPLpYAg=; b=K3wY+pJiNQLKteHkYIyEwWed7WZF6d4Z0a98WTKkwQSrEGL2UazlZ12GWjdUACArPSyJYjAnL9QrhZ+RLAbOwRhT7sp5vkmewNqLel8+nh0rEqfbu+sR9GIhSvU7rAVtU+m4MZr0BjFaqLKAvialmzbWTexivjSK5p0jo72YZn8WCHs67DDG4OtzRtbhzlotW2tqHq2SSbT+iNzYu1pce5MmrEiR1op0ZAfFhJURb7K+kkRfDuSHsVuO/TNqkm0HTaDIFv+cMbtv0khEf0SYbbPE9rklJ7+F+0qAWkcZOjKVHV95CVthzdIQy9zh44BNRd9wSVSZX4sW8cjAWsDXpg== 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=Ql0pCQOS3CAeoxS7mRqc3Ab6tOYr3xmfvbzsyPLpYAg=; b=1dnlwF8isg0G8rg24M+w0GO6EkdIwoVwIjVVj5WB3SrKtom11x710+4hwBNLfhBq5liWGlsbvDXoxLDTXU6z/Q5X/ieZNLl+mAxjezgQmmPWbBu868ryAmqonS9NqOFesYtcXRNXp9OZogf8h37WynzJlvaaXX5vWJh1CPX++ko= Received: from AM6P192CA0016.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::29) by AS8PR08MB7337.eurprd08.prod.outlook.com (2603:10a6:20b:444::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Wed, 2 Nov 2022 15:07:41 +0000 Received: from VI1EUR03FT028.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:83:cafe::c4) by AM6P192CA0016.outlook.office365.com (2603:10a6:209:83::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Wed, 2 Nov 2022 15:07:41 +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 VI1EUR03FT028.mail.protection.outlook.com (100.127.144.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Wed, 2 Nov 2022 15:07:39 +0000 Received: ("Tessian outbound 2ff13c8f2c05:v130"); Wed, 02 Nov 2022 15:07:39 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cfaca6c12b5fded2 X-CR-MTA-TID: 64aa7808 Received: from 77451d702192.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 06849503-A34C-45F8-B97A-ADFE99900053.1; Wed, 02 Nov 2022 15:07:32 +0000 Received: from EUR03-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 77451d702192.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 02 Nov 2022 15:07:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mQ4GUy0xzoP0zozsyoJkfGnvz9Ln9FH5fdOIOqc6iF9IFqxRhb/81pfQtyRg/39iLIc9oeNYmzmBqxM17EZkeU+lAGFRyGVj7NIeFSkAadg8uGbD7h/ZzSRRj9bZdt2wPQDG7p4ipYTocFstSgUdv9eFJdzEIdEOkUeiWQIsKzsvrouhQZTyvv0S5peSi/upBmmdbeRDURtyAT6XAnBa+65EsjUE6+LcCtcdN7aYi+lgmDZpqm4GCfyJwPRJsSKYZ5zVB8CFmCFEsBfOCC+p6gwHi+S0tyg9CTguVF5LyWv8eGX9qzelFPqzDiGzFFqZ3ApisBtt4gmyv3NpNyoy/w== 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=Ql0pCQOS3CAeoxS7mRqc3Ab6tOYr3xmfvbzsyPLpYAg=; b=Pnhx9TuEwiImXjUlT/9aDPeMLr6HiP4QNBMZhoixmJ2FGybsHB0hDkKdvT476C0Tw+GXdA/TtOL2eUGawCuBnr0Pv1PMteMptdbFZ0hKOEcypWvfHfUkwMEa2B+YWco7noETDWNQj+zIz5ygEPHaTn2niQrO1N2zsXdT9Ajps8S7aUenZDxUM7Y54ALVR7bpVxbOS9K2FzSXqLVUK12wzqRaOD34glydnTGI60qtE3JTSTvaBteDaiVbp4kxu0RfBvlmnKxszXQe6JWv2dTxPLEAcp6j9C6NOJD5oxil7dmH9yDaI3eQkJHglZuZFikZgPA22Qm7hjYsRulOvi6jog== 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=Ql0pCQOS3CAeoxS7mRqc3Ab6tOYr3xmfvbzsyPLpYAg=; b=1dnlwF8isg0G8rg24M+w0GO6EkdIwoVwIjVVj5WB3SrKtom11x710+4hwBNLfhBq5liWGlsbvDXoxLDTXU6z/Q5X/ieZNLl+mAxjezgQmmPWbBu868ryAmqonS9NqOFesYtcXRNXp9OZogf8h37WynzJlvaaXX5vWJh1CPX++ko= 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 DBAPR08MB5637.eurprd08.prod.outlook.com (2603:10a6:10:1b0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Wed, 2 Nov 2022 15:07:30 +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; Wed, 2 Nov 2022 15:07:29 +0000 Message-ID: Date: Wed, 2 Nov 2022 15:07:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] gdb: new $_inferior_threads convenience variable Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <20221102143416.3307157-1-aburgess@redhat.com> From: Luis Machado In-Reply-To: <20221102143416.3307157-1-aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO6P265CA0014.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:339::12) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DBAPR08MB5637:EE_|VI1EUR03FT028:EE_|AS8PR08MB7337:EE_ X-MS-Office365-Filtering-Correlation-Id: f0588000-3374-4e09-20d5-08dabce3fbeb 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: JZpX3O7SSssjrPwU3nWyuX19HGsfy6u5SP0h2A9Bml1ukF7lBbjAw+cdKuuTIiy0kA2zWKArxzcNfkjBP8pJlN9eJTLZRuEHDGpspiLs75PNuuTHXG9bYbA1gZ88QHYPYdwFnP3qw4QEvwC8qD6xsXSEVWHKUifSu8kQozdlB1quW+fTixxGtNvyPLk9Ol+kMdft9uExs7AVZrafLDHIwcSTpSM4j3+WSuY4X/ejoiqr3eoHoR6BFGs17aNCQihllkFGZCJE1DdJ7a8YawN2R5EyHLBeUK/GeHveQ+f9NRDsc9cEhKsEbyEahpX/BmipAyKRN0tkG/8hxj5hsbxw66DH+gzRJ29FbUDG7cP6a2vE0Jmw5au2Prp7uwr178SV25kjzCUOt0XOCoQHIw10iuJrm+JTijHRFV2BHILs5T9hIcqNFPnjt42jftHx+mfSFl3rsYA4LSWCnIRupdV/8YtmAUIkXtwaBT5he9+Yeka0FydzyZHrYNrGmp0Wj26Gvtqmviq+bTW+gd5IQAk1O9dydRHtAzu9sqURU6Y+iu73Sk5NzSi7dv6kvyiIk2xFrmztOk7+3Za9DVDcvd3DClTLqGt0Or+3NQo5NL80RuBDSPBbrPyZ/s4tvdr6ML4pn2eONl+M4oNXRV+lr+p1uR5oiYjvZuRVM1PQsnJSkj/MkCre7YwGKu6E2hiw+UUJZ4KF22qSS3MI0GpXz1r3w1FH9qfAMIg1dxbaxQ+sBBFs0Jl81n5Uux4yksHXjh5jhGJJynIHhwjCCN+9Z0fFTQQ8rd+WrQnHvOct6i6i4VY= 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)(346002)(136003)(366004)(39860400002)(376002)(396003)(451199015)(41300700001)(5660300002)(2906002)(66476007)(316002)(44832011)(8676002)(66556008)(66946007)(478600001)(26005)(6486002)(8936002)(83380400001)(186003)(38100700002)(86362001)(31696002)(2616005)(31686004)(53546011)(6512007)(6506007)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5637 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: VI1EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 44fcb5b5-cf89-49e9-2c1b-08dabce3f594 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rSZONatKT8qIn9pUVJhBschbmJbcg5yAI5XNwn7KoCCiYLqALtG3s9XNqIviL9GT8DZd8Uv4XJ3Ppic+LXXfJCZSuLEZNnoJwZmP9KhPLOeWSiJbANPhifD0TknA2q5v0yCKjhUnHmlGbODBgyye6ON++HALudp9dQxUQKWsoxM5sjdqV5AeW7iRiCr9MBr0/VEzGEbXd5kUz/EoLRYezGSwzooOcB9gc+CW+Y+kRZ+IJsTUUJ7CZ4vtFwItFlLxwvfyAKn5fM4YCpeE+8Wo+UNEfymAWozDbuU7UcZaKtDtZOO7TdWvMdgrJt7WCRVCZfC12Z6O7Wi2T1hBc3vQVIC3vpDnx1ZGQYGVoKX19sh9lTOniczSDO5sw2wq6f8MisehSIcJqnvw2yf7NTgQBIKY8357rIkhvxGEm29BYEc6SKsmurkCrg6wc8uOgC5B7r09qWJhdn+5XYtcu88va1WpKWnf/Q77JouadGELqRmFaVSUyJUddPvJ1nwIinTsO9j0aUv7IOLfhV9IkDcr4AHGbRjax3iqmAXEhvhHAk83/+zLynVHyeemPkzmnGYOAeFjRoaIxATmGyP75jUWRkWRwBkEd2M5KS7uQVOVbHrm4LGTobNf/VlFa8Z8hVGeCi/rTUZMpJIxR2WAkWqAcPPV9L0B6yCKFngqHH8CdFj3AHe+ELZ6JNRI8GW9i8+vEufUWkGYrm62VK58M9zLwLXsfsO6nBxl4d1QcXFMIZmT0Y2KZQaYEt+3wmIi6wTWNHvVsCz896EQASAMwTXrCm4RjCUe9v59DEIkWTIEHZQ= 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)(39860400002)(376002)(346002)(136003)(396003)(451199015)(40470700004)(36840700001)(46966006)(81166007)(186003)(41300700001)(2906002)(36756003)(8936002)(44832011)(356005)(2616005)(47076005)(336012)(83380400001)(5660300002)(40480700001)(53546011)(6512007)(82310400005)(6506007)(6486002)(26005)(316002)(40460700003)(36860700001)(82740400003)(478600001)(70586007)(70206006)(8676002)(86362001)(31696002)(31686004)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2022 15:07:39.5185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f0588000-3374-4e09-20d5-08dabce3fbeb 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: VI1EUR03FT028.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7337 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/2/22 14:34, Andrew Burgess via Gdb-patches wrote: > Add a new convenience variable $_inferior_threads that contains the > number of (non-exited) threads in the current inferior. This can be Just a couple comments. Should we call them "live" threads instead of non-exited? > used in command scripts, or breakpoint conditions, etc to adjust the > behaviour for multi-threaded inferiors. Could this number be a bit misleading at times? For example, a nonstop debugging session with threads coming and going and everything running. I'm guessing the number wouldn't be reliable enough to walk some list, right? > --- > gdb/NEWS | 3 +++ > gdb/doc/gdb.texinfo | 9 +++++++-- > gdb/testsuite/gdb.base/default.exp | 1 + > gdb/testsuite/gdb.multi/tids.exp | 20 ++++++++++++++++++++ > gdb/thread.c | 25 +++++++++++++++++++++++++ > gdbsupport/iterator-range.h | 4 ++++ > 6 files changed, 60 insertions(+), 2 deletions(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 8b519a648f7..3642d42e55a 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_threads contains the number of > + non-exited 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..977cabd3771 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -3642,8 +3642,10 @@ > @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_threads} > +contains the number of non-exited threads in the current inferior. > +@xref{Convenience Vars,, Convenience Variables}, for general > +information on convenience variables. > > 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 +12657,9 @@ > @item $_gthread > The global number of the current thread. @xref{global thread numbers}. > > +@item $_inferior_threads > +The number of non-exited 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..cae131cc59b 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_threads = 0} \ > {$_exception = } \ > {$_probe_argc = } \ > {$_probe_arg0 = } \ > diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp > index fb7c2a29a71..1bcba02a1c9 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_threads" " = 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_threads" " = 0" \ > + "no threads before we start the second inferior" > + > runto_main > > + gdb_test "print \$_inferior_threads" " = 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_threads" " = 2" \ > + "second thread started in inferior 2" > gdb_test "inferior 1" "Switching to inferior 1 .*" > + gdb_test "print \$_inferior_threads" " = 1" \ > + "still only one thread in inferior 1" > gdb_continue_to_breakpoint "twice" > + gdb_test "print \$_inferior_threads" " = 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_threads" " = 3" \ > + "third thread started in inferior 2" > > gdb_test "inferior 1" "Switching to inferior 1 .*" > + gdb_test "print \$_inferior_threads" " = 2" \ > + "still only two threads in inferior 1" > gdb_continue_to_breakpoint "twice" > + gdb_test "print \$_inferior_threads" " = 3" \ > + "third thread started in inferior 1" > } > > thr_apply_info_thr "1" \ > diff --git a/gdb/thread.c b/gdb/thread.c > index 349fc01dd48..f8942f1c5e4 100644 > --- a/gdb/thread.c > +++ b/gdb/thread.c > @@ -2123,6 +2123,21 @@ 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 threads in the current inferior. > + If there are no threads in the current inferior return a value of 0. */ > + > +static struct value * > +inferior_threads_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 +2157,14 @@ static const struct internalvar_funcs gthread_funcs = > NULL, > }; > > +/* Implementation of `_inferior_threads` convenience variable. */ > + > +static const struct internalvar_funcs inferior_threads_funcs = > +{ > + inferior_threads_make_value, > + NULL, > +}; > + > void _initialize_thread (); > void > _initialize_thread () > @@ -2258,4 +2281,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_threads", > + &inferior_threads_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; > };