From cdb3a8b6b6acf054343aec33b9132250c6841ece Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 13 Jun 2025 13:11:28 +0100 Subject: [PATCH 1/3] [lldb][DWARF] Don't try to compute address range information of forward declarations This fixes the error reported in https://github.com/llvm/llvm-project/pull/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. --- .../SymbolFile/DWARF/DWARFDebugInfoEntry.cpp | 3 ++- .../forward-declaration-address-ranges.test | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test 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 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 From 939fe5a92a8bba351aed601868b4341d854f06f7 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 13 Jun 2025 13:37:37 +0100 Subject: [PATCH 2/3] fixup! add comment --- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index d9deffbe7f8b5..8217c85f86014 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -611,6 +611,9 @@ void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable( DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const { Log *log = GetLog(DWARFLog::DebugInfo); if (m_tag) { + // Subprogram forward declarations don't have + // DW_AT_ranges/DW_AT_low_pc/DW_AT_high_pc attributes, so don't even try + // getting address range information for them. if (m_tag == DW_TAG_subprogram && !GetAttributeValueAsOptionalUnsigned(cu, DW_AT_declaration)) { if (llvm::Expected ranges = From 9856f35f93e963d8522c843282b96935e1967b98 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 13 Jun 2025 13:37:55 +0100 Subject: [PATCH 3/3] fixup! remove test --- .../forward-declaration-address-ranges.test | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test diff --git a/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test b/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test deleted file mode 100644 index 011e2080a8101..0000000000000 --- a/lldb/test/Shell/SymbolFile/DWARF/forward-declaration-address-ranges.test +++ /dev/null @@ -1,25 +0,0 @@ -# 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