diff options
| author | Enrico Granata <egranata@apple.com> | 2012-12-19 23:42:07 +0000 |
|---|---|---|
| committer | Enrico Granata <egranata@apple.com> | 2012-12-19 23:42:07 +0000 |
| commit | 557fd00a6f58e7df81c19f4ccd00314daab12759 (patch) | |
| tree | fa5c4ae46f149c802e285c45f6b5fe0ea6f84a65 /lldb/source/Interpreter/ScriptInterpreterPython.cpp | |
| parent | 6c2b11cc50e84b497771e721448e7c2a7a4e6351 (diff) | |
| download | bcm5719-llvm-557fd00a6f58e7df81c19f4ccd00314daab12759.tar.gz bcm5719-llvm-557fd00a6f58e7df81c19f4ccd00314daab12759.zip | |
<rdar://problem/12446222>
Implement the ability for Python commands to be interrupted by pressing CTRL+C
Also add a new Mutex subclass that attempts to be helpful for debugging by logging actions performed on it
FYI of all interested - there is a separate deadlocking issue related to how LLDB dispatches CTRL+C that might cause LLDB to deadlock upon pressing CTRL+C while in a Python command.
This is not a regression, and was just previously masked by us not even trying to bail out of Python commands, so that it would not be clear from a user perspective whether we were
deadlocked or stuck in an inconsistent state within the Python interpreter.
llvm-svn: 170612
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
| -rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index a94f8709a41..78f8524d29c 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -371,7 +371,22 @@ ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback break; case eInputReaderInterrupt: - reader.SetIsDone(true); + { + PyThreadState* state = _PyThreadState_Current; + if (!state) + state = script_interpreter->m_command_thread_state; + if (state) + { + long tid = state->thread_id; + _PyThreadState_Current = state; + int num_threads = PyThreadState_SetAsyncExc(tid, PyExc_KeyboardInterrupt); + if (log) + log->Printf("ScriptInterpreterPython::NonInteractiveInputReaderCallback, eInputReaderInterrupt, tid = %ld, num_threads = %d, state = %p", + tid,num_threads,state); + } + else if (log) + log->Printf("ScriptInterpreterPython::NonInteractiveInputReaderCallback, eInputReaderInterrupt, state = NULL"); + } break; case eInputReaderEndOfFile: @@ -446,7 +461,8 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete m_dictionary_name (interpreter.GetDebugger().GetInstanceName().AsCString()), m_terminal_state (), m_session_is_active (false), - m_valid_session (true) + m_valid_session (true), + m_command_thread_state (NULL) { static int g_initialized = false; @@ -2643,8 +2659,16 @@ ScriptInterpreterPython::RunScriptBasedCommand(const char* impl_function, Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::InitGlobals, Locker::FreeLock | Locker::TearDownSession); + SynchronicityHandler synch_handler(debugger_sp, synchronicity); + + // we need to save the thread state when we first start the command + // because we might decide to interrupt it while some action is taking + // place outside of Python (e.g. printing to screen, waiting for the network, ...) + // in that case, _PyThreadState_Current will be NULL - and we would be unable + // to set the asynchronous exception - not a desirable situation + m_command_thread_state = _PyThreadState_Current; PythonInputReaderManager py_input(this); |

