summaryrefslogtreecommitdiffstats
path: root/lldb/source/Target
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2010-08-09 23:31:02 +0000
committerJim Ingham <jingham@apple.com>2010-08-09 23:31:02 +0000
commit5aee162f978eac7ffb6363d25b193e51edfbc0b1 (patch)
treeaffe5547d828a14a967f9b5deff564248940554b /lldb/source/Target
parent394a69ed528c403248c6354baeedaf0533b33afc (diff)
downloadbcm5719-llvm-5aee162f978eac7ffb6363d25b193e51edfbc0b1.tar.gz
bcm5719-llvm-5aee162f978eac7ffb6363d25b193e51edfbc0b1.zip
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. llvm-svn: 110624
Diffstat (limited to 'lldb/source/Target')
-rw-r--r--lldb/source/Target/Process.cpp57
-rw-r--r--lldb/source/Target/StopInfo.cpp2
-rw-r--r--lldb/source/Target/Target.cpp65
-rw-r--r--lldb/source/Target/TargetList.cpp59
4 files changed, 154 insertions, 29 deletions
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9f5c42a73f6..148eabe1ea3 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1048,6 +1048,24 @@ Process::CompleteAttach ()
if (state == eStateStopped || state == eStateCrashed)
{
DidAttach ();
+ // Figure out which one is the executable, and set that in our target:
+ ModuleList &modules = GetTarget().GetImages();
+
+ size_t num_modules = modules.GetSize();
+ for (int i = 0; i < num_modules; i++)
+ {
+ ModuleSP module_sp = modules.GetModuleAtIndex(i);
+ if (module_sp->IsExecutable())
+ {
+ ModuleSP exec_module = GetTarget().GetExecutableModule();
+ if (!exec_module || exec_module != module_sp)
+ {
+
+ GetTarget().SetExecutableModule (module_sp, false);
+ }
+ break;
+ }
+ }
// This delays passing the stopped event to listeners till DidLaunch gets
// a chance to complete...
@@ -1073,6 +1091,16 @@ Process::Attach (lldb::pid_t attach_pid)
m_target_triple.Clear();
m_abi_sp.reset();
+ // Find the process and its architecture. Make sure it matches the architecture
+ // of the current Target, and if not adjust it.
+
+ ArchSpec attach_spec = GetArchSpecForExistingProcess (attach_pid);
+ if (attach_spec != GetTarget().GetArchitecture())
+ {
+ // Set the architecture on the target.
+ GetTarget().SetArchitecture(attach_spec);
+ }
+
Error error (WillAttachToProcessWithID(attach_pid));
if (error.Success())
{
@@ -1102,6 +1130,16 @@ Process::Attach (const char *process_name, bool wait_for_launch)
{
m_target_triple.Clear();
m_abi_sp.reset();
+
+ // Find the process and its architecture. Make sure it matches the architecture
+ // of the current Target, and if not adjust it.
+
+ ArchSpec attach_spec = GetArchSpecForExistingProcess (process_name);
+ if (attach_spec != GetTarget().GetArchitecture())
+ {
+ // Set the architecture on the target.
+ GetTarget().SetArchitecture(attach_spec);
+ }
Error error (WillAttachToProcessWithName(process_name, wait_for_launch));
if (error.Success())
@@ -1863,3 +1901,22 @@ Process::GetObjCObjectPrinter()
return m_objc_object_printer;
}
+uint32_t
+Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids)
+{
+ return 0;
+}
+
+ArchSpec
+Process::GetArchSpecForExistingProcess (lldb::pid_t pid)
+{
+ return Host::GetArchSpecForExistingProcess (pid);
+}
+
+ArchSpec
+Process::GetArchSpecForExistingProcess (const char *process_name)
+{
+ return Host::GetArchSpecForExistingProcess (process_name);
+}
+
+
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index 9d48e8188d4..54fc6daeaf7 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -79,7 +79,7 @@ public:
&m_thread.GetProcess(),
&m_thread,
m_thread.GetStackFrameAtIndex(0).get(),
- false);
+ true);
m_should_stop = bp_site_sp->ShouldStop (&context);
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index fdff5ad3818..c8ed3c568c4 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -373,6 +373,10 @@ Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
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,18 +430,63 @@ Target::GetImages ()
ArchSpec
Target::GetArchitecture () const
{
- ArchSpec arch;
- if (m_images.GetSize() > 0)
+ return m_arch_spec;
+}
+
+bool
+Target::SetArchitecture (const ArchSpec &arch_spec)
+{
+ if (m_arch_spec == arch_spec)
{
- Module *exe_module = m_images.GetModulePointerAtIndex(0);
- if (exe_module)
- arch = exe_module->GetArchitecture();
+ // 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;
+ }
}
- return arch;
}
-
-
bool
Target::GetTargetTriple(ConstString &triple)
{
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 4e2952ec0a3..ac169465e28 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -60,30 +60,50 @@ TargetList::CreateTarget
file.GetFilename().AsCString(),
arch.AsCString(),
uuid_ptr);
- ModuleSP exe_module_sp;
- FileSpec resolved_file(file);
- if (!Host::ResolveExecutableInBundle (&resolved_file))
- resolved_file = file;
-
- Error error = ModuleList::GetSharedModule(resolved_file,
- arch,
- uuid_ptr,
- NULL,
- 0,
- exe_module_sp,
- NULL,
- NULL);
- if (exe_module_sp)
+ Error error;
+
+ if (!file)
{
target_sp.reset(new Target(debugger));
- target_sp->SetExecutableModule (exe_module_sp, get_dependent_files);
+ target_sp->SetArchitecture(arch);
+ }
+ else
+ {
+ ModuleSP exe_module_sp;
+ FileSpec resolved_file(file);
+ if (!Host::ResolveExecutableInBundle (&resolved_file))
+ resolved_file = file;
- if (target_sp.get())
+ error = ModuleList::GetSharedModule(resolved_file,
+ arch,
+ uuid_ptr,
+ NULL,
+ 0,
+ exe_module_sp,
+ NULL,
+ NULL);
+ if (exe_module_sp)
{
- Mutex::Locker locker(m_target_list_mutex);
- m_current_target_idx = m_target_list.size();
- m_target_list.push_back(target_sp);
+ if (exe_module_sp->GetObjectFile() == NULL)
+ {
+ error.SetErrorStringWithFormat("%s%s%s: doesn't contain architecture %s",
+ file.GetDirectory().AsCString(),
+ file.GetDirectory() ? "/" : "",
+ file.GetFilename().AsCString(),
+ arch.AsCString());
+ return error;
+ }
+ target_sp.reset(new Target(debugger));
+ target_sp->SetExecutableModule (exe_module_sp, get_dependent_files);
}
+ }
+
+ if (target_sp.get())
+ {
+ Mutex::Locker locker(m_target_list_mutex);
+ m_current_target_idx = m_target_list.size();
+ m_target_list.push_back(target_sp);
+ }
// target_sp.reset(new Target);
// // Let the target resolve any funky bundle paths before we try and get
@@ -107,7 +127,6 @@ TargetList::CreateTarget
// m_target_list.push_back(target_sp);
// }
// }
- }
else
{
target_sp.reset();
OpenPOWER on IntegriCloud