From patchwork Thu Jun 8 15:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot Six X-Patchwork-Id: 70792 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 912913857019 for ; Thu, 8 Jun 2023 15:40:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 912913857019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686238806; bh=1catj0sdwDUem7znXXfjLlKeQA+M2Rjfgnb2Iv53Gcg=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dm4KfdoA/my1NvtwCLq0qN9H2VYb7tIf2aAROFNlkkdGvDadf9ZOqXFGAx1up28n9 luxPOtmWOc7u9Eg+KeCZMbHWaE0mDe+C5GIXd4dbIp6SAFL67f2JNbwlp5FiWidXYY NS+Xlg3W1DiMlsvcmBwhiaVUGGonEXzt4LA8Itew= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2071.outbound.protection.outlook.com [40.107.94.71]) by sourceware.org (Postfix) with ESMTPS id 915793858C62 for ; Thu, 8 Jun 2023 15:39:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 915793858C62 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O+xW2XIE2fzeYwjBITq4n/49pg+IIEhSYCe9eu+92Xql80skBHz8FQJYF70kuMjy8W+20ed4bWzFLugqVqkpJEux5ZDuLzQjj7pnlXmx28wj/Gq5j9iYny/6OzBVddyIsxGrAUMTIgzCEXsnNXdyz/RpgersCpNdSXoO0KIwOZF7cS1ZnsEF1LsWquF5KlK4UCX8Dn76wMdwHYaL/QxgCPCuzftJV28mrQ7EaR+8Kxv6acodhndIsP54Gpr3x6LnEw9JVFeQ4x1o6qiN1myAEWA6TzySNgopxLAFOPOzpzgISCHbqjMP6lAqysr90MtYFfQ5zo5ARYgYCjTJSG9gFQ== 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=1catj0sdwDUem7znXXfjLlKeQA+M2Rjfgnb2Iv53Gcg=; b=RKuWDd+Il1B+ov9V9WXO/UzAG7KN9R81R2qIJrksN8pPHesZvL1YlUrQKjNHf/JZzN4lIVF3MyRdihEhzXIXOj/RoVBhP3bzd9W53Z3I5rUOK80g7ZgiQGSQrKMTIXgabgFuLWVMwrbd0HPwwJIkTkt4p6zuIlRyvbANfEwV86LAC5crOZgEZjXqqh5AZ1IwGfV1pbP8fGS1FE3WNDucoD9i3TJQSJVR2Hqy9EhF03fB6fJNxbioVpSQvHGoDkyzzewdfDsKGi01EEAPVuyUYgCY+Lc6vvFTA2dMmLobsbbIwQgRW7nOc7Ek6rWpkz++lPoMvQ9TBf2Egb4fS4JAtA== 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 SJ0PR13CA0094.namprd13.prod.outlook.com (2603:10b6:a03:2c5::9) by PH7PR12MB6443.namprd12.prod.outlook.com (2603:10b6:510:1f9::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.41; Thu, 8 Jun 2023 15:39:38 +0000 Received: from SN1PEPF000252A2.namprd05.prod.outlook.com (2603:10b6:a03:2c5:cafe::69) by SJ0PR13CA0094.outlook.office365.com (2603:10b6:a03:2c5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.14 via Frontend Transport; Thu, 8 Jun 2023 15:39:38 +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 SN1PEPF000252A2.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6477.13 via Frontend Transport; Thu, 8 Jun 2023 15:39:38 +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; Thu, 8 Jun 2023 10:39:15 -0500 To: CC: , Lancelot SIX Subject: [PATCH] gdb/testsuite: use proper int size for gdb.dwarf2/symbol_needs_eval*.exp Date: Thu, 8 Jun 2023 16:38:42 +0100 Message-ID: <20230608153842.353415-1-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 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: SN1PEPF000252A2:EE_|PH7PR12MB6443:EE_ X-MS-Office365-Filtering-Correlation-Id: d3dac967-2273-46c2-d822-08db68369193 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GEZLxb8GOUkrGyp2X4ZHfZjksb15af5o3tiPWGuwysiOnhOVeangXyjK+zSzTX1tZyiKbS9s77FDvbEwG3Ky6vTJCC0bu73wNN84pRu+TVYeAPWs9OPTTfzLiKaoX/2JnSKVFy8OTEqaiuJlyRlFDSnH5MyyL+m9yfpbfkuqW62HHN+N80yvOqUf+io0DFF5BX6p7fN8XWWeySAlj9TgxHfsd/KWlphhC7AgBrm+V6u7RECLcqdPWU2FbktxEjANsq89q8/LLvqWNLjYiDRtsoGkazE+XzVji6+l5x+RZQFes2qwbEcX6EOeI2r9OIOVOfiIhvHhVzC/nTmdv2y3ckjfIJGSIKeXrc2kn6nEy01HuX09gWlUFMkBfe4MIiGC2nOs/EXuWj9MitYdQFTKb8S8bQFoUMl82vYSh6/JYi0RE8lvjCVEVkYb/ivlBNm1LEvbykcOnKsyhIo42YHH3di+cCd2Ys73z8cXqpPlFkOvz2kLIr00fQ0qLdUIHczKN14xBASRoyfq1X9ooOThiQ09PFHYe691UKAzfTZD9gPjFVYxA/ZX0xMduQQtks/BxPqk6lxcjYZrQa8kHBw3Nn3bXMTnO3tMntB9Zm5PAsLDvVjZh4KuxjOHYPvEEjxneBfLwTtsbOP78zHksxCbRrMt3A93WgPoPQmrVZiDonBZoJww+4Vwu311OJC31eY+xYru6zBn9rNSARsUuS2SX1NmyioW+FX4zgXMojjryWeC+QP1FTj6A8IqGCObUOIX1V3siVS2bGNK7xT8+brHDg== 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:(13230028)(4636009)(396003)(136003)(39860400002)(376002)(346002)(451199021)(40470700004)(46966006)(36840700001)(7696005)(6666004)(36756003)(82310400005)(2616005)(426003)(336012)(36860700001)(83380400001)(47076005)(86362001)(40480700001)(81166007)(356005)(82740400003)(1076003)(26005)(16526019)(40460700003)(186003)(316002)(8936002)(8676002)(41300700001)(4326008)(2906002)(5660300002)(6916009)(478600001)(54906003)(70206006)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2023 15:39:38.2340 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3dac967-2273-46c2-d822-08db68369193 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: SN1PEPF000252A2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6443 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, 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-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" We recently realized that symbol_needs_eval_fail.exp and symbol_needs_eval_timeout.exp invalidly dereference an int (4 bytes on x86_64) by reading 8 bytes (the size of a pointer). Here how it goes: In gdb/testsuite/gdb.dwarf2/symbol_needs_eval.c a global variable is defined: int exec_mask = 1; and later both tests build some DWARF using the assembler doing: set exec_mask_var [gdb_target_symbol exec_mask] ... DW_TAG_variable { {DW_AT_name a} {DW_AT_type :$int_type_label} {DW_AT_location { DW_OP_addr $exec_mask_var DW_OP_deref ... } } The definition of the DW_OP_deref (from Dwarf5 2.5.1.3 Stack Operations) says that "The size of the data retrieved from the dereferenced address is the size of an address on the target machine." On x86_64, the size of an int is 4 while the size of an address is 8. The result is that when evaluating this expression, the debugger reads outside of the `a` variable. Fix this by using `DW_OP_deref_size $int_size` instead. To achieve this, this patch adds the necessary steps so we can figure out what `sizeof(int)` evaluates to for the current target. While at it, also change the definition of the int type in the assembled DWARF information so we use the actual target's size for an int instead of the literal 4. Tested on x86_64 Linux. --- .../gdb.dwarf2/symbol_needs_eval_fail.exp | 14 +++++++++++--- .../gdb.dwarf2/symbol_needs_eval_timeout.exp | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) base-commit: 12f7174bf069f407d5b6f12e926ceabe45e450e1 diff --git a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp index cb9826e90df..c3440d970dc 100644 --- a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp +++ b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp @@ -47,11 +47,19 @@ if { [is_aarch64_target] } { standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S +if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] { + return +} + +clean_restart ${testfile} + +set int_size [get_sizeof "int" -1] + # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { - global dwarf_regnum regname + global dwarf_regnum regname int_size set exec_mask_var [gdb_target_symbol exec_mask] @@ -66,7 +74,7 @@ Dwarf::assemble $asm_file { int_type_label: DW_TAG_base_type { {DW_AT_name "int"} {DW_AT_encoding @DW_ATE_signed} - {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_byte_size $int_size DW_FORM_sdata} } # define artificial variable a @@ -75,7 +83,7 @@ Dwarf::assemble $asm_file { {DW_AT_type :$int_type_label} {DW_AT_location { DW_OP_addr $exec_mask_var - DW_OP_deref + DW_OP_deref_size $int_size # conditional jump to DW_OP_bregx DW_OP_bra 4 diff --git a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp index 0e6ee6112ea..ecdeb62a1a8 100644 --- a/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp +++ b/gdb/testsuite/gdb.dwarf2/symbol_needs_eval_timeout.exp @@ -47,11 +47,19 @@ if { [is_aarch64_target] } { standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S +if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] { + return +} + +clean_restart ${testfile} + +set int_size [get_sizeof "int" -1] + # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { - global dwarf_regnum regname + global dwarf_regnum regname int_size set exec_mask_var [gdb_target_symbol exec_mask] @@ -66,7 +74,7 @@ Dwarf::assemble $asm_file { int_type_label: DW_TAG_base_type { {DW_AT_name "int"} {DW_AT_encoding @DW_ATE_signed} - {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_byte_size $int_size DW_FORM_sdata} } # add info for variable exec_mask @@ -93,7 +101,7 @@ Dwarf::assemble $asm_file { {DW_AT_location { DW_OP_lit1 DW_OP_addr $exec_mask_var - DW_OP_deref + DW_OP_deref_size $int_size # jump to DW_OP_fbreg DW_OP_skip 4