[Lldb-commits] [lldb] r144061 - in /lldb/trunk: include/lldb/Target/Process.h include/lldb/Target/Target.h source/Commands/CommandObjectPlatform.cpp source/Commands/CommandObjectProcess.cpp source/Commands/CommandObjectSettings.cpp source/Host/macosx/Host.mm source/Target/Process.cpp source/Target/Target.cpp test/api/check_public_api_headers/TestPublicAPIHeaders.py test/functionalities/load_unload/TestLoadUnload.py test/settings/TestSettings.py tools/driver/Driver.cpp

Greg Clayton gclayton at apple.com
Mon Nov 7 18:43:14 PST 2011


Author: gclayton
Date: Mon Nov  7 20:43:13 2011
New Revision: 144061

URL: http://llvm.org/viewvc/llvm-project?rev=144061&view=rev
Log:
Moved many of the "settings" that used to be in "target.process.*" to just
be in the target. All of the environment, args, stdin/out/err files, etc have
all been moved. Also re-enabled the ability to launch a process in a separate
terminal on MacOSX.


Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Commands/CommandObjectPlatform.cpp
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Commands/CommandObjectSettings.cpp
    lldb/trunk/source/Host/macosx/Host.mm
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
    lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py
    lldb/trunk/test/settings/TestSettings.py
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Nov  7 20:43:13 2011
@@ -79,111 +79,6 @@
                               Error *err);
 
 
-    const Args &
-    GetRunArguments () const
-    {
-        return m_run_args;
-    }
-
-    void
-    SetRunArguments (const Args &args)
-    {
-        m_run_args = args;
-    }
-
-    void
-    GetHostEnvironmentIfNeeded ();
-
-    size_t
-    GetEnvironmentAsArgs (Args &env);
-
-    const char *
-    GetStandardInputPath () const
-    {
-        if (m_input_path.empty())
-            return NULL;
-        return m_input_path.c_str();
-    }
-
-    void
-    SetStandardInputPath (const char *path)
-    {
-        if (path && path[0])
-            m_input_path.assign (path);
-        else
-        {
-            // Make sure we deallocate memory in string...
-            std::string tmp;
-            tmp.swap (m_input_path);
-        }
-    }
-
-    const char *
-    GetStandardOutputPath () const
-    {
-        if (m_output_path.empty())
-            return NULL;
-        return m_output_path.c_str();
-    }
-
-    void
-    SetStandardOutputPath (const char *path)
-    {
-        if (path && path[0])
-            m_output_path.assign (path);
-        else
-        {
-            // Make sure we deallocate memory in string...
-            std::string tmp;
-            tmp.swap (m_output_path);
-        }
-    }
-
-    const char *
-    GetStandardErrorPath () const
-    {
-        if (m_error_path.empty())
-            return NULL;
-        return m_error_path.c_str();
-    }
-
-    void
-    SetStandardErrorPath (const char *path)
-    {
-        if (path && path[0])
-            m_error_path.assign (path);
-        else
-        {
-            // Make sure we deallocate memory in string...
-            std::string tmp;
-            tmp.swap (m_error_path);
-        }
-    }
-    
-    bool
-    GetDisableASLR () const
-    {
-        return m_disable_aslr;
-    }
-    
-    void
-    SetDisableASLR (bool b)
-    {
-        m_disable_aslr = b;
-    }
-    
-    bool
-    GetDisableSTDIO () const
-    {
-        return m_disable_stdio;
-    }
-    
-    void
-    SetDisableSTDIO (bool b)
-    {
-        m_disable_stdio = b;
-    }
-
 protected:
 
     void
@@ -192,43 +87,6 @@
 
     const ConstString
     CreateInstanceName ();
-
-    static const ConstString &
-    RunArgsVarName ();
-
-    static const ConstString &
-    EnvVarsVarName ();
-
-    static const ConstString &
-    InheritHostEnvVarName ();
-
-    static const ConstString &
-    InputPathVarName ();
-
-    static const ConstString &
-    OutputPathVarName ();
-
-    static const ConstString &
-    ErrorPathVarName ();
-
-    static const ConstString &
-    DisableASLRVarName();
-
-    static const ConstString &
-    DisableSTDIOVarName ();
-    
-private:
-
-    typedef std::map<std::string, std::string> dictionary;
-    Args m_run_args;
-    dictionary m_env_vars;
-    std::string m_input_path;
-    std::string m_output_path;
-    std::string m_error_path;
-    bool m_disable_aslr;
-    bool m_disable_stdio;
-    bool m_inherit_host_env;
-    bool m_got_host_env;
 };
 
 //----------------------------------------------------------------------
@@ -677,43 +535,63 @@
         if (working_directory)
             SetWorkingDirectory(working_directory);        
     }
+
     void
     AppendFileAction (const FileAction &info)
     {
         m_file_actions.push_back(info);
     }
 
-    void
+    bool
     AppendCloseFileAction (int fd)
     {
         FileAction file_action;
-        file_action.Close (fd);
-        AppendFileAction (file_action);
+        if (file_action.Close (fd))
+        {
+            AppendFileAction (file_action);
+            return true;
+        }
+        return false;
     }
 
-    void
+    bool
     AppendDuplciateFileAction (int fd, int dup_fd)
     {
         FileAction file_action;
-        file_action.Duplicate (fd, dup_fd);
-        AppendFileAction (file_action);
+        if (file_action.Duplicate (fd, dup_fd))
+        {
+            AppendFileAction (file_action);
+            return true;
+        }
+        return false;
     }
 
-    void
+    bool
     AppendOpenFileAction (int fd, const char *path, bool read, bool write)
     {
         FileAction file_action;
-        file_action.Open (fd, path, read, write);
-        AppendFileAction (file_action);
+        if (file_action.Open (fd, path, read, write))
+        {
+            AppendFileAction (file_action);
+            return true;
+        }
+        return false;
     }
 
-    void
+    bool
     AppendSuppressFileAction (int fd, bool read, bool write)
     {
         FileAction file_action;
-        file_action.Open (fd, "/dev/null", read, write);
-        AppendFileAction (file_action);
+        if (file_action.Open (fd, "/dev/null", read, write))
+        {
+            AppendFileAction (file_action);
+            return true;
+        }
+        return false;
     }
+    
+    void
+    FinalizeFileActions (Target *target, Process *process);
 
     size_t
     GetNumFileActions () const

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Nov  7 20:43:13 2011
@@ -25,6 +25,7 @@
 #include "lldb/Core/UserSettingsController.h"
 #include "lldb/Core/SourceManager.h"
 #include "lldb/Expression/ClangPersistentVariables.h"
+#include "lldb/Interpreter/Args.h"
 #include "lldb/Interpreter/NamedOptionValue.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Target/ABI.h"
@@ -102,6 +103,113 @@
     {
         return m_breakpoints_use_platform_avoid;
     }
+    
+    
+    const Args &
+    GetRunArguments () const
+    {
+        return m_run_args;
+    }
+    
+    void
+    SetRunArguments (const Args &args)
+    {
+        m_run_args = args;
+    }
+    
+    void
+    GetHostEnvironmentIfNeeded ();
+    
+    size_t
+    GetEnvironmentAsArgs (Args &env);
+    
+    const char *
+    GetStandardInputPath () const
+    {
+        if (m_input_path.empty())
+            return NULL;
+        return m_input_path.c_str();
+    }
+    
+    void
+    SetStandardInputPath (const char *path)
+    {
+        if (path && path[0])
+            m_input_path.assign (path);
+        else
+        {
+            // Make sure we deallocate memory in string...
+            std::string tmp;
+            tmp.swap (m_input_path);
+        }
+    }
+    
+    const char *
+    GetStandardOutputPath () const
+    {
+        if (m_output_path.empty())
+            return NULL;
+        return m_output_path.c_str();
+    }
+    
+    void
+    SetStandardOutputPath (const char *path)
+    {
+        if (path && path[0])
+            m_output_path.assign (path);
+        else
+        {
+            // Make sure we deallocate memory in string...
+            std::string tmp;
+            tmp.swap (m_output_path);
+        }
+    }
+    
+    const char *
+    GetStandardErrorPath () const
+    {
+        if (m_error_path.empty())
+            return NULL;
+        return m_error_path.c_str();
+    }
+    
+    void
+    SetStandardErrorPath (const char *path)
+    {
+        if (path && path[0])
+            m_error_path.assign (path);
+        else
+        {
+            // Make sure we deallocate memory in string...
+            std::string tmp;
+            tmp.swap (m_error_path);
+        }
+    }
+    
+    bool
+    GetDisableASLR () const
+    {
+        return m_disable_aslr;
+    }
+    
+    void
+    SetDisableASLR (bool b)
+    {
+        m_disable_aslr = b;
+    }
+    
+    bool
+    GetDisableSTDIO () const
+    {
+        return m_disable_stdio;
+    }
+    
+    void
+    SetDisableSTDIO (bool b)
+    {
+        m_disable_stdio = b;
+    }
+
 
 protected:
 
@@ -114,13 +222,23 @@
     
     OptionValueFileSpec m_expr_prefix_file;
     lldb::DataBufferSP m_expr_prefix_contents_sp;
-    int                m_prefer_dynamic_value;
+    int m_prefer_dynamic_value;
     OptionValueBoolean m_skip_prologue;
     PathMappingList m_source_map;
     uint32_t m_max_children_display;
     uint32_t m_max_strlen_length;
     OptionValueBoolean m_breakpoints_use_platform_avoid;
-    
+    typedef std::map<std::string, std::string> dictionary;
+    Args m_run_args;
+    dictionary m_env_vars;
+    std::string m_input_path;
+    std::string m_output_path;
+    std::string m_error_path;
+    bool m_disable_aslr;
+    bool m_disable_stdio;
+    bool m_inherit_host_env;
+    bool m_got_host_env;
+
 
 };
 

Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Mon Nov  7 20:43:13 2011
@@ -374,17 +374,21 @@
             Error error;
             const uint32_t argc = args.GetArgumentCount();
             Target *target = m_interpreter.GetExecutionContext().GetTargetPtr();
-            if (target)
+            if (target == NULL)
             {
-                Module *exe_module = target->GetExecutableModulePointer();
-                if (exe_module)
-                {
-                    m_options.launch_info.GetExecutableFile () = exe_module->GetFileSpec();
-                    char exe_path[PATH_MAX];
-                    if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
-                        m_options.launch_info.GetArguments().AppendArgument (exe_path);
-                    m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
-                }
+                result.AppendError ("invalid target, create a debug target using the 'target create' command");
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+
+            Module *exe_module = target->GetExecutableModulePointer();
+            if (exe_module)
+            {
+                m_options.launch_info.GetExecutableFile () = exe_module->GetFileSpec();
+                char exe_path[PATH_MAX];
+                if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
+                    m_options.launch_info.GetArguments().AppendArgument (exe_path);
+                m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
             }
 
             if (argc > 0)
@@ -412,21 +416,9 @@
 
                 if (argc == 0)
                 {
-                    lldb::UserSettingsControllerSP process_usc_sp (Process::GetSettingsController ());
-                    if (process_usc_sp)
-                    {
-                        SettableVariableType type;
-                        StringList settings_args (process_usc_sp->GetVariable ("process.run-args", 
-                                                                               type,
-                                                                               m_interpreter.GetDebugger().GetInstanceName().GetCString(),
-                                                                               error));
-                        if (error.Success())
-                        {
-                            const size_t num_settings_args = settings_args.GetSize();
-                            for (size_t i=0; i<num_settings_args; ++i)
-                                m_options.launch_info.GetArguments().AppendArgument (settings_args.GetStringAtIndex(i));
-                        }
-                    }
+                    const Args &target_settings_args = target->GetRunArguments();
+                    if (target_settings_args.GetArgumentCount())
+                        m_options.launch_info.GetArguments() = target_settings_args;
                 }
 
                 ProcessSP process_sp (platform_sp->DebugProcess (m_options.launch_info, 

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Mon Nov  7 20:43:13 2011
@@ -151,7 +151,9 @@
     bool
     Execute (Args& launch_args, CommandReturnObject &result)
     {
-        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+        Debugger &debugger = m_interpreter.GetDebugger();
+        Target *target = debugger.GetSelectedTarget().get();
+        Error error;
 
         if (target == NULL)
         {
@@ -159,7 +161,6 @@
             result.SetStatus (eReturnStatusFailed);
             return false;
         }
-
         // If our listener is NULL, users aren't allows to launch
         char filename[PATH_MAX];
         const Module *exe_module = target->GetExecutableModulePointer();
@@ -197,102 +198,110 @@
                 }
                 else
                 {
-                    Error error (process->Destroy());
-                    if (error.Success())
+                    Error destroy_error (process->Destroy());
+                    if (destroy_error.Success())
                     {
                         result.SetStatus (eReturnStatusSuccessFinishResult);
                     }
                     else
                     {
-                        result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString());
+                        result.AppendErrorWithFormat ("Failed to kill process: %s\n", destroy_error.AsCString());
                         result.SetStatus (eReturnStatusFailed);
                     }
                 }
             }
         }
         
-        if (state != eStateConnected)
-        {
-            const char *plugin_name = m_options.launch_info.GetProcessPluginName();
-
-            process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name).get();
-            if (process == NULL)
-            {
-                result.AppendErrorWithFormat ("Failed to find a process plugin for executable.\n");
-                result.SetStatus (eReturnStatusFailed);
-                return false;
-            }
-        }
-
         if (launch_args.GetArgumentCount() > 0)
         {
             m_options.launch_info.GetArguments().AppendArguments (launch_args);
         }
-        else
-        {
-            const Args &process_args = process->GetRunArguments();
-            if (process_args.GetArgumentCount() > 0)
-                m_options.launch_info.GetArguments().AppendArguments (process_args);
-        }
-        
 
-        if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
+        
+        if (state == eStateConnected)
         {
-            if (state == eStateConnected)
+            if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
             {
-                result.AppendWarning("launch in tty option is ignored when launching through a remote connection");
+                result.AppendWarning("can't launch in tty when launching through a remote connection");
                 m_options.launch_info.GetFlags().Clear (eLaunchFlagLaunchInTTY);
             }
         }
