This is an archive of the discontinued LLVM Phabricator instance.

[lldb] fix -print-script-interpreter-info on windows
ClosedPublic

Authored by lawrence_danna on Nov 10 2021, 11:57 PM.

Details

Summary

Apparently "{sys.prefix}/bin/python3" isn't where you find the
python interpreter on windows, so the test I wrote for
-print-script-interpreter-info is failing.

We can't rely on sys.executable at runtime, because that will point
to lldb.exe not python.exe.

We can't just record sys.executable from build time, because python
could have been moved to a different location.

But it should be OK to apply relative path from sys.prefix to sys.executable
from build-time to the sys.prefix at runtime.

Diff Detail

Event Timeline

lawrence_danna requested review of this revision.Nov 10 2021, 11:57 PM
lawrence_danna created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2021, 11:57 PM
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
413

Does sys.executable not work for some reason?

432

Python on windows could have a version too (e.g. python3.exe)

lawrence_danna added inline comments.Nov 11 2021, 9:52 AM
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
413

Yes, unfortunately it will point to lldb.exe, not python.exe

432

Under what circumstances? How do we determine if it does? The one from python.org doesn't.

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
432

I am not sure. I *think* it depends on whether you have python 2 and python 3 installed at the same time.

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
432

yikes, OK I think I have a better idea.....

maybe this approach is better

lawrence_danna edited the summary of this revision. (Show Details)Nov 11 2021, 11:14 AM
lawrence_danna marked 3 inline comments as done.Nov 11 2021, 11:15 AM

OK this should work in all configs I think, as long as sys.executable ultimately points at something under sys.prefix

lawrence_danna edited the summary of this revision. (Show Details)

fix cmake error message condition for cross-compile

cleanup cmake usage

Can you please disable the test on Windows or back your change out until there's a fix? There are already other failures that are getting missed because the bot is red.

Can you please disable the test on Windows or back your change out until there's a fix? There are already other failures that are getting missed because the bot is red.

done.

revert change that disabled the test

JDevlieghere accepted this revision.Nov 16 2021, 1:14 PM

LGTM if the Windows bot is happy :-)

This revision is now accepted and ready to land.Nov 16 2021, 1:14 PM

This seems to have broken the green dragon incremental bot: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/38387/

lawrence_danna added a comment.EditedNov 16 2021, 5:52 PM

This seems to have broken the green dragon incremental bot: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/38387/

(edited)

ah dang you’re not cross compiling you shouldn’t get that error. i’ll fix it.

This seems to have broken the green dragon incremental bot: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/38387/

looks like its fixed now.

I can't build on macOS now. I checked out the source code and tried to do:

cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug -DLLVM_ENABLE_ASSERTIONS:BOOL=TRUE -DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi;lldb' -DLLDB_BUILD_FRAMEWORK:BOOL=TRUE -DLLDB_USE_SYSTEM_DEBUGSERVER=ON -DLLDB_EDITLINE_USE_WCHAR=0 -DLLDB_ENABLE_LIBEDIT:BOOL=TRUE -DLLDB_ENABLE_CURSES:BOOL=TRUE -DLLDB_ENABLE_PYTHON:BOOL=TRUE -DLLDB_ENABLE_LIBXML2:BOOL=TRUE -DLLDB_ENABLE_LUA:BOOL=FALSE ../llvm-project/llvm

The error is:

Traceback (most recent call last):
  File "/Users/gclayton/Documents/src/lldb/clean/llvm-project/lldb/bindings/python/get-python-config.py", line 60, in <module>
    main()
  File "/Users/gclayton/Documents/src/lldb/clean/llvm-project/lldb/bindings/python/get-python-config.py", line 33, in main
    print(relpath_nodots(sysconfig.get_path("platlib"), sys.prefix))
  File "/Users/gclayton/Documents/src/lldb/clean/llvm-project/lldb/bindings/python/get-python-config.py", line 14, in relpath_nodots
    raise ValueError(f"{path} is not under {base}")
ValueError: /Library/Python/3.8/site-packages is not under /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8
CMake Error at /Users/gclayton/Documents/src/lldb/clean/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt:2 (message):
  LLDB_PYTHON_RELATIVE_PATH is not set.

if I try to manually set the python3 executable with:

-DPYTHON_EXECUTABLE=/Applications/Xcode.app/Contents/Developer/usr/bin/python3

I get the following error:

[cmake] CMake Error at /Users/gclayton/Documents/src/lldb/clean/llvm-project/lldb/CMakeLists.txt:53 (message):
[cmake]   Crosscompiling LLDB with Python requires manually setting
[cmake]   LLDB_PYTHON_RELATIVE_PATH.

I am not cross compiling in this case.

Yes it does! Thanks

nealsid added a subscriber: nealsid.Dec 6 2021, 9:09 AM

I can't build on macOS now. I checked out the source code and tried to do:

cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug -DLLVM_ENABLE_ASSERTIONS:BOOL=TRUE -DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi;lldb' -DLLDB_BUILD_FRAMEWORK:BOOL=TRUE -DLLDB_USE_SYSTEM_DEBUGSERVER=ON -DLLDB_EDITLINE_USE_WCHAR=0 -DLLDB_ENABLE_LIBEDIT:BOOL=TRUE -DLLDB_ENABLE_CURSES:BOOL=TRUE -DLLDB_ENABLE_PYTHON:BOOL=TRUE -DLLDB_ENABLE_LIBXML2:BOOL=TRUE -DLLDB_ENABLE_LUA:BOOL=FALSE ../llvm-project/llvm

Random drive-by comment - any particular reason you compile without WCHAR support in libedit? I have a patch that removes the conditional support from our Editline class (actually it was committed and had to be reverted :P). But I was under the impression that nobody was using the non-WCHAR support anymore. Thanks.

I can't build on macOS now. I checked out the source code and tried to do:

cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug -DLLVM_ENABLE_ASSERTIONS:BOOL=TRUE -DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi;lldb' -DLLDB_BUILD_FRAMEWORK:BOOL=TRUE -DLLDB_USE_SYSTEM_DEBUGSERVER=ON -DLLDB_EDITLINE_USE_WCHAR=0 -DLLDB_ENABLE_LIBEDIT:BOOL=TRUE -DLLDB_ENABLE_CURSES:BOOL=TRUE -DLLDB_ENABLE_PYTHON:BOOL=TRUE -DLLDB_ENABLE_LIBXML2:BOOL=TRUE -DLLDB_ENABLE_LUA:BOOL=FALSE ../llvm-project/llvm

Random drive-by comment - any particular reason you compile without WCHAR support in libedit? I have a patch that removes the conditional support from our Editline class (actually it was committed and had to be reverted :P). But I was under the impression that nobody was using the non-WCHAR support anymore. Thanks.

No real reason. I would be fine if this went away. Not sure if there are any platforms that have an older libedit shared library that need to avoid bugs in the wide character implementation, but I don't work on any. So feel free to remove this and see how things go!