[Lldb-commits] [lldb] r300836 - Recompute ArchSpec core after MergeFrom

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 20 05:30:20 PDT 2017


Author: labath
Date: Thu Apr 20 07:30:18 2017
New Revision: 300836

URL: http://llvm.org/viewvc/llvm-project?rev=300836&view=rev
Log:
Recompute ArchSpec core after MergeFrom

Summary:
MergeFrom was updating the architecture if the target triple did not
have it set. However, it was leaving the core field as invalid. This
resulted in assertion failures in core file tests as a missing core
meant we were unable to compute the address byte size properly.

Add a unit test for the new behaviour.

Reviewers: jingham, clayborg

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D32221

Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/TestGCore.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/unittests/Core/ArchSpecTest.cpp

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Thu Apr 20 07:30:18 2017
@@ -625,6 +625,7 @@ public:
 
 protected:
   bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
+  void UpdateCore();
 
   llvm::Triple m_triple;
   Core m_core = kCore_invalid;

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py Thu Apr 20 07:30:18 2017
@@ -39,7 +39,6 @@ class LinuxCoreTestCase(TestBase):
         super(LinuxCoreTestCase, self).tearDown()
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_i386(self):
         """Test that lldb can read the process information from an i386 linux core file."""
@@ -58,21 +57,18 @@ class LinuxCoreTestCase(TestBase):
         self.do_test("linux-mips64el-gnuabi64", self._mips64_n64_pid, self._mips_regions)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_x86_64(self):
         """Test that lldb can read the process information from an x86_64 linux core file."""
         self.do_test("linux-x86_64", self._x86_64_pid, self._x86_64_regions)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_s390x(self):
         """Test that lldb can read the process information from an s390x linux core file."""
         self.do_test("linux-s390x", self._s390x_pid, self._s390x_regions)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_same_pid_running(self):
         """Test that we read the information from the core correctly even if we have a running
@@ -102,7 +98,6 @@ class LinuxCoreTestCase(TestBase):
             self.RemoveTempFile("linux-x86_64-pid.core")
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_two_cores_same_pid(self):
         """Test that we handle the situation if we have two core files with the same PID
@@ -132,7 +127,6 @@ class LinuxCoreTestCase(TestBase):
         self.do_test("linux-x86_64", self._x86_64_pid, self._x86_64_regions)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_FPR_SSE(self):
         # check x86_64 core file

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/TestGCore.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/TestGCore.py?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/TestGCore.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/TestGCore.py Thu Apr 20 07:30:18 2017
@@ -23,14 +23,12 @@ class GCoreTestCase(TestBase):
     _x86_64_pid = 5669
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_i386(self):
         """Test that lldb can read the process information from an i386 linux core file."""
         self.do_test("linux-i386", self._i386_pid)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_x86_64(self):
         """Test that lldb can read the process information from an x86_64 linux core file."""

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py Thu Apr 20 07:30:18 2017
@@ -27,14 +27,12 @@ class LinuxCoreThreadsTestCase(TestBase)
     _x86_64_tid = 5250
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_i386(self):
         """Test that lldb can read the process information from an i386 linux core file."""
         self.do_test("linux-i386", self._i386_pid, self._i386_tid)
 
     @skipIf(oslist=['windows'])
-    @skipIfDarwin # <rdar://problem/31380097>, fails started happening with r299199
     @skipIf(triple='^mips')
     def test_x86_64(self):
         """Test that lldb can read the process information from an x86_64 linux core file."""

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Thu Apr 20 07:30:18 2017
@@ -834,19 +834,7 @@ lldb::ByteOrder ArchSpec::GetByteOrder()
 
 bool ArchSpec::SetTriple(const llvm::Triple &triple) {
   m_triple = triple;
-
-  llvm::StringRef arch_name(m_triple.getArchName());
-  const CoreDefinition *core_def = FindCoreDefinition(arch_name);
-  if (core_def) {
-    m_core = core_def->core;
-    // Set the byte order to the default byte order for an architecture.
-    // This can be modified if needed for cases when cores handle both
-    // big and little endian
-    m_byte_order = core_def->default_byte_order;
-  } else {
-    Clear();
-  }
-
+  UpdateCore();
   return IsValid();
 }
 
@@ -994,8 +982,10 @@ void ArchSpec::MergeFrom(const ArchSpec
     GetTriple().setVendor(other.GetTriple().getVendor());
   if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown())
     GetTriple().setOS(other.GetTriple().getOS());
-  if (GetTriple().getArch() == llvm::Triple::UnknownArch)
+  if (GetTriple().getArch() == llvm::Triple::UnknownArch) {
     GetTriple().setArch(other.GetTriple().getArch());
+    UpdateCore();
+  }
   if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
       !TripleVendorWasSpecified()) {
     if (other.TripleVendorWasSpecified())
@@ -1190,6 +1180,20 @@ bool ArchSpec::IsEqualTo(const ArchSpec
   return false;
 }
 
+void ArchSpec::UpdateCore() {
+  llvm::StringRef arch_name(m_triple.getArchName());
+  const CoreDefinition *core_def = FindCoreDefinition(arch_name);
+  if (core_def) {
+    m_core = core_def->core;
+    // Set the byte order to the default byte order for an architecture.
+    // This can be modified if needed for cases when cores handle both
+    // big and little endian
+    m_byte_order = core_def->default_byte_order;
+  } else {
+    Clear();
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Helper methods.
 

Modified: lldb/trunk/unittests/Core/ArchSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/ArchSpecTest.cpp?rev=300836&r1=300835&r2=300836&view=diff
==============================================================================
--- lldb/trunk/unittests/Core/ArchSpecTest.cpp (original)
+++ lldb/trunk/unittests/Core/ArchSpecTest.cpp Thu Apr 20 07:30:18 2017
@@ -134,3 +134,22 @@ TEST(ArchSpecTest, TestSetTriple) {
   AS = ArchSpec();
   EXPECT_FALSE(AS.SetTriple(""));
 }
+
+TEST(ArchSpecTest, MergeFrom) {
+  ArchSpec A;
+  ArchSpec B("x86_64-pc-linux");
+
+  EXPECT_FALSE(A.IsValid());
+  ASSERT_TRUE(B.IsValid());
+  EXPECT_EQ(llvm::Triple::ArchType::x86_64, B.GetTriple().getArch());
+  EXPECT_EQ(llvm::Triple::VendorType::PC, B.GetTriple().getVendor());
+  EXPECT_EQ(llvm::Triple::OSType::Linux, B.GetTriple().getOS());
+  EXPECT_EQ(ArchSpec::eCore_x86_64_x86_64, B.GetCore());
+
+  A.MergeFrom(B);
+  ASSERT_TRUE(A.IsValid());
+  EXPECT_EQ(llvm::Triple::ArchType::x86_64, A.GetTriple().getArch());
+  EXPECT_EQ(llvm::Triple::VendorType::PC, A.GetTriple().getVendor());
+  EXPECT_EQ(llvm::Triple::OSType::Linux, A.GetTriple().getOS());
+  EXPECT_EQ(ArchSpec::eCore_x86_64_x86_64, A.GetCore());
+}




More information about the lldb-commits mailing list