对我来说,它在某种程度上有效。
这是我的设置:
这是我的launch.json(大部分是样板文件,我只填写了“program”和“args”部分,并设置了PYTHONPATH环境变量)。
注意:似乎重要的是要有“stopAtEntry:false”(默认情况下),否则VSCode会尝试定位一个入口.c文件或其他内容。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch 1123",
"type": "cppdbg",
"request": "launch",
"program": "/home/sergey/anaconda3/bin/python",
"args": [
"/storage/projects/cython-vst-loader/cython_vst_loader/test_load_plugin.py"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PYTHONPATH",
"value": "/storage/projects/cython-vst-loader"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
“setupCommands”:[ { “description”:“启用gdb的漂亮打印”, “text”:“-enable-pretty-printing”, “ignoreFailures”:true }
- MegaNightdude很遗憾,目前没有办法将Python代码转换为C代码以进行调试(据我所知,只有Visual Studio具备这种能力)。
谢谢 @user1312695,你的方法对我很有用!
现在我能够进入pybullet.c了!让我以此为例。 https://github.com/bulletphysics/bullet3
我想将可调试版本的pybullet包安装到conda环境中,并使用VScode开始调试,这是我所做的:
(0) 创建一个名为debug_pybullet
的新conda环境。
(1) 修改cmake/FindPythonLibs.cmake
FindPythonLibs.cmake
无法识别conda环境,因此在它找到错误的_PYTHON_EXECUTABLE
后,我需要手动设置路径,大约在第143行左右:
set(_PYTHON_EXECUTABLE /home/MyName/anaconda3/envs/debug_pybullet/bin/python)
(2)修改CMakeLists.txt
我需要手动添加文件build_cmake_pybullet_double.sh
中包含的定义,除了CMAKE_BUILD_TYPE=Release
的定义(我更喜欢让VSCode控制这个定义)。
此外,我在第93行左右手动设置了PYTHON_SITE_PACKAGES
:
set(PYTHON_SITE_PACKAGES /home/MyName/anaconda3/envs/debug_pybullet/lib/python3.6/site-packages)
launch.json
。launch.json
版本:{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/MyName/anaconda3/envs/debug_pybullet/bin/python",
"args": [
"/home/MyName/<path_to_python_file>/main.py"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
}
]
}
由于我手动设置了路径,所以这里不需要environments
和setupCommands
。
(4) 在VScode中,构建全部。
(5) 安装可调试包:
$ source activate pybullet_debug
(pybullet_debug)$ pip install -e .
(6) 在pybullet.c
中设置断点。
(7) 按下F5,运行Python,就可以了!