+        else
+        {
+            const char *plugin_name = m_options.launch_info.GetProcessPluginName();
 
-        Args environment;
-        process->GetEnvironmentAsArgs (environment);
-        m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
-        
-        if (process->GetDisableASLR())
-            m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
-
-        if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY) == false &&
-            m_options.launch_info.GetNumFileActions() == 0)
-        {
-            // Only use the settings value if the user hasn't specified any options that would override it.
-            if (process->GetDisableSTDIO())
-                m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
-            
-            const char *path;
-            path = process->GetStandardErrorPath();
-            if (path)
-            {
-                ProcessLaunchInfo::FileAction file_action;
-                const bool read = true;
-                const bool write = true;
-                if (file_action.Open(STDERR_FILENO, path, read, write))
-                    m_options.launch_info.AppendFileAction (file_action);
-            }
-            path = process->GetStandardInputPath();
-            if (path)
-            {
-                ProcessLaunchInfo::FileAction file_action;
-                const bool read = true;
-                const bool write = false;
-                if (file_action.Open(STDIN_FILENO, path, read, write))
-                    m_options.launch_info.AppendFileAction (file_action);
-            }
-
-            path = process->GetStandardOutputPath();
-            if (path)
-            {
-                ProcessLaunchInfo::FileAction file_action;
-                const bool read = false;
-                const bool write = true;
-                if (file_action.Open(STDOUT_FILENO, path, read, write))
-                    m_options.launch_info.AppendFileAction (file_action);
+            if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
+            {
+                process = target->GetPlatform()->DebugProcess (m_options.launch_info, 
+                                                               debugger,
+                                                               target,
+                                                               debugger.GetListener(),
+                                                               error).get();
             }
-        }
-        Error error;
+            else
+            {
+                process = target->CreateProcess (debugger.GetListener(), plugin_name).get();
+        
+                if (launch_args.GetArgumentCount() == 0)
+                {
+                    const Args &process_args = target->GetRunArguments();
+                    if (process_args.GetArgumentCount() > 0)
+                        m_options.launch_info.GetArguments().AppendArguments (process_args);
+                }
+
+                Args environment;
+                target->GetEnvironmentAsArgs (environment);
+                m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
+                
+                if (target->GetDisableASLR())
+                    m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
+
+                if (m_options.launch_info.GetNumFileActions() == 0)
+                {
+                    // Only use the settings value if the user hasn't specified any options that would override it.
+                    if (target->GetDisableSTDIO())
+                        m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
+                    
+                    const char *path;
+                    path = target->GetStandardErrorPath();
+                    if (path)
+                    {
+                        ProcessLaunchInfo::FileAction file_action;
+                        const bool read = true;
+                        const bool write = true;
+                        if (file_action.Open(STDERR_FILENO, path, read, write))
+                            m_options.launch_info.AppendFileAction (file_action);
+                    }
+                    path = target->GetStandardInputPath();
+                    if (path)
+                    {
+                        ProcessLaunchInfo::FileAction file_action;
+                        const bool read = true;
+                        const bool write = false;
+                        if (file_action.Open(STDIN_FILENO, path, read, write))
+                            m_options.launch_info.AppendFileAction (file_action);
+                    }
 
-        error = process->Launch (m_options.launch_info);
-                     
+                    path = target->GetStandardOutputPath();
+                    if (path)
+                    {
+                        ProcessLaunchInfo::FileAction file_action;
+                        const bool read = false;
+                        const bool write = true;
+                        if (file_action.Open(STDOUT_FILENO, path, read, write))
+                            m_options.launch_info.AppendFileAction (file_action);
+                    }
+                }
+                error = process->Launch (m_options.launch_info);
+            }
+            if (process == NULL)
+            {
+                result.AppendErrorWithFormat ("Failed to find a process plugin for executable.\n");
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+        }
+             
         if (error.Success())
         {
             const char *archname = exe_module->GetArchitecture().GetArchitectureName();

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Mon Nov  7 20:43:13 2011
@@ -83,14 +83,14 @@
 "When setting a dictionary or array variable, you can set multiple entries \n\
 at once by giving the values to the set command.  For example: \n\
 \n\
-(lldb) settings set target.process.run-args value1  value2 value3 \n\
-(lldb) settings set target.process.env-vars [\"MYPATH\"]=~/.:/usr/bin  [\"SOME_ENV_VAR\"]=12345 \n\
+(lldb) settings set target.run-args value1  value2 value3 \n\
+(lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin  [\"SOME_ENV_VAR\"]=12345 \n\
 \n\
-(lldb) settings show target.process.run-args \n\
+(lldb) settings show target.run-args \n\
   [0]: 'value1' \n\
   [1]: 'value2' \n\
   [3]: 'value3' \n\
-(lldb) settings show target.process.env-vars \n\
+(lldb) settings show target.env-vars \n\
   'MYPATH=~/.:/usr/bin'\n\
   'SOME_ENV_VAR=12345' \n\
 \n\

Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Mon Nov  7 20:43:13 2011
@@ -431,17 +431,30 @@
 	do script the_shell_script\n\
 end tell\n";
 
+static const char *
+GetShellSafeArgument (const char *unsafe_arg, std::string &safe_arg)
+{
+    safe_arg.assign (unsafe_arg);
+    size_t prev_pos = 0;
+    while (prev_pos < safe_arg.size())
+    {
+        // Escape spaces and quotes
+        size_t pos = safe_arg.find_first_of(" '\"", prev_pos);
+        if (pos != std::string::npos)
+        {
+            safe_arg.insert (pos, 1, '\\');
+            prev_pos = pos + 2;
+        }
+        else
+            break;
+    }
+    return safe_arg.c_str();
+}
+
 static Error
-LaunchInNewTerminalWithAppleScript (const char *exe_path,
-                                    ProcessLaunchInfo &launch_info)
+LaunchInNewTerminalWithAppleScript (const char *exe_path, ProcessLaunchInfo &launch_info)
 {
     Error error;
-    if (exe_path == NULL || exe_path[0] == '\0')
-    {
-        error.SetErrorString ("invalid executable path");
-        return error;
-    }
-    
     char unix_socket_name[PATH_MAX] = "/tmp/XXXXXX";    
     if (::mktemp (unix_socket_name) == NULL)
     {
@@ -485,15 +498,41 @@
     
     if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR))
         command.PutCString(" --disable-aslr");
-        
-    command.Printf(" -- '%s'", exe_path);
-
-    const char **argv = launch_info.GetArguments().GetConstArgumentVector ();
-    if (argv)
+    
+    if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
     {
-        for (size_t i=0; argv[i] != NULL; ++i)
+        const char *shell_executable = getenv("SHELL");
+        std::string safe_arg;
+        command.Printf(" -- %s -c '", shell_executable);
+        const char **argv = launch_info.GetArguments().GetConstArgumentVector ();
+        if (argv)
+        {
+            for (size_t i=0; argv[i] != NULL; ++i)
+            {
+                const char *arg = GetShellSafeArgument (i == 0 ? exe_path : argv[i], safe_arg);
+                command.Printf(" %s", arg);
+            }
+        }
+        command.PutChar('\'');
+    }
+    else
+    {
+        command.PutCString(" -- ");
+
+        const char **argv = launch_info.GetArguments().GetConstArgumentVector ();
+        if (argv)
+        {
+            for (size_t i=0; argv[i] != NULL; ++i)
+            {
+                if (i==0)
+                    command.Printf(" '%s'", exe_path);
+                else
+                    command.Printf(" '%s'", argv[i]);
+            }
+        }
+        else
         {
-            command.Printf(" '%s'", argv[i]);
+            command.Printf(" '%s'", exe_path);
         }
     }
     command.PutCString (" ; echo Process exited with status $?");

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Nov  7 20:43:13 2011
@@ -250,6 +250,60 @@
     }
 }
 
+void
+ProcessLaunchInfo::FinalizeFileActions (Target *target, Process *process)
+{
+    // If notthing was specified, then check the process for any default 
+    // settings that were set with "settings set"
+    if (m_file_actions.empty())
+    {
+        const char *path;
+        if (m_flags.Test(eLaunchFlagDisableSTDIO))
+        {
+            AppendSuppressFileAction (STDERR_FILENO, true , true );
+            AppendSuppressFileAction (STDIN_FILENO , true , false);
+            AppendSuppressFileAction (STDOUT_FILENO, false, true );
+        }
+        else
+        {
+            // Check for any values that might have gotten set with any of:
+            // (lldb) settings set target.input-path
+            // (lldb) settings set target.output-path
+            // (lldb) settings set target.error-path
+            if (target)
+            {
+                path = target->GetStandardErrorPath();
+                if (path)
+                {
+                    const bool read = true;
+                    const bool write = true;
+                    AppendOpenFileAction(STDERR_FILENO, path, read, write);
+                }
+                path = target->GetStandardInputPath();
+                if (path)
+                {
+                    const bool read = true;
+                    const bool write = false;
+                    AppendOpenFileAction(STDIN_FILENO, path, read, write);
+                }
+                
+                path = target->GetStandardOutputPath();
+                if (path)
+                {
+                    const bool read = false;
+                    const bool write = true;
+                    AppendOpenFileAction(STDOUT_FILENO, path, read, write);
+                }
+            }
+
+            // If we still don't have any actions...
+            if (m_file_actions.empty())
+            {
+            }
+        }
+    }
+}
+
 bool
 ProcessLaunchInfo::FileAction::Open (int fd, const char *path, bool read, bool write)
 {
@@ -466,6 +520,7 @@
 { LLDB_OPT_SET_ALL, false, "working-dir",   'w', required_argument, NULL, 0, eArgTypePath,          "Set the current working directory to <path> when running the inferior."},
 { LLDB_OPT_SET_ALL, false, "arch",          'a', required_argument, NULL, 0, eArgTypeArchitecture,  "Set the architecture for the process to launch when ambiguous."},
 { LLDB_OPT_SET_ALL, false, "environment",   'v', required_argument, NULL, 0, eArgTypeNone,          "Specify an environment variable name/value stirng (--environement NAME=VALUE). Can be specified multiple times for subsequent environment entries."},
+{ LLDB_OPT_SET_ALL, false, "shell",         'c', no_argument,       NULL, 0, eArgTypeNone,          "Run the process in a shell (not supported on all platforms)."},
 
 { LLDB_OPT_SET_1  , false, "stdin",         'i', required_argument, NULL, 0, eArgTypePath,    "Redirect stdin for the process to <path>."},
 { LLDB_OPT_SET_1  , false, "stdout",        'o', required_argument, NULL, 0, eArgTypePath,    "Redirect stdout for the process to <path>."},
@@ -475,7 +530,6 @@
 
 { LLDB_OPT_SET_3  , false, "no-stdio",      'n', no_argument,       NULL, 0, eArgTypeNone,    "Do not set up for terminal I/O to go to running process."},
 
-{ LLDB_OPT_SET_4  , false, "shell",         'c', no_argument,       NULL, 0, eArgTypeNone,    "Run the process in a shell (not supported on all platforms)."},
 { 0               , false, NULL,             0,  0,                 NULL, 0, eArgTypeNone,    NULL }
 };
 
@@ -949,50 +1003,6 @@
 }
 
 
-void
-Process::ProcessInstanceSettings::GetHostEnvironmentIfNeeded ()
-{
-    if (m_inherit_host_env && !m_got_host_env)
-    {
-        m_got_host_env = true;
-        StringList host_env;
-        const size_t host_env_count = Host::GetEnvironment (host_env);
-        for (size_t idx=0; idx<host_env_count; idx++)
-        {
-            const char *env_entry = host_env.GetStringAtIndex (idx);
-            if (env_entry)
-            {
-                const char *equal_pos = ::strchr(env_entry, '=');
-                if (equal_pos)
-                {
-                    std::string key (env_entry, equal_pos - env_entry);
-                    std::string value (equal_pos + 1);
-                    if (m_env_vars.find (key) == m_env_vars.end())
-                        m_env_vars[key] = value;
-                }
-            }
-        }
-    }
-}
-
-
-size_t
-Process::ProcessInstanceSettings::GetEnvironmentAsArgs (Args &env)
-{
-    GetHostEnvironmentIfNeeded ();
-
-    dictionary::const_iterator pos, end = m_env_vars.end();
-    for (pos = m_env_vars.begin(); pos != end; ++pos)
-    {
-        std::string env_var_equal_value (pos->first);
-        env_var_equal_value.append(1, '=');
-        env_var_equal_value.append (pos->second);
-        env.AppendArgument (env_var_equal_value.c_str());
-    }
-    return env.GetArgumentCount();
-}
-
-
 const char *
 Process::GetExitDescription ()
 {
@@ -4044,28 +4054,19 @@
     bool live_instance, 
     const char *name
 ) :
-    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), 
-    m_run_args (),
-    m_env_vars (),
-    m_input_path (),
-    m_output_path (),
-    m_error_path (),
-    m_disable_aslr (true),
-    m_disable_stdio (false),
-    m_inherit_host_env (true),
-    m_got_host_env (false)
+    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
 {
     // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
     // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers.
     // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
     // This is true for CreateInstanceName() too.
-
+    
     if (GetInstanceName () == InstanceSettings::InvalidName())
     {
         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
         m_owner.RegisterInstanceSettings (this);
     }
-
+    
     if (live_instance)
     {
         const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
@@ -4075,14 +4076,7 @@
 }
 
 ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) :
