Skip to content

Conversation

@JDevlieghere
Copy link
Member

This is a reland of #129135 (by dingxiangfei2009) with Vladislav (dzhidzhoev) fix on top.

Fixes #92603

This is a reland of llvm#129135 (by dingxiangfei2009) with Vladislav
(dzhidzhoev) fix on top.

Fixes llvm#92603
@JDevlieghere
Copy link
Member Author

CC @dingxiangfei2009

@llvmbot llvmbot added the lldb label Nov 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 3, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

This is a reland of #129135 (by dingxiangfei2009) with Vladislav (dzhidzhoev) fix on top.

Fixes #92603


Full diff: https://github.com/llvm/llvm-project/pull/166265.diff

3 Files Affected:

  • (modified) lldb/bindings/python/CMakeLists.txt (+6-2)
  • (modified) lldb/bindings/python/python.swig (+6-1)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+1)
diff --git a/lldb/bindings/python/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt
index ef6def3f26872..de3ea7091ad1f 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -60,8 +60,10 @@ endfunction()
 function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
   # Add a Post-Build Event to copy over Python files and create the symlink to
   # liblldb.so for the Python API(hardlink on Windows).
+  # Note that Swig-generated code is located one level deeper in the `native`
+  # module, in order to avoid cyclic importing.
   add_custom_target(${swig_target} ALL VERBATIM
-    COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}
+    COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}/native/
     DEPENDS ${lldb_python_bindings_dir}/lldb.py
     COMMENT "Python script sym-linking LLDB Python API")
 
@@ -75,6 +77,8 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
       "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py"
       "${lldb_python_target_dir}")
 
+  create_python_package(${swig_target} ${lldb_python_target_dir} "native" FILES)
+
   # Distribute the examples as python packages.
   create_python_package(
     ${swig_target}
@@ -142,7 +146,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
   endif()
   set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
-                          ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
+                          ${lldb_python_target_dir}/native/ ${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
 
   if (NOT WIN32)
diff --git a/lldb/bindings/python/python.swig b/lldb/bindings/python/python.swig
index 4a5a39dc4b06d..155e1c64fb103 100644
--- a/lldb/bindings/python/python.swig
+++ b/lldb/bindings/python/python.swig
@@ -50,7 +50,12 @@ Older swig versions will simply ignore this setting.
     import $module
 except ImportError:
     # Relative import should work if we are being loaded by Python.
-    from . import $module"
+    # The cpython module built by swig is pushed one level down into
+    # the native submodule, because at this point the interpreter
+    # is still constructing the lldb module itself.
+    # Simply importing anything using `from . import` constitutes
+    # a cyclic importing.
+    from .native import $module"
 %enddef
 
 // The name of the module to be created.
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index d257a08a2c62c..5e4c39cb2886c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -272,6 +272,7 @@ void ScriptInterpreterPython::SharedLibraryDirectoryHelper(
   // does.
   if (this_file.GetFileNameExtension() == ".pyd") {
     this_file.RemoveLastPathComponent(); // _lldb.pyd or _lldb_d.pyd
+    this_file.RemoveLastPathComponent(); // native
     this_file.RemoveLastPathComponent(); // lldb
     llvm::StringRef libdir = LLDB_PYTHON_RELATIVE_LIBDIR;
     for (auto it = llvm::sys::path::begin(libdir),

@JDevlieghere JDevlieghere changed the title Push down the SWIG module to avoid an import cycle [lldb] Push down the SWIG module to avoid an import cycle Nov 17, 2025
@JDevlieghere
Copy link
Member Author

Let's see if this sticks :-)

@JDevlieghere JDevlieghere merged commit 18b5e2a into llvm:main Nov 17, 2025
12 checks passed
@JDevlieghere JDevlieghere deleted the reland-129135 branch November 17, 2025 18:56
@dzhidzhoev
Copy link
Member

Nice!
(Sorry, missed the notification)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building lldb at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/22746

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/instruction-breakpoint/TestDAP_instruction_breakpoint.py (1235 of 2600)
PASS: lldb-api :: tools/lldb-dap/invalidated-event/TestDAP_invalidatedEvent.py (1236 of 2600)
PASS: lldb-api :: tools/lldb-dap/io/TestDAP_io.py (1237 of 2600)
PASS: lldb-api :: tools/lldb-dap/locations/TestDAP_locations.py (1238 of 2600)
PASS: lldb-api :: tools/lldb-dap/memory/TestDAP_memory.py (1239 of 2600)
UNSUPPORTED: lldb-api :: tools/lldb-dap/module/TestDAP_module.py (1240 of 2600)
PASS: lldb-api :: tools/lldb-dap/moduleSymbols/TestDAP_moduleSymbols.py (1241 of 2600)
PASS: lldb-api :: tools/lldb-dap/evaluate/TestDAP_evaluate.py (1242 of 2600)
PASS: lldb-api :: tools/lldb-dap/optimized/TestDAP_optimized.py (1243 of 2600)
PASS: lldb-api :: tools/lldb-dap/module-event/TestDAP_module_event.py (1244 of 2600)
FAIL: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (1245 of 2600)
******************** TEST 'lldb-api :: tools/lldb-dap/output/TestDAP_output.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --cmake-build-type Release /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/output -p TestDAP_output.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06)
  clang revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06
  llvm revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06
Skipping the following test categories: ['libc++', 'msvcstl', 'dsym', 'pdb', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py:389: UserWarning: received a malformed packet, expected 'seq != 0' for {'body': {'$__lldb_version': 'lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06)\n  clang revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06\n  llvm revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06', 'completionTriggerCharacters': ['.', ' ', '\t'], 'exceptionBreakpointFilters': [{'description': 'C++ Catch', 'filter': 'cpp_catch', 'label': 'C++ Catch', 'supportsCondition': True}, {'description': 'C++ Throw', 'filter': 'cpp_throw', 'label': 'C++ Throw', 'supportsCondition': True}, {'description': 'Objective-C Catch', 'filter': 'objc_catch', 'label': 'Objective-C Catch', 'supportsCondition': True}, {'description': 'Objective-C Throw', 'filter': 'objc_throw', 'label': 'Objective-C Throw', 'supportsCondition': True}], 'supportTerminateDebuggee': True, 'supportsBreakpointLocationsRequest': True, 'supportsCancelRequest': True, 'supportsCompletionsRequest': True, 'supportsConditionalBreakpoints': True, 'supportsConfigurationDoneRequest': True, 'supportsDataBreakpoints': True, 'supportsDelayedStackTraceLoading': True, 'supportsDisassembleRequest': True, 'supportsEvaluateForHovers': True, 'supportsExceptionFilterOptions': True, 'supportsExceptionInfoRequest': True, 'supportsFunctionBreakpoints': True, 'supportsHitConditionalBreakpoints': True, 'supportsInstructionBreakpoints': True, 'supportsLogPoints': True, 'supportsModuleSymbolsRequest': True, 'supportsModulesRequest': True, 'supportsReadMemoryRequest': True, 'supportsSetVariable': True, 'supportsSteppingGranularity': True, 'supportsValueFormattingOptions': True, 'supportsWriteMemoryRequest': True}, 'command': 'initialize', 'request_seq': 1, 'seq': 0, 'success': True, 'type': 'response'}
  warnings.warn(
========= DEBUG ADAPTER PROTOCOL LOGS =========
1763426772.904145479 (stdio) --> {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryEvent":true,"$__lldb_sourceInitFile":false},"seq":1}
1763426772.904422045 (stdio) queued (command=initialize seq=1)
1763426772.907992125 (stdio) <-- {"body":{"$__lldb_version":"lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06)\n  clang revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06\n  llvm revision 18b5e2a7266bfe8f211be7ae1198e6bed4ab0c06","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"description":"C++ Catch","filter":"cpp_catch","label":"C++ Catch","supportsCondition":true},{"description":"C++ Throw","filter":"cpp_throw","label":"C++ Throw","supportsCondition":true},{"description":"Objective-C Catch","filter":"objc_catch","label":"Objective-C Catch","supportsCondition":true},{"description":"Objective-C Throw","filter":"objc_throw","label":"Objective-C Throw","supportsCondition":true}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModuleSymbolsRequest":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsSetVariable":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true,"supportsWriteMemoryRequest":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}
1763426772.909413576 (stdio) --> {"command":"launch","type":"request","arguments":{"program":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/output/TestDAP_output.test_output/a.out","initCommands":["settings clear --all","settings set symbols.enable-external-lookup false","settings set target.inherit-tcc true","settings set target.disable-aslr false","settings set target.detach-on-error false","settings set target.auto-apply-fixits false","settings set plugin.process.gdb-remote.packet-timeout 60","settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"","settings set use-color false","settings set show-statusline false"],"exitCommands":["?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)","?script print('err\\0\\0', end='\\r\\n', file=sys.stderr)"],"disableASLR":false,"enableAutoVariableSummaries":false,"enableSyntheticChildDebugging":false,"displayExtendedBacktrace":false},"seq":2}
1763426772.909476280 (stdio) queued (command=launch seq=2)
1763426772.909914255 (stdio) <-- {"body":{"category":"console","output":"Running initCommands:\n"},"event":"output","seq":1,"type":"event"}
1763426772.910095692 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings clear --all\n"},"event":"output","seq":2,"type":"event"}
1763426772.910171747 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set symbols.enable-external-lookup false\n"},"event":"output","seq":3,"type":"event"}
1763426772.910235882 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.inherit-tcc true\n"},"event":"output","seq":4,"type":"event"}
1763426772.910311222 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.disable-aslr false\n"},"event":"output","seq":5,"type":"event"}
1763426772.910382986 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.detach-on-error false\n"},"event":"output","seq":6,"type":"event"}
1763426772.910479784 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.auto-apply-fixits false\n"},"event":"output","seq":7,"type":"event"}
1763426772.910548925 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set plugin.process.gdb-remote.packet-timeout 60\n"},"event":"output","seq":8,"type":"event"}
1763426772.910629749 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set symbols.clang-modules-cache-path \"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api\"\n"},"event":"output","seq":9,"type":"event"}
1763426772.910706520 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set use-color false\n"},"event":"output","seq":10,"type":"event"}
1763426772.910778761 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set show-statusline false\n"},"event":"output","seq":11,"type":"event"}
1763426773.304860592 (stdio) <-- {"body":{"module":{"addressRange":"0xf450e000","debugInfoSize":"983.3KB","id":"C8C14F49-271D-D5EC-D97C-F1A70B997423-FCAC2BC1","name":"ld-linux-armhf.so.3","path":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolFilePath":"/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":12,"type":"event"}
1763426773.305544853 (stdio) <-- {"body":{"module":{"addressRange":"0xfad0000","debugInfoSize":"1.2KB","id":"ADE42BB1","name":"a.out","path":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/output/TestDAP_output.test_output/a.out","symbolFilePath":"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/tools/lldb-dap/output/TestDAP_output.test_output/a.out","symbolStatus":"Symbols loaded."},"reason":"new"},"event":"module","seq":13,"type":"event"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot run LLDB API Tests on MacOS

4 participants