调试期间VSCode python'未验证的断点'?

时间:2018-05-30 10:06:56

标签: python visual-studio-code breakpoints vscode-settings vscode-debugger

我正在使用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"
            ]
        }
    ]
}

由于

2 个答案:

答案 0 :(得分: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)调试站点包中的文件。

我应该注意,调试器的“断点”部分为我提供了有关为何未验证断点以及对启动配置进行哪些调整的提示:

Breakpoints section of VSCode Debugger with useful tip

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

答案 1 :(得分:1)

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