llvm-project/lldb
Ralf Grosse-Kunstleve a6598575f4 [LLDB] Fix Python GIL-not-held issues
The GIL must be held when calling any Python C API functions. In multithreaded applications that use callbacks this requirement can easily be violated by accident. A general tool to ensure GIL health is not available, but patching Python Py_INCREF to add an assert provides a basic health check:

```
+int PyGILState_Check(void); /* Include/internal/pystate.h */
+
 #define Py_INCREF(op) (                         \
+    assert(PyGILState_Check()),                 \
     _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
     ((PyObject *)(op))->ob_refcnt++)

 #define Py_DECREF(op)                                   \
     do {                                                \
+        assert(PyGILState_Check());                     \
         PyObject *_py_decref_tmp = (PyObject *)(op);    \
         if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
         --(_py_decref_tmp)->ob_refcnt != 0)             \
```

Adding this assertion causes around 50 test failures in LLDB. Adjusting the scope of things guarded by `py_lock` fixes them.

More background: https://docs.python.org/3/glossary.html#term-global-interpreter-lock

Patch by Ralf Grosse-Kunstleve

Differential Revision: https://reviews.llvm.org/D114722
2022-01-17 10:32:19 +01:00
..
bindings [CMake][LLDB] Resolve install conflict when `LLDB_BUILD_FRAMEWORK=ON` 2022-01-15 10:43:05 -08:00
cmake [lldb] Use `GNUInstallDirs` to support custom installation dirs. 2021-12-22 00:28:53 +00:00
docs [lldb/doc] Rephrase tutorial paragraph (NFC) 2022-01-14 16:23:26 -08:00
examples [LLDB][NFC] Fix a typo in comment 2022-01-14 22:01:18 +08:00
include/lldb Revert "Revert "[LLDB][NativePDB] Add support for inlined functions"" 2022-01-13 14:00:24 -08:00
packages/Python/lldbsuite [lldb] [llgs] Implement qXfer:siginfo:read 2022-01-13 11:24:36 +01:00
resources [lldb] Remove stale LLDB-Info.plist 2021-01-08 10:12:16 -08:00
scripts Prefer /usr/bin/env xxx over /usr/bin/xxx where xxx = perl, python, awk 2021-02-25 11:32:27 +01:00
source [LLDB] Fix Python GIL-not-held issues 2022-01-17 10:32:19 +01:00
test [lldb] Correctly display the number of types found 2022-01-15 10:31:49 -08:00
third_party/Python/module [lldb][NFC] Inclusive language: replace master/slave names for ptys 2021-11-12 10:54:18 -06:00
tools [lldb] Remove lldb-instr 2022-01-10 11:48:16 -08:00
unittests [lldb] Remove PlatformDarwin::GetCompatibleArch helper 2022-01-15 09:51:16 -08:00
utils [lldb] Match test dependencies name to other LLVM projects. 2021-05-21 00:10:27 -07:00
.clang-format
.clang-tidy [lldb] Replace default bodies of special member functions with = default; 2021-07-02 11:31:16 -07:00
.gitignore
CMakeLists.txt [lldb] Use `GNUInstallDirs` to support custom installation dirs. 2021-12-22 00:28:53 +00:00
CODE_OWNERS.txt [CODE OWNERS] Add wallace as code owner 2022-01-12 12:36:30 -08:00
LICENSE.TXT
use_lldb_suite_root.py