diff options
author | Greg Clayton <gclayton@apple.com> | 2011-01-27 01:01:10 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2011-01-27 01:01:10 +0000 |
commit | 645bf5420d9afc9dbcc9a59f45c48b3b15ca8a14 (patch) | |
tree | 27ea45a7da6afe33ec02eda29c2d0149e71b4d40 | |
parent | 582813596a1005bf1bba2b6630f78a197f2e019b (diff) | |
download | bcm5719-llvm-645bf5420d9afc9dbcc9a59f45c48b3b15ca8a14.tar.gz bcm5719-llvm-645bf5420d9afc9dbcc9a59f45c48b3b15ca8a14.zip |
Added support for some new environment variables within LLDB to enable some
extra launch options:
LLDB_LAUNCH_FLAG_DISABLE_ASLR disables ASLR for all launched processes
LLDB_LAUNCH_FLAG_DISABLE_STDIO will disable STDIO (reroute to "/dev/null")
for all launched processes
LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY will force all launched processes to be
launched in new terminal windows.
Also, don't init python if we never create a script interpreter.
llvm-svn: 124341
-rw-r--r-- | lldb/source/API/SBTarget.cpp | 104 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreter.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 8 |
3 files changed, 95 insertions, 21 deletions
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 13d227700bd..820327b12a9 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -151,36 +151,102 @@ SBTarget::Launch if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - if (sb_process.IsValid()) + if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) + launch_flags |= eLaunchFlagDisableASLR; + + if ((launch_flags & eLaunchFlagLaunchInTTY) || getenv("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY")) { - error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory)); - if (error.Success()) + ArchSpec arch (m_opaque_sp->GetArchitecture ()); + + Module *exe_module = m_opaque_sp->GetExecutableModule().get(); + if (exe_module) { - // We we are stopping at the entry point, we can return now! - if (stop_at_entry) - return sb_process; - - // Make sure we are stopped at the entry - StateType state = sb_process->WaitForProcessToStop (NULL); - if (state == eStateStopped) + char exec_file_path[PATH_MAX]; + exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path)); + if (exe_module->GetFileSpec().Exists()) { - // resume the process to skip the entry point - error.SetError (sb_process->Resume()); - if (error.Success()) + // Make a new argument vector + std::vector<const char *> exec_path_plus_argv; + // Append the resolved executable path + exec_path_plus_argv.push_back (exec_file_path); + + // Push all args if there are any + if (argv) { - // If we are doing synchronous mode, then wait for the - // process to stop yet again! - if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + for (int i = 0; argv[i]; ++i) + exec_path_plus_argv.push_back(argv[i]); + } + + // Push a NULL to terminate the args. + exec_path_plus_argv.push_back(NULL); + + + lldb::pid_t pid = Host::LaunchInNewTerminal (NULL, + &exec_path_plus_argv[0], + envp, + working_directory, + &arch, + true, + launch_flags & eLaunchFlagDisableASLR); + + if (pid != LLDB_INVALID_PROCESS_ID) + { + sb_process = AttachToProcessWithID(pid, error); + } + else + { + error.SetErrorStringWithFormat("failed to launch process in terminal"); } } + else + { + error.SetErrorStringWithFormat("executable doesn't exist: \"%s\"", exec_file_path); + } + } + else + { + error.SetErrorStringWithFormat("invalid executable"); } } else { - error.SetErrorString ("unable to create lldb_private::Process"); + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + + if (sb_process.IsValid()) + { + + if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) + launch_flags |= eLaunchFlagDisableSTDIO; + + + error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory)); + if (error.Success()) + { + // We we are stopping at the entry point, we can return now! + if (stop_at_entry) + return sb_process; + + // Make sure we are stopped at the entry + StateType state = sb_process->WaitForProcessToStop (NULL); + if (state == eStateStopped) + { + // resume the process to skip the entry point + error.SetError (sb_process->Resume()); + if (error.Success()) + { + // If we are doing synchronous mode, then wait for the + // process to stop yet again! + if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) + sb_process->WaitForProcessToStop (NULL); + } + } + } + } + else + { + error.SetErrorString ("unable to create lldb_private::Process"); + } } } else diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index cfc2572997d..fd1e10abfbc 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -93,12 +93,12 @@ ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language) void ScriptInterpreter::Initialize () { - ScriptInterpreterPython::Initialize (); +// ScriptInterpreterPython::Initialize (); } void ScriptInterpreter::Terminate () { - ScriptInterpreterPython::Terminate (); +// ScriptInterpreterPython::Terminate (); } diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 224ea7f6d37..368399b08e5 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -224,6 +224,14 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete m_valid_session (true) { + static int g_initialized = false; + + if (!g_initialized) + { + g_initialized = true; + ScriptInterpreterPython::Initialize (); + } + bool safe_to_run = false; bool need_to_release_lock = true; int interval = 5; // Number of seconds to try getting the Python lock before timing out. |