1

我正在使用 VSCode 调试我的 python 应用程序。

我有一个启动调试器的主要 python 文件。我可以在这个文件中放置断点,但是如果我想在主文件调用的其他文件中放置断点,我将它们作为“未验证的断点”获取,并且调试器会忽略它们。

如何更改我的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": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}"
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "${workspaceFolder}",
            "port": 3000,
            "secret": "my_secret",
            "host": "localhost"
        },
        {
            "name": "Python: Terminal (integrated)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Terminal (external)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "debugOptions": [
                "RedirectOutput",
                "Django"
            ]
        },
        {
            "name": "Python: Flask (0.11.x or later)",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "${workspaceFolder}/app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ]
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "nf.session.session"
        },
        {
            "name": "Python: Pyramid",
            "type": "python",
            "request": "launch",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            "debugOptions": [
                "RedirectOutput",
                "Pyramid"
            ]
        },
        {
            "name": "Python: Watson",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/console.py",
            "args": [
                "dev",
                "runserver",
                "--noreload=True"
            ]
        },
        {
            "name": "Python: All debug Options",
            "type": "python",
            "request": "launch",
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "module": "module.name",
            "env": {
                "VAR1": "1",
                "VAR2": "2"
            },
            "envFile": "${workspaceFolder}/.env",
            "args": [
                "arg1",
                "arg2"
            ],
            "debugOptions": [
                "RedirectOutput"
            ]
        }
    ]
}

谢谢

4

2 回答 2

5

这可能是“ justMyCode ”配置选项的结果,因为它默认为 true。

虽然提供者的描述是“......仅对用户编写的代码进行调试。设置为 False 以启用标准库函数的调试。”,我认为它们的意思是当前站点包中的任何内容python环境不会被调试。

我想调试 Django 堆栈以确定源自我的代码的异常在哪里被吃掉而不是浮出水面,所以我对 VSCode 的调试器的启动配置执行了此操作:

   {
        // 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": "Control Center",
                "type": "python",
                "request": "launch",
                "program": "${workspaceFolder}/manage.py",
                "args": [
                    "runserver",
                    "--noreload"
                ],
                "justMyCode": false, // I want to debug through Django framework code sometimes
                "django": true
            }
        ]
    }

一旦我这样做了,调试器就删除了“未验证的断点”消息,并允许我为我正在处理的包含 Django 的虚拟环境调试站点包中的文件。

我应该注意到调试器的断点部分给了我一个提示,说明为什么断点未被验证以及对启动配置进行哪些调整:

带有有用提示的 VSCode 调试器的断点部分

另一个注意事项:“--noreload”参数也很重要。在使用 Flask 调试不同的应用程序时,调试器不会在任何断点处停止,直到我将其添加到启动配置中。

于 2019-10-08T13:08:48.757 回答
1

其他模块的导入在字符串内部并使用该execute函数调用。这就是为什么 VSCode 不能非常清楚其他文件中的断点,因为它不知道这些其他文件被主文件使用。

于 2018-06-13T11:54:05.063 回答