Change Target & Process so they can really be initialized with an invalid architecture.
Arrange that this then gets properly set on attach, or when a "file" is set.
Add a completer for "process attach -n".
Caveats: there isn't currently a way to handle multiple processes with the same name. That
will have to wait on a way to pass annotations along with the completion strings.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@110624 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index fdff5ad..c8ed3c5 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -373,6 +373,10 @@
m_images.Append(executable_sp); // The first image is our exectuable file
ArchSpec exe_arch = executable_sp->GetArchitecture();
+ // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
+ if (!m_arch_spec.IsValid())
+ m_arch_spec = exe_arch;
+
FileSpecList dependent_files;
ObjectFile * executable_objfile = executable_sp->GetObjectFile();
if (executable_objfile == NULL)
@@ -426,17 +430,62 @@
ArchSpec
Target::GetArchitecture () const
{
- ArchSpec arch;
- if (m_images.GetSize() > 0)
- {
- Module *exe_module = m_images.GetModulePointerAtIndex(0);
- if (exe_module)
- arch = exe_module->GetArchitecture();
- }
- return arch;
+ return m_arch_spec;
}
-
+bool
+Target::SetArchitecture (const ArchSpec &arch_spec)
+{
+ if (m_arch_spec == arch_spec)
+ {
+ // If we're setting the architecture to our current architecture, we
+ // don't need to do anything.
+ return true;
+ }
+ else if (!m_arch_spec.IsValid())
+ {
+ // If we haven't got a valid arch spec, then we just need to set it.
+ m_arch_spec = arch_spec;
+ return true;
+ }
+ else
+ {
+ // If we have an executable file, try to reset the executable to the desired architecture
+ m_arch_spec = arch_spec;
+ ModuleSP executable_sp = GetExecutableModule ();
+ m_images.Clear();
+ m_scratch_ast_context_ap.reset();
+ m_triple.Clear();
+ // Need to do something about unsetting breakpoints.
+
+ if (executable_sp)
+ {
+ FileSpec exec_file_spec = executable_sp->GetFileSpec();
+ Error error = ModuleList::GetSharedModule(exec_file_spec,
+ arch_spec,
+ NULL,
+ NULL,
+ 0,
+ executable_sp,
+ NULL,
+ NULL);
+
+ if (!error.Fail() && executable_sp)
+ {
+ SetExecutableModule (executable_sp, true);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
bool
Target::GetTargetTriple(ConstString &triple)