diff options
| -rw-r--r-- | lldb/include/lldb/API/SBProcess.h | 21 | ||||
| -rw-r--r-- | lldb/include/lldb/API/SBTarget.h | 6 | ||||
| -rw-r--r-- | lldb/source/API/SBProcess.cpp | 82 | ||||
| -rw-r--r-- | lldb/source/API/SBTarget.cpp | 35 |
4 files changed, 144 insertions, 0 deletions
diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 342a7b34398..20eb7720f03 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -72,6 +72,27 @@ public: AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result); //------------------------------------------------------------------ + // Remote connection related functions. These will fail if the + // process is not in eStateConnected. They are intended for use + // when connecting to an externally managed debugserver instance. + //------------------------------------------------------------------ + bool + RemoteAttachToProcessWithID (lldb::pid_t pid, + lldb::SBError& error); + + // See SBTarget.Launch for argument description and usage. + bool + RemoteLaunch (char const **argv, + char const **envp, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_directory, + uint32_t launch_flags, + bool stop_at_entry, + lldb::SBError& error); + + //------------------------------------------------------------------ // Thread related functions //------------------------------------------------------------------ uint32_t diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 56d1f36e07e..05ffa5ac826 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -179,6 +179,12 @@ public: bool wait_for, // if true wait for a new instance of "name" to be launched lldb::SBError& error); // An error explaining what went wrong if attach fails + lldb::SBProcess + ConnectRemote (SBListener &listener, + const char *url, + const char *plugin_name, // Can be NULL + SBError& error); + lldb::SBFileSpec GetExecutable (); diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index b56df41ac05..4566f76687f 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -95,6 +95,88 @@ SBProcess::IsValid() const return m_opaque_sp.get() != NULL; } +bool +SBProcess::RemoteLaunch (char const **argv, + char const **envp, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_directory, + uint32_t launch_flags, + bool stop_at_entry, + lldb::SBError& error) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) { + log->Printf ("SBProcess(%p)::RemoteLaunch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", + m_opaque_sp.get(), + argv, + envp, + stdin_path ? stdin_path : "NULL", + stdout_path ? stdout_path : "NULL", + stderr_path ? stderr_path : "NULL", + working_directory ? working_directory : "NULL", + launch_flags, + stop_at_entry, + error.get()); + } + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + if (m_opaque_sp->GetState() == eStateConnected) + { + error.SetError (m_opaque_sp->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory)); + } + else + { + error.SetErrorString ("must be in eStateConnected to call RemoteLaunch"); + } + } + else + { + error.SetErrorString ("unable to attach pid"); + } + + if (log) { + SBStream sstr; + error.GetDescription (sstr); + log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", error.get(), sstr.GetData()); + } + + return error.Success(); +} + +bool +SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) +{ + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + if (m_opaque_sp->GetState() == eStateConnected) + { + error.SetError (m_opaque_sp->Attach (pid)); + } + else + { + error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID"); + } + } + else + { + error.SetErrorString ("unable to attach pid"); + } + + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) { + SBStream sstr; + error.GetDescription (sstr); + log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%d) => SBError (%p): %s", error.get(), sstr.GetData()); + } + + return error.Success(); +} + uint32_t SBProcess::GetNumThreads () diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 7358a386946..d1a1f275e33 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -366,6 +366,41 @@ SBTarget::AttachToProcessWithName } +lldb::SBProcess +SBTarget::ConnectRemote +( + SBListener &listener, + const char *url, + const char *plugin_name, + SBError& error +) +{ + SBProcess sb_process; + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + if (listener.IsValid()) + sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name)); + else + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name)); + + + if (sb_process.IsValid()) + { + error.SetError (sb_process->ConnectRemote (url)); + } + else + { + error.SetErrorString ("unable to create lldb_private::Process"); + } + } + else + { + error.SetErrorString ("SBTarget is invalid"); + } + return sb_process; +} + SBFileSpec SBTarget::GetExecutable () { |

