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

llvm-svn: 300836
This commit is contained in:
Pavel Labath 2017-04-20 12:30:18 +00:00
parent 7b46633c4b
commit 68e3886e57
6 changed files with 38 additions and 24 deletions

View File

@ -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;

View File

@ -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

View File

@ -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."""

View File

@ -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."""

View File

@ -834,19 +834,7 @@ lldb::ByteOrder ArchSpec::GetByteOrder() const {
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 &other) {
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 &rhs, bool exact_match) const {
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.

View File

@ -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());
}