调试基础
调试动作
官方文档:https://code.visualstudio.com/docs/editor/debugging#_debug-actions
一旦开始一个调试会话,调试动作面板将出现在编辑器的最上方
调试动作 | 含义 | 翻译 | 快捷键 |
---|---|---|---|
Continue / Pause | 继续:恢复正常的程序/脚本执行(直到下一个断点) 暂停:检查在当前行执行的代码并逐行调试 | 继续 / 暂停 | F5 |
Step Over | 将下一个方法作为单个命令执行 | 单步跳过 | F10 |
Step Into | 进入下一个方法,逐行跟随它的执行 | 单步跳入 | F11 |
Step Out | 在方法或子例程中时,通过完成当前方法的剩余行返回到较早的执行上下文 | 单步跳出 | ⇧F11 |
Restart | 重新启动调试 | 重新启动 | ⇧⌘F5 |
Stop | 停止调试 | 停止 | ⇧F5 |
launch.json
${userHome}
-/home/your-username
${workspaceFolder}
-/home/your-username/your-project
${workspaceFolderBasename}
-your-project
${file}
-/home/your-username/your-project/folder/file.ext
${fileWorkspaceFolder}
-/home/your-username/your-project
${relativeFile}
-folder/file.ext
${relativeFileDirname}
-folder
${fileBasename}
-file.ext
${fileBasenameNoExtension}
-file
${fileDirname}
-/home/your-username/your-project/folder
${fileExtname}
-.ext
${lineNumber}
- line number of the cursor${selectedText}
- text selected in your code editor${execPath}
- location of Code.exe${pathSeparator}
-/
on macOS or linux,\
on Windows
示例
Golang 程序调试
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Package",
"type": "go",
"request": "launch",
// "mode": "auto",
"mode": "debug",
"program": "${workspaceFolder}/lib/dex/cmd/dex/",
"cwd": "${workspaceFolder}/lib/dex",
"env": {},
"args": [
"serve",
"${workspaceFolder}/dev/dev-local/config-dev.yaml"
],
"buildFlags": "-mod=mod",
"showGlobalVariables": false
}
]
}