From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2073.outbound.protection.outlook.com [40.107.212.73]) by sourceware.org (Postfix) with ESMTPS id 0258B3851AB1 for ; Mon, 20 Jun 2022 17:19:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0258B3851AB1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nAMWM4hq07i8DVYBoLG4vVBGOaoL3JPEJS3NoUT8xJWCfeVqGXJj11MbiQoJxroKrmN1wL6hUMoHh2WObFCacngg6MlHfWTM8p4N/aSnoJKUKMmqWAQ0rRaVwUZcTYDvUUlOmwDc3jzYU+E1LBC/Jjap7yu0FVEhiCrn2wncH8YUTiMwnnzM0hP4T190+drBqNA5iZ77uuOUSj4pIOQ26c3jACv+x91YLilCvmQjpkI/Y4NFscTyQL9180WvHX8GhRY64r8JDHkZZ16b7VBEI5Py/bt3/Mj8Xu5V+FXQe4LRhF0A0vCKI7xJ34TWbeUmHGokvOkyHuLa5B6c1OhWIg== 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=1BTYH9eyLxeN5M4vghRR3tKLpGpegw4WKL1xPMHFMoU=; b=O6XwMu+LnUmrha+JMjdwLW6yURN2LM//p1ik1/+VuZkpOjiuTyjaUepCOn7viSl6+6BCfHpe1zhV/LC3TRa+L3SsTXd2ZLVtsCxAL/Xux3GlduSUC8fssjMUi4tpja8yBCWp1kpAEBQoGpkBYX0sjUssIpugsIqpzp21wMu/cvYtNfwISo/jHrLJdfyf33DCpV4+eHFks97zQcn9kGCsz+epsOw/LDid0pu8THbmwv+Z7LhhGd9tLYroshurOUTMEGa4HxdyXGVLtaM56TAC0B24FL1hQR+VL2IYYcjnLLPwKB/xFiwSYa7/Cbtzb233ty2g1AUtkzvjdqcDUt2OIg== 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 MW3PR06CA0017.namprd06.prod.outlook.com (2603:10b6:303:2a::22) by DM6PR12MB5024.namprd12.prod.outlook.com (2603:10b6:5:20a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14; Mon, 20 Jun 2022 17:19:40 +0000 Received: from CO1NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::72) by MW3PR06CA0017.outlook.office365.com (2603:10b6:303:2a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.20 via Frontend Transport; Mon, 20 Jun 2022 17:19:39 +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 CO1NAM11FT067.mail.protection.outlook.com (10.13.174.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5353.14 via Frontend Transport; Mon, 20 Jun 2022 17:19:39 +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; Mon, 20 Jun 2022 12:19:37 -0500 From: Lancelot SIX To: CC: , Lancelot SIX Subject: [PATCH v2 3/3] gdb/varobj: Fix varobj_invalidate_iter Date: Mon, 20 Jun 2022 18:19:15 +0100 Message-ID: <20220620171915.509358-4-lancelot.six@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620171915.509358-1-lancelot.six@amd.com> References: <20220620171915.509358-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bde69627-6f51-478b-67fd-08da52e10ed9 X-MS-TrafficTypeDiagnostic: DM6PR12MB5024: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: WjnR4w2depEnyIaiz0G0um/sm+dbc3HkHEbmBNkq9H3neQeS73yIM6a2lvgJsRxjY6dzYGRqoF4Rdvpp6nljHxzWLthAtM3UjvuD7pmtCwbViIuYXbxK+2MlnTaBVOnTlEanwJdJ1m7qwdbYqdPjhioUCXbmapItkgrTa/Pdhg+9AIbe1w7E0T88BpVf9uxRC261n6jzsDwR00OuR4G2mXH9vO7vym/DGd6JcGTOq+K+QpY6oTnn9mz3pHVuqK2P5UTvqRSpbX1mDiQFG6c+iJQD5uV/pdYN/u4ck9LxokDDJNYcHCgLFRpS988TliPdM3fHxMM4Yo2mmHatXE9CRp/O4wOmXp6dWXZyuZJTPcDK9XYqGNSMduOkk3ypr805yhRajvvLg4m/+Q+DNTMsbnRlkQIfeaGf815SY3ITYzmTGvk8IZ71boV+8GhbFzfMAm6ktYD/b3nL3ShQn3zVrm8l/7wga90OcTzqBo6dUCecWSCUULMKTOsfZQ1Ty2sNSU/gQOZAsBWrB6wrbKE9uugpWkWtwxea28aKT6uzb31hqQnEGs4xr1tvikCboBaGolDTJIhMCQ1i5Vik42mkpueFdCO/xxRLum5QMyTrMSV8k7zHKLbv8T1nImJxPyR3vr86RAe3jzIK9XeP8c4Ilup+LFrczMkFlaprJummFNgznMNv0CLnXtXDwx5loG0fGmPIDOHaaAt5hY3vBpDWVn9c2nxBk1oJmo3v41Yc+rV9VCKLcvK3jlKDcWkZ5D1J 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)(376002)(136003)(346002)(396003)(39860400002)(46966006)(40470700004)(36840700001)(478600001)(8936002)(36860700001)(6916009)(54906003)(40480700001)(83380400001)(2906002)(36756003)(82310400005)(8676002)(70586007)(4326008)(316002)(5660300002)(2616005)(70206006)(6666004)(16526019)(1076003)(336012)(26005)(7696005)(47076005)(426003)(186003)(86362001)(41300700001)(40460700003)(81166007)(356005)(82740400003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2022 17:19:39.4563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bde69627-6f51-478b-67fd-08da52e10ed9 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: CO1NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5024 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: Mon, 20 Jun 2022 17:19:43 -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.c | 2 + .../gdb.mi/mi-var-invalidate-shlib.exp | 44 +++++++++++++++++++ gdb/varobj.c | 20 ++++++--- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.c b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.c index f9237c3b853..2cb70104d80 100644 --- a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.c +++ b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.c @@ -17,6 +17,8 @@ #include +int global_var = 5; + static void no_varobj_in_scope (void) { diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp index da2750c7b5b..090bb5b8885 100644 --- a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp +++ b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp @@ -52,6 +52,7 @@ with_test_prefix "setup" { mi_runto foo -pending + mi_create_varobj global_var global_var "create global global_var" mi_create_varobj global_shlib_var global_shlib_var "create global gloal_shlib_var" mi_create_floating_varobj floating_local local_var "create floating local_var" @@ -65,6 +66,10 @@ with_test_prefix "after objfile deleted" { "\\^done,changelist=\\\[\{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"\}\]" \ "global_shlib_var invalidated" + mi_gdb_test "-var-update global_var" \ + "\\^done,changelist=\\\[\\\]" \ + "global_var still valid" + # The floating var is still valid but not in scope. mi_gdb_test "-var-update floating_local" \ "\\^done,changelist=\\\[{name=\"floating_local\",in_scope=\"false\",type_changed=\"false\",has_more=\"0\"}\\\]" \ @@ -78,3 +83,42 @@ with_test_prefix "after objfile deleted" { "floating_local in scope with new type and value" } + +# Reload the entire process +with_test_prefix "restart process" { + mi_delete_breakpoints + mi_gdb_load ${binfile} + mi_runto_main +} + +with_test_prefix "in new process" { + # When reloading the symbol file, only the var for the global in the main + # executable is re-created. + mi_gdb_test "-var-update global_var" \ + "\\^done,changelist=\\\[{name=\"global_var\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}\\\]" \ + "global_var recreated" + mi_gdb_test "-var-update global_shlib_var" \ + "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \ + "global_shlib_var invalid" + + # Floating varobj should still be valid, but out of scope at the moment. + 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=\"true\",new_type=\"struct bar\",new_num_children=\"2\",has_more=\"0\"}\\\]" \ + "floating_local still valid and in scope" + + # The var for the global in the shlib stays invalid even after reloading the shlib. + mi_gdb_test "-var-update global_shlib_var" \ + "\\^done,changelist=\\\[{name=\"global_shlib_var\",in_scope=\"invalid\",has_more=\"0\"}\\\]" \ + "global_shlib_var invalid after shlib loaded" +} diff --git a/gdb/varobj.c b/gdb/varobj.c index 1fb61d2ced4..ca702b65e86 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2354,22 +2354,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