[Lldb-commits] [lldb] r151344 - in /lldb/trunk: include/lldb/API/SBFileSpec.h include/lldb/API/SBTarget.h include/lldb/Target/Process.h include/lldb/lldb-forward.h scripts/Python/interface/SBTarget.i source/API/SBProcess.cpp source/API/SBTarget.cpp

Greg Clayton gclayton at apple.com
Thu Feb 23 21:03:03 PST 2012


Author: gclayton
Date: Thu Feb 23 23:03:03 2012
New Revision: 151344

URL: http://llvm.org/viewvc/llvm-project?rev=151344&view=rev
Log:
Added the new way we will eventually do all attaches and launches. First clients
will fill out either a SBLaunchInfo or SBAttachInfo class, then call:

SBProcess SBTarget::Launch (SBLaunchInfo &, SBError &);
SBProcess SBTarget::Attach (SBAttachInfo &, SBError &);

The attach is working right now and allows the ability to set many filters such
as the parent process ID, the user/group ID, the effective user/group ID, and much
more.

The launch is not yet working, but I will get this working soon. By changing our
launch and attach calls to take an object, it allows us to add more capabilities to
launching and attaching without having to have launch and attach functions that
take more and more arguments. 

Once this is all working we will deprecated the older launch and attach fucntions
and eventually remove them.


Modified:
    lldb/trunk/include/lldb/API/SBFileSpec.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/include/lldb/lldb-forward.h
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/source/API/SBProcess.cpp
    lldb/trunk/source/API/SBTarget.cpp

Modified: lldb/trunk/include/lldb/API/SBFileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpec.h?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFileSpec.h (original)
+++ lldb/trunk/include/lldb/API/SBFileSpec.h Thu Feb 23 23:03:03 2012
@@ -55,10 +55,12 @@
     GetDescription (lldb::SBStream &description) const;
 
 private:
+    friend class SBAttachInfo;
     friend class SBBlock;
     friend class SBCompileUnit;
     friend class SBFileSpecList;
     friend class SBHostOS;
