Skip to content

[lldb][DWARF] Don't try to compute address range information of forward declarations #144059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Jun 13, 2025

This fixes the error reported in
#144037.

When computing the aranges table of a CU, LLDB would currently visit all DW_TAG_subprogram DIEs and check their DW_AT_low_pc/DW_AT_high_pc/DW_AT_ranges attributes. If those don't exist it would error out and spam the console. Some subprograms (particularly forward declarations) don't have low/high pc attributes, so it's not really an "error". See DWARFv5 spec section 3.3.3 Subroutine and Entry Point Locations:

A subroutine entry may have either a DW_AT_low_pc and DW_AT_high_pc
pair of attributes or a DW_AT_ranges attribute whose values encode the
contiguous or non-contiguous address ranges, respectively, of the machine
instructions generated for the subroutine (see Section 2.17 on page 51).
...
A subroutine entry representing a subroutine declaration that is not also a
definition does not have code address or range attributes.

We should just ignore those DIEs.

…rd declarations

This fixes the error reported in
llvm#144037.

When computing the aranges table of a CU, LLDB would currently visit all
`DW_TAG_subprogram` DIEs and check their `DW_AT_low_pc`/`DW_AT_high_pc`.
If those don't exist it would error out and spam the console. Some
subprograms (particularly forward declarations) don't have low/high pc
attributes, so it's not really an "error". We should just ignore those
DIEs.
@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

This fixes the error reported in
#144037.

When computing the aranges table of a CU, LLDB would currently visit all DW_TAG_subprogram DIEs and check their DW_AT_low_pc/DW_AT_high_pc. If those don't exist it would error out and spam the console. Some subprograms (particularly forward declarations) don't have low/high pc attributes, so it's not really an "error". We should just ignore those DIEs.


Full diff: https://github.com/llvm/llvm-project/pull/144059.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (+2-1)
  • (added) lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test (+25)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
index 5196ce89a2c13..d9deffbe7f8b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -611,7 +611,8 @@ void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
     DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const {
   Log *log = GetLog(DWARFLog::DebugInfo);
   if (m_tag) {
-    if (m_tag == DW_TAG_subprogram) {
+    if (m_tag == DW_TAG_subprogram &&
+        !GetAttributeValueAsOptionalUnsigned(cu, DW_AT_declaration)) {
       if (llvm::Expected<llvm::DWARFAddressRangesVector> ranges =
               GetAttributeAddressRanges(cu, /*check_hi_lo_pc=*/true)) {
         for (const auto &r : *ranges)
diff --git a/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test b/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test
new file mode 100644
index 0000000000000..011e2080a8101
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test
@@ -0,0 +1,25 @@
+# Test that we don't try to determine address range
+# information of forward declaration DIEs which have
+# no DW_AT_low_pc/DW_AT_high_pc in DWARF.
+
+# RUN: split-file %s %t
+# RUN: %clang_host -c -g -gdwarf %t/main.cpp -o %t.o
+# RUN: %lldb -x -b -s %t/commands.input %t.o -o exit 2>&1 \
+# RUN:       | FileCheck %s
+
+#--- main.cpp
+
+struct Foo {
+  void func() {}
+} foo;
+
+void baz() {
+  foo.func();
+}
+
+#--- commands.input
+
+log enable -v dwarf info
+target modules lookup -n func
+
+# CHECK-NOT: DIE has no address range information

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I don't think the test is very useful. Since all it tests is a negative, the test could be easily invalidated (e.g. by changing the error string), and we would never notice.

You can keep it if you want, but I'd be fine with this even without a test (on the account of us not testing log messages).

@Michael137
Copy link
Member Author

Yea that's fair. I'll remove the test and just add a comment in the source

@Michael137 Michael137 merged commit c3ec9e3 into llvm:main Jun 13, 2025
7 checks passed
@Michael137 Michael137 deleted the lldb/address-range-ignore-fwd branch June 13, 2025 13:40
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
…rd declarations (llvm#144059)

This fixes the error reported in
llvm#144037.

When computing the aranges table of a CU, LLDB would currently visit all
`DW_TAG_subprogram` DIEs and check their
`DW_AT_low_pc`/`DW_AT_high_pc`/`DW_AT_ranges` attributes. If those don't
exist it would error out and spam the console. Some subprograms
(particularly forward declarations) don't have low/high pc attributes,
so it's not really an "error". See DWARFv5 spec section `3.3.3
Subroutine and Entry Point Locations`:
```
A subroutine entry may have either a DW_AT_low_pc and DW_AT_high_pc
pair of attributes or a DW_AT_ranges attribute whose values encode the
contiguous or non-contiguous address ranges, respectively, of the machine
instructions generated for the subroutine (see Section 2.17 on page 51).
...
A subroutine entry representing a subroutine declaration that is not also a
definition does not have code address or range attributes.
```

We should just ignore those DIEs.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
…rd declarations (llvm#144059)

This fixes the error reported in
llvm#144037.

When computing the aranges table of a CU, LLDB would currently visit all
`DW_TAG_subprogram` DIEs and check their
`DW_AT_low_pc`/`DW_AT_high_pc`/`DW_AT_ranges` attributes. If those don't
exist it would error out and spam the console. Some subprograms
(particularly forward declarations) don't have low/high pc attributes,
so it's not really an "error". See DWARFv5 spec section `3.3.3
Subroutine and Entry Point Locations`:
```
A subroutine entry may have either a DW_AT_low_pc and DW_AT_high_pc
pair of attributes or a DW_AT_ranges attribute whose values encode the
contiguous or non-contiguous address ranges, respectively, of the machine
instructions generated for the subroutine (see Section 2.17 on page 51).
...
A subroutine entry representing a subroutine declaration that is not also a
definition does not have code address or range attributes.
```

We should just ignore those DIEs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants