Skip to content

Commit 6030419

Browse files
authored
Revert "[lldb] Fix that the embedded Python REPL crashes if it receives SIGINT"
1 parent ec45ce2 commit 6030419

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
@@ -1050,23 +1050,6 @@ void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
10501050
}
10511051

10521052
bool ScriptInterpreterPythonImpl::Interrupt() {
1053-
// PyErr_SetInterrupt was introduced in 3.2.
1054-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
1055-
// If the interpreter isn't evaluating any Python at the moment then return
1056-
// false to signal that this function didn't handle the interrupt and the
1057-
// next component should try handling it.
1058-
if (!IsExecutingPython())
1059-
return false;
1060-
1061-
// Tell Python that it should pretend to have received a SIGINT.
1062-
PyErr_SetInterrupt();
1063-
// PyErr_SetInterrupt has no way to return an error so we can only pretend the
1064-
// signal got successfully handled and return true.
1065-
// Python 3.10 introduces PyErr_SetInterruptEx that could return an error, but
1066-
// the error handling is limited to checking the arguments which would be
1067-
// just our (hardcoded) input signal code SIGINT, so that's not useful at all.
1068-
return true;
1069-
#else
10701053
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
10711054

10721055
if (IsExecutingPython()) {
@@ -1088,7 +1071,6 @@ bool ScriptInterpreterPythonImpl::Interrupt() {
10881071
"ScriptInterpreterPythonImpl::Interrupt() python code not running, "
10891072
"can't interrupt");
10901073
return false;
1091-
#endif
10921074
}
10931075

10941076
bool ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn(
@@ -3294,28 +3276,6 @@ ScriptInterpreterPythonImpl::AcquireInterpreterLock() {
32943276
return py_lock;
32953277
}
32963278

3297-
namespace {
3298-
/// Saves the current signal handler for the specified signal and restores
3299-
/// it at the end of the current scope.
3300-
struct RestoreSignalHandlerScope {
3301-
/// The signal handler.
3302-
struct sigaction m_prev_handler;
3303-
int m_signal_code;
3304-
RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
3305-
// Initialize sigaction to their default state.
3306-
std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
3307-
// Don't install a new handler, just read back the old one.
3308-
struct sigaction *new_handler = nullptr;
3309-
int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
3310-
lldbassert(signal_err == 0 && "sigaction failed to read handler");
3311-
}
3312-
~RestoreSignalHandlerScope() {
3313-
int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
3314-
lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
3315-
}
3316-
};
3317-
} // namespace
3318-
33193279
void ScriptInterpreterPythonImpl::InitializePrivate() {
33203280
if (g_initialized)
33213281
return;
@@ -3351,25 +3311,6 @@ void ScriptInterpreterPythonImpl::InitializePrivate() {
33513311
"lldb.embedded_interpreter; from "
33523312
"lldb.embedded_interpreter import run_python_interpreter; "
33533313
"from lldb.embedded_interpreter import run_one_line");
3354-
3355-
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
3356-
// Python will not just overwrite its internal SIGINT handler but also the
3357-
// one from the process. Backup the current SIGINT handler to prevent that
3358-
// Python deletes it.
3359-
RestoreSignalHandlerScope save_sigint(SIGINT);
3360-
3361-
// Setup a default SIGINT signal handler that works the same way as the
3362-
// normal Python REPL signal handler which raises a KeyboardInterrupt.
3363-
// Also make sure to not pollute the user's REPL with the signal module nor
3364-
// our utility function.
3365-
PyRun_SimpleString("def lldb_setup_sigint_handler():\n"
3366-
" import signal;\n"
3367-
" def signal_handler(sig, frame):\n"
3368-
" raise KeyboardInterrupt()\n"
3369-
" signal.signal(signal.SIGINT, signal_handler);\n"
3370-
"lldb_setup_sigint_handler();\n"
3371-
"del lldb_setup_sigint_handler\n");
3372-
#endif
33733314
}
33743315

33753316
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)