无法使用VSCode调试Bash脚本。

4
我已经安装了带有Bash调试扩展的VSCode。
在那之前,我已经安装了bashdb,并使用bashdb --version验证了它的版本,是4.4。
现在,该扩展创建了一个名为launch.json的空文件。
我写了以下内容来开始调试,但是仍然没有任何反应。
{
    "version": "0.2.0",
   
    "scriptPath": "${command:SelectScriptName}",
 
    "configurations": [
    ],
    "compounds": [
        {
            "type": "bashdb",
            "name": "Compound",
            "configurations": []
        }
    ]
}

如何启用调试?
3个回答

0

安装了 bashdb 扩展后,将以下代码块添加到 launch.json 文件中。此配置允许您在 VS Code 上调试当前打开的脚本。因此,要开始调试脚本,您必须在 VS Code 上打开它,并键入 F5 以开始调试。或者,也可以在 VS Code 上打开相同的脚本,然后打开左侧栏上的 运行和调试 菜单,点击 播放

{
  "type": "bashdb",
  "request": "launch",
  "name": "Bash-Debug (simplest configuration)",
  "cwd": "${workspaceFolder}",
  "program": "${file}",
  "showDebugOutput": true,
  "terminalKind": "integrated"
}

在上述代码块中添加args参数,可以在调试时传递带有参数的数组到脚本中。

-1

我使用Bash Debug扩展测试了这段代码:

{
"version": "0.2.0",
"configurations": 
[
{
    "type": "bashdb",
    "request": "launch",
    "name": "Bash-Debug (select script from list of sh files)",
    "cwd": "${workspaceFolder}",
    "program": "${command:SelectScriptName}",
    "args": []
}
]
}

Visual Studio Code 展示了一个脚本列表,你可以选择你想要运行的脚本。或者你也可以选择“Bash-Debug (hardcoded script name)” 配置,这样就可以硬编码脚本路径。

-2
如果您想调试Bash脚本,我建议您使用-x标志执行您的脚本。例如:
bash -x script.sh

或者在脚本中添加:

set -x 
<DEBUG_CODE_LINES>
set +x

1
我知道这个选项。我正在尝试使用VSCode。 - Macnux

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接