-    InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString()),
-    m_run_args (rhs.m_run_args),
-    m_env_vars (rhs.m_env_vars),
-    m_input_path (rhs.m_input_path),
-    m_output_path (rhs.m_output_path),
-    m_error_path (rhs.m_error_path),
-    m_disable_aslr (rhs.m_disable_aslr),
-    m_disable_stdio (rhs.m_disable_stdio)
+    InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString())
 {
     if (m_instance_name != InstanceSettings::GetDefaultName())
     {
@@ -4101,14 +4095,6 @@
 {
     if (this != &rhs)
     {
-        m_run_args = rhs.m_run_args;
-        m_env_vars = rhs.m_env_vars;
-        m_input_path = rhs.m_input_path;
-        m_output_path = rhs.m_output_path;
-        m_error_path = rhs.m_error_path;
-        m_disable_aslr = rhs.m_disable_aslr;
-        m_disable_stdio = rhs.m_disable_stdio;
-        m_inherit_host_env = rhs.m_inherit_host_env;
     }
 
     return *this;
@@ -4125,45 +4111,16 @@
                                                          Error &err,
                                                          bool pending)
 {
-    if (var_name == RunArgsVarName())
-        UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
-    else if (var_name == EnvVarsVarName())
-    {
-        // This is nice for local debugging, but it is isn't correct for
-        // remote debugging. We need to stop process.env-vars from being 
-        // populated with the host environment and add this as a launch option
-        // and get the correct environment from the Target's platform.
-        // GetHostEnvironmentIfNeeded ();
-        UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
-    }
-    else if (var_name == InputPathVarName())
-        UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
-    else if (var_name == OutputPathVarName())
-        UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
-    else if (var_name == ErrorPathVarName())
-        UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
-    else if (var_name == DisableASLRVarName())
-        UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
-    else if (var_name == DisableSTDIOVarName ())
-        UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
 }
 
 void
 ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
                                                bool pending)
 {
-    if (new_settings.get() == NULL)
-        return;
-
-    ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get();
-
-    m_run_args = new_process_settings->m_run_args;
-    m_env_vars = new_process_settings->m_env_vars;
-    m_input_path = new_process_settings->m_input_path;
-    m_output_path = new_process_settings->m_output_path;
-    m_error_path = new_process_settings->m_error_path;
-    m_disable_aslr = new_process_settings->m_disable_aslr;
-    m_disable_stdio = new_process_settings->m_disable_stdio;
+//    if (new_settings.get() == NULL)
+//        return;
+//
+//    ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get();
 }
 
 bool
@@ -4172,69 +4129,9 @@
                                                    StringList &value,
                                                    Error *err)
 {
-    if (var_name == RunArgsVarName())
-    {
-        if (m_run_args.GetArgumentCount() > 0)
-        {
-            for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
-                value.AppendString (m_run_args.GetArgumentAtIndex (i));
-        }
-    }
-    else if (var_name == EnvVarsVarName())
-    {
-        GetHostEnvironmentIfNeeded ();
-
-        if (m_env_vars.size() > 0)
-        {
-            std::map<std::string, std::string>::iterator pos;
-            for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
-            {
-                StreamString value_str;
-                value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
-                value.AppendString (value_str.GetData());
-            }
-        }
-    }
-    else if (var_name == InputPathVarName())
-    {
-        value.AppendString (m_input_path.c_str());
-    }
-    else if (var_name == OutputPathVarName())
-    {
-        value.AppendString (m_output_path.c_str());
-    }
-    else if (var_name == ErrorPathVarName())
-    {
-        value.AppendString (m_error_path.c_str());
-    }
-    else if (var_name == InheritHostEnvVarName())
-    {
-        if (m_inherit_host_env)
-            value.AppendString ("true");
-        else
-            value.AppendString ("false");
-    }
-    else if (var_name == DisableASLRVarName())
-    {
-        if (m_disable_aslr)
-            value.AppendString ("true");
-        else
-            value.AppendString ("false");
-    }
-    else if (var_name == DisableSTDIOVarName())
-    {
-        if (m_disable_stdio)
-            value.AppendString ("true");
-        else
-            value.AppendString ("false");
-    }
-    else
-    {
-        if (err)
-            err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
-        return false;
-    }
-    return true;
+    if (err)
+        err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
+    return false;
 }
 
 const ConstString
@@ -4250,70 +4147,6 @@
     return ret_val;
 }
 
