[英]How to configure VS Code to be able to step into a shared library (.so) that is loaded when debugging a Python script?
Using gdb from the command line I'm able to break when the shared library is loaded.从命令行使用 gdb 我可以在加载共享库时中断。 How can I get the same behavior in VS Code knowing that I have the source code of the shared library?
知道我拥有共享库的源代码,如何在 VS Code 中获得相同的行为?
For me it works somehow.对我来说,它以某种方式起作用。
Here's my setup:这是我的设置:
here's my launch.json (for the most part, it's boilerplate, I only filled in the "program" and "args" parts and set up PYTHONPATH environment var).这是我的 launch.json(在大多数情况下,它是样板文件,我只填写了“程序”和“参数”部分并设置了 PYTHONPATH 环境变量)。
note: it seems to be important to have "stopAtEntry:false" (which it is by default), otherwise VSCode tries to locate an entry .c file or something.注意:拥有“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
}
]
}
]
anyway, in this setup I see my VSCode showing the execution stopping on my breakpoints无论如何,在这个设置中,我看到我的 VSCode 显示在我的断点处停止执行
不幸的是,没有一种方法可以从 Python 代码流入 C 代码以进行调试(据我所知,只有 Visual Studio 具有这种能力)。
Thank you @user1312695, your method works for me!谢谢@user1312695,你的方法对我有用!
I was able to step into pybullet.c now!我现在可以进入 pybullet.c 了! So let me take this as an example.
所以让我以此为例。 https://github.com/bulletphysics/bullet3
https://github.com/bulletphysics/bullet3
I want to install the debuggable version pybullet package into a conda environment and use VScode to start my debugging, here is what I did:我想将可调试版本的 pybullet 包安装到 conda 环境中并使用 VScode 开始我的调试,这是我所做的:
(0) create a new conda environment called debug_pybullet
. (0) 创建一个名为
debug_pybullet
的新debug_pybullet
环境。
(1) modify cmake/FindPythonLibs.cmake
(1)修改
cmake/FindPythonLibs.cmake
FindPythonLibs.cmake
can't recognize conda environments, so after it found the wrong _PYTHON_EXECUTABLE
, I need to manually set the path at around line 143: FindPythonLibs.cmake
无法识别FindPythonLibs.cmake
环境,因此在发现错误的_PYTHON_EXECUTABLE
,我需要在第 143 行附近手动设置路径:
set(_PYTHON_EXECUTABLE /home/MyName/anaconda3/envs/debug_pybullet/bin/python)
(2) modify CMakeLists.txt
(2)修改
CMakeLists.txt
I need to manually add the definitions which are included in file build_cmake_pybullet_double.sh
, except the definition of CMAKE_BUILD_TYPE=Release
(I prefer to let VSCode control this definition).我需要手动添加包含在文件
build_cmake_pybullet_double.sh
的定义,除了CMAKE_BUILD_TYPE=Release
的定义(我更喜欢让 VSCode 控制这个定义)。
also I manually set PYTHON_SITE_PACKAGES
at around line 93:我也在第 93 行附近手动设置
PYTHON_SITE_PACKAGES
:
set(PYTHON_SITE_PACKAGES /home/MyName/anaconda3/envs/debug_pybullet/lib/python3.6/site-packages)
(3) Create launch.json
in VScode. (3)创建
launch.json
在VScode。
Here is my version of 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",
}
]
}
Since I manually set the path, I don't need the environments
and setupCommands
here.由于我手动设置路径,因此我不需要这里的
environments
和设置setupCommands
。
(4) In VScode, build all. (4)在VScode中,全部编译。
(5) Install the debuggable package: (5) 安装可调试包:
$ source activate pybullet_debug
(pybullet_debug)$ pip install -e .
(6) Set the breakpoints in pybullet.c
. (6) 在
pybullet.c
设置断点。
(7) Press F5, Run the python, and here we are! (7) 按F5,运行python,我们来了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.