[Lldb-commits] [lldb] r126974 - in /lldb/trunk: include/lldb/API/SBProcess.h include/lldb/API/SBTarget.h source/API/SBProcess.cpp source/API/SBTarget.cpp
James McIlree
jmcilree at apple.com
Thu Mar 3 16:31:13 PST 2011
Author: jmcilree
Date: Thu Mar 3 18:31:13 2011
New Revision: 126974
URL: http://llvm.org/viewvc/llvm-project?rev=126974&view=rev
Log:
Expose ConnectRemote API through SBTarget and SBProcess.
Patch verified by Greg Clayton prior to checkin.
Modified:
lldb/trunk/include/lldb/API/SBProcess.h
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/source/API/SBProcess.cpp
lldb/trunk/source/API/SBTarget.cpp
Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=126974&r1=126973&r2=126974&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Thu Mar 3 18:31:13 2011
@@ -72,6 +72,27 @@
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
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=126974&r1=126973&r2=126974&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Thu Mar 3 18:31:13 2011
@@ -179,6 +179,12 @@
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 ();
Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=126974&r1=126973&r2=126974&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Thu Mar 3 18:31:13 2011
@@ -95,6 +95,88 @@
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 ()
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=126974&r1=126973&r2=126974&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Thu Mar 3 18:31:13 2011
@@ -366,6 +366,41 @@
}
+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 ()
{
More information about the lldb-commits
mailing list