Author: Greg Clayton Date: 2022-09-12T16:53:19-07:00 New Revision: 376c7bd92aff0e4256b2842400936a9b29343045
URL: https://github.com/llvm/llvm-project/commit/376c7bd92aff0e4256b2842400936a9b29343045 DIFF: https://github.com/llvm/llvm-project/commit/376c7bd92aff0e4256b2842400936a9b29343045.diff LOG: Fix DW_OP_convert to resolve the CU relative offset correctly. Debugging some DWARF5 binaries was causing errors to appear when DWARFExpression::Evaluate was called: error: GetDIE for DIE 0x31 is outside of its CU 0x123450 The issue is in the DWARF expression evaluator. Fixed with this. Differential Revision: https://reviews.llvm.org/D133623 Added: Modified: lldb/source/Expression/DWARFExpression.cpp lldb/unittests/Expression/DWARFExpressionTest.cpp lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h Removed: ################################################################################ diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index 283e04021a52a..8e9c868a6405b 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -2374,9 +2374,11 @@ bool DWARFExpression::Evaluate( return false; } } else { - // Retrieve the type DIE that the value is being converted to. + // Retrieve the type DIE that the value is being converted to. This + // offset is compile unit relative so we need to fix it up. + const uint64_t abs_die_offset = die_offset + dwarf_cu->GetOffset(); // FIXME: the constness has annoying ripple effects. - DWARFDIE die = const_cast<DWARFUnit *>(dwarf_cu)->GetDIE(die_offset); + DWARFDIE die = const_cast<DWARFUnit *>(dwarf_cu)->GetDIE(abs_die_offset); if (!die) { if (error_ptr) error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE"); diff --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp index 2678db9aa6a42..8d23f1c49564b 100644 --- a/lldb/unittests/Expression/DWARFExpressionTest.cpp +++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -61,6 +61,9 @@ static llvm::Expected<Scalar> Evaluate(llvm::ArrayRef<uint8_t> expr, class DWARFExpressionTester : public YAMLModuleTester { public: + DWARFExpressionTester(llvm::StringRef yaml_data, size_t cu_index) : + YAMLModuleTester(yaml_data, cu_index) {} + using YAMLModuleTester::YAMLModuleTester; llvm::Expected<Scalar> Eval(llvm::ArrayRef<uint8_t> expr) { return ::Evaluate(expr, m_module_sp, m_dwarf_unit); @@ -179,6 +182,17 @@ TEST(DWARFExpression, DW_OP_convert) { debug_info: - Version: 4 AddrSize: 8 + AbbrevTableID: 0 + AbbrOffset: 0x0 + Entries: + - AbbrCode: 0x00000001 + Values: + - Value: 0x000000000000000C + - AbbrCode: 0x00000000 + - Version: 4 + AddrSize: 8 + AbbrevTableID: 0 + AbbrOffset: 0x0 Entries: - AbbrCode: 0x00000001 Values: @@ -214,14 +228,16 @@ TEST(DWARFExpression, DW_OP_convert) { - Value: 0x000000000000000b # DW_ATE_numeric_string - Value: 0x0000000000000001 - AbbrCode: 0x00000000 + )"; + // Compile unit relative offsets to each DW_TAG_base_type uint8_t offs_uint32_t = 0x0000000e; uint8_t offs_uint64_t = 0x00000011; uint8_t offs_sint64_t = 0x00000014; uint8_t offs_uchar = 0x00000017; uint8_t offs_schar = 0x0000001a; - DWARFExpressionTester t(yamldata); + DWARFExpressionTester t(yamldata, /*cu_index=*/1); ASSERT_TRUE((bool)t.GetDwarfUnit()); // Constant is given as little-endian. diff --git a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp index 15db62451f91a..14e7c7d5203ed 100644 --- a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp +++ b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp @@ -14,7 +14,7 @@ using namespace lldb_private; -YAMLModuleTester::YAMLModuleTester(llvm::StringRef yaml_data) { +YAMLModuleTester::YAMLModuleTester(llvm::StringRef yaml_data, size_t cu_index) { llvm::Expected<TestFile> File = TestFile::fromYaml(yaml_data); EXPECT_THAT_EXPECTED(File, llvm::Succeeded()); m_file = std::move(*File); @@ -22,5 +22,5 @@ YAMLModuleTester::YAMLModuleTester(llvm::StringRef yaml_data) { m_module_sp = std::make_shared<Module>(m_file->moduleSpec()); auto &symfile = *llvm::cast<SymbolFileDWARF>(m_module_sp->GetSymbolFile()); - m_dwarf_unit = symfile.DebugInfo().GetUnitAtIndex(0); + m_dwarf_unit = symfile.DebugInfo().GetUnitAtIndex(cu_index); } diff --git a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h index 60715ab2c16a6..1b1bf22be1cb2 100644 --- a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h +++ b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h @@ -33,7 +33,7 @@ class YAMLModuleTester { public: /// Parse the debug info sections from the YAML description. - YAMLModuleTester(llvm::StringRef yaml_data); + YAMLModuleTester(llvm::StringRef yaml_data, size_t cu_index = 0); DWARFUnit *GetDwarfUnit() const { return m_dwarf_unit; } lldb::ModuleSP GetModule() const { return m_module_sp; } }; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits