Skip to content

Windows Deug Env #8601

Open
Open

Description

@xuanranxiaoshi

Hi everyone, I now want to develop and debug the Taichi project on Windows through Visual Studio 2022. After I built the project using the debug configuration documentation on the Taichi website: https://docs.taichi-lang.cn/docs/windows_debug, a puzzling exception appeared in Step 4.

The project was successfully built at run time without error, but the debugging did not break at the breakpoint, but directly exited.

11:16:57:106	“python.exe”(Win32): 已加载“D:\development\anaconda\python.exe”。已加载符号。
11:16:57:106	“python.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。
11:16:57:106	“python.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。
11:16:57:106	“python.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\ucrtbase.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“D:\development\anaconda\python39.dll”。已加载符号。
11:16:57:610	“python.exe”(Win32): 已加载“D:\development\anaconda\vcruntime140.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\ws2_32.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\rpcrt4.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\version.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\msvcrt.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\advapi32.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\sechost.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\cryptsp.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\rsaenh.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\cryptbase.dll”。
11:16:57:610	“python.exe”(Win32): 已加载“C:\Windows\System32\bcryptprimitives.dll”。
11:16:57:648	“python.exe”(Win32): 已加载“C:\Windows\System32\kernel.appcore.dll”。
11:16:57:648	线程 49892 已退出,返回值为 1 (0x1)。
11:16:57:648	线程 13100 已退出,返回值为 1 (0x1)。
11:16:57:648	线程 29124 已退出,返回值为 1 (0x1)。
11:16:57:648	程序“[1776] python.exe”已退出,返回值为 1 (0x1)。

Is there something wrong with my process of building Taichi? Here's how I built from the source code:

The LLVM Debug build process is as follows:

cmake ..\llvm\ -G "Visual Studio 17 2022" -A x64 -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" -DLLVM_ENABLE_ASSERTIONS=ON -Thost=x64 -DLLVM_BUILD_TESTS:BOOL=OFF -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DCMAKE_CXX_STANDARD=17
git clone --recursive https://github.com/taichi-dev/taichi  
  
cd taichi  
  
$env:TAICHI_CMAKE_ARGS += " -DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_CUDA:BOOL=ON"  

$env:DEBUG = 1 # Uncomment it if you wish to keep debug information.  

$env:TAICHI_USE_MSBUILD = 1
  
python build.py --shell  

# 指定自己生成 LLVM Debug 版本路径后执行

python setup.py develop

Then I open ... /taichi/_skbuild/win-amd64-3.9/cmake-build/taichi. sln, the debugging environment is as follows:

image

The result is above!

Activity

  1. xuanranxiaoshi commented on Nov 12, 2024

    @xuanranxiaoshi
    Author

    I found a new problem.

    After building Taichi in the above way, I execute it directly on the command line:

    python tiDemo.py

    (tiDemo.py is a simple taichi sample program)

    Generate an error:

    Share object taichi_python import failed, check this page for possible solutions:
    https://docs.taichi-lang.org/docs/install
    Traceback (most recent call last):
      File "E:\Code\Cplusplus\TrnasTest\TransTest01\taichi\tiDemo.py", line 1, in <module>
        import taichi as ti
      File "e:\code\cplusplus\taichi\python\taichi\__init__.py", line 1, in <module>
        from taichi._funcs import *
      File "e:\code\cplusplus\taichi\python\taichi\_funcs.py", line 3, in <module>
        from taichi.lang import impl, ops
      File "e:\code\cplusplus\taichi\python\taichi\lang\__init__.py", line 1, in <module>
        from taichi.lang import impl, simt
      File "e:\code\cplusplus\taichi\python\taichi\lang\impl.py", line 6, in <module>
        from taichi._lib import core as _ti_core
      File "e:\code\cplusplus\taichi\python\taichi\_lib\__init__.py", line 1, in <module>
        from taichi._lib.utils import ti_python_core as core
      File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 110, in <module>
        ti_python_core = import_ti_python_core()
      File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 57, in import_ti_python_core
        raise e from None
      File "e:\code\cplusplus\taichi\python\taichi\_lib\utils.py", line 46, in import_ti_python_core
        from taichi._lib.core import taichi_python as core  # pylint: disable=C0415
    ImportError: DLL load failed while importing taichi_python: 找不到指定的模块。
    Consider installing Microsoft Visual C++ Redistributable: https://aka.ms/vs/16/release/vc_redist.x64.exe

    I installed 'vc_redis.x64.exe' but still did not solve the problem.

    I'm wondering how compiling Taichi in this way can be imported by a Python program?

  2. xuanranxiaoshi commented on Nov 13, 2024

    @xuanranxiaoshi
    Author

    Now I have solved the problem: ImportError: DLL load failed while importing taichi_python: The specified module could not be found.

    Instead of compiling Taichi in Debug mode, I set the environment variable to 0;

    However, debugging in VS 2022 still reported an error: the python.c source file could not be found.

    image

  3. PDE26jjk commented on Jan 8, 2026

    @PDE26jjk

    Have you solved the issue of breakpoint? I have same problem.

  4. PDE26jjk commented on Jan 8, 2026

    @PDE26jjk

    I asked Claude, and following his advice seems to have fixed the breakpoint issue. But now I have to manually copy the generated pyd and pdb files into taichi\python\taichi_lib\core after compiling. I'm looking for a solution.

    Here is Claude's output content

    > 你错了,我已经生成了pdb文件,也在VS调试中被识别到,一些库,比如GLFW3是可以打断点的,但是taichi_core、taichi_python
    等项目打不了断点
    
    ● 感谢纠正!让我重新分析这个问题。既然PDB文件已经生成并且GLFW3可以打断点,问题出在 taichi_core、taichi_python 这些特定项目上。
    
    ● Web Search("taichi visual studio breakpoint taichi_python taichi_core not working pybind11")
      ⎿  Did 5 searches in 35s
    
    ● Web Search("site:github.com/taichi-dev/taichi pybind11 visual studio debug breakpoint attach")
      ⎿  Did 1 search in 24s
    
    ● Search(pattern: "taichi_python|taichi_core", path: "cmake")
      ⎿  Found 4 files (ctrl+o to expand)
    
    ● 让我查看 taichi_core/taichi_python 的构建配置,看看是否有特殊的编译选项:
    
    ● Read(cmake\TaichiCore.cmake)
      ⎿  Read 439 lines
    
    ● Search(pattern: "add_library.*taichi_python|PYTHON_MODULE|pybind11", path: "cmake", output_mode: "content")
      ⎿  Found 27 lines (ctrl+o to expand)
    
    ● 找到了关键信息!在 TaichiCore.cmake:361 中使用了 pybind11_add_module,并且有这段代码(第415-417行):
    
      if (MSVC)
          set_property(TARGET ${CORE_WITH_PYBIND_LIBRARY_NAME} APPEND PROPERTY LINK_FLAGS /DEBUG)
      endif ()
    
      这里只是设置了链接器的 /DEBUG 标志,但可能没有设置编译器的 /Zi 标志来生成调试信息。让我检查 pybind11_add_module 的行为:
    
    ● Web Search("pybind11_add_module NO_EXTRAS visual studio debug symbols /Zi pdb not working")
      ⎿  Did 5 searches in 22s
    
    ● Bash(python -c "import pybind11; print(pybind11.__version__)")
      ⎿  3.0.1
    
    ● Search(pattern: "CMAKE_CXX_FLAGS.*MSVC|/Zi|/DEBUG", path: "cmake\TaichiCXXFlags.cmake", output_mode: "content")
      ⎿  Found 7 lines (ctrl+o to expand)
    
    ● 现在我明白问题了!关键在于:
    
      1. 全局编译标志(TaichiCXXFlags.cmake:47-49)设置 /Zi,但这只对 TI_GENERATE_PDB=ON 生效
      2. pybind11 模块使用 NO_EXTRAS 选项(TaichiCore.cmake:361),这可能会阻止某些默认的调试选项
      3. 只设置了链接器的 /DEBUG(TaichiCore.cmake:416),但可能没有为 pybind11 模块设置编译器的 /Zi
    
      让我查看是否需要为 taichi_python 目标显式添加编译选项:
    
    ● Web Search("pybind11_add_module NO_EXTRAS override CMAKE_CXX_FLAGS /Zi debug symbols windows")
      ⎿  Did 5 searches in 38s
    
    ● Bash(python -c "import pybind11; import os; print(os.path.dirname(pybind11.__file__))")
      ⎿  R:\miniconda3\lib\site-packages\pybind11
    
    ● 让我查看 pybind11 的 CMake 工具文件,了解 NO_EXTRAS 和调试符号设置:
    
    ● Read(R:\miniconda3\lib\site-packages\pybind11\tools\pybind11Tools.cmake)
      ⎿  Error reading file
    
    ● Bash(dir /s /b R:\miniconda3\lib\site-packages\pybind11\*.cmake 2>nul | head -5)
      ⎿  dir: cannot access '/s': No such file or directory
         dir: cannot access '/b': No such file or directory
         dir: cannot access 'R:miniconda3libsite-packagespybind11*.cmake': No such file or directory
         dir: cannot access '2': No such file or directory
    
    ● Bash(ls -la R:/miniconda3/lib/site-packages/pybind11/share/cmake/pybind11/ 2>/dev/null | head -20)
      ⎿  total 88
         drwxr-xr-x 1 26jjk 197609     0  1月  7 15:51 .
         drwxr-xr-x 1 26jjk 197609     0  1月  7 15:51 ..
         … +8 lines (ctrl+o to expand)
    
    ● Read(R:\miniconda3\lib\site-packages\pybind11\share\cmake\pybind11\pybind11Tools.cmake)
      ⎿  Read 218 lines
    
    ● 找到关键了!第185-187行:
    
      if(ARG_NO_EXTRAS)
          return()
      endif()
    
      NO_EXTRAS 选项导致 pybind11 跳过了所有额外的配置,包括第206行的 pybind11::windows_extras!
    
      让我查看 pybind11Common.cmake 看看 windows_extras 包含了什么:
    
    ● Read(R:\miniconda3\lib\site-packages\pybind11\share\cmake\pybind11\pybind11Common.cmake)
      ⎿  Read 448 lines
    
    ● 现在我完全理解了!pybind11::windows_extras 只包含 /bigobj 和 /MP 选项,没有调试符号相关的内容。
    
      问题的关键在于:虽然 TaichiCore.cmake:416 设置了链接器的 /DEBUG,但可能编译器的 /Zi 标志没有正确应用到 taichi_python 模块。
    
      让我提供一个解决方案:修改 TaichiCore.cmake,为 taichi_python 模块显式添加编译调试选项:
    
      解决方案
    
      需要在 cmake/TaichiCore.cmake 中,为 taichi_python 目标显式添加 /Zi 编译选项。以下是修改建议:
    
      在 TaichiCore.cmake 的第 415-417 行之后添加:
    
      # 原有代码(第415-417行)
      if (MSVC)
          set_property(TARGET ${CORE_WITH_PYBIND_LIBRARY_NAME} APPEND PROPERTY LINK_FLAGS /DEBUG)
      endif ()
    
      # 添加以下代码
      if (MSVC AND TI_GENERATE_PDB)
          # 显式为 pybind11 模块添加调试符号编译选项
          target_compile_options(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE /Zi /Zf)
          # 确保链接时也生成调试信息
          target_link_options(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE /DEBUG)
      endif ()
    
      这样可以确保即使 NO_EXTRAS 跳过了 pybind11 的默认配置,taichi_python 模块仍然能正确生成调试符号。
    
      完整的修复步骤
    
      # 1. 编辑 cmake/TaichiCore.cmake,在第417行之后添加上述代码
    
      # 2. 清理并重新构建
      Remove-Item -Recurse -Force _skbuild -ErrorAction SilentlyContinue
      $env:TAICHI_USE_MSBUILD = 1
      $env:TAICHI_CMAKE_ARGS = "-DTI_GENERATE_PDB=ON"
      python setup.py develop
    
      # 3. 在VS2022中重新打开解决方案,测试断点
    
      Sources:
      - https://pybind11.readthedocs.io/en/stable/cmake/
      - https://github.com/taichi-dev/taichi/issues/8601
    
      这个修改应该能解决 taichi_python 和 taichi_core 项目断点无法命中(即使有PDB文件)的问题。
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion on using Taichi

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions