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/Commands/CommandObjectFile.cpp b/source/Commands/CommandObjectFile.cpp
index 50f3394..fa62bad 100644
--- a/source/Commands/CommandObjectFile.cpp
+++ b/source/Commands/CommandObjectFile.cpp
@@ -138,9 +138,8 @@
TargetSP target_sp;
- ArchSpec arch = m_options.m_arch;
Debugger &debugger = m_interpreter.GetDebugger();
- Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_options.m_arch, NULL, true, target_sp);
+ Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_options.m_arch, true, target_sp);
if (target_sp)
{
diff --git a/source/Commands/CommandObjectProcess.cpp b/source/Commands/CommandObjectProcess.cpp
index 9b2b2a4..0dbc9b8 100644
--- a/source/Commands/CommandObjectProcess.cpp
+++ b/source/Commands/CommandObjectProcess.cpp
@@ -18,8 +18,9 @@
#include "lldb/Core/State.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "./CommandObjectThread.h"
+#include "CommandObjectThread.h"
#include "lldb/Host/Host.h"
+#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -518,38 +519,24 @@
// Look to see if there is a -P argument provided, and if so use that plugin, otherwise
// use the default plugin.
- Process *process = interpeter.GetDebugger().GetExecutionContext().process;
- bool need_to_delete_process = false;
const char *partial_name = NULL;
partial_name = input.GetArgumentAtIndex(opt_arg_pos);
-
- if (process && process->IsAlive())
- return true;
-
- Target *target = interpeter.GetDebugger().GetSelectedTarget().get();
- if (target == NULL)
+
+ PlatformSP platform_sp (Platform::GetSelectedPlatform ());
+ if (platform_sp)
{
- // No target has been set yet, for now do host completion. Otherwise I don't know how we would
- // figure out what the right target to use is...
- std::vector<lldb::pid_t> pids;
- Host::ListProcessesMatchingName (partial_name, matches, pids);
- return true;
- }
- if (!process)
- {
- process = target->CreateProcess (interpeter.GetDebugger().GetListener(), partial_name).get();
- need_to_delete_process = true;
- }
-
- if (process)
- {
- matches.Clear();
- std::vector<lldb::pid_t> pids;
- process->ListProcessesMatchingName (NULL, matches, pids);
- if (need_to_delete_process)
- target->DeleteCurrentProcess();
- return true;
+ ProcessInfoList process_infos;
+ platform_sp->FindProcessesByName (partial_name, partial_name ? lldb::eNameMatchStartsWith : lldb::eNameMatchIgnore, process_infos);
+ const uint32_t num_matches = process_infos.GetSize();
+ if (num_matches > 0)
+ {
+ for (uint32_t i=0; i<num_matches; ++i)
+ {
+ matches.AppendString (process_infos.GetProcessNameAtIndex(i),
+ process_infos.GetProcessNameLengthAtIndex(i));
+ }
+ }
}
}
@@ -612,7 +599,6 @@
error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
emptyFileSpec,
emptyArchSpec,
- NULL,
false,
new_target_sp);
target = new_target_sp.get();
@@ -716,17 +702,19 @@
if (attach_pid == LLDB_INVALID_PROCESS_ID && wait_name != NULL)
{
- std::vector<lldb::pid_t> pids;
- StringList matches;
-
- process->ListProcessesMatchingName(wait_name, matches, pids);
- if (matches.GetSize() > 1)
+ ProcessInfoList process_infos;
+ PlatformSP platform_sp (Platform::GetSelectedPlatform ());
+ if (platform_sp)
+ {
+ platform_sp->FindProcessesByName (wait_name, eNameMatchEquals, process_infos);
+ }
+ if (process_infos.GetSize() > 1)
{
result.AppendErrorWithFormat("More than one process named %s\n", wait_name);
result.SetStatus (eReturnStatusFailed);
return false;
}
- else if (matches.GetSize() == 0)
+ else if (process_infos.GetSize() == 0)
{
result.AppendErrorWithFormat("Could not find a process named %s\n", wait_name);
result.SetStatus (eReturnStatusFailed);
@@ -734,9 +722,8 @@
}
else
{
- attach_pid = pids[0];
+ attach_pid = process_infos.GetProcessIDAtIndex (0);
}
-
}
if (attach_pid != LLDB_INVALID_PROCESS_ID)
@@ -1085,7 +1072,6 @@
error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
emptyFileSpec,
emptyArchSpec,
- NULL,
false,
target_sp);
if (!target_sp || error.Fail())