Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable python scripting in lldb #1362

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_info/lldb-14.control
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Section: Development
Version: @DEB_LLVM_V@
Architecture: @DEB_ARCH@
Maintainer: @DEB_MAINTAINER@
Depends: liblldb-14 (= @DEB_LLVM_V@), debugserver-14 (= @DEB_LLVM_V@)
Depends: liblldb-14 (= @DEB_LLVM_V@), debugserver-14 (= @DEB_LLVM_V@), python3-lldb-14 (= @DEB_LLVM_V@)
Priority: optional
Homepage: https://www.llvm.org/
Description: Next generation, high-performance debugger
9 changes: 9 additions & 0 deletions build_info/python3-lldb-14.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: python3-lldb-14
Section: Development
Version: @DEB_LLVM_V@
Architecture: @DEB_ARCH@
Maintainer: @DEB_MAINTAINER@
Depends: python3.9 (= 3.9.9-1), libpython3.9 (= 3.9.9-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Depends: python3.9 (= 3.9.9-1), libpython3.9 (= 3.9.9-1)
Depends: python3.9, libpython3.9

Priority: optional
Homepage: https://www.llvm.org/
Description: Next generation, high-performance debugger
10 changes: 10 additions & 0 deletions build_patch/llvm/lldb-swig-multiple-declaration.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- llvm/lldb/bindings/interfaces.swig 2022-11-12 00:14:17.000000000 +0100
+++ llvm/lldb/bindings/interfaces.swig 2023-02-22 23:47:51.000000000 +0100
@@ -2,7 +2,6 @@
#define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
/* The ISO C99 standard specifies that in C++ implementations limit macros such
as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
-#define __STDC_LIMIT_MACROS
%include "stdint.i"

%include "lldb/lldb-defines.h"
11 changes: 11 additions & 0 deletions build_patch/llvm/python-typemaps-patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- llvm/lldb/bindings/python/python-typemaps.swig 2022-11-12 00:14:17.000000000 +0100
+++ llvm/lldb/bindings/python/python-typemaps.swig 2023-02-23 17:48:52.000000000 +0100
@@ -435,7 +435,7 @@

%typemap(out) lldb::FileSP {
$result = nullptr;
- lldb::FileSP &sp = $1;
+ const lldb::FileSP &sp = $1;
if (sp) {
PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp));
if (!pyfile.IsValid())
26 changes: 21 additions & 5 deletions makefiles/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ ifneq ($(PROCURSUS),1)
$(error Use the main Makefile)
endif

#Checking if swig and python3 is installed
HAS_COMMAND = $(shell type $(1) >/dev/null 2>&1 && echo 1)
ifneq ($(call HAS_COMMAND,swig),1)
$(error Install swig)
endif
ifneq ($(call HAS_COMMAND,python3),1)
$(error Install python3)
endif
PYTHON3_PATH := $(shell which python3)

#### Consider mlir/pstl/flang too

SUBPROJECTS += llvm
Expand Down Expand Up @@ -71,6 +81,8 @@ ifeq ($(wildcard $(BUILD_WORK)/../../native/llvm/.build_complete),)
touch $(BUILD_WORK)/../../native/llvm/.build_complete
endif



ifeq ($(wildcard $(BUILD_WORK)/llvm/build/.build_complete),)
case $(MEMO_TARGET) in \
*"darwin"*) \
Expand Down Expand Up @@ -145,7 +157,8 @@ ifeq ($(wildcard $(BUILD_WORK)/llvm/build/.build_complete),)
-DLLDB_TABLEGEN_EXE="$(BUILD_WORK)/../../native/llvm/bin/lldb-tblgen" \
-DLLDB_BUILD_FRAMEWORK=OFF \
-DLLDB_ENABLE_LUA=OFF \
-DLLDB_ENABLE_PYTHON=OFF \
-DLLDB_PYTHON_RELATIVE_PATH="$(PYTHON3_PATH)" \
-DLLDB_ENABLE_PYTHON=ON \
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_IOS="$(IPHONEOS_DEPLOYMENT_TARGET)" \
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_OSX="$(MACOSX_DEPLYMENT_TARGET)" \
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS="$(WATCHOS_DEPLOYMENT_TARGET)" \
Expand Down Expand Up @@ -311,7 +324,7 @@ endif
# llvm.mk Prep liblldb-$(LLVM_MAJOR_V)
mkdir -p $(BUILD_DIST)/liblldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib
cp -a $(BUILD_STAGE)/llvm/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib/liblldb.$(LLVM_VERSION).dylib $(BUILD_DIST)/liblldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib

# llvm.mk Prep liblldb-$(LLVM_MAJOR_V)-dev
mkdir -p $(BUILD_DIST)/liblldb-$(LLVM_MAJOR_V)-dev/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/{include,lib}
cp -a $(BUILD_STAGE)/llvm/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/include/lldb $(BUILD_DIST)/liblldb-$(LLVM_MAJOR_V)-dev/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/include
Expand All @@ -332,10 +345,14 @@ endif
cp -a $(BUILD_STAGE)/llvm/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib/libLLVM.dylib $(BUILD_DIST)/libllvm$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib
$(LN_S) libLLVM.dylib $(BUILD_DIST)/libllvm$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/lib/libLLVM-$(LLVM_MAJOR_V).dylib

#llvm.mk Prep python3-lldb-$(LLVM_MAJOR_V)
mkdir -p $(BUILD_DIST)/python3-lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/local/lib/python3.9/dist-packages
cp -a $(BUILD_STAGE)/llvm/opt/procursus/bin/python3/. $(BUILD_DIST)/python3-lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/local/lib/python3.9/dist-packages/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem correct...
Won't this break on rootless and stuff?

Copy link
Contributor

@TheRealKeto TheRealKeto Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They just didn't use the prefix variables. I don't like that period though.

Suggested change
cp -a $(BUILD_STAGE)/llvm/opt/procursus/bin/python3/. $(BUILD_DIST)/python3-lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/local/lib/python3.9/dist-packages/
cp -a $(BUILD_STAGE)/llvm/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/bin/python3/. $(BUILD_DIST)/python3-lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/python3.9/dist-packages/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it copying from bin to local/lib???


# llvm.mk Prep lldb-$(LLVM_MAJOR_V)
mkdir -p $(BUILD_DIST)/lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/bin
cp -a $(BUILD_STAGE)/llvm/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/bin/lldb{,-argdumper,-instr,-server,-vscode} $(BUILD_DIST)/lldb-$(LLVM_MAJOR_V)/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/lib/llvm-$(LLVM_MAJOR_V)/bin

# llvm.mk Prep lldb
mkdir -p $(BUILD_DIST)/lldb/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/bin
for bin in lldb{,-argdumper,-instr,-server,-vscode}; do \
Expand Down Expand Up @@ -415,8 +432,6 @@ endif
# llvm.mk Prep lld
mkdir -p $(BUILD_DIST)/lld/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/bin
$(LN_S) ../lib/llvm-$(LLVM_MAJOR_V)/bin/{ld.lld,ld64.lld,lld,lld-link,wasm-ld} $(BUILD_DIST)/lld/$(MEMO_PREFIX)$(MEMO_SUB_PREFIX)/bin/


# llvm.mk Sign
$(call SIGN,clang-$(LLVM_MAJOR_V),general.xml)
$(call SIGN,clangd-$(LLVM_MAJOR_V),general.xml)
Expand Down Expand Up @@ -461,6 +476,7 @@ endif
$(call PACK,liblldb-$(LLVM_MAJOR_V),DEB_LLVM_V)
$(call PACK,liblldb-$(LLVM_MAJOR_V)-dev,DEB_LLVM_V)
$(call PACK,libllvm$(LLVM_MAJOR_V),DEB_LLVM_V) # Provides libllvm-polly
$(call PACK,python3-lldb-$(LLVM_MAJOR_V),DEB_LLVM_V)
$(call PACK,lldb-$(LLVM_MAJOR_V),DEB_LLVM_V)
$(call PACK,lldb,DEB_LLVM_V)
$(call PACK,swift-$(SWIFT_VERSION),DEB_SWIFT_V)
Expand Down