[llvm] [llvm][dwarfdump] Print the name (if available) of entities referenced by DW_AT_import (PR #171859)
Michael Buch via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 13:00:50 PST 2025
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/171859
>From b50a662bc3b5ee157c47b8391dd90fea1035931c Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 11 Dec 2025 16:14:16 +0000
Subject: [PATCH 1/4] [llvm][dwarfdump] Print the name (if available) of
entities referenced by DW_AT_import
---
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 2 +-
.../llvm-dwarfdump/AArch64/DW_AT_import.yaml | 73 +++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_import.yaml
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index deafee80f559f..a10becb252006 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -246,7 +246,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
// having both the raw value and the pretty-printed value is
// interesting. These attributes are handled below.
if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin ||
- Attr == DW_AT_call_origin) {
+ Attr == DW_AT_call_origin || Attr == DW_AT_import) {
if (const char *Name =
Die.getAttributeValueAsReferencedDie(FormValue).getName(
DINameKind::LinkageName))
diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_import.yaml b/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_import.yaml
new file mode 100644
index 0000000000000..fec25bdd9ba30
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/AArch64/DW_AT_import.yaml
@@ -0,0 +1,73 @@
+# RUN: yaml2obj %s | llvm-dwarfdump -verify - | FileCheck %s --check-prefix=VERIFY
+# VERIFY: No errors.
+#
+# RUN: yaml2obj %s | llvm-dwarfdump - | FileCheck %s
+# CHECK: DW_AT_import ({{.*}} "Foo")
+# CHECK: DW_AT_import ({{.*}} "")
+# CHECK: DW_AT_import ({{.*}})
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_AARCH64
+DWARF:
+ debug_abbrev:
+ - ID: 0
+ Table:
+ - Code: 0x1
+ Tag: DW_TAG_compile_unit
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_language
+ Form: DW_FORM_data2
+ - Code: 0x2
+ Tag: DW_TAG_imported_declaration
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_import
+ Form: DW_FORM_ref4
+ - Code: 0x3
+ Tag: DW_TAG_module
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Code: 0x4
+ Tag: DW_TAG_module
+ Children: DW_CHILDREN_no
+
+ debug_info:
+ - Version: 5
+ UnitType: DW_UT_compile
+ AddrSize: 8
+ Entries:
+
+ - AbbrCode: 0x1
+ Values:
+ - Value: 0x04
+
+ - AbbrCode: 0x2
+ Values:
+ - Value: 0x1e
+
+ - AbbrCode: 0x2
+ Values:
+ - Value: 0x23
+
+ - AbbrCode: 0x2
+ Values:
+ - Value: 0x19
+
+ - AbbrCode: 0x3
+ Values:
+ - CStr: Foo
+
+ - AbbrCode: 0x3
+ Values:
+ - CStr: ''
+
+ - AbbrCode: 0x4
+ - AbbrCode: 0x0
+...
>From 9f649b283e8b88f597a8325d65b31d15fe2b1d22 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 11 Dec 2025 17:24:54 +0000
Subject: [PATCH 2/4] fixup! fix some tests
---
.../Generic/import-inlined-declaration.ll | 2 +-
llvm/test/DebugInfo/Generic/namespace.ll | 28 +++++++++----------
.../X86/dimodule-external-fortran.ll | 2 +-
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/llvm/test/DebugInfo/Generic/import-inlined-declaration.ll b/llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
index 6a5209548a257..e6ad77a799b97 100644
--- a/llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
+++ b/llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
@@ -30,7 +30,7 @@
; CHECK: DW_TAG_variable
; CHECK: NULL
; CHECK: DW_TAG_imported_declaration
-; CHECK: DW_AT_import ([[FOO]])
+; CHECK: DW_AT_import ([[FOO]] "_ZN2ns3fooEv")
; CHECK: NULL
; CHECK: NULL
diff --git a/llvm/test/DebugInfo/Generic/namespace.ll b/llvm/test/DebugInfo/Generic/namespace.ll
index 48b40938716fd..da6b156e186c2 100644
--- a/llvm/test/DebugInfo/Generic/namespace.ll
+++ b/llvm/test/DebugInfo/Generic/namespace.ll
@@ -52,7 +52,7 @@
; CHECK: DW_TAG_imported_module
; CHECK: DW_AT_decl_file ([[F2:.*]])
; CHECK: DW_AT_decl_line (15)
-; CHECK: DW_AT_import ([[NS2]])
+; CHECK: DW_AT_import ([[NS2]] "B")
; CHECK: DW_TAG_imported_declaration
; CHECK: NULL
@@ -72,60 +72,60 @@
; CHECK: DW_TAG_imported_module
; CHECK: DW_AT_decl_file ([[F2:.*]])
; CHECK: DW_AT_decl_line (26)
-; CHECK: DW_AT_import ([[NS1]])
+; CHECK: DW_AT_import ([[NS1]] "A")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (27)
-; CHECK: DW_AT_import ([[FOO]])
+; CHECK: DW_AT_import ([[FOO]] "foo")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (28)
-; CHECK: DW_AT_import ([[BAR]])
+; CHECK: DW_AT_import ([[BAR]] "bar")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (29)
-; CHECK: DW_AT_import ([[FUNC1]])
+; CHECK: DW_AT_import ([[FUNC1]] {{.*}})
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (30)
-; CHECK: DW_AT_import ([[I]])
+; CHECK: DW_AT_import ([[I]] "_ZN1A1B1iE")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (31)
-; CHECK: DW_AT_import ([[BAZ]])
+; CHECK: DW_AT_import ([[BAZ]] "baz")
; CHECK: [[X:0x[0-9a-f]*]]:{{ *}}DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (32)
-; CHECK: DW_AT_import ([[NS1]])
+; CHECK: DW_AT_import ([[NS1]] "A")
; CHECK: DW_AT_name ("X")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (33)
-; CHECK: DW_AT_import ([[X]])
+; CHECK: DW_AT_import ([[X]] "X")
; CHECK: DW_AT_name ("Y")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (34)
-; CHECK: DW_AT_import ([[VAR_DECL]])
+; CHECK: DW_AT_import ([[VAR_DECL]] "_ZN1A1B8var_declE")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (35)
-; CHECK: DW_AT_import ([[FUNC_DECL]])
+; CHECK: DW_AT_import ([[FUNC_DECL]] "_ZN1A1B9func_declEv")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (36)
-; CHECK: DW_AT_import ([[VAR_FWD]])
+; CHECK: DW_AT_import ([[VAR_FWD]] "_ZN1A1B7var_fwdE")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_AT_decl_file ([[F2]])
; CHECK: DW_AT_decl_line (37)
-; CHECK: DW_AT_import ([[FUNC_FWD]])
+; CHECK: DW_AT_import ([[FUNC_FWD]] "_ZN1A1B8func_fwdEv")
; CHECK: NULL
; CHECK: DW_TAG_subprogram
; CHECK: DW_TAG_imported_module
; CHECK: DW_AT_decl_file ([[F2:.*]])
; CHECK: DW_AT_decl_line (18)
-; CHECK: DW_AT_import ([[NS1]])
+; CHECK: DW_AT_import ([[NS1]] "A")
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_TAG_base_type
; CHECK: NULL
diff --git a/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll b/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
index 810feca0c8175..60010c50a8f12 100644
--- a/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
+++ b/llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
@@ -29,7 +29,7 @@
; CHECK: DW_TAG_imported_module
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
-; CHECK-NEXT: DW_AT_import ([[DIE_ID]])
+; CHECK-NEXT: DW_AT_import ([[DIE_ID]] "external_module")
; When the debugger sees the module being imported is a declaration,
; it should go to the global scope to find the module's definition.
>From 641ae0943d779052e9081465d6a90344cdfe1ac3 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 11 Dec 2025 20:57:06 +0000
Subject: [PATCH 3/4] fixup! fix dsymutil test
---
llvm/test/tools/dsymutil/X86/modules-empty.m | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/tools/dsymutil/X86/modules-empty.m b/llvm/test/tools/dsymutil/X86/modules-empty.m
index 2cfed54dc2965..cb03735729493 100644
--- a/llvm/test/tools/dsymutil/X86/modules-empty.m
+++ b/llvm/test/tools/dsymutil/X86/modules-empty.m
@@ -30,5 +30,5 @@ int main() {
// The empty CU from the pcm should not get copied into the dSYM.
// Check that module name occured only once.
-// CHECK: "Empty"
-// CHECK-NOT: "Empty"
+// CHECK: DW_AT_name ("Empty")
+// CHECK-NOT: DW_AT_name ("Empty")
>From b7eb0d83a77f8236fd26ac5257e23b82c5b5f6c3 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 11 Dec 2025 20:59:45 +0000
Subject: [PATCH 4/4] fixup! fix Windows CI
---
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll | 2 +-
.../test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll b/llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
index c45edfeb18176..2d467586ea1e9 100644
--- a/llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
+++ b/llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll
@@ -21,7 +21,7 @@ target triple = "x86_64-unknown-linux-gnu"
; CHECK: [[ABSTRACT_FOO:0x[0-9a-f]+]]: DW_TAG_subprogram
; CHECK: DW_AT_name ("foo")
; CHECK: DW_TAG_imported_declaration
-; CHECK: DW_AT_import ([[A:0x[0-9a-f]+]])
+; CHECK: DW_AT_import ([[A:0x[0-9a-f]+]]
; CHECK: NULL
; CHECK: DW_TAG_base_type
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
index 09591dbdb9774..4f5d61780f0ac 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
+++ b/llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
@@ -13,9 +13,9 @@
; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_name ("use_renamed")
; CHECK: DW_TAG_imported_module
-; CHECK: DW_AT_import ([[MYMOD]])
+; CHECK: DW_AT_import ([[MYMOD]] "mymod")
; CHECK: DW_TAG_imported_declaration
-; CHECK: DW_AT_import ([[VAR1]])
+; CHECK: DW_AT_import ([[VAR1]] "var1")
; CHECK: DW_AT_name ("var4")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
More information about the llvm-commits
mailing list