labath updated this revision to Diff 302269.
labath added a comment.

Add (test) changes I accidentally left out.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90598/new/

https://reviews.llvm.org/D90598

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
  lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
  lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
  lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h

Index: lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
===================================================================
--- lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
+++ lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
@@ -29,13 +29,14 @@
       subsystems;
   llvm::Optional<TestFile> m_file;
   lldb::ModuleSP m_module_sp;
-  DWARFUnit *m_dwarf_unit;
 
 public:
   /// Parse the debug info sections from the YAML description.
   YAMLModuleTester(llvm::StringRef yaml_data);
-  DWARFUnit *GetDwarfUnit() const { return m_dwarf_unit; }
   lldb::ModuleSP GetModule() const { return m_module_sp; }
+
+  size_t GetNumUnits();
+  DWARFUnit *GetUnitAtIndex(size_t idx);
 };
 
 } // namespace lldb_private
Index: lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
===================================================================
--- lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
+++ lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
@@ -20,7 +20,16 @@
   m_file = std::move(*File);
 
   m_module_sp = std::make_shared<Module>(m_file->moduleSpec());
-  auto &symfile = *llvm::cast<SymbolFileDWARF>(m_module_sp->GetSymbolFile());
+}
+
+size_t YAMLModuleTester::GetNumUnits() {
+  return llvm::cast<SymbolFileDWARF>(m_module_sp->GetSymbolFile())
+      ->DebugInfo()
+      .GetNumUnits();
+}
 
-  m_dwarf_unit = symfile.DebugInfo().GetUnitAtIndex(0);
+DWARFUnit *YAMLModuleTester::GetUnitAtIndex(size_t idx) {
+  return llvm::cast<SymbolFileDWARF>(m_module_sp->GetSymbolFile())
+      ->DebugInfo()
+      .GetUnitAtIndex(idx);
 }
Index: lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -67,7 +67,8 @@
 )";
 
   YAMLModuleTester t(yamldata);
-  DWARFUnit *dwarf_unit = t.GetDwarfUnit();
+  ASSERT_EQ(1u, t.GetNumUnits());
+  DWARFUnit *dwarf_unit = t.GetUnitAtIndex(0);
   auto *dwarf_cu = llvm::cast<DWARFCompileUnit>(dwarf_unit);
   ASSERT_TRUE(static_cast<bool>(dwarf_cu));
   SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -90,12 +90,12 @@
 )";
 
   YAMLModuleTester t(yamldata);
-  ASSERT_TRUE((bool)t.GetDwarfUnit());
+  ASSERT_EQ(1u, t.GetNumUnits());
 
   TypeSystemClang ast_ctx("dummy ASTContext", HostInfoBase::GetTargetTriple());
   DWARFASTParserClangStub ast_parser(ast_ctx);
 
-  DWARFUnit *unit = t.GetDwarfUnit();
+  DWARFUnit *unit = t.GetUnitAtIndex(0);
   const DWARFDebugInfoEntry *die_first = unit->DIE().GetDIE();
   const DWARFDebugInfoEntry *die_child0 = die_first->GetFirstChild();
   const DWARFDebugInfoEntry *die_child1 = die_child0->GetSibling();
Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===================================================================
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -54,8 +54,8 @@
 class DWARFExpressionTester : public YAMLModuleTester {
 public:
   using YAMLModuleTester::YAMLModuleTester;
-  llvm::Expected<Scalar> Eval(llvm::ArrayRef<uint8_t> expr) {
-    return ::Evaluate(expr, m_module_sp, m_dwarf_unit);
+  llvm::Expected<Scalar> Eval(llvm::ArrayRef<uint8_t> expr, DWARFUnit *unit) {
+    return ::Evaluate(expr, m_module_sp, unit);
   }
 };
 
@@ -86,7 +86,8 @@
   Machine: EM_386
 DWARF:
   debug_abbrev:
-    - Table:
+    - ID:    0
+      Table:
         - Code:            0x00000001
           Tag:             DW_TAG_compile_unit
           Children:        DW_CHILDREN_yes
@@ -104,50 +105,64 @@
   debug_info:
     - Version:         4
       AddrSize:        8
+      AbbrevTableID:   0
+      Entries:
+        - AbbrCode:        0x00000001
+          Values:
+            - Value:           0x000000000000000C
+        - AbbrCode:        0x00000002
+          Values:
+            - Value:           0x0000000000000007 # DW_ATE_unsigned
+            - Value:           0x0000000000000004
+        - AbbrCode:        0x00000000
+    - Version:         4
+      AddrSize:        8
+      AbbrevTableID:   0
       Entries:
         - AbbrCode:        0x00000001
           Values:
             - Value:           0x000000000000000C
-        # 0x0000000e:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x0000000000000007 # DW_ATE_unsigned
             - Value:           0x0000000000000004
-        # 0x00000011:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x0000000000000007 # DW_ATE_unsigned
             - Value:           0x0000000000000008
-        # 0x00000014:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x0000000000000005 # DW_ATE_signed
             - Value:           0x0000000000000008
-        # 0x00000017:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x0000000000000008 # DW_ATE_unsigned_char
             - Value:           0x0000000000000001
-        # 0x0000001a:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x0000000000000006 # DW_ATE_signed_char
             - Value:           0x0000000000000001
-        # 0x0000001d:
         - AbbrCode:        0x00000002
           Values:
             - Value:           0x000000000000000b # DW_ATE_numeric_string
             - Value:           0x0000000000000001
         - AbbrCode:        0x00000000
 )";
