LLDB now has "Platform" plug-ins. Platform plug-ins are plug-ins that provide
an interface to a local or remote debugging platform. By default each host OS
that supports LLDB should be registering a "default" platform that will be
used unless a new platform is selected. Platforms are responsible for things
such as:
- getting process information by name or by processs ID
- finding platform files. This is useful for remote debugging where there is
an SDK with files that might already or need to be cached for debug access.
- getting a list of platform supported architectures in the exact order they
should be selected. This helps the native x86 platform on MacOSX select the
correct x86_64/i386 slice from universal binaries.
- Connect to remote platforms for remote debugging
- Resolving an executable including finding an executable inside platform
specific bundles (macosx uses .app bundles that contain files) and also
selecting the appropriate slice of universal files for a given platform.
So by default there is always a local platform, but remote platforms can be
connected to. I will soon be adding a new "platform" command that will support
the following commands:
(lldb) platform connect --name machine1 macosx connect://host:port
Connected to "machine1" platform.
(lldb) platform disconnect macosx
This allows LLDB to be well setup to do remote debugging and also once
connected process listing and finding for things like:
(lldb) process attach --name x<TAB>
The currently selected platform plug-in can now auto complete any available
processes that start with "x". The responsibilities for the platform plug-in
will soon grow and expand.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@127286 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index cb6a3cf..37516ba 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -11,14 +11,16 @@
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Error.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/Endian.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Mutex.h"
+#include "lldb/Target/Process.h"
#include "llvm/Support/Host.h"
+#include "llvm/Support/MachO.h"
#include <dlfcn.h>
#include <errno.h>
@@ -1027,11 +1029,66 @@
return false;
}
-uint32_t
-Host::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids)
-{
- uint32_t num_matches = 0;
+#if defined (__APPLE__)
+static bool
+GetMacOSXProcessName (lldb::pid_t pid,
+ NameMatchType name_match_type,
+ const char *name_match,
+ ProcessInfo &proc_info)
+{
+ char process_name[MAXCOMLEN * 2 + 1];
+ int name_len = ::proc_name(pid, process_name, MAXCOMLEN * 2);
+ if (name_len == 0)
+ return false;
+
+ if (NameMatches(process_name, name_match_type, name_match))
+ {
+ proc_info.SetName (process_name);
+ return true;
+ }
+ else
+ {
+ proc_info.SetName (NULL);
+ return false;
+ }
+}
+
+
+static bool
+GetMacOSXProcessCPUType (lldb::pid_t pid, ProcessInfo &proc_info)
+{
+ // Make a new mib to stay thread safe
+ int mib[CTL_MAXNAME]={0,};
+ size_t mib_len = CTL_MAXNAME;
+ if (::sysctlnametomib("sysctl.proc_cputype", mib, &mib_len))
+ return false;
+
+ mib[mib_len] = pid;
+ mib_len++;
+
+ cpu_type_t cpu, sub;
+ size_t cpu_len = sizeof(cpu);
+ if (::sysctl (mib, mib_len, &cpu, &cpu_len, 0, 0) == 0)
+ {
+ switch (cpu)
+ {
+ case llvm::MachO::CPUTypeI386: sub = llvm::MachO::CPUSubType_I386_ALL; break;
+ case llvm::MachO::CPUTypeX86_64: sub = llvm::MachO::CPUSubType_X86_64_ALL; break;
+ default: break;
+ }
+ proc_info.GetArchitecture ().SetArchitecture (lldb::eArchTypeMachO, cpu, sub);
+ return true;
+ }
+ return false;
+}
+
+#endif
+
+uint32_t
+Host::FindProcessesByName (const char *name, NameMatchType name_match_type, ProcessInfoList &process_infos)
+{
+ process_infos.Clear();
#if defined (__APPLE__)
int num_pids;
int size_of_pids;
@@ -1064,56 +1121,35 @@
|| (bsd_info.pbi_status == SZOMB)
|| (bsd_info.pbi_pid == our_pid))
continue;
- char pid_name[MAXCOMLEN * 2 + 1];
- int name_len;
- name_len = proc_name(bsd_info.pbi_pid, pid_name, MAXCOMLEN * 2);
- if (name_len == 0)
- continue;
- if (strstr(pid_name, name) != pid_name)
- continue;
- matches.AppendString (pid_name);
- pids.push_back (bsd_info.pbi_pid);
- num_matches++;
+ ProcessInfo process_info;
+ if (GetMacOSXProcessName (bsd_info.pbi_pid, name_match_type, name, process_info))
+ {
+ process_info.SetProcessID (bsd_info.pbi_pid);
+ GetMacOSXProcessCPUType (bsd_info.pbi_pid, process_info);
+ process_infos.Append (process_info);
+ }
}
#endif
- return num_matches;
+ return process_infos.GetSize();
}
-ArchSpec
-Host::GetArchSpecForExistingProcess (lldb::pid_t pid)
+bool
+Host::GetProcessInfo (lldb::pid_t pid, ProcessInfo &process_info)
{
- ArchSpec return_spec;
-
#if defined (__APPLE__)
- struct proc_bsdinfo bsd_info;
- int error = proc_pidinfo (pid, PROC_PIDTBSDINFO, (uint64_t) 0, &bsd_info, PROC_PIDTBSDINFO_SIZE);
- if (error == 0)
- return return_spec;
- if (bsd_info.pbi_flags & PROC_FLAG_LP64)
- return_spec.SetTriple (LLDB_ARCH_DEFAULT_64BIT);
- else
- return_spec.SetTriple (LLDB_ARCH_DEFAULT_32BIT);
-#endif
-
- return return_spec;
-}
-ArchSpec
-Host::GetArchSpecForExistingProcess (const char *process_name)
-{
- ArchSpec returnSpec;
- StringList matches;
- std::vector<lldb::pid_t> pids;
- if (ListProcessesMatchingName(process_name, matches, pids))
+ if (GetMacOSXProcessName (pid, eNameMatchIgnore, NULL, process_info))
{
- if (matches.GetSize() == 1)
- {
- return GetArchSpecForExistingProcess(pids[0]);
- }
- }
- return returnSpec;
+ process_info.SetProcessID (pid);
+ if (GetMacOSXProcessCPUType (pid, process_info) == false)
+ process_info.GetArchitecture().Clear();
+ return true;
+ }
+#endif
+ process_info.Clear();
+ return false;
}
#if !defined (__APPLE__) // see macosx/Host.mm