[英]How to configure VS Code to be able to step into a shared library (.so) that is loaded when debugging a Python script?
从命令行使用 gdb 我可以在加载共享库时中断。 知道我拥有共享库的源代码,如何在 VS Code 中获得相同的行为?
对我来说,它以某种方式起作用。
这是我的设置:
这是我的 launch.json(在大多数情况下,它是样板文件,我只填写了“程序”和“参数”部分并设置了 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
}
]
}
]
无论如何,在这个设置中,我看到我的 VSCode 显示在我的断点处停止执行
不幸的是,没有一种方法可以从 Python 代码流入 C 代码以进行调试(据我所知,只有 Visual Studio 具有这种能力)。
谢谢@user1312695,你的方法对我有用!
我现在可以进入 pybullet.c 了! 所以让我以此为例。 https://github.com/bulletphysics/bullet3
我想将可调试版本的 pybullet 包安装到 conda 环境中并使用 VScode 开始我的调试,这是我所做的:
(0) 创建一个名为debug_pybullet
的新debug_pybullet
环境。
(1)修改cmake/FindPythonLibs.cmake
FindPythonLibs.cmake
无法识别FindPythonLibs.cmake
环境,因此在发现错误的_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)
(3)创建launch.json
在VScode。
这是我的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,我们来了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.