From 1d8859668f49b36a8240f6b9da1c1db49fb60bf8 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Tue, 8 Nov 2011 02:43:13 +0000 Subject: [PATCH] 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. llvm-svn: 144061 --- lldb/include/lldb/Target/Process.h | 186 ++--------- lldb/include/lldb/Target/Target.h | 122 ++++++- .../source/Commands/CommandObjectPlatform.cpp | 42 +-- lldb/source/Commands/CommandObjectProcess.cpp | 163 ++++----- .../source/Commands/CommandObjectSettings.cpp | 8 +- lldb/source/Host/macosx/Host.mm | 69 +++- lldb/source/Target/Process.cpp | 309 ++++-------------- lldb/source/Target/Target.cpp | 271 +++++++++++++-- .../TestPublicAPIHeaders.py | 4 +- .../load_unload/TestLoadUnload.py | 6 +- lldb/test/settings/TestSettings.py | 93 +++--- lldb/tools/driver/Driver.cpp | 4 +- 12 files changed, 684 insertions(+), 593 deletions(-) diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 9d4cba70e5e8..42064bf85cba 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -79,111 +79,6 @@ public: 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 @@ protected: 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 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 @@ public: 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 diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index ec4f67103a7d..cf8d79b5b596 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -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 @@ public: { 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 @@ protected: 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 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; + }; diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 7c7762c60a7c..e2136d32cac2 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -374,17 +374,21 @@ public: 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 @@ public: 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; iGetRunArguments(); + if (target_settings_args.GetArgumentCount()) + m_options.launch_info.GetArguments() = target_settings_args; } ProcessSP process_sp (platform_sp->DebugProcess (m_options.launch_info, diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 2c8a0dd022dc..ae6984e0f0a7 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -151,7 +151,9 @@ public: 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 @@ public: 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,25 +198,102 @@ public: } 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) + if (launch_args.GetArgumentCount() > 0) + { + m_options.launch_info.GetArguments().AppendArguments (launch_args); + } + + + if (state == eStateConnected) + { + if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY)) + { + 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(); - process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name).get(); + if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY)) + { + process = target->GetPlatform()->DebugProcess (m_options.launch_info, + debugger, + target, + debugger.GetListener(), + error).get(); + } + 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); + } + + 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"); @@ -223,76 +301,7 @@ public: 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) - { - result.AppendWarning("launch in tty option is ignored when launching through a remote connection"); - m_options.launch_info.GetFlags().Clear (eLaunchFlagLaunchInTTY); - } - } - - 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); - } - } - Error error; - - error = process->Launch (m_options.launch_info); - + if (error.Success()) { const char *archname = exe_module->GetArchitecture().GetArchitectureName(); diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 2421af5e882a..63f5048b8758 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -83,14 +83,14 @@ CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpre "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\ diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index d38c5f1abfcd..0b09d35ff1f6 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -431,17 +431,30 @@ tell application \"Terminal\"\n\ 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 @@ LaunchInNewTerminalWithAppleScript (const char *exe_path, 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) { - command.Printf(" '%s'", argv[i]); + 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'", exe_path); } } command.PutCString (" ; echo Process exited with status $?"); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index a7279c1bc59c..bfc731906b37 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -250,6 +250,60 @@ ProcessInfo::SetArguments (const Args& args, } } +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 @@ ProcessLaunchCommandOptions::g_option_table[] = { LLDB_OPT_SET_ALL, false, "working-dir", 'w', required_argument, NULL, 0, eArgTypePath, "Set the current working directory to 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 ."}, { LLDB_OPT_SET_1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to ."}, @@ -475,7 +530,6 @@ ProcessLaunchCommandOptions::g_option_table[] = { 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 @@ Process::GetExitStatus () } -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; idxsecond); - env.AppendArgument (env_var_equal_value.c_str()); - } - return env.GetArgumentCount(); -} - - const char * Process::GetExitDescription () { @@ -4044,28 +4054,19 @@ ProcessInstanceSettings::ProcessInstanceSettings 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 } 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 @@ ProcessInstanceSettings::operator= (const ProcessInstanceSettings &rhs) { 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 @@ ProcessInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_ 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 @@ ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, 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::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 @@ ProcessInstanceSettings::CreateInstanceName () 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 @@ SettingEntry 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 } }; + diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index aec81ffee67f..866810c2bf59 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1973,14 +1973,22 @@ Target::SettingsController::CreateInstanceSettings (const char *instance_name) } -#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 @@ GetSettingNameForPlatformAvoid () 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 @@ TargetInstanceSettings::TargetInstanceSettings 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 @@ TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rh 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 @@ TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) { 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 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n { 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 @@ TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &ne 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 @@ TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, 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::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; idxsecond); + env.AppendArgument (env_var_equal_value.c_str()); + } + return env.GetArgumentCount(); +} + + const ConstString TargetInstanceSettings::CreateInstanceName () { @@ -2395,5 +2617,14 @@ Target::SettingsController::instance_settings_table[] = { 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 } }; diff --git a/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py b/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py index 7a7dc3b3c1aa..ff549c29407c 100644 --- a/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py +++ b/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py @@ -67,11 +67,11 @@ class SBDirCheckerCase(TestBase): 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, diff --git a/lldb/test/functionalities/load_unload/TestLoadUnload.py b/lldb/test/functionalities/load_unload/TestLoadUnload.py index 864bdcfd3b91..1c4beda3d4b4 100644 --- a/lldb/test/functionalities/load_unload/TestLoadUnload.py +++ b/lldb/test/functionalities/load_unload/TestLoadUnload.py @@ -82,13 +82,13 @@ class LoadUnloadTestCase(TestBase): # 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, diff --git a/lldb/test/settings/TestSettings.py b/lldb/test/settings/TestSettings.py index 01af654a1116..2f2ee824ce43 100644 --- a/lldb/test/settings/TestSettings.py +++ b/lldb/test/settings/TestSettings.py @@ -23,7 +23,7 @@ class SettingsCommandTestCase(TestBase): """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 @@ class SettingsCommandTestCase(TestBase): # 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 @@ class SettingsCommandTestCase(TestBase): 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 @@ class SettingsCommandTestCase(TestBase): "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.error-path", + SETTING_MSG("target.error-path"), + startstr = 'target.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.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 @@ class SettingsCommandTestCase(TestBase): # 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 @@ class SettingsCommandTestCase(TestBase): 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 @@ class SettingsCommandTestCase(TestBase): "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) =" ]) diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 1f5e485f2b8b..8ce6da95ecce 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -1251,13 +1251,13 @@ Driver::MainLoop () 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); }