以便能够进入调试

以便能够进入调试

本文介绍了如何配置 VS Code 以便能够进入调试 Python 脚本时加载的共享库 (.so)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从命令行使用 gdb 我可以在加载共享库时中断.知道我拥有共享库的源代码,如何在 VS Code 中获得相同的行为?

Using gdb from the command line I'm able to break when the shared library is loaded. How can I get the same behavior in VS Code knowing that I have the source code of the shared library?

推荐答案

对我来说它以某种方式工作.

For me it works somehow.

这是我的设置:

  • Ubuntu 18.04,调试我从 Python3 加载的 C++ 共享库(更具体地说 - 通过 Cython,但 IIRC 在通过 ctypes 加载 .so 时同样有效,我还记得它在调试纯 C 库时工作类似设置)
  • 在 VSCode 中,我有一个项目可以编译成 .so
  • 在那里我放了一堆断点
  • 我创建了一个启动配置(下面的文字)
  • 另外,我已经用调试信息编译了 .so

这是我的launch.json(在大多数情况下,它是样板文件,我只填写了程序"和参数"部分并​​设置了PYTHONPATH环境变量).

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).

注意:stopAtEntry:false"(默认情况下)似乎很重要,否则 VSCode 会尝试定位条目 .c 文件或其他内容.

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.

{
// 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 显示在我的断点处停止执行

anyway, in this setup I see my VSCode showing the execution stopping on my breakpoints

这篇关于如何配置 VS Code 以便能够进入调试 Python 脚本时加载的共享库 (.so)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 14:42