Skip to content

Commit c3a3e65

Browse files
committed
Revert "[lldb] Fix that the embedded Python REPL crashes if it receives SIGINT"
This reverts commit cef1e07. It broke the windows bot.
1 parent 5417232 commit c3a3e65

File tree

2 files changed

+0
-132
lines changed

2 files changed

+0
-132
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,23 +1067,6 @@ void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
10671067
}
10681068

10691069
bool ScriptInterpreterPythonImpl::Interrupt() {
1070-
// PyErr_SetInterrupt was introduced in 3.2.
1071-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
1072-
// If the interpreter isn't evaluating any Python at the moment then return
1073-
// false to signal that this function didn't handle the interrupt and the
1074-
// next component should try handling it.
1075-
if (!IsExecutingPython())
1076-
return false;
1077-
1078-
// Tell Python that it should pretend to have received a SIGINT.
1079-
PyErr_SetInterrupt();
1080-
// PyErr_SetInterrupt has no way to return an error so we can only pretend the
1081-
// signal got successfully handled and return true.
1082-
// Python 3.10 introduces PyErr_SetInterruptEx that could return an error, but
1083-
// the error handling is limited to checking the arguments which would be
1084-
// just our (hardcoded) input signal code SIGINT, so that's not useful at all.
1085-
return true;
1086-
#else
10871070
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
10881071

10891072
if (IsExecutingPython()) {
@@ -1105,7 +1088,6 @@ bool ScriptInterpreterPythonImpl::Interrupt() {
11051088
"ScriptInterpreterPythonImpl::Interrupt() python code not running, "
11061089
"can't interrupt");
11071090
return false;
1108-
#endif
11091091
}
11101092

11111093
bool ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn(
@@ -3311,28 +3293,6 @@ ScriptInterpreterPythonImpl::AcquireInterpreterLock() {
33113293
return py_lock;
33123294
}
33133295

3314-
namespace {
3315-
/// Saves the current signal handler for the specified signal and restores
3316-
/// it at the end of the current scope.
3317-
struct RestoreSignalHandlerScope {
3318-
/// The signal handler.
3319-
struct sigaction m_prev_handler;
3320-
int m_signal_code;
3321-
RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
3322-
// Initialize sigaction to their default state.
3323-
std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
3324-
// Don't install a new handler, just read back the old one.
3325-
struct sigaction *new_handler = nullptr;
3326-
int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
3327-
lldbassert(signal_err == 0 && "sigaction failed to read handler");
3328-
}
3329-
~RestoreSignalHandlerScope() {
3330-
int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
3331-
lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
3332-
}
3333-
};
3334-
} // namespace
3335-
33363296
void ScriptInterpreterPythonImpl::InitializePrivate() {
33373297
if (g_initialized)
33383298
return;
@@ -3368,25 +3328,6 @@ void ScriptInterpreterPythonImpl::InitializePrivate() {
33683328
"lldb.embedded_interpreter; from "
33693329
"lldb.embedded_interpreter import run_python_interpreter; "
33703330
"from lldb.embedded_interpreter import run_one_line");
3371-
3372-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
3373-
// Python will not just overwrite its internal SIGINT handler but also the
3374-
// one from the process. Backup the current SIGINT handler to prevent that
3375-
// Python deletes it.
3376-
RestoreSignalHandlerScope save_sigint(SIGINT);
3377-
3378-
// Setup a default SIGINT signal handler that works the same way as the
3379-
// normal Python REPL signal handler which raises a KeyboardInterrupt.
3380-
// Also make sure to not pollute the user's REPL with the signal module nor
3381-
// our utility function.
3382-
PyRun_SimpleString("def lldb_setup_sigint_handler():\n"
3383-
" import signal;\n"
3384-
" def signal_handler(sig, frame):\n"
3385-
" raise KeyboardInterrupt()\n"
3386-
" signal.signal(signal.SIGINT, signal_handler);\n"
3387-
"lldb_setup_sigint_handler();\n"
3388-
"del lldb_setup_sigint_handler\n");
3389-
#endif
33903331
}
33913332

33923333
void ScriptInterpreterPythonImpl::AddToSysPath(AddLocation location,

lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)