-const ConstString &
-ProcessInstanceSettings::RunArgsVarName ()
-{
-    static ConstString run_args_var_name ("run-args");
-
-    return run_args_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::EnvVarsVarName ()
-{
-    static ConstString env_vars_var_name ("env-vars");
-
-    return env_vars_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::InheritHostEnvVarName ()
-{
-    static ConstString g_name ("inherit-env");
-
-    return g_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::InputPathVarName ()
-{
-  static ConstString input_path_var_name ("input-path");
-
-    return input_path_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::OutputPathVarName ()
-{
-    static ConstString output_path_var_name ("output-path");
-
-    return output_path_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::ErrorPathVarName ()
-{
-    static ConstString error_path_var_name ("error-path");
-
-    return error_path_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::DisableASLRVarName ()
-{
-    static ConstString disable_aslr_var_name ("disable-aslr");
-
-    return disable_aslr_var_name;
-}
-
-const ConstString &
-ProcessInstanceSettings::DisableSTDIOVarName ()
-{
-    static ConstString disable_stdio_var_name ("disable-stdio");
-    
-    return disable_stdio_var_name;
-}
-
 //--------------------------------------------------
 // SettingsController Variable Tables
 //--------------------------------------------------
@@ -4330,17 +4163,9 @@
 Process::SettingsController::instance_settings_table[] =
 {
   //{ "var-name",       var-type,              "default",       enum-table, init'd, hidden, "help-text"},
-    { "run-args",       eSetVarTypeArray,       NULL,           NULL,       false,  false,  "A list containing all the arguments to be passed to the executable when it is run." },
-    { "env-vars",       eSetVarTypeDictionary,  NULL,           NULL,       false,  false,  "A list of all the environment variables to be passed to the executable's environment, and their values." },
-    { "inherit-env",    eSetVarTypeBoolean,     "true",         NULL,       false,  false,  "Inherit the environment from the process that is running LLDB." },
-    { "input-path",     eSetVarTypeString,      NULL,           NULL,       false,  false,  "The file/path to be used by the executable program for reading its input." },
-    { "output-path",    eSetVarTypeString,      NULL,           NULL,       false,  false,  "The file/path to be used by the executable program for writing its output." },
-    { "error-path",     eSetVarTypeString,      NULL,           NULL,       false,  false,  "The file/path to be used by the executable program for writings its error messages." },
-    { "plugin",         eSetVarTypeEnum,        NULL,           NULL,       false,  false,  "The plugin to be used to run the process." }, 
-    { "disable-aslr",   eSetVarTypeBoolean,     "true",         NULL,       false,  false,  "Disable Address Space Layout Randomization (ASLR)" },
-    { "disable-stdio",  eSetVarTypeBoolean,     "false",        NULL,       false,  false,  "Disable stdin/stdout for process (e.g. for a GUI application)" },
     {  NULL,            eSetVarTypeNone,        NULL,           NULL,       false,  false,  NULL }
 };
 
 
 
+

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Nov  7 20:43:13 2011
@@ -1973,14 +1973,22 @@
 }
 
 
-#define TSC_DEFAULT_ARCH      "default-arch"
-#define TSC_EXPR_PREFIX       "expr-prefix"
-#define TSC_PREFER_DYNAMIC    "prefer-dynamic-value"
-#define TSC_SKIP_PROLOGUE     "skip-prologue"
-#define TSC_SOURCE_MAP        "source-map"
-#define TSC_MAX_CHILDREN      "max-children-count"
-#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
-#define TSC_PLATFORM_AVOID    "breakpoints-use-platform-avoid-list"
+#define TSC_DEFAULT_ARCH        "default-arch"
+#define TSC_EXPR_PREFIX         "expr-prefix"
+#define TSC_PREFER_DYNAMIC      "prefer-dynamic-value"
+#define TSC_SKIP_PROLOGUE       "skip-prologue"
+#define TSC_SOURCE_MAP          "source-map"
+#define TSC_MAX_CHILDREN        "max-children-count"
+#define TSC_MAX_STRLENSUMMARY   "max-string-summary-length"
+#define TSC_PLATFORM_AVOID      "breakpoints-use-platform-avoid-list"
+#define TSC_RUN_ARGS            "run-args"
+#define TSC_ENV_VARS            "env-vars"
+#define TSC_INHERIT_ENV         "inherit-env"
+#define TSC_STDIN_PATH          "input-path"
+#define TSC_STDOUT_PATH         "output-path"
+#define TSC_STDERR_PATH         "error-path"
+#define TSC_DISABLE_ASLR        "disable-aslr"
+#define TSC_DISABLE_STDIO       "disable-stdio"
 
 
 static const ConstString &
@@ -2039,6 +2047,61 @@
     return g_const_string;
 }
 
+const ConstString &
+GetSettingNameForRunArgs ()
+{
+    static ConstString g_const_string (TSC_RUN_ARGS);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForEnvVars ()
+{
+    static ConstString g_const_string (TSC_ENV_VARS);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForInheritHostEnv ()
+{
+    static ConstString g_const_string (TSC_INHERIT_ENV);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForInputPath ()
+{
+    static ConstString g_const_string (TSC_STDIN_PATH);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForOutputPath ()
+{
+    static ConstString g_const_string (TSC_STDOUT_PATH);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForErrorPath ()
+{
+    static ConstString g_const_string (TSC_STDERR_PATH);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForDisableASLR ()
+{
+    static ConstString g_const_string (TSC_DISABLE_ASLR);
+    return g_const_string;
+}
+
+const ConstString &
+GetSettingNameForDisableSTDIO ()
+{
+    static ConstString g_const_string (TSC_DISABLE_STDIO);
+    return g_const_string;
+}
 
 bool
 Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
@@ -2094,7 +2157,16 @@
     m_source_map (NULL, NULL),
     m_max_children_display(256),
     m_max_strlen_length(1024),
-    m_breakpoints_use_platform_avoid (true, true)
+    m_breakpoints_use_platform_avoid (true, true),
+    m_run_args (),
+    m_env_vars (),
+    m_input_path (),
+    m_output_path (),
+    m_error_path (),
+    m_disable_aslr (true),
+    m_disable_stdio (false),
+    m_inherit_host_env (true),
+    m_got_host_env (false)
 {
     // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
     // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
@@ -2121,9 +2193,17 @@
     m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
     m_skip_prologue (rhs.m_skip_prologue),
     m_source_map (rhs.m_source_map),
-    m_max_children_display(rhs.m_max_children_display),
-    m_max_strlen_length(rhs.m_max_strlen_length),
-    m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid)
+    m_max_children_display (rhs.m_max_children_display),
+    m_max_strlen_length (rhs.m_max_strlen_length),
+    m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
+    m_run_args (rhs.m_run_args),
+    m_env_vars (rhs.m_env_vars),
+    m_input_path (rhs.m_input_path),
+    m_output_path (rhs.m_output_path),
+    m_error_path (rhs.m_error_path),
+    m_disable_aslr (rhs.m_disable_aslr),
+    m_disable_stdio (rhs.m_disable_stdio),
+    m_inherit_host_env (rhs.m_inherit_host_env)
 {
     if (m_instance_name != InstanceSettings::GetDefaultName())
     {
@@ -2141,6 +2221,22 @@
 {
     if (this != &rhs)
     {
+        m_expr_prefix_file = rhs.m_expr_prefix_file;
+        m_expr_prefix_contents_sp = rhs.m_expr_prefix_contents_sp;
+        m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
+        m_skip_prologue = rhs.m_skip_prologue;
+        m_source_map = rhs.m_source_map;
+        m_max_children_display = rhs.m_max_children_display;
+        m_max_strlen_length = rhs.m_max_strlen_length;
+        m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
+        m_run_args = rhs.m_run_args;
+        m_env_vars = rhs.m_env_vars;
+        m_input_path = rhs.m_input_path;
+        m_output_path = rhs.m_output_path;
+        m_error_path = rhs.m_error_path;
+        m_disable_aslr = rhs.m_disable_aslr;
+        m_disable_stdio = rhs.m_disable_stdio;
+        m_inherit_host_env = rhs.m_inherit_host_env;
     }
 
     return *this;
@@ -2274,6 +2370,39 @@
     {
         err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
     }
+    else if (var_name == GetSettingNameForRunArgs())
+    {
+        UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
+    }
+    else if (var_name == GetSettingNameForEnvVars())
+    {
+        // This is nice for local debugging, but it is isn't correct for
+        // remote debugging. We need to stop process.env-vars from being 
+        // populated with the host environment and add this as a launch option
+        // and get the correct environment from the Target's platform.
+        // GetHostEnvironmentIfNeeded ();
+        UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
+    }
+    else if (var_name == GetSettingNameForInputPath())
+    {
+        UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
+    }
+    else if (var_name == GetSettingNameForOutputPath())
+    {
+        UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
+    }
+    else if (var_name == GetSettingNameForErrorPath())
+    {
+        UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
+    }
+    else if (var_name == GetSettingNameForDisableASLR())
+    {
+        UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
+    }
+    else if (var_name == GetSettingNameForDisableSTDIO ())
+    {
+        UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
+    }
 }
 
 void
@@ -2284,13 +2413,7 @@
     if (!new_settings_ptr)
         return;
     
-    m_expr_prefix_file               = new_settings_ptr->m_expr_prefix_file;
-    m_expr_prefix_contents_sp        = new_settings_ptr->m_expr_prefix_contents_sp;
-    m_prefer_dynamic_value           = new_settings_ptr->m_prefer_dynamic_value;
-    m_skip_prologue                  = new_settings_ptr->m_skip_prologue;
-    m_max_children_display           = new_settings_ptr->m_max_children_display;
-    m_max_strlen_length              = new_settings_ptr->m_max_strlen_length;
-    m_breakpoints_use_platform_avoid = new_settings_ptr->m_breakpoints_use_platform_avoid;
+    *this = *new_settings_ptr;
 }
 
 bool
@@ -2339,16 +2462,115 @@
         else
             value.AppendString ("false");
     }
+    else if (var_name == GetSettingNameForRunArgs())
+    {
+        if (m_run_args.GetArgumentCount() > 0)
+        {
+            for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
+                value.AppendString (m_run_args.GetArgumentAtIndex (i));
+        }
+    }
+    else if (var_name == GetSettingNameForEnvVars())
+    {
+        GetHostEnvironmentIfNeeded ();
+        
+        if (m_env_vars.size() > 0)
+        {
+            std::map<std::string, std::string>::iterator pos;
+            for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
+            {
+                StreamString value_str;
+                value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
+                value.AppendString (value_str.GetData());
+            }
+        }
+    }
+    else if (var_name == GetSettingNameForInputPath())
+    {
+        value.AppendString (m_input_path.c_str());
+    }
+    else if (var_name == GetSettingNameForOutputPath())
+    {
+        value.AppendString (m_output_path.c_str());
+    }
+    else if (var_name == GetSettingNameForErrorPath())
+    {
+        value.AppendString (m_error_path.c_str());
+    }
+    else if (var_name == GetSettingNameForInheritHostEnv())
+    {
+        if (m_inherit_host_env)
+            value.AppendString ("true");
+        else
+            value.AppendString ("false");
+    }
+    else if (var_name == GetSettingNameForDisableASLR())
+    {
+        if (m_disable_aslr)
+            value.AppendString ("true");
+        else
+            value.AppendString ("false");
+    }
+    else if (var_name == GetSettingNameForDisableSTDIO())
+    {
+        if (m_disable_stdio)
+            value.AppendString ("true");
+        else
+            value.AppendString ("false");
+    }
     else 
     {
         if (err)
             err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
         return false;
     }
-
     return true;
 }
 
+void
+Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
+{
+    if (m_inherit_host_env && !m_got_host_env)
+    {
+        m_got_host_env = true;
+        StringList host_env;
+        const size_t host_env_count = Host::GetEnvironment (host_env);
+        for (size_t idx=0; idx<host_env_count; idx++)
+        {
+            const char *env_entry = host_env.GetStringAtIndex (idx);
+            if (env_entry)
+            {
+                const char *equal_pos = ::strchr(env_entry, '=');
+                if (equal_pos)
+                {
+                    std::string key (env_entry, equal_pos - env_entry);
+                    std::string value (equal_pos + 1);
+                    if (m_env_vars.find (key) == m_env_vars.end())
+                        m_env_vars[key] = value;
+                }
+            }
+        }
+    }
+}
+
+
+size_t
+Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
+{
+    GetHostEnvironmentIfNeeded ();
+    
+    dictionary::const_iterator pos, end = m_env_vars.end();
+    for (pos = m_env_vars.begin(); pos != end; ++pos)
+    {
+        std::string env_var_equal_value (pos->first);
+        env_var_equal_value.append(1, '=');
+        env_var_equal_value.append (pos->second);
+        env.AppendArgument (env_var_equal_value.c_str());
+    }
+    return env.GetArgumentCount();
+}
+
+
 const ConstString
 TargetInstanceSettings::CreateInstanceName ()
 {
@@ -2395,5 +2617,14 @@
     { TSC_MAX_CHILDREN      , eSetVarTypeInt    , "256"         , NULL,                  true,  false, "Maximum number of children to expand in any level of depth." },
     { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt    , "1024"        , NULL,                  true,  false, "Maximum number of characters to show when using %s in summary strings." },
     { TSC_PLATFORM_AVOID    , eSetVarTypeBoolean, "true"        , NULL,                  false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
+    { TSC_RUN_ARGS          , eSetVarTypeArray  , NULL          , NULL,                  false,  false,  "A list containing all the arguments to be passed to the executable when it is run." },
+    { TSC_ENV_VARS          , eSetVarTypeDictionary, NULL       , NULL,                  false,  false,  "A list of all the environment variables to be passed to the executable's environment, and their values." },
+    { TSC_INHERIT_ENV       , eSetVarTypeBoolean, "true"        , NULL,                  false,  false,  "Inherit the environment from the process that is running LLDB." },
+    { TSC_STDIN_PATH        , eSetVarTypeString , NULL          , NULL,                  false,  false,  "The file/path to be used by the executable program for reading its standard input." },
+    { TSC_STDOUT_PATH       , eSetVarTypeString , NULL          , NULL,                  false,  false,  "The file/path to be used by the executable program for writing its standard output." },
+    { TSC_STDERR_PATH       , eSetVarTypeString , NULL          , NULL,                  false,  false,  "The file/path to be used by the executable program for writing its standard error." },
+//    { "plugin",         eSetVarTypeEnum,        NULL,           NULL,                  false,  false,  "The plugin to be used to run the process." }, 
+    { TSC_DISABLE_ASLR      , eSetVarTypeBoolean, "true"        , NULL,                  false,  false,  "Disable Address Space Layout Randomization (ASLR)" },
+    { TSC_DISABLE_STDIO     , eSetVarTypeBoolean, "false"       , NULL,                  false,  false,  "Disable stdin/stdout for process (e.g. for a GUI application)" },
     { NULL                  , eSetVarTypeNone   , NULL          , NULL,                  false, false, NULL }
 };

Modified: lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py (original)
+++ lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py Mon Nov  7 20:43:13 2011
@@ -67,11 +67,11 @@
             env_var = 'DYLD_FRAMEWORK_PATH'
             env_val = self.build_dir
 
-        env_cmd = "settings set target.process.env-vars %s=%s" %(env_var, env_val)
+        env_cmd = "settings set target.env-vars %s=%s" %(env_var, env_val)
         if self.TraceOn():
             print "Set environment to: ", env_cmd
         self.runCmd(env_cmd)
-        self.addTearDownHook(lambda: self.runCmd("settings remove target.process.env-vars %s" % env_var))
+        self.addTearDownHook(lambda: self.runCmd("settings remove target.env-vars %s" % env_var))
 
         self.expect('breakpoint set -f %s -l %d' % (self.source, self.line_to_break),
                     BREAKPOINT_CREATED,

Modified: lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py (original)
+++ lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py Mon Nov  7 20:43:13 2011
@@ -82,13 +82,13 @@
         # Try running with the DYLD_LIBRARY_PATH environment variable set, make sure
         # we pick up the hidden dylib.
 
-        env_cmd_string = "settings set target.process.env-vars " + dylibPath + "=" + new_dir
+        env_cmd_string = "settings set target.env-vars " + dylibPath + "=" + new_dir
         if self.TraceOn():
             print "Set environment to: ", env_cmd_string
         self.runCmd(env_cmd_string)
-        self.runCmd("settings show target.process.env-vars")
+        self.runCmd("settings show target.env-vars")
 
-        remove_dyld_path_cmd = "settings remove target.process.env-vars " + dylibPath
+        remove_dyld_path_cmd = "settings remove target.env-vars " + dylibPath
         self.addTearDownHook(lambda: self.runCmd(remove_dyld_path_cmd))
 
         self.expect("breakpoint set -f d.c -l %d" % self.line_d_function,

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Mon Nov  7 20:43:13 2011
@@ -23,7 +23,7 @@
         """Test that 'apropos' command should also search descriptions for the settings variables."""
 
         self.expect("apropos 'environment variable'",
-            substrs = ["target.process.env-vars",
+            substrs = ["target.env-vars",
                        "environment variables",
                        "executable's environment"])
 
@@ -99,12 +99,12 @@
 
         # Set the run-args and the env-vars.
         # And add hooks to restore the settings during tearDown().
-        self.runCmd('settings set target.process.run-args A B C')
+        self.runCmd('settings set target.run-args A B C')
         self.addTearDownHook(
-            lambda: self.runCmd("settings set -r target.process.run-args"))
-        self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
+            lambda: self.runCmd("settings set -r target.run-args"))
+        self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
         self.addTearDownHook(
-            lambda: self.runCmd("settings set -r target.process.env-vars"))
+            lambda: self.runCmd("settings set -r target.env-vars"))
 
         self.runCmd("run", RUN_SUCCEEDED)
 
@@ -126,8 +126,8 @@
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # By default, inherit-env is 'true'.
-        self.expect('settings show target.process.inherit-env', "Default inherit-env is 'true'",
-            startstr = "target.process.inherit-env (boolean) = true")
+        self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
+            startstr = "target.inherit-env (boolean) = true")
 
         # Set some host environment variables now.
         os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
@@ -150,34 +150,34 @@
                        "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
 
     def test_set_error_output_path(self):
-        """Test that setting target.process.error/output-path for the launched process works."""
+        """Test that setting target.error/output-path for the launched process works."""
         self.buildDefault()
 
         exe = os.path.join(os.getcwd(), "a.out")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # Set the error-path and output-path and verify both are set.
-        self.runCmd("settings set target.process.error-path stderr.txt")
-        self.runCmd("settings set target.process.output-path stdout.txt")
+        self.runCmd("settings set target.error-path stderr.txt")
+        self.runCmd("settings set target.output-path stdout.txt")
         # And add hooks to restore the original settings during tearDown().
         self.addTearDownHook(
-            lambda: self.runCmd("settings set -r target.process.output-path"))
+            lambda: self.runCmd("settings set -r target.output-path"))
         self.addTearDownHook(
-            lambda: self.runCmd("settings set -r target.process.error-path"))
+            lambda: self.runCmd("settings set -r target.error-path"))
 
-        self.expect("settings show target.process.error-path",
-                    SETTING_MSG("target.process.error-path"),
-            startstr = 'target.process.error-path (string) = "stderr.txt"')
-
-        self.expect("settings show target.process.output-path",
-                    SETTING_MSG("target.process.output-path"),
-            startstr = 'target.process.output-path (string) = "stdout.txt"')
+        self.expect("settings show target.error-path",
+                    SETTING_MSG("target.error-path"),
+            startstr = 'target.error-path (string) = "stderr.txt"')
+
+        self.expect("settings show target.output-path",
+                    SETTING_MSG("target.output-path"),
+            startstr = 'target.output-path (string) = "stdout.txt"')
 
         self.runCmd("run", RUN_SUCCEEDED)
 
         # The 'stderr.txt' file should now exist.
         self.assertTrue(os.path.isfile("stderr.txt"),
-                        "'stderr.txt' exists due to target.process.error-path.")
+                        "'stderr.txt' exists due to target.error-path.")
 
         # Read the output file produced by running the program.
         with open('stderr.txt', 'r') as f:
@@ -188,7 +188,7 @@
 
         # The 'stdout.txt' file should now exist.
         self.assertTrue(os.path.isfile("stdout.txt"),
-                        "'stdout.txt' exists due to target.process.output-path.")
+                        "'stdout.txt' exists due to target.output-path.")
 
         # Read the output file produced by running the program.
         with open('stdout.txt', 'r') as f:
@@ -198,35 +198,35 @@
             startstr = "This message should go to standard out.")
 
     def test_print_dictionary_setting(self):
-        self.runCmd ("settings set -r target.process.env-vars")
-        self.runCmd ("settings set target.process.env-vars [\"MY_VAR\"]=some-value")
-        self.expect ("settings show target.process.env-vars",
+        self.runCmd ("settings set -r target.env-vars")
+        self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
+        self.expect ("settings show target.env-vars",
                      substrs = [ "MY_VAR=some-value" ])
-        self.runCmd ("settings set -r target.process.env-vars")
+        self.runCmd ("settings set -r target.env-vars")
 
     def test_print_array_setting(self):
-        self.runCmd ("settings set -r target.process.run-args")
-        self.runCmd ("settings set target.process.run-args gobbledy-gook")
-        self.expect ("settings show target.process.run-args",
+        self.runCmd ("settings set -r target.run-args")
+        self.runCmd ("settings set target.run-args gobbledy-gook")
+        self.expect ("settings show target.run-args",
                      substrs = [ '[0]: "gobbledy-gook"' ])
-        self.runCmd ("settings set -r target.process.run-args")
+        self.runCmd ("settings set -r target.run-args")
 
     def test_settings_with_quotes (self):
-        self.runCmd ("settings set -r target.process.run-args")
-        self.runCmd ("settings set target.process.run-args a b c")
-        self.expect ("settings show target.process.run-args",
+        self.runCmd ("settings set -r target.run-args")
+        self.runCmd ("settings set target.run-args a b c")
+        self.expect ("settings show target.run-args",
                      substrs = [ '[0]: "a"',
                                  '[1]: "b"',
                                  '[2]: "c"' ])
-        self.runCmd ("settings set target.process.run-args 'a b c'")
-        self.expect ("settings show target.process.run-args",
+        self.runCmd ("settings set target.run-args 'a b c'")
+        self.expect ("settings show target.run-args",
                      substrs = [ '[0]: "a b c"' ])
-        self.runCmd ("settings set -r target.process.run-args")
-        self.runCmd ("settings set -r target.process.env-vars")
-        self.runCmd ('settings set target.process.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
-        self.expect ("settings show target.process.env-vars",
+        self.runCmd ("settings set -r target.run-args")
+        self.runCmd ("settings set -r target.env-vars")
+        self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
+        self.expect ("settings show target.env-vars",
                      substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
-        self.runCmd ("settings set -r target.process.env-vars")
+        self.runCmd ("settings set -r target.env-vars")
 
 
     def test_all_settings_exist (self):
@@ -240,15 +240,14 @@
                                  "auto-confirm (boolean) = ",
                                  "target.default-arch (string) =",
                                  "target.expr-prefix (string) = ",
-                                 "target.process.run-args (array) =",
-                                 "target.process.env-vars (dictionary) =",
-                                 "target.process.inherit-env (boolean) = ",
-                                 "target.process.input-path (string) = ",
-                                 "target.process.output-path (string) = ",
-                                 "target.process.error-path (string) = ",
-                                 "target.process.plugin (enum) =",
-                                 "target.process.disable-aslr (boolean) = ",
-                                 "target.process.disable-stdio (boolean) = ",
+                                 "target.run-args (array) =",
+                                 "target.env-vars (dictionary) =",
+                                 "target.inherit-env (boolean) = ",
+                                 "target.input-path (string) = ",
+                                 "target.output-path (string) = ",
+                                 "target.error-path (string) = ",
+                                 "target.disable-aslr (boolean) = ",
+                                 "target.disable-stdio (boolean) = ",
                                  "target.process.thread.step-avoid-regexp (string) =",
                                  "target.process.thread.trace-thread (boolean) =" ])
         

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=144061&r1=144060&r2=144061&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Mon Nov  7 20:43:13 2011
@@ -1251,13 +1251,13 @@
                 
                 if (num_args > 1)
                 {
-                    m_debugger.HandleCommand ("settings clear target.process.run-args");
+                    m_debugger.HandleCommand ("settings clear target.run-args");
                     char arg_cstr[1024];
                     for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx)
                     {
                         ::snprintf (arg_cstr, 
                                     sizeof(arg_cstr), 
-                                    "settings append target.process.run-args \"%s\"", 
+                                    "settings append target.run-args \"%s\"", 
                                     m_option_data.m_args[arg_idx].c_str());
                         m_debugger.HandleCommand (arg_cstr);
                     }





More information about the lldb-commits mailing list