[Bug 42284] New: Support SWIG 4.0

Bug ID 42284
Summary Support SWIG 4.0
Product lldb
Version 8.0
Hardware All
OS All
Status NEW
Severity enhancement
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter pyry.kontio@drasa.eu
CC jdevlieghere@apple.com, llvm-bugs@lists.llvm.org

Created attachment 22106 [details]
A Python wrapper generated by SWIG 4

The SWIG project released SWIG 4.0.0 on 2019-04-27. Some package managers such
as Homebrew rapidly included it as the default version. However, the current
interface files seem to generate broken wrappers with SWIG 4.

Having SWIG 4 installed and LLDB built using it, it errors like this:

$ echo "import lldb" > test_lldb.py
$ bin/lldb
(lldb) command script import test_lldb.py

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File
"/Users/kon/repos/llvm-project/build/lib/python2.7/site-packages/lldb/__init__.py",
line 1500, in <module>
    class SBAddress(object):
  File
"/Users/kon/repos/llvm-project/build/lib/python2.7/site-packages/lldb/__init__.py",
line 1675, in SBAddress
    __swig_getmethods__["module"] = GetModule
NameError: name '__swig_getmethods__' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
error: module importing failed: No module named test_script.py
  File "temp.py", line 1, in <module>

The important difference seems to be that SWIG 4 doesn't, by default, generate
dictionaries __swig_getmethods__ and __swig_setmethods__ to the objects.

Looking at the release notes, the passage "Python module overhaul by
simplifying the generated code and turning most optimizations on by default."
like the likely culprit.

I'm going to ask about the recommended way to migrate on the SWIG users mailing
list, but if someone knows a good fix, please reply.

Some projects such as Rust's LLDB support were already regressed by accidental
upgrade to SWIG 4. ( [https://github.com/rust-lang/rust/pull/61827](https://github.com/rust-lang/rust/pull/61827) ) It would be
great if LLDB could quickly support the 4.x series.

Jonas Devlieghere changed bug 42284