From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2053.outbound.protection.outlook.com [40.107.223.53]) by sourceware.org (Postfix) with ESMTPS id 0FB64385E00A for ; Fri, 17 Jun 2022 10:10:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FB64385E00A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHrAXkrG+0dNJLUIFTdUqgkamRBlWKebM9Uuhv/jwaIRjzxZEdG+huLk82PvIVZMTGMZLEsyDufgC/FwuXb+tfgBlGB2zjQfoWC6NumMVWTqq9DZr3d3jxxa14027VJDHIdkP3FPdEu9CZuy5ZX+kmoOpc5MuK1dwTnaaYm2K54IfGylnmBj55iehl53n+5gpvY6G3p8BeqJUR1tZYFgVKfFZx2D3mszy0oJYDnpfFppTxYb7I4BwcpBh+IEfzyxfndUDpaYHesWHgvcNfJn6jCO6hC8TjZby23Ntl8M4ZaXVdHkIZvZZ2+SmrcoF4Ri47YWEq9M7zwx6uVw584IFQ== 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=fL9kM/v0o1XxlENGCxKpXapa6kzCcj3JGgr3KmRyPBw=; b=LrDJA4IZfPDVEfNszm62DiaYkosCs/I7jaYnmJvPOyssKx/RKw4Gx3tpJVJigTo5B5F/yD515p6R2wCqkRiQHWIbSYDIgENUraYS0aHOmj1DTnMpTJ8AtODM8t7CG6nXsxYEMkaKlmKCh260HkP90hDsxeITmDy78zRDPHwgPPXoCi/SaD4QFOQDwvxLek4jlcvrG23DZQe9oDJbb/USGq/a2EgyrHdc6A8Rtwpt6THssWcoegWSAGcZtkHkZfUM6FNyXBPzfiZslqTGhLg1xBxl282uMSb43f952MeAybvjqhHmLAurHgWd0h+BvPhDKo3GTKOKyUwTvcNzItLuxA== 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 MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) by PH0PR12MB5434.namprd12.prod.outlook.com (2603:10b6:510:d5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Fri, 17 Jun 2022 10:10:53 +0000 Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::cc) by MW4PR02CA0021.outlook.office365.com (2603:10b6:303:16d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.14 via Frontend Transport; Fri, 17 Jun 2022 10:10:53 +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 CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5353.14 via Frontend Transport; Fri, 17 Jun 2022 10:10:52 +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.28; Fri, 17 Jun 2022 05:10:48 -0500 From: Lancelot SIX To: CC: , Lancelot SIX Subject: [PATCH 3/3] gdb/varobj: Fix varobj_invalidate_iter Date: Fri, 17 Jun 2022 11:10:24 +0100 Message-ID: <20220617101024.2830260-4-lancelot.six@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617101024.2830260-1-lancelot.six@amd.com> References: <20220617101024.2830260-1-lancelot.six@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ab925b6-99df-447b-f8dc-08da5049a952 X-MS-TrafficTypeDiagnostic: PH0PR12MB5434:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1aMB/SU+Yg4R2hE5aOQKGRjPNs8lOyT0WADs8nyP5CwrnF6XaKu7mQ7fb6xAGPFwpNLUtgz6hRmzExX15VCv5X9lfVv7GhQT4VfQ9Smjtv4I3MyKcZJeudJRgKVANhztFUveB1gKaVCnQDZOQSUzZUsr8wZA5O0Gb3zayvCjOlp7WfcdcqdLYAFq1kex2LnrCPoCiNBNBgNSCjyjwnQGypsRbBdwq6Q7MRxkDB1FpC2j5XZXyP9YumlDUlrh4j4GzEwqturGu3NwJAHV3a/gJ8LchWOWCydjm1zSDejj91FGB/UbZLXZ7vrUy8qSROy4eDf1LHhD+FnobUbwArG/49koED64ATa2zVVYK/1IDkgrl92j71/QhjSGcCEXqxCuQOreQVzi9JY4HkuuXSPBVsn1+axbG4oqb0GU4PL9Woi54K2OqJ+ye5BazWZCsnL8AiRY6KHi4DCk8qmVxGl7Z9ar8i8sQCTx4J3/Ngw1k/+UABiIrjAxudotnkZJMNgRqqRmP8StyHp4qWHV1slx8yygiY5d/cbAJB/ftQWiBGf8YlCXoKimvTuSq9TUSI6j8hbp9azsVMiXkbnGqn/c22S/391qa1cTP8RsnD5E8wE/DgswguBTgTZi0JvMTryYqUCr+/f+ipW8irWAzsf1dWGWARnTDEyw5hkcw0jKk/DclXpzyJ8FoxdyzXEpDu0pvqIa9QRn1gl99yS7uwy2kw== 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:(13230016)(4636009)(46966006)(36840700001)(40470700004)(2616005)(2906002)(26005)(7696005)(6666004)(40460700003)(16526019)(426003)(336012)(47076005)(8936002)(1076003)(86362001)(5660300002)(186003)(83380400001)(6916009)(36860700001)(4326008)(36756003)(70586007)(356005)(54906003)(81166007)(316002)(82310400005)(498600001)(8676002)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 10:10:52.8093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ab925b6-99df-447b-f8dc-08da5049a952 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: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5434 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Fri, 17 Jun 2022 10:10:58 -0000 The varobj_invalidate function is used meant to be called when restarting a process, and check at this point if some of the previously existing varobj can be recreated in the context of the new process. Two kind of varobj are subject to re-creation: global varobj (i.e. varobj which reference a global variable), and floating varobj (i.e. varobj which are always re-evaluated in the context of whatever is the currently selected frame at the time of evaluation). However, in the re-creation process, the varobj_invalidate_iter recreates floating varobj as non-floating, due to an invalid parameter. This patches fixes this and adds an assertion to check that if a varobj is indeed recreated, it matches the original varobj "floating" property. Another issue is that if at this recreation time the expression watched by the floating varobj is not in scope, then the varobj is marked as invalid. If later the user selects a frame where the expression becomes valid, the varobj remains invalid and this is wrong. This patch also make sure that floating varobj are not invalidated if they cannot be evaluated. The last important thing to note is that due to the previous patch, when varobj_invalidate is executed (in the context of a new process), any global var have already been invalidated (this has been done when the objfile it referred to got invalidated). As a consequence, varobj_invalidate tries to recreate vars which are already marked as invalid. This does not entirely feels right, but I keep this behavior for backward compatibility. Tested on x86_64-linux --- .../gdb.mi/mi-var-invalidate-shlib.exp | 11 ++++++++++ gdb/varobj.c | 20 ++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp index 5219946d845..3ae76755309 100644 --- a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp +++ b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp @@ -77,4 +77,15 @@ with_test_prefix "in new process" { mi_gdb_test "-var-update floating_local" \ "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \ "floating_local still valid but not in scope" + + # Continue inside foo + mi_gdb_test "299-break-insert -f -t foo" \ + "&\"Function \\\\\"foo\\\\\" not defined.\\\\n\"\r\n299\\^done,[mi_make_breakpoint_pending -type breakpoint -disp del -pending foo]" + mi_send_resuming_command "exec-continue" "continue to foo" + mi_expect_stop "breakpoint-hit" foo ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "arrived at foo" + + # Floating varobj is still valid, and now in scope. + mi_gdb_test "-var-update floating_local" \ + "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}\\\]" \ + "floating_local still valid and in scope" } diff --git a/gdb/varobj.c b/gdb/varobj.c index caaffe4ea70..a316f90c9e2 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2360,22 +2360,28 @@ static void varobj_invalidate_iter (struct varobj *var) { /* global and floating var must be re-evaluated. */ - if (var->root->floating || var->root->valid_block == NULL) + if (var->root->floating || var->root->valid_block == nullptr) { struct varobj *tmp_var; /* Try to create a varobj with same expression. If we succeed replace the old varobj, otherwise invalidate it. */ - tmp_var = varobj_create (NULL, var->name.c_str (), (CORE_ADDR) 0, - USE_CURRENT_FRAME); - if (tmp_var != NULL) - { + tmp_var = varobj_create (nullptr, var->name.c_str (), (CORE_ADDR) 0, + var->root->floating + ? USE_SELECTED_FRAME : USE_CURRENT_FRAME); + if (tmp_var != nullptr) + { + gdb_assert (var->root->floating == tmp_var->root->floating); tmp_var->obj_name = var->obj_name; varobj_delete (var, 0); install_variable (tmp_var); } - else - var->root->is_valid = false; + else if (!var->root->floating) + { + /* Only invalidate globals as floating vars might still be valid in + some other frame. */ + var->root->is_valid = false; + } } else /* locals must be invalidated. */ var->root->is_valid = false; -- 2.25.1