Bug 2361538

Summary: Cannot use lldb when in a virtual envrionment.
Product: [Fedora] Fedora Reporter: Ezike Ebuka <yerimyah1>
Component: lldbAssignee: Nikita Popov <npopov>
Status: CLOSED COMPLETED QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 42CC: airlied, jan, jchecahi, kkleine, npopov, sergesanspaille, siddharth.kde, suraj.ghimire7, tstellar, tuliom
Target Milestone: ---Flags: npopov: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2025-07-10 07:53:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ezike Ebuka 2025-04-21 22:45:26 UTC
Description of problem:
LLDB does not working in a virtual environment.


Version-Release number of selected component (if applicable):
20.1 fedora 42. 


How reproducible:
$ python -m venv venv
$ source ./venv/bin/activate
$ lldb 


Actual results:
LLDB starts with python error of missing modules 

```sh
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lldb.embedded_interpreter'
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
Traceback (most recent call last):
  File "/home/da-viper/Dev/contribute/llvm-project/llvm/utils/lldbDataFormatters.py", line 14, in __lldb_init_module
    debugger.HandleCommand("type category define -e llvm -l c++")
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SwigPyObject' object has no attribute 'HandleCommand'
swig/python detected a memory leak of type 'lldb::SBDebugger *', no destructor found.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'lldb' is not defined
```

Expected results: LLDB lauches fine. 


Additional info: 
After reading the LLVM.spec file i think this is caused by the line 
```
%if %{without compat_build}
	
# Move python package out of llvm prefix.
	
mkdir -p %{buildroot}%{python3_sitearch}
	
mv %{buildroot}%{install_prefix}/%{_lib}/python%{python3_version}/site-packages/lldb %{buildroot}/%{python3_sitearch}
	
rmdir %{buildroot}%{install_prefix}/%{_lib}/python%{python3_version}/site-packages
	
rmdir %{buildroot}%{install_prefix}/%{_lib}/python%{python3_version}
```
Since it is moved to the default site packages on the OS, when we create a virtual environment the site packages that is checked is overridden, Then it will not find the required module. 

file spec link https://src.fedoraproject.org/rpms/llvm/blob/rawhide/f/llvm.spec

This is not in set in Fedora 41 branch

Comment 1 Nikita Popov 2025-04-22 07:33:37 UTC
I think the location on f41 is the same, it's just that it gets there in a different way. On f41 it was directly installed there, on f42 we first install to a different path and then move it. The lldb binary itself will be in a different location though, maybe that makes a difference?

Comment 2 Tulio Magno Quites Machado Filho 2025-04-25 14:07:56 UTC
I confirmed that f41 and rawhide are indeed installing python files in the same location.
The problem appears to be in lldb itself.

On Rawhide we have:
$ lldb -P
/usr/lib64/llvm20/lib64/python3.13/site-packages

While on f41:
$ lldb -P
/usr/lib64/python3.13/site-packages

Comment 3 Tulio Magno Quites Machado Filho 2025-04-25 14:10:46 UTC
While this is investigated/fixed, the following might help as a workaround:

    PYTHONPATH=/usr/lib64/python3.13/site-packages lldb

Comment 4 Nikita Popov 2025-07-10 07:53:11 UTC
This has been fixed a while ago as part of (mostly) undoing the prefix changes.

Tested in https://src.fedoraproject.org/tests/llvm/pull-request/55.