From patchwork Tue Dec 10 21:40:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liushuyu X-Patchwork-Id: 102793 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 8967C385828E for ; Tue, 10 Dec 2024 21:43:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8967C385828E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eFEln1AF X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id E3E3B3858423 for ; Tue, 10 Dec 2024 21:42:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3E3B3858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E3E3B3858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733866950; cv=none; b=Q1rB09uXSi0IzvnTnr4cgkfpdPKEfFZ6TFwLAQgVsYF8Y4nKeJe06KLtDgDbBhg0xhwde4m0Au13AQQCfqJuGYkXx5mqgQdQoHmI8m3NWfHbECMq9EUrvvcnFGiVUq0vlTUaxsIgmebrgaeb8EHPV01Y3Go6nTtNs96Xw/LbCT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733866950; c=relaxed/simple; bh=+DMkPOtlnoEFa00rqxv5PtfKEDbBUrc5N6T/WAmzrr0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kGiTerySK3ETpH94LaKUlp0kB/gTKTR/vIsrPJXWG53iGW2KxWkqyUkqVUIi0sLW5gLvkUQPjgb70ciklh1aEhMCXX9k0v899gTLO83YjORDfssNCMPZG1Olj9MbY1RWMauH4h7T8I2/t7m2r4bGNB0toDCWHNnY6K85r28kg9c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3E3B3858423 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-728ea1573c0so747106b3a.0 for ; Tue, 10 Dec 2024 13:42:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733866948; x=1734471748; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tS3U4eD2ADxywP2+/p3nczbuXTQDcKD1s1y4cFvDSdU=; b=eFEln1AFq5VYUfCcT/ISJopGBCFkeKB4K6nzH5MzGWNDkbiNOMX5Kx/lFKpb0jTy4J SAx17/GjEANfPB//vVWtyqjKP3HIEmwGCYGLDdj57josQ1JKzl/eEPmxLBniXRDO4G+t 6AH2A4yw9HhRi+QP218GeNmEAfim+vrqa71HEuEpOSjJyBhcKRsgoLqFZjwdKJLGN9B5 yqZ3GGgd1xqo6aSDszJD9szKAk8+sy4/prPfPkh4+0uFDyPESxP9BtXz0L15L0eqm/Km /tUeq4TqdftSw8dfPGvnwYC8WQI4rzMoaO2u8ImLRrEmHPCxfcnk0U2RMEkoR4EACY/B gMug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733866948; x=1734471748; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tS3U4eD2ADxywP2+/p3nczbuXTQDcKD1s1y4cFvDSdU=; b=AkT5M1dl5kDMo4oRY+aLFa3BgpKW6rj+ZnbqDSjQfI58x5x65/l4OGqDESNNj4YAjz XTLhQq4BLu95G5+OIRow5kP+bi6tTMQf0+OvBYSafozB7UB6oGs1JOF5AuNS8Ukptn5+ qPf2Hajcj58fxb8owOx2v0g/SEP+HUVAACVH9CQe3mpNRenmNLxxMdIwGqFW1I+Msb6R fqDVYnXqk3iiGHX3jfBnVVBmrigaen92hKITggcghmZKZ405mEtLvtIyCV1j8e3hrhrB T5jD00QwGF+u7XF5Xso6KMg0zj2d/FTd3dMbXy6RU7KPFXIDhXQX76fa2XanHBDZTPth au/w== X-Gm-Message-State: AOJu0YwCETPI2zCcSPEIx6poZa6mI0br7GYNVvwyNk13hVBLUHu4CoMJ BzdFZp4/ChXsct9ov/kTNhCOZ9pBIKXAMywkl6TgWY7g6GmosJjrRup90Q== X-Gm-Gg: ASbGncsJXEJLdv5ZX3G/ZdtF15Nd5NUEHDET2wxCW/eLdtMBR4nyENhzFrurqz3Luga 5wL+Zwor14vy+LsB26WiTZVA4Ngp+rWUNilBnXiofuVWkbaEHc/nRIXW0i6Q8W8bp9mo0wF2u0h MAe+vf7nRAQFrfKFTBdB3/jCjbiAoFToVevqOU+GLkSev3xNIedoC4LgHZAzRvPFCqfDqb2lKDz JxTa+J2F3bjwec9GwMvz8QesbsOu/vZSPCn6s2qXAhJtoF77jgnhuwE2Z86A/4bTQ== X-Google-Smtp-Source: AGHT+IGc58QDnVq3hA/v35yeCADkOESvX8KIhT7fOza6aJnylsW2qyMCZ3t8C0AzV2FIceubJDrCmQ== X-Received: by 2002:a05:6a20:cf83:b0:1e1:a07f:9679 with SMTP id adf61e73a8af0-1e1c124a789mr1342893637.4.1733866948397; Tue, 10 Dec 2024 13:42:28 -0800 (PST) Received: from liushuyu-p15.lan ([2001:56a:fa5b:e200:c6d4:465e:93a2:7490]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725d2bfba50sm6386784b3a.57.2024.12.10.13.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 13:42:28 -0800 (PST) From: liushuyu To: gdb-patches@sourceware.org Cc: liushuyu Subject: [PATCH] [PR GDB/32398] Fix name resolution for imported D modules Date: Tue, 10 Dec 2024 14:40:08 -0700 Message-ID: <20241210214037.94012-1-liushuyu011@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This fixes the name lookup regression since GDB 10 for the D language where if an import is nested inside a function declaration, the lookup will fail due to scope information is missing. --- gdb/dwarf2/read.c | 6 ++ gdb/testsuite/gdb.dlang/imports.c | 34 +++++++++++ gdb/testsuite/gdb.dlang/imports.exp | 88 +++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 gdb/testsuite/gdb.dlang/imports.c create mode 100644 gdb/testsuite/gdb.dlang/imports.exp diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1ae56d3fb5..48bb09b2b0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -20377,6 +20377,12 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu) else if (die->tag == DW_TAG_entry_point) return determine_prefix (parent, cu); } + /* Imports in D langauge might be nested inside functions or delegates. + We will bubble up through the tree to find the module name. */ + if (cu->lang () == language_d) + { + return determine_prefix (parent, cu); + } return ""; case DW_TAG_enumeration_type: parent_type = read_type_die (parent, cu); diff --git a/gdb/testsuite/gdb.dlang/imports.c b/gdb/testsuite/gdb.dlang/imports.c new file mode 100644 index 0000000000..8a91f30d0c --- /dev/null +++ b/gdb/testsuite/gdb.dlang/imports.c @@ -0,0 +1,34 @@ +/* Copyright 2017-2024 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 . */ + +/* DWARF will describe these contents as being inside a D module. */ +float _D6import6b_Globf = 55.22; + +int +_Dmain (void) +{ + asm ("_Dmain_label: .globl _Dmain_label"); + _D6import6b_Globf = 0.125; + asm ("_Dmain_break_label: .globl _Dmain_break_label"); + return 0; +} + +asm ("_Dmain_end: .globl _Dmain_end"); + +int +main (void) +{ + return _Dmain (); +} diff --git a/gdb/testsuite/gdb.dlang/imports.exp b/gdb/testsuite/gdb.dlang/imports.exp new file mode 100644 index 0000000000..936ee94bba --- /dev/null +++ b/gdb/testsuite/gdb.dlang/imports.exp @@ -0,0 +1,88 @@ +# Copyright (C) 2017-2024 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 . + +# Test symbol lookup when there are multiple circular imports. + +load_lib "d-support.exp" +load_lib "dwarf.exp" + +require allow_d_tests dwarf2_support + +standard_testfile imports.c imports-dw.S + +lassign [function_range _Dmain ${srcdir}/${subdir}/${srcfile}] \ + dmain_start dmain_length + + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global dmain_start dmain_length + + cu { label cu_start } { + compile_unit { + {language @DW_LANG_D} + } { + declare_labels main_module_label imported_module_label float_label + + float_label: base_type { + {name float} + {encoding @DW_ATE_float} + {byte_size 4 DW_FORM_sdata} + } + + imported_module_label: module { + {name import} + } { + tag_variable { + {name b_Globf} + {MIPS_linkage_name _D6import6b_Globf} + {external 1 flag} + {type :$float_label} + } + } + + main_module_label: module { + {name main} + } { + subprogram { + {MACRO_AT_func { "_Dmain" }} + {external 1 flag_present} + } { + imported_module { + { import :$imported_module_label } + } + } + } + } + } + + aranges {} cu_start { + arange {} $dmain_start $dmain_length + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test_no_output "set language d" + +if {![runto "_Dmain_break_label"]} { + return -1 +} + +gdb_test "print b_Glob" "= 0.125"