summaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectProcess.cpp
diff options
context:
space:
mode:
authorTamas Berghammer <tberghammer@google.com>2015-12-08 14:08:19 +0000
committerTamas Berghammer <tberghammer@google.com>2015-12-08 14:08:19 +0000
commitccd6cffba3545bec41864b0c3fa4ca7cc3e854c5 (patch)
tree47ae8040ff8d1ce1485f2789a848bd181403c605 /lldb/source/Commands/CommandObjectProcess.cpp
parent59d092f883a44c35822f3038128a11452801c7a4 (diff)
Modify "platform connect" to connect to processes as well
The standard remote debugging workflow with gdb is to start the application on the remote host under gdbserver (e.g.: gdbserver :5039 a.out) and then connect to it with gdb. The same workflow is supported by debugserver/lldb-gdbserver with a very similar syntax but to access all features of lldb we need to be connected also to an lldb-platform instance running on the target. Before this change this had to be done manually with starting a separate lldb-platform on the target machine and then connecting to it with lldb before connecting to the process. This change modifies the behavior of "platform connect" with automatically connecting to the process instance if it was started by the remote platform. With this command replacing gdbserver in a gdb based worflow is usually as simple as replacing the command to execute gdbserver with executing lldb-platform. Differential revision: http://reviews.llvm.org/D14952 llvm-svn: 255016
Diffstat (limited to 'lldb/source/Commands/CommandObjectProcess.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp90
1 files changed, 29 insertions, 61 deletions
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index 293b762295f2..b7f894f6dcf5 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -1051,78 +1051,46 @@ protected:
bool
DoExecute (Args& command, CommandReturnObject &result) override
{
-
- TargetSP target_sp (m_interpreter.GetDebugger().GetSelectedTarget());
- Error error;
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process)
+ if (command.GetArgumentCount() != 1)
{
- if (process->IsAlive())
- {
- result.AppendErrorWithFormat ("Process %" PRIu64 " is currently being debugged, kill the process before connecting.\n",
- process->GetID());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n",
+ m_cmd_name.c_str(),
+ m_cmd_syntax.c_str());
+ result.SetStatus (eReturnStatusFailed);
+ return false;
}
+
- if (!target_sp)
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive())
{
- // If there isn't a current target create one.
-
- error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
- NULL,
- NULL,
- false,
- NULL, // No platform options
- target_sp);
- if (!target_sp || error.Fail())
- {
- result.AppendError(error.AsCString("Error creating target"));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target_sp.get());
+ result.AppendErrorWithFormat ("Process %" PRIu64 " is currently being debugged, kill the process before connecting.\n",
+ process->GetID());
+ result.SetStatus (eReturnStatusFailed);
+ return false;
}
-
- if (command.GetArgumentCount() == 1)
- {
- const char *plugin_name = NULL;
- if (!m_options.plugin_name.empty())
- plugin_name = m_options.plugin_name.c_str();
- const char *remote_url = command.GetArgumentAtIndex(0);
- process = target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
-
- if (process)
- {
- error = process->ConnectRemote (process->GetTarget().GetDebugger().GetOutputFile().get(), remote_url);
+ const char *plugin_name = nullptr;
+ if (!m_options.plugin_name.empty())
+ plugin_name = m_options.plugin_name.c_str();
- if (error.Fail())
- {
- result.AppendError(error.AsCString("Remote connect failed"));
- result.SetStatus (eReturnStatusFailed);
- target_sp->DeleteCurrentProcess();
- return false;
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Unable to find process plug-in for remote URL '%s'.\nPlease specify a process plug-in name with the --plugin option, or specify an object file using the \"file\" command.\n",
- remote_url);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
+ Error error;
+ Debugger& debugger = m_interpreter.GetDebugger();
+ PlatformSP platform_sp = m_interpreter.GetPlatform(true);
+ ProcessSP process_sp = platform_sp->ConnectProcess(command.GetArgumentAtIndex(0),
+ plugin_name,
+ debugger,
+ debugger.GetSelectedTarget().get(),
+ error);
+ if (error.Fail() || process_sp == nullptr)
{
- result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n",
- m_cmd_name.c_str(),
- m_cmd_syntax.c_str());
+ result.AppendError(error.AsCString("Error connecting to the process"));
result.SetStatus (eReturnStatusFailed);
+ return false;
}
- return result.Succeeded();
+ return true;
}
-
+
CommandOptions m_options;
};