The first part of a fix for being able to select an architecture slice from

a file when the target has a triple with an unknown vendor and/or OS and the
slice of the file itself has a valid vendor and/or OS.

The Module now adopts the ObjectFile's architecture after a valid architecture
has been loaded to make sure the module matches the object file.

llvm-svn: 140236
This commit is contained in:
Greg Clayton 2011-09-21 03:57:31 +00:00
parent 11ab5f8a02
commit 593577a13a
4 changed files with 54 additions and 14 deletions

View File

@ -99,12 +99,6 @@
ReferencedContainer = "container:lldb.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "/Volumes/work/gclayton/Documents/src/args/a.out"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "LLDB_LAUNCH_FLAG_DISABLE_ASLR"

View File

@ -538,7 +538,9 @@ ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t su
{
m_core = core_def->core;
update_triple = false;
m_triple.setArch (core_def->machine);
// Always use the architecture name because it might be more descriptive
// than the architecture enum ("armv7" -> llvm::Triple::arm).
m_triple.setArchName(llvm::StringRef(core_def->name));
if (arch_type == eArchTypeMachO)
{
m_triple.setVendor (llvm::Triple::Apple);
@ -549,6 +551,9 @@ ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t su
m_triple.setVendor (llvm::Triple::UnknownVendor);
m_triple.setOS (llvm::Triple::UnknownOS);
}
// Fall back onto setting the machine type if the arch by name failed...
if (m_triple.getArch () == llvm::Triple::UnknownArch)
m_triple.setArch (core_def->machine);
}
}
}
@ -665,13 +670,38 @@ lldb_private::operator== (const ArchSpec& lhs, const ArchSpec& rhs)
{
const llvm::Triple &lhs_triple = lhs.GetTriple();
const llvm::Triple &rhs_triple = rhs.GetTriple();
if (lhs_triple.getVendor() != rhs_triple.getVendor()
|| lhs_triple.getOS() != rhs_triple.getOS()
|| lhs_triple.getArch() != rhs_triple.getArch()
|| lhs_triple.getEnvironment() != rhs_triple.getEnvironment())
return false;
else
return true;
const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
if (lhs_triple_vendor != rhs_triple_vendor)
{
// Only fail if both vendor types are not unknown
if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
rhs_triple_vendor != llvm::Triple::UnknownVendor)
return false;
}
const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
if (lhs_triple_os != rhs_triple_os)
{
// Only fail if both os types are not unknown
if (lhs_triple_os != llvm::Triple::UnknownOS &&
rhs_triple_os != llvm::Triple::UnknownOS)
return false;
}
const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
if (lhs_triple_env != rhs_triple_env)
{
// Only fail if both environment types are not unknown
if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
rhs_triple_env != llvm::Triple::UnknownEnvironment)
return false;
}
return true;
}
}

View File

@ -637,6 +637,13 @@ Module::GetObjectFile()
Timer scoped_timer(__PRETTY_FUNCTION__,
"Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
m_objfile_sp = ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize());
if (m_objfile_sp)
{
// Once we get the object file, update our module with the object file's
// architecture since it might differ in vendor/os if some parts were
// unknown.
m_objfile_sp->GetArchitecture (m_arch);
}
}
return m_objfile_sp.get();
}

View File

@ -1792,6 +1792,15 @@ ObjectFileMachO::GetArchitecture (ArchSpec &arch)
{
lldb_private::Mutex::Locker locker(m_mutex);
arch.SetArchitecture (eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
// Files with type MH_PRELOAD are currently used in cases where the image
// debugs at the addresses in the file itself. Below we set the OS to
// unknown to make sure we use the DynamicLoaderStatic()...
if (m_header.filetype == HeaderFileTypePreloadedExecutable)
{
arch.GetTriple().setOS (llvm::Triple::UnknownOS);
}
return true;
}