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

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