This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][MIPS] Fix TestMiniDumpNew
ClosedPublic

Authored by nitesh.jain on Jan 27 2017, 12:11 AM.

Details

Summary

In case of a core file, if the core file architecture(like x86_64) is incompatible with that of Host architecture(like Mips64) then platform is set to remote-platform. If the remote-platform is not connected then SBPlatform::GetTriple() will return none. Hence we assume target platform is same as the host platform.

(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.

import lldb
dbg = lldb.SBDebugger.Create()
print dbg.GetSelectedPlatform().GetName()

host

print dbg.GetSelectedPlatform().GetTriple()

mips64el--linux-gnu

dbg.CreateTarget("linux-x86_64")

<lldb.SBTarget; proxy of <Swig Object of type 'lldb::SBTarget *' at 0x7f1fb4615390> >

print dbg.GetSelectedPlatform().GetName()

remote-linux

print dbg.GetSelectedPlatform().GetTriple()

None

print dbg.GetSelectedPlatform().IsConnected()

False

Diff Detail

Repository
rL LLVM

Event Timeline

nitesh.jain created this revision.Jan 27 2017, 12:11 AM
labath requested changes to this revision.Jan 27 2017, 1:38 AM

This seems like it's fixing the problem in the wrong place. Also, the assumption that the platform == host_platform is not correct (what about when the test is run on windows?)

I think we should either fix SBPlatform::GetTriple to return a correct triple (lldb already knows the triple since it has the core file. Whether that triple should be returned by the platform is a somewhat different question though) or make the test suite not depend on that.

I am confused as to why would this behavior occur only on mips hosts. I've seen the platform being set to remote-linux when the test is run from windows, and it works fine there. What is the actual error message you are getting?

This revision now requires changes to proceed.Jan 27 2017, 1:38 AM
nitesh.jain added a comment.EditedJan 27 2017, 1:47 AM

Hi Labath,

I think on window your host architecture is x86_64 hence when TargetList::CreateTargetInternal(..) is call, at line 269 the code is

if (!prefer_platform_arch && arch.IsValid()) {
  if (!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
    platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch);
    if (!is_dummy_target && platform_sp)
      debugger.GetPlatformList().SetSelectedPlatform(platform_sp);

The line platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch) will be true , if your host architecture is x86(which is your case). In our case since host architecture is Mips it will return false. hence Platform::GetPlatformForArchitecture(arch, &platform_arch) will set platform to remote-linux

ERROR: test_two_cores_same_pid (TestMiniDumpNew.MiniDumpNewTestCase)

Test that we handle the situation if we have two core files with the same PID

Traceback (most recent call last):

File "/export/tmp/nin/LLVM/llvm/tools/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1884, in setUp
  Base.setUp(self)
File "/export/tmp/nin/LLVM/llvm/tools/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 835, in setUp
  self.darwinWithFramework = self.platformIsDarwin()
File "/export/tmp/nin/LLVM/llvm/tools/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1300, in platformIsDarwin
  return lldbplatformutil.platformIsDarwin()
File "/export/tmp/nin/LLVM/llvm/tools/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py", line 140, in platformIsDarwin
  return getPlatform() in getDarwinOSTriples()
File "/export/tmp/nin/LLVM/llvm/tools/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py", line 130, in getPlatform
  platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2]

AttributeError: 'NoneType' object has no attribute 'split'

Ok, I've just checked and this does not happen on windows. It does however happen (GetTriple() returning None) when we try to open the s390x core file (functionalities/postmortem/elf-core/linux-s390x.out). The test suite seems to be handling it fine.

The only difference I see there is that the other test has a bit of setUp/tearDown code which saves and restores the original platform after each run. Can you check whether that will make things work for you ? (It's still not ideal, but at least it will be consistent with the other test).

As an alternative fix -- the checking of the *target* platform in the code which is throwing this exception seems to be a bug. "Whether we have an LLDB.framework" is a property of the host, not the target. Changing that would probably allow you to make progress here. (although it won't fix the underlying problem).

nitesh.jain edited edge metadata.

Added setUp/tearDown code, which saves and restores the original platform after each run. Thanks

clayborg accepted this revision.Jan 30 2017, 9:31 AM
labath accepted this revision.Jan 30 2017, 6:23 PM

I am glad we could come closer to the cause of the problem. At one point we should have a common base class for all core tests, so that we don't have to do this manually (and also avoid doing things that don't make sense for core files), but this will do for now.

This revision is now accepted and ready to land.Jan 30 2017, 6:23 PM
This revision was automatically updated to reflect the committed changes.