【问题标题】:can't debug bash scripts using VSCode无法使用 VSCode 调试 bash 脚本
【发布时间】:2018-02-15 11:24:55
【问题描述】:

我已经安装了带有 Bash 调试扩展的 VSCode。

在此之前,我已经安装了 bashdb,并使用 (bashdb --version) 验证了它的版本,它是 4.4。

现在,扩展程序会创建一个名为 launch.json 的空文件。

我写了以下开始调试,但仍然没有发生任何事情

{
    "version": "0.2.0",

    "scriptPath": "${command:SelectScriptName}",

    "configurations": [
    ],
    "compounds": [
        {
            "type": "bashdb",
            "name": "Compound",
            "configurations": []
        }
    ]
}

我应该怎么做才能启用调试?

问候,

【问题讨论】:

    标签: bash shell visual-studio-code sh


    【解决方案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(硬编码脚本名称)”配置,允许硬编码脚本路径。

    【讨论】:

      【解决方案2】:

      安装了bashdb 扩展后,将以下块添加到launch.json 文件中。此配置允许您调试当前在 VS Code 上打开的脚本。因此,为了开始调试脚本,您必须在 VS Code 上打开它,然后输入 F5 以开始调试它。或者,也可以在 VS Code 上打开相同的脚本,打开 VS Code 左侧栏上的 Run and Debug 菜单,然后单击 Play

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

      args 参数添加到上述块中,允许您在调试时将带有参数的数组传递给脚本。

      【讨论】:

        【解决方案3】:

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

        bash -x script.sh
        

        或在脚本中添加:

        set -x 
        <DEBUG_CODE_LINES>
        set +x
        

        【讨论】:

        • 我知道这个选项。我正在尝试使用 VSCode
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-10
        • 2017-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多