【问题标题】:VSCode python 'Unverified breakpoint' during debugging?调试期间VSCode python'未验证断点'?
【发布时间】:2018-05-30 10:06:56
【问题描述】:

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

谢谢

【问题讨论】:

  • 你能用实验性调试器试试这个,看看是否有什么不同吗?
  • 这也可能是未将 justMyCode 配置选项设置为 false 的结果。请参阅下面的答案。

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


【解决方案1】:

这可能是“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 的虚拟环境调试站点包中的文件。

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 那么,解决方案是什么?
    • @dmitry 您需要将调试器附加到运行这些execute 命令发送到的python 进程(在我的情况下为jupyter 内核)的进程
    • 这也可能是未将 justMyCode 配置选项设置为 false 的结果。请参阅下面的答案。
    猜你喜欢
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2022-01-17
    • 2020-01-27
    相关资源
    最近更新 更多