Error running LLDB tests on Windows

Hello,

I’ve built lldb from source on Windows, following the instructions here Building - :bug: LLDB (llvm.org) but I am having problems running the test-api tests. All tests fail because python cannot find the module ‘use_lldb_suite’.

ModuleNotFoundError: no module named ‘use_lldb_suite’

I configured the build with:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS=“lldb;llvm;clang;lld” -DPYTHON_HOME=c:\python36 -DLLDB_ENABLE_PYTHON=TRUE …\llvm

Is this a common error, what am I doing wrong?

Thanks!
Paolo

Python 3.6 has been end-of-life for a couple of years now. I’d suggest moving to at least 3.11. More details here: Status of Python versions

I think the issue could be either lldb is not configured correctly to use Python, or the test run is not configured correctly to find the test suite.

For test suite configuration:
How are you running the tests?
What are the command line arguments to dotest.py? You can get command line args by using Process Explorer from Microsoft.

For Python configuration:
You can test this by running lldb manually and typing “script”. That gets you into the script interpreter. If that works, try “import sys; sys.version; sys.path” and see if the values are sane. Then type “lldb.debugger” and see if you get something like 'Debugger (instance: “debugger_1”, id: 1)
If these work, then your Python config is more than likely good.

You don’t need to set LLDB_ENABLE_PYTHON to TRUE on the cmake line. cmake will turn it on automatically if it can find a supported Python and supported swig. The code to do this is in llvm-project/lldb/cmake/modules/LLDBConfig.cmake .

You don’t mention swig, and don’t have it set on your cmake line, so my guess is you don’t have it. You can get it from http://swig.org . You need swig 4 or later to run tests.

If that’s not the issue, post the output from a fresh cmake run. You can simply delete CMakeCache.txt to force a fresh run. Interesting things to look for are what Python clang is picking up (clang uses Python before lldb, and cmake will use that python for lldb) and if lldb is happy with the Python and swig that cmake detects.

This is true but it can also turn it off automatically :slight_smile: So in this particular case it’s a good idea to enable it explicitly.

This log Buildbot from the Windows build bot shows what you should expect to see. Ctrl-f for “swig” and “python”.

(it is a Windows on Arm machine, but it shouldn’t make a difference here)

Thank you all for your replies!

I already had swig 4.11 installed and added to the PATH, so that should not be the problem.

I uninstalled all versions of Python from my Windows 11 and installed Python 3.11 as suggested. (Before there were several issues, for example I was using an embedded distribution, .zip file, for Python 3.6, and the PYTHONPATH environment variable was not respected).

After reinstalling Python I rerun cmake in a new folder, and the problem with ‘use_lldb_suite’ is actually solved, but I see this error:

ImportError: DLL load failed while importing _lldb: The specified module could not be found.

This time I think I have a clue about the issue: in my build folder
llvm-project\dbg64\lib\site-packages\lldb
there should be a file _lldb.pyd but instead there is a file _lldb.cp311-win_amd64.pyd.

What could have caused this renaming?

Thanks again,
Paolo

This page can help you setup your environment for running LLDB testsuite on windows. It contains instructions on how to setup a windows on Arm buildbot but intructions should work equally well for x64 or any other LLVM build.

An important point to note is that you are building LLDB in Debug mode which will require python libs installed with debug symbols. You can opt for debug python libs when installing python.

As far as python is concerned following two folders should be in PATH:
Python\Python311\ and Python\Python311\Scripts\

Thank you! I will look at that page.

I have done some progress in my investigation. The failure to import _lldb was not caused by the name of the file _lldb.cp311-win_amd64.pyd but by the fact that I am building with XML support, so the _lldb.cp311-win_amd64.pyd DLL was trying to load libxml2.dll.
And since version 3.8 Python stopped searching dlls in directories specified by PATH, as described in this bug 46891 – "import _lldb" doesn't work on Windows with Python 3.8+.
A quick fix was to just copy libxml2.dll into the site-packages\lldb folder.

Now tests work fine in release builds :slight_smile:
In debug builds instead I now get this error:

Fatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL).

According to stack overflow, this should be fixed by running the debug version of python (python_d). But running the test with python_d the error DLL load failed while importing _lldb: comes back, maybe caused by some other “missing” dependency.

Interestingly, the Buildbot log Buildbot is building without XML support:
– Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) (Required is at least version “2.8”)