-  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);
-  ASSERT_TRUE((bool)t.GetDwarfUnit());
+  ASSERT_EQ(2u, t.GetNumUnits());
+  DWARFUnit *unit = t.GetUnitAtIndex(1);
+  DWARFDIE uint32_die = unit->DIE().GetFirstChild();
+  DWARFDIE uint64_die = uint32_die.GetSibling();
+  DWARFDIE sint64_die = uint64_die.GetSibling();
+  DWARFDIE uchar_die = sint64_die.GetSibling();
+  DWARFDIE schar_die = uchar_die.GetSibling();
+  DWARFDIE numeric_string_die = schar_die.GetSibling();
+  auto offset = [](DWARFDIE die) -> uint8_t {
+    dw_offset_t result = die.GetOffset() - die.GetCU()->GetOffset();
+    assert(result <= 0x7f);
+    return result;
+  };
 
   // Constant is given as little-endian.
   bool is_signed = true;
@@ -160,54 +175,62 @@
   // Truncate to default unspecified (pointer-sized) type.
   EXPECT_THAT_EXPECTED(
       t.Eval({DW_OP_const8u, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, //
-              DW_OP_convert, 0x00}),
+              DW_OP_convert, 0x00},
+             unit),
       llvm::HasValue(GetScalar(32, 0x44332211, not_signed)));
   // Truncate to 32 bits.
-  EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const8u, //
-                               0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,//
-                               DW_OP_convert, offs_uint32_t}),
-                       llvm::HasValue(GetScalar(32, 0x44332211, not_signed)));
+  EXPECT_THAT_EXPECTED(
+      t.Eval({DW_OP_const8u, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, //
+              DW_OP_convert, offset(uint32_die)},
+             unit),
+      llvm::HasValue(GetScalar(32, 0x44332211, not_signed)));
 
   // Leave as is.
   EXPECT_THAT_EXPECTED(
       t.Eval({DW_OP_const8u, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, //
-              DW_OP_convert, offs_uint64_t}),
+              DW_OP_convert, offset(uint64_die)},
+             unit),
       llvm::HasValue(GetScalar(64, 0x8877665544332211, not_signed)));
 
   // Sign-extend to 64 bits.
   EXPECT_THAT_EXPECTED(
       t.Eval({DW_OP_const4s, 0xcc, 0xdd, 0xee, 0xff, //
-              DW_OP_convert, offs_sint64_t}),
+              DW_OP_convert, offset(sint64_die)},
+             unit),
       llvm::HasValue(GetScalar(64, 0xffffffffffeeddcc, is_signed)));
 
   // Truncate to 8 bits.
-  EXPECT_THAT_EXPECTED(
-      t.Eval({DW_OP_const4s, 'A', 'B', 'C', 'D', DW_OP_convert, offs_uchar}),
-      llvm::HasValue(GetScalar(8, 'A', not_signed)));
+  EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4s, 'A', 'B', 'C', 'D', //
+                               DW_OP_convert, offset(uchar_die)},
+                              unit),
+                       llvm::HasValue(GetScalar(8, 'A', not_signed)));
 
   // Also truncate to 8 bits.
-  EXPECT_THAT_EXPECTED(
-      t.Eval({DW_OP_const4s, 'A', 'B', 'C', 'D', DW_OP_convert, offs_schar}),
-      llvm::HasValue(GetScalar(8, 'A', is_signed)));
+  EXPECT_THAT_EXPECTED(t.Eval({DW_OP_const4s, 'A', 'B', 'C', 'D', //
+                               DW_OP_convert, offset(schar_die)},
+                              unit),
+                       llvm::HasValue(GetScalar(8, 'A', is_signed)));
 
   //
   // Errors.
   //
 
   // No Module.
-  EXPECT_THAT_ERROR(Evaluate({DW_OP_const1s, 'X', DW_OP_convert, 0x00}, nullptr,
-                             t.GetDwarfUnit())
-                        .takeError(),
-                    llvm::Failed());
+  EXPECT_THAT_ERROR(
+      Evaluate({DW_OP_const1s, 'X', DW_OP_convert, 0x00}, nullptr, unit)
+          .takeError(),
+      llvm::Failed());
 
   // No DIE.
   EXPECT_THAT_ERROR(
-      t.Eval({DW_OP_const1s, 'X', DW_OP_convert, 0x01}).takeError(),
+      t.Eval({DW_OP_const1s, 'X', DW_OP_convert, 0x01}, unit).takeError(),
       llvm::Failed());
 
   // Unsupported.
   EXPECT_THAT_ERROR(
-      t.Eval({DW_OP_const1s, 'X', DW_OP_convert, 0x1d}).takeError(),
+      t.Eval({DW_OP_const1s, 'X', DW_OP_convert, offset(numeric_string_die)},
+             unit)
+          .takeError(),
       llvm::Failed());
 }
 
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -2387,7 +2387,8 @@
       } else {
         // Retrieve the type DIE that the value is being converted to.
         // 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(
+            dwarf_cu->GetOffset() + die_offset);
         if (!die) {
           if (error_ptr)
             error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE");
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to