[Lldb-commits] [PATCH] D77661: [lldb/Python] Add lldbconfig Python module to make the lldb module configurable.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 7 10:18:57 PDT 2020


JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
Herald added a subscriber: mgorny.
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.


================
Comment at: lldb/packages/Python/lldbsuite/test/dotest.py:957
 
+    import lldbconfig
     import lldb
----------------
This is a NO-OP for now, but just shows that we can load the lldbconfig module. 


Using the approach described in [1] and suggested by Pavel D77588 <https://reviews.llvm.org/D77588> , this patch introduces a new `lldbconfig` module that lives next to the `lldb` module. It makes it possible to make the `lldb` module configurable. More specifically it makes it possible to delay initializing the debugger, which is needed for testing the reproducer.

I chose to name the module lldbconfig rather than `lldb.config` because I thought it would be weird to import a "submodule" before the main module, but if anyone feels the other approach is more desirable I'd be happy to change it.

[1] https://stackoverflow.com/questions/3720740/pass-variable-on-import/39360070#39360070


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D77661

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python.swig
  lldb/bindings/python/lldbconfig.py
  lldb/packages/Python/lldbsuite/test/dotest.py


Index: lldb/packages/Python/lldbsuite/test/dotest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -954,7 +954,9 @@
 
     setupSysPath()
 
+    import lldbconfig
     import lldb
+
     # Use host platform by default.
     lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
 
Index: lldb/bindings/python/lldbconfig.py
===================================================================
--- /dev/null
+++ lldb/bindings/python/lldbconfig.py
@@ -0,0 +1 @@
+INITIALIZE = True
Index: lldb/bindings/python.swig
===================================================================
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -128,8 +128,15 @@
 %include "./python/python-wrapper.swig"
 
 %pythoncode%{
+INITIALIZE = True
+try:
+   import lldbconfig
+   INITIALIZE = lldbconfig.INITIALIZE
+except ImportError:
+   pass
 debugger_unique_id = 0
-SBDebugger.Initialize()
+if INITIALIZE:
+   SBDebugger.Initialize()
 debugger = None
 target = None
 process = None
Index: lldb/CMakeLists.txt
===================================================================
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -99,11 +99,13 @@
   get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
 
   if(LLDB_BUILD_FRAMEWORK)
-    set(lldb_python_build_path "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
+    set(python_build_path "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python")
   else()
-    set(lldb_python_build_path "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
+    set(python_build_path "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}")
   endif()
 
+  set(lldb_python_build_path "${python_build_path}/lldb")
+
   # Add a Post-Build Event to copy over Python files and create the symlink
   # to liblldb.so for the Python API(hardlink on Windows).
   add_custom_target(finish_swig ALL VERBATIM
@@ -115,14 +117,24 @@
     add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
       COMMAND ${CMAKE_COMMAND} -E copy
         "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py"
-        "${lldb_python_build_path}/../six.py")
+        "${python_build_path}/six.py")
   endif()
 
+  add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
+    COMMAND ${CMAKE_COMMAND} -E make_directory
+      "${python_build_path}/lldbconfig")
+
+  add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
+    COMMAND ${CMAKE_COMMAND} -E copy
+      "${LLDB_SOURCE_DIR}/bindings/python/lldbconfig.py"
+      "${python_build_path}/lldbconfig/__init__.py")
+
   add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
     COMMAND ${CMAKE_COMMAND} -E copy
       "${lldb_bindings_dir}/lldb.py"
       "${lldb_python_build_path}/__init__.py")
 
+
   function(create_python_package pkg_dir)
     cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
     if(ARG_FILES)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77661.255706.patch
Type: text/x-patch
Size: 3015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200407/f17052e3/attachment-0001.bin>


More information about the lldb-commits mailing list