+    friend class SBLaunchInfo;
     friend class SBLineEntry;
     friend class SBModule;
     friend class SBProcess;

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Thu Feb 23 23:03:03 2012
@@ -20,7 +20,206 @@
 
 namespace lldb {
 
-class SBBreakpoint;
+class SBLaunchInfo
+{
+public:
+    SBLaunchInfo ();
+    
+    SBLaunchInfo (const char *executable_path, 
+                  const char *triple, 
+                  const char **argv);
+    
+    lldb::SBFileSpec
+    GetExecutable ();
+    
+    void
+    SetExecutable (const char *path);
+    
+    void
+    SetExecutable (lldb::SBFileSpec executable);
+    
+    uint32_t
+    GetUserID();
+    
+    uint32_t
+    GetGroupID();
+    
+    bool
+    UserIDIsValid ();
+    
+    bool
+    GroupIDIsValid ();
+    
+    void
+    SetUserID (uint32_t uid);
+    
+    void
+    SetGroupID (uint32_t gid);
+    
+    const char *
+    GetTriple ();
+    
+    void
+    SetTriple (const char *triple);
+    
+    uint32_t
+    GetNumArguments ();
+    
+    const char *
+    GetArgumentAtIndex (uint32_t idx);
+    
+    void
+    SetArguments (const char **argv, bool append);
+    
+    uint32_t
+    GetNumEnvironmentEntries ();
+    
+    const char *
+    GetEnvironmentEntryAtIndex (uint32_t idx);
+    
+    void
+    SetEnvironmentEntries (const char **envp, bool append);
+    
+    void
+    Clear ();
+    
+    const char *
+    GetWorkingDirectory () const;
+    
+    void
+    SetWorkingDirectory (const char *working_dir);
+    
+    uint32_t
+    GetLaunchFlags ();
+    
+    void
+    SetLaunchFlags (uint32_t flags);
+    
+    const char *
+    GetProcessPluginName ();
+    
+    void
+    SetProcessPluginName (const char *plugin_name);
+    
+    const char *
+    GetShell ();
+    
+    void
+    SetShell (const char * path);
+    
+    uint32_t
+    GetResumeCount ();
+    
+    void
+    SetResumeCount (uint32_t c);
+    
+    bool
+    AddCloseFileAction (int fd);
+    
+    bool
+    AddDuplicateFileAction (int fd, int dup_fd);
+    
+    bool
+    AddOpenFileAction (int fd, const char *path, bool read, bool write);
+    
+    bool
+    AddSuppressFileAction (int fd, bool read, bool write);
+    
+protected:
+    friend class SBTarget;
+    
+    lldb_private::ProcessLaunchInfo &
+    ref ()
+    {
+        return *m_opaque_sp;
+    }
+
+    ProcessLaunchInfoSP m_opaque_sp;
+};
+
+class SBAttachInfo
+{
+public:
+    SBAttachInfo ();
+    
+    SBAttachInfo (lldb::pid_t pid);
+    
+    SBAttachInfo (const char *path, bool wait_for);
+    
+    SBAttachInfo (const SBAttachInfo &rhs);
+    
+    SBAttachInfo &
+    operator = (const SBAttachInfo &rhs);
+    
+    lldb::pid_t
+    GetProcessID ();
+    
+    void
+    SetProcessID (lldb::pid_t pid);
+    
+    void
+    SetExecutable (const char *path);
+    
+    void
+    SetExecutable (lldb::SBFileSpec exe_file);
+    
+    bool
+    GetWaitForLaunch ();
+    
+    void
+    SetWaitForLaunch (bool b);
+    
+    uint32_t
+    GetResumeCount ();
+    
+    void
+    SetResumeCount (uint32_t c);
+    
+    const char *
+    GetProcessPluginName ();
+    
+    void
+    SetProcessPluginName (const char *plugin_name);
+    
+    uint32_t
+    GetEffectiveUserID();
+    
+    uint32_t
+    GetEffectiveGroupID();
+    
+    bool
+    EffectiveUserIDIsValid ();
+    
+    bool
+    EffectiveGroupIDIsValid ();
+    
+    void
+    SetEffectiveUserID (uint32_t uid);
+    
+    void
+    SetEffectiveGroupID (uint32_t gid);
+    
+    lldb::pid_t
+    GetParentProcessID ();
+    
+    void
+    SetParentProcessID (lldb::pid_t pid);
+    
+    bool
+    ParentProcessIDIsValid();
+    
+    
+protected:
+    friend class SBTarget;
+
+    lldb_private::ProcessAttachInfo &
+    ref ()
+    {
+        return *m_opaque_sp;
+    }
+    
+    ProcessAttachInfoSP m_opaque_sp;
+};
 
 class SBTarget
 {
@@ -154,11 +353,17 @@
     /// @return
     ///      A process object for the newly created process.
     //------------------------------------------------------------------
-    lldb::SBProcess
+    SBProcess
     LaunchSimple (const char **argv, 
                   const char **envp,
                   const char *working_directory);
     
+    SBProcess
+    Launch (SBLaunchInfo &launch_info, SBError& error);
+
+    SBProcess
+    Attach (SBAttachInfo &attach_info, SBError& error);
+
     //------------------------------------------------------------------
     /// Attach to process with pid.
     ///

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Thu Feb 23 23:03:03 2012
@@ -570,7 +570,7 @@
     }
 
     bool
-    AppendDuplciateFileAction (int fd, int dup_fd)
+    AppendDuplicateFileAction (int fd, int dup_fd)
     {
         FileAction file_action;
         if (file_action.Duplicate (fd, dup_fd))

Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Thu Feb 23 23:03:03 2012
@@ -267,6 +267,8 @@
     typedef std::tr1::shared_ptr<lldb_private::OptionValue> OptionValueSP;
     typedef std::tr1::shared_ptr<lldb_private::Platform> PlatformSP;
     typedef std::tr1::shared_ptr<lldb_private::Process> ProcessSP;
+    typedef std::tr1::shared_ptr<lldb_private::ProcessAttachInfo> ProcessAttachInfoSP;
+    typedef std::tr1::shared_ptr<lldb_private::ProcessLaunchInfo> ProcessLaunchInfoSP;
     typedef std::tr1::weak_ptr<lldb_private::Process> ProcessWP;
     typedef std::tr1::shared_ptr<lldb_private::RegisterContext> RegisterContextSP;
     typedef std::tr1::shared_ptr<lldb_private::RegularExpression> RegularExpressionSP;

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Thu Feb 23 23:03:03 2012
@@ -9,6 +9,182 @@
 
 namespace lldb {
 
+class SBLaunchInfo
+{
+    public:
+    SBLaunchInfo ();
+    
+    SBLaunchInfo (const char *executable_path, 
+                  const char *triple, 
+                  const char **argv);
+    
+    lldb::SBFileSpec
+    GetExecutable ();
+    
+    void
+    SetExecutable (const char *path);
+    
+    void
+    SetExecutable (lldb::SBFileSpec executable);
+    
+    uint32_t
+    GetUserID();
+    
+    uint32_t
+    GetGroupID();
+    
+    bool
+    UserIDIsValid ();
+    
+    bool
+    GroupIDIsValid ();
+    
+    void
+    SetUserID (uint32_t uid);
+    
+    void
+    SetGroupID (uint32_t gid);
+    
+    const char *
+    GetTriple ();
+    
+    void
+    SetTriple (const char *triple);
+    
+    uint32_t
+    GetNumArguments ();
+    
+    const char *
+    GetArgumentAtIndex (uint32_t idx);
+    
+    void
+    SetArguments (const char **argv, bool append);
+    
+    uint32_t
+    GetNumEnvironmentEntries ();
+    
+    const char *
+    GetEnvironmentEntryAtIndex (uint32_t idx);
+    
+    void
+    SetEnvironmentEntries (const char **envp, bool append);
+    
+    void
+    Clear ();
+    
+    const char *
+    GetWorkingDirectory () const;
+    
+    void
+    SetWorkingDirectory (const char *working_dir);
+    
+    uint32_t
+    GetLaunchFlags ();
+    
+    void
+    SetLaunchFlags (uint32_t flags);
+    
+    const char *
+    GetProcessPluginName ();
+    
+    void
+    SetProcessPluginName (const char *plugin_name);
+    
+    const char *
+    GetShell ();
+    
+    void
+    SetShell (const char * path);
+    
+    uint32_t
+    GetResumeCount ();
+    
+    void
+    SetResumeCount (uint32_t c);
+    
+    bool
+    AddCloseFileAction (int fd);
+    
+    bool
+    AddDuplicateFileAction (int fd, int dup_fd);
+    
+    bool
+    AddOpenFileAction (int fd, const char *path, bool read, bool write);
+    
+    bool
+    AddSuppressFileAction (int fd, bool read, bool write);
+};
+
+class SBAttachInfo
+{
+public:
+    SBAttachInfo ();
+    
+    SBAttachInfo (lldb::pid_t pid);
+    
+    SBAttachInfo (const char *path, bool wait_for);
+    
+    SBAttachInfo (const lldb::SBAttachInfo &rhs);
+    
+    lldb::pid_t
+    GetProcessID ();
+    
+    void
+    SetProcessID (lldb::pid_t pid);
+    
+    void
+    SetExecutable (const char *path);
+    
+    void
+    SetExecutable (lldb::SBFileSpec exe_file);
+    
+    bool
+    GetWaitForLaunch ();
+    
+    void
+    SetWaitForLaunch (bool b);
+    
+    uint32_t
+    GetResumeCount ();
+    
+    void
+    SetResumeCount (uint32_t c);
+    
+    const char *
+    GetProcessPluginName ();
+    
+    void
+    SetProcessPluginName (const char *plugin_name);
+    
+    uint32_t
+    GetEffectiveUserID();
+    
+    uint32_t
+    GetEffectiveGroupID();
+    
+    bool
+    EffectiveUserIDIsValid ();
+    
+    bool
+    EffectiveGroupIDIsValid ();
+    
+    void
+    SetEffectiveUserID (uint32_t uid);
+    
+    void
+    SetEffectiveGroupID (uint32_t gid);
+    
+    lldb::pid_t
+    GetParentProcessID ();
+    
+    void
+    SetParentProcessID (lldb::pid_t pid);
+    
+    bool
+    ParentProcessIDIsValid();
+};
+    
+    
 %feature("docstring",
 "Represents the target program running under the debugger.
 
@@ -205,6 +381,13 @@
                   const char **envp,
                   const char *working_directory);
     
+    lldb::SBProcess
+    Launch (lldb::SBLaunchInfo &launch_info, lldb::SBError& error);
+    
+    lldb::SBProcess
+    Attach (lldb::SBAttachInfo &attach_info, lldb::SBError& error);
+    
+
     %feature("docstring", "
     //------------------------------------------------------------------
     /// Attach to process with pid.

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Thu Feb 23 23:03:03 2012
@@ -26,9 +26,10 @@
 // Project includes
 
 #include "lldb/API/SBBroadcaster.h"
-#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBCommandReturnObject.h"
+#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBEvent.h"
+#include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBThread.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBStringList.h"
@@ -37,7 +38,6 @@
 using namespace lldb_private;
 
 
-
 SBProcess::SBProcess () :
     m_opaque_sp()
 {

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=151344&r1=151343&r2=151344&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Thu Feb 23 23:03:03 2012
@@ -54,6 +54,414 @@
 
 #define DEFAULT_DISASM_BYTE_SIZE 32
 
+
+
+SBLaunchInfo::SBLaunchInfo () : 
+m_opaque_sp(new ProcessLaunchInfo())
+{
+}
+
+SBLaunchInfo::SBLaunchInfo (const char *path, const char *triple, const char **argv) : 
+m_opaque_sp(new ProcessLaunchInfo())
+{
+    SetExecutable(path);
+    if (triple && triple[0])
+        m_opaque_sp->GetArchitecture().SetTriple(triple, NULL);
+    if (argv)
+        SetArguments(argv, false);
+}
+
+SBFileSpec
+SBLaunchInfo::GetExecutable ()
+{
+    SBFileSpec exe_file;
+    exe_file.SetFileSpec (m_opaque_sp->GetExecutableFile());
+    return exe_file;
+}
+
+void
+SBLaunchInfo::SetExecutable (const char *path)
+{
+    if (path && path[0])
+        m_opaque_sp->GetExecutableFile().SetFile(path, false);
+    else
+        m_opaque_sp->GetExecutableFile().Clear();
+}
+
+void
+SBLaunchInfo::SetExecutable (SBFileSpec exe_file)
+{
+    if (exe_file.IsValid())
+        m_opaque_sp->GetExecutableFile() = exe_file.ref();
+    else
+        m_opaque_sp->GetExecutableFile().Clear();
+}
+
+uint32_t
+SBLaunchInfo::GetUserID()
+{
+    return m_opaque_sp->GetUserID();
+}
+
+uint32_t
+SBLaunchInfo::GetGroupID()
+{
+    return m_opaque_sp->GetGroupID();
+}
+
+bool
+SBLaunchInfo::UserIDIsValid ()
+{
+    return m_opaque_sp->UserIDIsValid();
+}
+
+bool
+SBLaunchInfo::GroupIDIsValid ()
+{
+    return m_opaque_sp->GroupIDIsValid();
+}
+
+void
+SBLaunchInfo::SetUserID (uint32_t uid)
+{
+    m_opaque_sp->SetUserID (uid);
+}
+
+void
+SBLaunchInfo::SetGroupID (uint32_t gid)
+{
+    m_opaque_sp->SetGroupID (gid);
+}
+
+const char *
+SBLaunchInfo::GetTriple ()
+{
+    const ArchSpec &arch = m_opaque_sp->GetArchitecture();
+    if (arch.IsValid())
+    {
+        std::string triple (arch.GetTriple().str());
+        if (!triple.empty())
+        {
+            // Unique the string so we don't run into ownership issues since
+            // the const strings put the string into the string pool once and
+            // the strings never comes out
+            ConstString const_triple (triple.c_str());
+            return const_triple.GetCString();
+        }
+    }
+    return NULL;
+}
+
+void
+SBLaunchInfo::SetTriple (const char *triple)
+{
+    m_opaque_sp->GetArchitecture().SetTriple(triple, NULL);
+}
+
+uint32_t
+SBLaunchInfo::GetNumArguments ()
+{
+    return m_opaque_sp->GetArguments().GetArgumentCount();
+}
+
+const char *
+SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
+{
+    return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
+}
+
+void
+SBLaunchInfo::SetArguments (const char **argv, bool append)
+{
+    if (append)
+    {
+        if (argv)
+            m_opaque_sp->GetArguments().AppendArguments(argv);
+    }
+    else
+    {
+        if (argv)
+            m_opaque_sp->GetArguments().SetArguments(argv);
+        else
+            m_opaque_sp->GetArguments().Clear();
+    }
+}
+
+uint32_t
+SBLaunchInfo::GetNumEnvironmentEntries ()
+{
+    return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
+}
+
+const char *
+SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
+{
+    return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
+}
+
+void
+SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
+{
+    if (append)
+    {
+        if (envp)
+            m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
+    }
+    else
+    {
+        if (envp)
+            m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
+        else
+            m_opaque_sp->GetEnvironmentEntries().Clear();
+    }
+}
+
+void
+SBLaunchInfo::Clear ()
+{
+    m_opaque_sp->Clear();
+}
+
+const char *
+SBLaunchInfo::GetWorkingDirectory () const
+{
+    return m_opaque_sp->GetWorkingDirectory();
+}
+
+void
+SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
+{
+    m_opaque_sp->SetWorkingDirectory(working_dir);
+}
+
+uint32_t
+SBLaunchInfo::GetLaunchFlags ()
+{
+    return m_opaque_sp->GetFlags().Get();
+}
+
+void
+SBLaunchInfo::SetLaunchFlags (uint32_t flags)
+{
+    m_opaque_sp->GetFlags().Reset(flags);
+}
+
+const char *
+SBLaunchInfo::GetProcessPluginName ()
+{
+    return m_opaque_sp->GetProcessPluginName();
+}
+
+void
+SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
+{
+    return m_opaque_sp->SetProcessPluginName (plugin_name);
+}
+
+const char *
+SBLaunchInfo::GetShell ()
+{
+    return m_opaque_sp->GetShell();
+}
+
+void
+SBLaunchInfo::SetShell (const char * path)
+{
+    m_opaque_sp->SetShell (path);
+}
+
+uint32_t
+SBLaunchInfo::GetResumeCount ()
+{
+    return m_opaque_sp->GetResumeCount();
+}
+
+void
+SBLaunchInfo::SetResumeCount (uint32_t c)
+{
+    m_opaque_sp->SetResumeCount (c);
+}
+
+bool
+SBLaunchInfo::AddCloseFileAction (int fd)
+{
+    return m_opaque_sp->AppendCloseFileAction(fd);
+}
+
+bool
+SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
+{
+    return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
+}
+
+bool
+SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
+{
+    return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
+}
+
+bool
+SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
+{
+    return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
+}
+
+
+SBAttachInfo::SBAttachInfo () :
+m_opaque_sp (new ProcessAttachInfo())
+{
+}
+
+SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
+m_opaque_sp (new ProcessAttachInfo())
+{
+    m_opaque_sp->SetProcessID (pid);
+}
+
+SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
+m_opaque_sp (new ProcessAttachInfo())
+{
+    if (path && path[0])
+        m_opaque_sp->GetExecutableFile().SetFile(path, false);
+    m_opaque_sp->SetWaitForLaunch (wait_for);
+}
+
+SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
+m_opaque_sp (new ProcessAttachInfo())
+{
+    *m_opaque_sp = *rhs.m_opaque_sp;
+}
+
+SBAttachInfo &
+SBAttachInfo::operator = (const SBAttachInfo &rhs)
+{
+    if (this != &rhs)
+        *m_opaque_sp = *rhs.m_opaque_sp;
+    return *this;
+}
+
+lldb::pid_t
+SBAttachInfo::GetProcessID ()
+{
+    return m_opaque_sp->GetProcessID();
+}
+
+void
+SBAttachInfo::SetProcessID (lldb::pid_t pid)
+{
+    m_opaque_sp->SetProcessID (pid);
+}
+
+
+uint32_t
+SBAttachInfo::GetResumeCount ()
+{
+    return m_opaque_sp->GetResumeCount();
+}
+
+void
+SBAttachInfo::SetResumeCount (uint32_t c)
+{
+    m_opaque_sp->SetResumeCount (c);
+}
+
+const char *
+SBAttachInfo::GetProcessPluginName ()
+{
+    return m_opaque_sp->GetProcessPluginName();
+}
+
+void
+SBAttachInfo::SetProcessPluginName (const char *plugin_name)
+{
+    return m_opaque_sp->SetProcessPluginName (plugin_name);
+}
+
+void
+SBAttachInfo::SetExecutable (const char *path)
+{
+    if (path && path[0])
+        m_opaque_sp->GetExecutableFile().SetFile(path, false);
+    else
+        m_opaque_sp->GetExecutableFile().Clear();
+}
+
+void
+SBAttachInfo::SetExecutable (SBFileSpec exe_file)
+{
+    if (exe_file.IsValid())
+        m_opaque_sp->GetExecutableFile() = exe_file.ref();
+    else
+        m_opaque_sp->GetExecutableFile().Clear();
+}
+
+bool
+SBAttachInfo::GetWaitForLaunch ()
+{
+    return m_opaque_sp->GetWaitForLaunch();
+}
+
+void
+SBAttachInfo::SetWaitForLaunch (bool b)
+{
+    m_opaque_sp->SetWaitForLaunch (b);
+}
+
+uint32_t
+SBAttachInfo::GetEffectiveUserID()
+{
+    return m_opaque_sp->GetEffectiveUserID();
+}
+
+uint32_t
+SBAttachInfo::GetEffectiveGroupID()
+{
+    return m_opaque_sp->GetEffectiveGroupID();
+}
+
+bool
+SBAttachInfo::EffectiveUserIDIsValid ()
+{
+    return m_opaque_sp->EffectiveUserIDIsValid();
+}
+
+bool
+SBAttachInfo::EffectiveGroupIDIsValid ()
+{
+    return m_opaque_sp->EffectiveGroupIDIsValid ();
+}
+
+void
+SBAttachInfo::SetEffectiveUserID (uint32_t uid)
+{
+    m_opaque_sp->SetEffectiveUserID(uid);
+}
+
+void
+SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
+{
+    m_opaque_sp->SetEffectiveGroupID(gid);
+}
+
+lldb::pid_t
+SBAttachInfo::GetParentProcessID ()
+{
+    return m_opaque_sp->GetParentProcessID();
+}
+
+void
+SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
+{
+    m_opaque_sp->SetParentProcessID (pid);
+}
+
+bool
+SBAttachInfo::ParentProcessIDIsValid()
+{
+    return m_opaque_sp->ParentProcessIDIsValid();
+}
+
+
 //----------------------------------------------------------------------
 // SBTarget constructor
 //----------------------------------------------------------------------
@@ -295,6 +703,142 @@
     return sb_process;
 }
 
+SBProcess
+SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
+{
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    
+    SBProcess sb_process;
+    ProcessSP process_sp;
+    TargetSP target_sp(GetSP());
+    
+    if (log)
+    {
+        log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
+    }
+    
+    if (target_sp)
+    {
+        Mutex::Locker api_locker (target_sp->GetAPIMutex());
+        StateType state = eStateInvalid;
+        process_sp = target_sp->GetProcessSP();
+        if (process_sp)
+        {
+            state = process_sp->GetState();
+            
+            if (process_sp->IsAlive() && state != eStateConnected)
+            {       
+                if (state == eStateAttaching)
+                    error.SetErrorString ("process attach is in progress");
+                else
+                    error.SetErrorString ("a process is already being debugged");
+                return sb_process;
+            }            
+        }
+        
+        if (state != eStateConnected)
+            process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
+        
+        if (process_sp)
+        {
+            sb_process.SetSP (process_sp);
+            lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
+            error.SetError (process_sp->Launch (launch_info));
+            if (error.Success())
+            {
+                // We we are stopping at the entry point, we can return now!
+                if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
+                    return sb_process;
+                
+                // Make sure we are stopped at the entry
+                StateType state = process_sp->WaitForProcessToStop (NULL);
+                if (state == eStateStopped)
+                {
+                    // resume the process to skip the entry point
+                    error.SetError (process_sp->Resume());
+                    if (error.Success())
+                    {
+                        // If we are doing synchronous mode, then wait for the
+                        // process to stop yet again!
+                        if (target_sp->GetDebugger().GetAsyncExecution () == false)
+                            process_sp->WaitForProcessToStop (NULL);
+                    }
+                }
+            }
+        }
+        else
+        {
+            error.SetErrorString ("unable to create lldb_private::Process");
+        }
+    }
+    else
+    {
+        error.SetErrorString ("SBTarget is invalid");
+    }
+    
+    log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
+    if (log)
+    {
+        log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", 
+                     target_sp.get(), process_sp.get());
+    }
+    
+    return sb_process;
+}
+
+lldb::SBProcess
+SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
+{
+    SBProcess sb_process;
+    ProcessSP process_sp;
+    TargetSP target_sp(GetSP());
+    if (target_sp)
+    {
+        Mutex::Locker api_locker (target_sp->GetAPIMutex());
+        
+        StateType state = eStateInvalid;
+        process_sp = target_sp->GetProcessSP();
+        if (process_sp)
+        {
+            state = process_sp->GetState();
+            
+            if (process_sp->IsAlive() && state != eStateConnected)
+            {       
+                if (state == eStateAttaching)
+                    error.SetErrorString ("process attach is in progress");
+                else
+                    error.SetErrorString ("a process is already being debugged");
+                return sb_process;
+            }            
+        }
+        
+        if (state != eStateConnected)
+            process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
+
+        if (process_sp)
+        {
+            sb_process.SetSP (process_sp);
+            
+            ProcessAttachInfo &attach_info = sb_attach_info.ref();
+            error.SetError (process_sp->Attach (attach_info));            
+            // If we are doing synchronous mode, then wait for the
+            // process to stop!
+            if (target_sp->GetDebugger().GetAsyncExecution () == false)
+                process_sp->WaitForProcessToStop (NULL);
+        }
+        else
+        {
+            error.SetErrorString ("unable to create lldb_private::Process");
+        }
+    }
+    else
+    {
+        error.SetErrorString ("SBTarget is invalid");
+    }
+    return sb_process;
+}
+
+
 #if defined(__APPLE__)
 
 lldb::SBProcess





More information about the lldb-commits mailing list