VSCode Debug

debug操作

行为 快捷键
Continue / Pause F5
Step Over F10
Step Into F11
Step Out Shift+F11
Restart Ctrl+Shift+F5 已经更改为Ctrl+F5
Stop Shift+F5

查看变量

在这里插入图片描述

1.Variables窗口可以查看当前内存中的变量值,并且可以进行设置
2.Watch窗口可以观察指定的变量

断点

在这里插入图片描述
1.普通断点
2.条件断点,当触发条件时才打断,经常用在循环里
3.日志断点,不打断,只输出

debug配置

https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes

debug所有配置文件都保存在.vscode/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: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

下面三个变量每个launch.json文件都包含

type - the type of debugger to use for this launch configuration. Every installed debug extension introduces a type: node for the built-in Node debugger, for example, or php and go for the PHP and Go extensions.
request - the request type of this launch configuration. Currently, launch and attach are supported.
name - the reader-friendly name to appear in the Debug launch configuration drop-down.

下面的是可选的变量

presentation - using the order, group, and hidden attributes in the presentation object you can sort, group, and hide configurations and compounds in the Debug configuration dropdown and in the Debug quick pick.
preLaunchTask - to launch a task before the start of a debug session, set this attribute to the name of a task specified in tasks.json (in the workspace’s .vscode folder). Or, this can be set to ${defaultBuildTask} to use your default build task.
postDebugTask - to launch a task at the very end of a debug session, set this attribute to the name of a task specified in tasks.json (in the workspace’s .vscode folder).
internalConsoleOptions - this attribute controls the visibility of the Debug Console panel during a debugging session.
debugServer - for debug extension authors only: this attribute allows you to connect to a specified port instead of launching the debug adapter.
serverReadyAction - if you want to open a URL in a web browser whenever the program under debugging outputs a specific message to the debug console or integrated terminal. For details see section Automatically open a URI when debugging a server program below.

很多的debug程序包含以下变量

program - executable or file to run when launching the debugger
args - arguments passed to the program to debug
env - environment variables (the value null can be used to “undefine” a variable)
cwd - current working directory for finding dependencies and other files
port - port when attaching to a running process
stopOnEntry - break immediately when the program launches
console - what kind of console to use, for example, internalConsole, integratedTerminal, or externalTerminal

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章