[llvm-branch-commits] [lldb] r199445 - Initialize the script interpreter during SBDebugger::Initialize() to make sure we don't end up with a deadlock later due to Python trying to flockfile(stdin) during its initialization call.
Greg Clayton
gclayton at apple.com
Thu Jan 16 16:18:54 PST 2014
Author: gclayton
Date: Thu Jan 16 18:18:54 2014
New Revision: 199445
URL: http://llvm.org/viewvc/llvm-project?rev=199445&view=rev
Log:
Initialize the script interpreter during SBDebugger::Initialize() to make sure we don't end up with a deadlock later due to Python trying to flockfile(stdin) during its initialization call.
Modified:
lldb/branches/iohandler/source/Interpreter/ScriptInterpreterPython.cpp
lldb/branches/iohandler/source/lldb.cpp
Modified: lldb/branches/iohandler/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Interpreter/ScriptInterpreterPython.cpp?rev=199445&r1=199444&r2=199445&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/branches/iohandler/source/Interpreter/ScriptInterpreterPython.cpp Thu Jan 16 18:18:54 2014
@@ -159,13 +159,7 @@ ScriptInterpreterPython::ScriptInterpret
m_command_thread_state (NULL)
{
- static int g_initialized = false;
-
- if (!g_initialized)
- {
- g_initialized = true;
- ScriptInterpreterPython::InitializePrivate ();
- }
+ ScriptInterpreterPython::InitializePrivate ();
m_dictionary_name.append("_dict");
StreamString run_string;
@@ -417,14 +411,25 @@ ScriptInterpreterPython::EnterSession (b
PythonDictionary &sys_module_dict = GetSysModuleDictionary ();
if (sys_module_dict)
{
+ lldb::StreamFileSP in_sp;
+ lldb::StreamFileSP out_sp;
+ lldb::StreamFileSP err_sp;
+ if (in == NULL || out == NULL || err == NULL)
+ m_interpreter.GetDebugger().AdoptTopIOHandlerFilesIfInvalid (in_sp, out_sp, err_sp);
+
+ if (in == NULL && in_sp)
+ in = in_sp->GetFile().GetStream();
if (in)
{
m_saved_stdin.Reset(sys_module_dict.GetItemForKey("stdin"));
+
sys_module_dict.SetItemForKey ("stdin", PyFile_FromFile (in, (char *) "", (char *) "r", 0));
}
else
m_saved_stdin.Reset();
+ if (out == NULL && out_sp)
+ out = out_sp->GetFile().GetStream();
if (out)
{
m_saved_stdout.Reset(sys_module_dict.GetItemForKey("stdout"));
@@ -432,7 +437,9 @@ ScriptInterpreterPython::EnterSession (b
}
else
m_saved_stdout.Reset();
-
+
+ if (err == NULL && err_sp)
+ err = err_sp->GetFile().GetStream();
if (err)
{
m_saved_stderr.Reset(sys_module_dict.GetItemForKey("stderr"));
@@ -2472,6 +2479,13 @@ ScriptInterpreterPython::InitializeInter
void
ScriptInterpreterPython::InitializePrivate ()
{
+ static int g_initialized = false;
+
+ if (g_initialized)
+ return;
+
+ g_initialized = true;
+
Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
// Python will muck with STDIN terminal state, so save off any current TTY
Modified: lldb/branches/iohandler/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/lldb.cpp?rev=199445&r1=199444&r2=199445&view=diff
==============================================================================
--- lldb/branches/iohandler/source/lldb.cpp (original)
+++ lldb/branches/iohandler/source/lldb.cpp Thu Jan 16 18:18:54 2014
@@ -19,6 +19,7 @@
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/Mutex.h"
+#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -120,6 +121,7 @@ lldb_private::Initialize ()
SymbolFileDWARFDebugMap::Initialize();
ItaniumABILanguageRuntime::Initialize();
#ifndef LLDB_DISABLE_PYTHON
+ ScriptInterpreterPython::InitializePrivate();
OperatingSystemPython::Initialize();
#endif
More information about the llvm-branch-commits
mailing list