[Lldb-commits] [lldb] r124341 - in /lldb/trunk/source: API/SBTarget.cpp Interpreter/ScriptInterpreter.cpp Interpreter/ScriptInterpreterPython.cpp
Greg Clayton
gclayton at apple.com
Wed Jan 26 17:01:10 PST 2011
Author: gclayton
Date: Wed Jan 26 19:01:10 2011
New Revision: 124341
URL: http://llvm.org/viewvc/llvm-project?rev=124341&view=rev
Log:
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.
Modified:
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=124341&r1=124340&r2=124341&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Jan 26 19:01:10 2011
@@ -151,36 +151,102 @@
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
Modified: lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreter.cpp?rev=124341&r1=124340&r2=124341&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreter.cpp Wed Jan 26 19:01:10 2011
@@ -93,12 +93,12 @@
void
ScriptInterpreter::Initialize ()
{
- ScriptInterpreterPython::Initialize ();
+// ScriptInterpreterPython::Initialize ();
}
void
ScriptInterpreter::Terminate ()
{
- ScriptInterpreterPython::Terminate ();
+// ScriptInterpreterPython::Terminate ();
}
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=124341&r1=124340&r2=124341&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Jan 26 19:01:10 2011
@@ -224,6 +224,14 @@
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.
More information about the lldb-commits
mailing list