diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake index fc84e581cc188..a9679d63e010d 100644 --- a/lldb/cmake/modules/LLDBConfig.cmake +++ b/lldb/cmake/modules/LLDBConfig.cmake @@ -68,6 +68,7 @@ add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON) option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF) option(LLDB_ENABLE_PROTOCOL_SERVERS "Enable protocol servers (e.g. MCP) in LLDB" ON) +option(LLDB_ENABLE_PYTHON_LIMITED_API "Force LLDB to only use the Python Limited API (requires SWIG 4.2 or later)" OFF) option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF) option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF) option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF) diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake index 46e9a95781c32..79eaf88216450 100644 --- a/lldb/include/lldb/Host/Config.h.cmake +++ b/lldb/include/lldb/Host/Config.h.cmake @@ -45,6 +45,8 @@ #cmakedefine01 LLDB_ENABLE_PYTHON +#cmakedefine01 LLDB_ENABLE_PYTHON_LIMITED_API + #cmakedefine01 LLDB_ENABLE_FBSDVMCORE #cmakedefine01 LLDB_EMBED_PYTHON_HOME diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h b/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h index 4a6c11dba02e8..9b4a1dd2cecb2 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h @@ -45,12 +45,20 @@ static llvm::Expected *g_fcxx_modules_workaround [[maybe_unused]]; #include #endif +#define LLDB_MINIMUM_PYTHON_VERSION 0x03080000 + +#if LLDB_ENABLE_PYTHON_LIMITED_API +// If defined, LLDB will be ABI-compatible with all Python 3 releases from the +// specified one onward, and can use Limited API introduced up to that version. +#define Py_LIMITED_API LLDB_MINIMUM_PYTHON_VERSION +#endif + // Include python for non windows machines #include // Provide a meaningful diagnostic error if someone tries to compile this file // with a version of Python we don't support. -static_assert(PY_VERSION_HEX >= 0x03080000, +static_assert(PY_VERSION_HEX >= LLDB_MINIMUM_PYTHON_VERSION, "LLDB requires at least Python 3.8"); #endif