From patchwork Wed Mar 22 16:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot SIX X-Patchwork-Id: 66753 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0218E385B517 for ; Wed, 22 Mar 2023 16:36:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0218E385B517 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679502985; bh=GxXY2sICo4V+8fe4Kg2Hx088Y48z7T61fupwVTzAGps=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uhtIu7Ty50xI+9oSt2z74ukjCVftY1vWOK2gmKBCEasAby42vn6lZOHloVnHmGeC8 4BRxUs92H958TVgfy15e3gdZQ2AEwwD1CQkLJg1QhH5pkfoK24i1zNslGBr0EqczwN 2v4f+9Oe0jqtevjkAbZRCFXDrWGeO+v9AD+crxw4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5a::60e]) by sourceware.org (Postfix) with ESMTPS id 29AC23858C1F for ; Wed, 22 Mar 2023 16:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29AC23858C1F ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eyARjnyDBDofTcUFvEuFcIcW7PObyCFrjb3RVciZselPbwFP3Bgh89JzaFTpGkeu87Hq1GtMe5g3qDQlJrn5+VUQA0o+6wm0vSo6puueteXyT7BIcjv+EUwj7ceeHuhYkJTxiClANdloD3pF9CPsFzptB66MAih/3Xcw7hUi2XAgoc1i7+N52X+fiaajIxvWE0lOBYPWc/bvJt+DFuifV9gJnnq12+NQRJaXzjsJERNIGXhaCvN5wsNuL+hKjdHWd27q95tsoiH/vwP/THgKsVcAu44f89V5vrXpEJHurisMkm5dqfzpM4asAeNJoPa8nlQKYva7ChfZIKVZgqAfAQ== 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=GxXY2sICo4V+8fe4Kg2Hx088Y48z7T61fupwVTzAGps=; b=MeFiwJgUZcfjbd8BRWQflVS3vNEa07Kw3M2KuC6FmeKp2bEIwNeGPKFK5c81jTwVBBUSBe++2I77IJzTRNBneRNIh34wkRDOSrMWQhLDIlhAeKj5YBcXj9dP1EKKc53bAHB896+Eaz+ga5VmOERv6f8dO16b9q8Ub6eoK6wuRj6qbASJ1+X2kVjzDDl174uWFxO9/eFrR7nUbJk//XCw2D0O24y/mTu4wGhD3TwL0HaeTUZXdzRX+fey89scG2CQ61vzNvN7U9xNP/Y0NiZj9pvyfb0Z3RJSaNc/2wDXgFudSFNBE8yfQF57LZpbd/l+671gmDa40IGNixzJScQY4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from BN9PR03CA0975.namprd03.prod.outlook.com (2603:10b6:408:109::20) by CH0PR12MB5043.namprd12.prod.outlook.com (2603:10b6:610:e2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 16:35:25 +0000 Received: from BN8NAM11FT083.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::da) by BN9PR03CA0975.outlook.office365.com (2603:10b6:408:109::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Wed, 22 Mar 2023 16:35:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT083.mail.protection.outlook.com (10.13.177.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.17 via Frontend Transport; Wed, 22 Mar 2023 16:35:25 +0000 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 22 Mar 2023 11:35:23 -0500 To: CC: , Lancelot SIX Subject: [PATCH v6 1/3] gdb: add inferior parameter to target_is_non_stop_p Date: Wed, 22 Mar 2023 16:35:02 +0000 Message-ID: <20230322163504.560986-2-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322163504.560986-1-lancelot.six@amd.com> References: <2daa1736-57cb-3c5a-f1cd-48f5aa03d010@simark.ca> <20230322163504.560986-1-lancelot.six@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT083:EE_|CH0PR12MB5043:EE_ X-MS-Office365-Filtering-Correlation-Id: b1560a6f-baa0-4cc1-33e1-08db2af3707f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: As6G+51jnIWF/BEfNW1ce2J8ZJESXiwv6nB7NPrxBP8YcwkJ1I5ViDkQOLue13nMyhUmxyN1M3aSG9NrTZw9RuLmP3HYr21BbJk5yo4QZvMsroscXOl+aCQnqvQl2YCb7Yk0DURxE3TQRPU3VCSsFPq0LHVb/e+1G0/lHE36GhxT5BEgEJzFRH6fkNY5HHaVxkgfs50ApQpj7Ks6CtZYSq4FJrezMuMyGSwXX9AeABBawtJQcgOvRfT8a5bb/qTe+c+EhsKNOgdp8SPnB2s9ZxerT/tpoKEcxRlZyErZvx1YvGChNpHTjjS0HwIeP7amkWbthxM+OQUtNJw+7wYY/zFP7nSUsY1WofbQM5WB1tRZ/JESU4Ggda/rtpB4VMmdLpUlbxmvmAg8IrcTKgU0E/AfeQPgfBbPCqUKeSsuEEZuSecjgvH1qVpY1JOeGxd/+B9uFQR0eGZNAcRDxyT1bvC3SzR4F9Lk4o1/Vq5ytOJXeW+c6UcQAXG8wAeS5p2IvW5C+AE5wq7apgzSUxc671WzYiZDM/jtjCO36Gadnm88VqH0lq8oOBTD/E9GYOqAkIUJZDKPVZbO4t97o4q1Qu8L9oAtIkpzx8I51AmFsZAR6nrmJn22Aq6aXvoUxcgpewUo+EkulnAs+aYXlEiCDKux7lw9ua/w7UCKlkeb5vx1dkEVJhG7gLbYZ9A+3cAtgo8lGH9fdHbyTvriq/vtxgnNkN1PmwgTHYDWIRwex5w= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(396003)(376002)(346002)(136003)(39860400002)(451199018)(40470700004)(46966006)(36840700001)(356005)(2616005)(6666004)(336012)(1076003)(16526019)(26005)(7696005)(186003)(86362001)(47076005)(426003)(82310400005)(54906003)(2906002)(40460700003)(478600001)(82740400003)(83380400001)(81166007)(316002)(4326008)(8676002)(40480700001)(36860700001)(41300700001)(70586007)(8936002)(6916009)(70206006)(5660300002)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 16:35:25.5392 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1560a6f-baa0-4cc1-33e1-08db2af3707f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT083.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5043 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lancelot SIX via Gdb-patches From: Lancelot SIX Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch add a "inferior *inf" parameter to the target_is_non_stop_p function. The default value is nullptr so all existing calls remain valid. This will be used in the following patch. --- gdb/target.c | 9 ++++++++- gdb/target.h | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 0cebecfafc3..5e5d1054541 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -4391,8 +4391,15 @@ target_always_non_stop_p (void) /* See target.h. */ bool -target_is_non_stop_p () +target_is_non_stop_p (inferior *inf) { + gdb::optional restore_thread; + if (inf != nullptr && inf != current_inferior ()) + { + restore_thread.emplace (); + switch_to_inferior_no_thread (inf); + } + return ((non_stop || target_non_stop_enabled == AUTO_BOOLEAN_TRUE || (target_non_stop_enabled == AUTO_BOOLEAN_AUTO diff --git a/gdb/target.h b/gdb/target.h index 2dac86c394d..ffa6d95becd 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1892,10 +1892,12 @@ extern void target_thread_events (int enable); non-stop mode is enabled. */ extern enum auto_boolean target_non_stop_enabled; -/* Is the target in non-stop mode? Some targets control the inferior +/* Is INF's target in non-stop mode? Some targets control the inferior in non-stop mode even with "set non-stop off". Always true if "set - non-stop" is on. */ -extern bool target_is_non_stop_p (); + non-stop" is on. + + If INF is nullptr, check the current inferior. */ +extern bool target_is_non_stop_p (inferior *inf = nullptr); /* Return true if at least one inferior has a non-stop target. */ extern bool exists_non_stop_target (); From patchwork Wed Mar 22 16:35:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot SIX X-Patchwork-Id: 66752 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAF2D3854836 for ; Wed, 22 Mar 2023 16:35:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAF2D3854836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679502954; bh=YNp4RA7qWkn4/Avw7HRYE2cKxeDehx/RZE8NQoLt9Fo=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TWPXlBTHh+n1aE3/X38MlLbAz6YBXDlSLaAOa+X93dRrsAd50iHqoS4weGQGMnc2u kA9wvMa3oObieUlMWYmQjnklWyHqAcKN05s/IjZndkHCYDkNbJoRueerfiaIVQVgoP OQaATkNznNR59EKS+uilSuOgHkgwzPQ9TZX0D6NE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20608.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5b::608]) by sourceware.org (Postfix) with ESMTPS id 8D3C53858D3C for ; Wed, 22 Mar 2023 16:35:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D3C53858D3C ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bGkWebNamheFKLcGQI5CENXA9PsxIS+7ZPDtLtnpki/rOrPdCcq70BWpYkU03i05JluPXMd7fd7OKHWH8wYOUpn1bDM/wtVZAc4i11uL1O2RL8jCx3kCeGcpZRkN88fu6jU6kfyvf6Gr2Rj7sgtThAitk55oo5Hmq+vMpcZ2LMAyPmDJ3Kopf4rKI64dt4dodHCzA1KXvLYUTry0Ft7B3biVB4x+YfVw0c9Ispx4bzN+2GYipYzXxhD74dBeSiVu43/oaZXTybttxmd1+gOpB2y/nd8qLiqmx+5LQSMi6feecPEb2y40yhH1vdQBTOOIiDjc2QN+qh4+jBr32qygpw== 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=YNp4RA7qWkn4/Avw7HRYE2cKxeDehx/RZE8NQoLt9Fo=; b=ZXsG1VGpAkIzF8ZbJng/4ka3EF6iLTPiQb/qI99f/qtooA/75tqPAOpmXZtVpD4TdPJEWRud5cdLAolo3i6G8npJ7vIxO3mpc5Y6sGjQ/C0vaW4Bxy8civhpcqNVz9yLvTJ9DXisnf/c08KiMnIUfrZ1pJ0HPdofOcFYdSZej+1etgpVHmv3WeK2GHiolK012aJPmmXlRZyqpv+2No5kNfMRqAROHSh1EgVmBWaDMX5MjUM5RInmbjQI+IQYJQhRVLHRcMi0KjNb9jfvOfsdoRQXc88kKTbpXgObTDwon2HKXH5FqVMTww7wHAb2gFbaUvsD0amHMxdlSNHDusZL2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from BN9PR03CA0970.namprd03.prod.outlook.com (2603:10b6:408:109::15) by IA1PR12MB7590.namprd12.prod.outlook.com (2603:10b6:208:42a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 16:35:26 +0000 Received: from BN8NAM11FT083.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::bc) by BN9PR03CA0970.outlook.office365.com (2603:10b6:408:109::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Wed, 22 Mar 2023 16:35:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT083.mail.protection.outlook.com (10.13.177.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.17 via Frontend Transport; Wed, 22 Mar 2023 16:35:25 +0000 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 22 Mar 2023 11:35:24 -0500 To: CC: , Lancelot SIX Subject: [PATCH v6 2/3] gdb/infrun: Improve assertion in stop_all_threads Date: Wed, 22 Mar 2023 16:35:03 +0000 Message-ID: <20230322163504.560986-3-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322163504.560986-1-lancelot.six@amd.com> References: <2daa1736-57cb-3c5a-f1cd-48f5aa03d010@simark.ca> <20230322163504.560986-1-lancelot.six@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT083:EE_|IA1PR12MB7590:EE_ X-MS-Office365-Filtering-Correlation-Id: 72ab6b89-2ce3-4c9a-f49f-08db2af370c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pDVQXsgTKtgDfwqh+7LOp1y5FOl/1aq+NPB6wh17n3/ZUdeBsqSTul72UoL1Z0YX4urnhKQXiFGyQmlZQth3EhJ/bIQT5LywiDzOLEJTwW9PYTqbG1s/EOUclkSsQqfS//GGV890r2k6BGfaHggTIYxLSk0OaWldi6PhxQ1/ZtYyyu92YD0BJnszrtvyPu4YoNcS1I9T5vJl2+jpFYBYCgVU2GcYaWAl7CaQsqAEkKJScB4Pe4Y/e7laJFxnmoe8o6lXUakKCj3oBKBYxfzTbWLBOzdxrHAz6LvfpV4u9b0S37bCHXwOh6VxpFOxPJB3kTXoZUKU6wzzSMJei6McNtiOkmImOculTBXG4ZbOfOAz+YKNkigoXTsRTWz73vVUlxQ1p2TbWYCaVIiSfzCUlph9WoRkdIXAJtpcgXRq20HYlbJAaVY8ApYqUTc+2tWW8R0ging+0oEHzgK8EdZnSEFF3L62aYCRQNCbT9j5RpWF+l2tJFdcM+5ShTp83ELx6AG+n81bsWeF9onALth9BXT/c6fkiSdsqD1vOOH9cSUIs0tlPepHf3H2Z1TRdhJgNwla+M9B2+mBfVOFCX2hc9Qj6DMM7VTzdzj7RZKPd2Och70M+gJVqlSj2K+ThWnxiOTzpfuwPxVxnavVxkOIxzvD4RQEE8HoNQ0t/GKZlVR8a3N9v6n7m5eu0eJKlCQ+rrD0uC88ngoOpCDn9oNFGRvuJ4oZcfsT/ETPnDpBnKc= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199018)(40470700004)(46966006)(36840700001)(40460700003)(86362001)(4326008)(356005)(316002)(426003)(6916009)(5660300002)(36756003)(54906003)(478600001)(336012)(70586007)(8676002)(81166007)(41300700001)(70206006)(8936002)(4744005)(2906002)(36860700001)(1076003)(83380400001)(82740400003)(40480700001)(26005)(47076005)(6666004)(186003)(7696005)(16526019)(2616005)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 16:35:25.9923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72ab6b89-2ce3-4c9a-f49f-08db2af370c1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT083.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7590 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lancelot SIX via Gdb-patches From: Lancelot SIX Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The stop_all_threads function has an assertion to check that there is a non-stop target. However, when called with a non-NULL INF parameter, we only need INF's target to be non-stop. This patch updates the assertion. If INF is non-NULL, check that INF's target is non-stop, otherwise keep the assertion as before. --- gdb/infrun.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 5c9babb9104..a509e0d5bef 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5189,7 +5189,10 @@ stop_all_threads (const char *reason, inferior *inf) int pass; int iterations = 0; - gdb_assert (exists_non_stop_target ()); + if (inf == nullptr) + gdb_assert (exists_non_stop_target ()); + else + gdb_assert (target_is_non_stop_p (inf)); INFRUN_SCOPED_DEBUG_START_END ("reason=%s, inf=%d", reason, inf != nullptr ? inf->num : -1); From patchwork Wed Mar 22 16:35:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot SIX X-Patchwork-Id: 66754 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A45D385B517 for ; Wed, 22 Mar 2023 16:36:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A45D385B517 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679503013; bh=JP//0RSq/1hSMY2K0SgLMgDq3Sq0tTEj5gUEmbrbA58=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=SuGUWEZLZOg6XV0mKmVQ2auDlx2YUEaJz72RfBnPfaDS9e1fc/+pLcQCrfi9cAktQ Io4O52bQ5Z4+JGuMGsv+YT4znitfdheWzhyw76MgUBNcRvjz3mEd6M302nOOzcgaz2 rVypSRVejXuzy4vB7yH8PZpITErfFBEyMPqVPgP4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::60a]) by sourceware.org (Postfix) with ESMTPS id 0C2D4385B538 for ; Wed, 22 Mar 2023 16:35:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C2D4385B538 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E+PZAkriXsjpvz93fCGuVT17vRqc2bh2L4m+irCBH3DzKoEhMBbOtJPJTBWd39OUsLOs9sCqZiaaQeuzBA0UsFkZDFOtIjTKLOionhZBdaToX8CgEOUmuq4cqS3jGA1YkBwnLwVXlqvvHBGUuqRlZiswk1Al4Rejr3wpZ2wQpAg2fFnwC13f2yikidkzbj7158/3Rs6NTubBQBjINVe2FIoA6LiIlhjRLsUydqI8IBZbqRSVtuxN6mYORbOAAxLdVpg6DO6BScxU8YrzQ4FKb+6GXZvKwvsauceU0A0K/YDQwNz/p6b1hnwUb5kLnUU9dxdXuqW6pWrxEvIugCridA== 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=JP//0RSq/1hSMY2K0SgLMgDq3Sq0tTEj5gUEmbrbA58=; b=P1lXvev1w1hXoM+TvHKIPpDeFFZ4CvuzALhfbv2iANeprZoSVnAX/z1TnpHMcEuxMOhXu0gaSh8aPnMSYGp4FkyuCVfpa9Drou/g24ljah+Q9IK9lA+/ZcStS/lsAObUU0btf0+UvbPEBPFnEh4oOk9O2WImaqvKzB7ZutYwYocuAJn7Kvh9Ig674NLOUaYEhq5pq8BEyf5Vq939Vhr83pNL2Bdik85HY14bYcgf+uMuQc9soWFgGnkFg7fJHXQ6kSVykZ0nMEkGVUp7FNLLM6uT6iKPirHasGUy+/rZNDA+FKn+kGVk6SzRYwix4uJhQArp8pVCd/o92OGIvg3Zig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from BN9PR03CA0856.namprd03.prod.outlook.com (2603:10b6:408:13d::21) by PH0PR12MB8125.namprd12.prod.outlook.com (2603:10b6:510:293::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 16:35:42 +0000 Received: from BN8NAM11FT106.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13d:cafe::3e) by BN9PR03CA0856.outlook.office365.com (2603:10b6:408:13d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Wed, 22 Mar 2023 16:35:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT106.mail.protection.outlook.com (10.13.177.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.17 via Frontend Transport; Wed, 22 Mar 2023 16:35:41 +0000 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 22 Mar 2023 11:35:26 -0500 To: CC: , Lancelot SIX Subject: [PATCH v6 3/3] gdb/gcore: interrupt all threads to generate core in non-stop targets Date: Wed, 22 Mar 2023 16:35:04 +0000 Message-ID: <20230322163504.560986-4-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322163504.560986-1-lancelot.six@amd.com> References: <2daa1736-57cb-3c5a-f1cd-48f5aa03d010@simark.ca> <20230322163504.560986-1-lancelot.six@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT106:EE_|PH0PR12MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: 05198a73-3a37-4c6e-8d72-08db2af37a1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 96222vSnWB1O+03zZ7YBdZ3T+ZaiqRyOTDkOMVPlCU2PbTGb2XgMzdTB4O+GLnS8jVSrsjNWI1TnVij75eEQbcT1h3cude+6yohHFNgkMUqSVSnWOLPsM6IKt2fiwfA/sAT8srf85b0flhEbupt8uDCPPe8vAW0+AjuPfvRA3mWzxJojjKqPZmMk6AsvVYbx4OkvEm+Fg+sfAzQRA/T40c7+YV703Yws/zZXJb4cqJaYz5UyUMncOWL4d+xsFlSZsV4gyASU+o2JUt/h9XxuLvriLZ7zG2t0WxsK9pmXyWWWIWHYIUPN/Ahm5k60ETMcNTGsICi1XWqz9Rhqx9Yjds4nmQcxhzUoJti6FCnUbHtVDpNAoHuz6A+ZKf1qw7lJFND/un2KEnJy4PYRu+BTsvRg2pe1TVN2LI3ygac6R/v23D95w5gSWnk5hCZ5KKNNaO2XZOlABoT+NpGqoBr5PC3xAtb/SK9QqsbbQqTFZyNUHSHQgCYfYJmBEWenTeKhkENslfG22k47NErywUZd9NE2CD1UWSGw5DjgBXVr8t+wQTONFcmwbaKNtiBKSEDSugiZ6UDdewP0x9dluAizsIa9UMxbiET0AjnnxJQNSMtb+yG+R4uJgkXTIrwKtdvsrOByAvrq58q9c5+Yg6d96iQYpQ8b61LQG1HzRTasNNQmusc/zIPckY9gdysKsjpTVPyBvCdP6+8+HOVaFLGamEPYKZ2f5ONwz2AD0H0JXSi+Cdm/MoWIGMiG2BepFfYx X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230025)(4636009)(136003)(346002)(39860400002)(376002)(396003)(451199018)(40470700004)(46966006)(36840700001)(7696005)(47076005)(356005)(1076003)(336012)(6666004)(478600001)(316002)(66899018)(54906003)(2616005)(426003)(186003)(16526019)(86362001)(83380400001)(26005)(82310400005)(5660300002)(4326008)(8676002)(6916009)(70206006)(70586007)(40480700001)(41300700001)(8936002)(36860700001)(82740400003)(40460700003)(30864003)(81166007)(36756003)(2906002)(2004002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 16:35:41.6765 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05198a73-3a37-4c6e-8d72-08db2af37a1d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT106.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8125 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lancelot SIX via Gdb-patches From: Lancelot SIX Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" If the user tries to generate a core dump (using the gcore command) while some threads are running, a non-helpful error message is shown. Lets consider the following session as an example (debugging the test program included in this patch): (gdb) set non-stop on (gdb) b 37 (gdb) r Thread 1 "gcore-nonstop" hit Breakpoint 1, main () at gcore-nonstop.c:39 (gdb) info thread Id Target Id Frame * 1 Thread 0x7ffff7d7a740 (LWP 431838) "gcore-nonstop" main () at gcore-nonstop.c:39 2 Thread 0x7ffff7d79640 (LWP 431841) "gcore-nonstop" (running) (gdb) gcore Couldn't get registers: No such process. The reported error ("No such process") does not help the user understand what happens. This is due to the fact that we cannot access the registers of a running thread. Even if we ignore this error, generating a core dump while any thread might update memory would most likely result in a core file with an inconsistent view of the process' memory. This patch proposes to change this. For non-stop targets change the gcore command so it first stops all running threads (from the current inferior) before generating the corefile, and then resumes them in their previous state. To achieve this, this patch exposes the restart_threads function in infrun.h (used to be local to infrun.c). We also allow the first parameter (event_thread) to be nullptr as it is possible that the gcore command is called while all threads are running, in which case we want all threads to be restarted at the end of the procedure. Similar change for all-stop targets turns out to be less straight forward. For this reason, when dealing with all-stop targets, this patch proposes to error-out early with a meaningful message. Tested on x86_64 on native GDB and the native-extended-gdbserver board. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 8 +++ gdb/doc/gdb.texinfo | 5 ++ gdb/gcore.c | 20 ++++++ gdb/infrun.c | 16 ++--- gdb/infrun.h | 9 +++ gdb/testsuite/gdb.base/gcore-nonstop.c | 44 +++++++++++++ gdb/testsuite/gdb.base/gcore-nonstop.exp | 79 ++++++++++++++++++++++++ 7 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 gdb/testsuite/gdb.base/gcore-nonstop.c create mode 100644 gdb/testsuite/gdb.base/gcore-nonstop.exp diff --git a/gdb/NEWS b/gdb/NEWS index cc262f1f8a6..65ac722bd2e 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -91,6 +91,14 @@ show always-read-ctf $2 = 1 (gdb) break func if $_shell("some command") == 0 +* Changed commands + +gcore +generate-core-file + For non-stop targets, GDB ensures that all threads are stopped before + generating a core dump. At the end of the command, threads are restored + to their previous state. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6c811b8be2e..574684d9e28 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -13763,6 +13763,11 @@ Produce a core dump of the inferior process. The optional argument specified, the file name defaults to @file{core.@var{pid}}, where @var{pid} is the inferior process ID. +If the current inferior's target is non-stop, @value{GDBN} ensures that +all the inferior's threads are stopped while generating the core dump. +@value{GDBN} stops every running threads of the inferior before +generating the core dump and resumes them when the command is done. + Note that this command is implemented only for some systems (as of this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390). diff --git a/gdb/gcore.c b/gdb/gcore.c index 973abadb013..217976ac4e0 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -34,6 +34,7 @@ #include "regset.h" #include "gdb_bfd.h" #include "readline/tilde.h" +#include "infrun.h" #include #include "gdbsupport/gdb_unlinker.h" #include "gdbsupport/byte-vector.h" @@ -131,6 +132,20 @@ gcore_command (const char *args, int from_tty) if (!target_has_execution ()) noprocess (); + scoped_restore_current_thread restore_current_thread; + scoped_disable_commit_resumed disable_commit_resume ("generating coredump"); + struct inferior *inf = current_inferior (); + scoped_finish_thread_state finish_state (inf->process_target (), + ptid_t (inf->pid)); + + if (target_is_non_stop_p (inf)) + stop_all_threads ("generating coredump", inf); + else + for (thread_info *thread : inf->non_exited_threads ()) + if (thread->executing ()) + error (_("At least one thread is still running, cannot generate a " + "core dump.")); + if (args && *args) corefilename.reset (tilde_expand (args)); else @@ -161,6 +176,11 @@ gcore_command (const char *args, int from_tty) } gdb_printf ("Saved corefile %s\n", corefilename.get ()); + + if (exists_non_stop_target ()) + restart_threads (nullptr, inf); + + disable_commit_resume.reset_and_commit (); } static enum bfd_architecture diff --git a/gdb/infrun.c b/gdb/infrun.c index a509e0d5bef..7364bfa623c 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -97,9 +97,6 @@ static void resume (gdb_signal sig); static void wait_for_inferior (inferior *inf); -static void restart_threads (struct thread_info *event_thread, - inferior *inf = nullptr); - static bool start_step_over (void); static bool step_over_info_valid_p (void); @@ -6008,18 +6005,15 @@ handle_inferior_event (struct execution_control_state *ecs) } } -/* Restart threads back to what they were trying to do back when we - paused them (because of an in-line step-over or vfork, for example). - The EVENT_THREAD thread is ignored (not restarted). - - If INF is non-nullptr, only resume threads from INF. */ +/* See infrun.h. */ -static void +void restart_threads (struct thread_info *event_thread, inferior *inf) { INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d", - event_thread->ptid.to_string ().c_str (), - inf != nullptr ? inf->num : -1); + (event_thread != nullptr + ? event_thread->ptid.to_string ().c_str () + : "None"), inf != nullptr ? inf->num : -1); gdb_assert (!step_over_info_valid_p ()); diff --git a/gdb/infrun.h b/gdb/infrun.h index 5219063586d..4b2a04e503b 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -182,6 +182,15 @@ extern void nullify_last_target_wait_ptid (); all threads of all inferiors. */ extern void stop_all_threads (const char *reason, inferior *inf = nullptr); +/* Restart threads back to what they were trying to do back when we + paused them (because of an in-line step-over or vfork, for example). + The EVENT_THREAD thread, if non-nullptr, is ignored (not restarted). + + If INF is non-nullptr, only resume threads from INF. */ + +extern void restart_threads (struct thread_info *event_thread, + inferior *inf = nullptr); + extern void prepare_for_detach (void); extern void fetch_inferior_event (); diff --git a/gdb/testsuite/gdb.base/gcore-nonstop.c b/gdb/testsuite/gdb.base/gcore-nonstop.c new file mode 100644 index 00000000000..a96c011ad14 --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore-nonstop.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022-2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +static pthread_barrier_t barrier; + +static void * +worker_func (void *ignored) +{ + pthread_barrier_wait (&barrier); + return NULL; +} + +int +main (void) +{ + pthread_t worker_thread; + pthread_barrier_init (&barrier, NULL, 2); + + pthread_create (&worker_thread, NULL, worker_func, NULL); + + /* Break here. */ + + pthread_barrier_wait (&barrier); + pthread_join (worker_thread, NULL); + pthread_barrier_destroy (&barrier); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/gcore-nonstop.exp b/gdb/testsuite/gdb.base/gcore-nonstop.exp new file mode 100644 index 00000000000..172dd760e73 --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore-nonstop.exp @@ -0,0 +1,79 @@ +# Copyright 2022-2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that in non-stop mode, if some threads are running when the user +# launches the "gcore" command, GDB suspends all threads, generates the core +# file and resumes threads which where running before the "gcore" command +# got issued. If running threads were not stopped, GDB would report errors +# when trying to capture the thread's state. + +standard_testfile + +if { [build_executable "failed to build" \ + ${testfile} ${srcfile} {pthreads debug}] } { + return +} + +save_vars { GDBFLAGS } { + append GDBFLAGS " -ex \"set non-stop on\"" + clean_restart ${binfile} +} + +set lineno [gdb_get_line_number "Break here"] +if { ![runto $lineno] } { + return +} + +# We should be stopped in thread 1 while thread 2 is running. +gdb_test_sequence "info threads" "info threads" { + {Id\s+Target Id\s+Frame} + {\*\s+1[^\n]*\n} + {\s+2\s+[^\n]*\(running\)[^\n]*\n} +} + +set th1_pc "" +gdb_test_multiple "p/x \$pc" "fetch thread 1 PC" { + -wrap -re "$::decimal = ($::hex)" { + set th1_pc $expect_out(1,string) + pass $gdb_test_name + } +} + +set corefile [standard_output_file "corefile"] +if {![gdb_gcore_cmd $corefile "generate corefile"]} { + # gdb_gcore_cmd issues a "UNSUPPORTED". + return +} + +# After the core file is generated, thread 2 should be back running +# and thread 1 should still be selected. +gdb_test_sequence "info threads" "correct thread selection after gcore" { + {Id\s+Target Id\s+Frame} + {\*\s+1[^\n]*\n} + {\s+2\s+[^\n]*\(running\)[^\n]*\n} +} + +# Thread 1 is at the same PC it was before calling the gcore command. +gdb_test "p/x \$pc" "\\\$$::decimal = $th1_pc" "thread 1 unchanged" + +clean_restart $binfile +gdb_test "core-file $corefile" "Core was generated by.*" "load corefile" + +# The core file has the 2 threads. +gdb_test_sequence "info threads" "threads in corefile" { + {Id\s+Target Id\s+Frame} + {\s+1\s+Thread[^\n]*\n} + {\s+2\s+Thread[^\n]*\n} +}