rogalmic/vscode-bash-debug

Bash debugging does not start with Visual Studio Code 1.44.0

Closed this issue · 21 comments

In addition to the details for issue, please provide us Executables information and Debug output unless you have confidence that they don't help us.

Executables

Version of bash-debug: 0.3.7
Version of Visual Studio Code: 1.44.0-1 (on Arch Linux; latest Arch updates, kernel 5.6.4-arch1-1)

Output of following commands (on windows, execute them in Command Prompt or PowerShell):

where bash
# if `code` not found on macOS, follow the instructions in:
# https://code.visualstudio.com/docs/setup/mac
code --version
bash -c 'uname -a; for P in bash bashdb cat mkfifo pkill; do echo ---; which -a $P; command $P --version; done'

Debug output

Paste here outputs in DEBUG CONSOLE (ctrl+shift+D or command+shift+D) with "showDebugOutput": true and "trace": true in launch.json.
Your launch.json may looks like:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "bashdb",
            "request": "launch",
            "name": "Bash Debug",
            "program": "${workspaceFolder}/src/foo.sh",
            "showDebugOutput": true,
            "trace": true
        }
    ]
}

Details

Bash debugging does not start with the latest Visual Studio Code 1.44.0. With many older Visual Studio Code versions debugging has worked as expected. Downgrading to the previous Visual Studio Code 1.43.2-2 helps, debugging works with that as expected.

See more details at microsoft/vscode#94982.

They claim that the Bash Debug extension is the cause, but they haven't so far given any details on the issue.

Cannot reproduce this in 1.44.1 VsCode.

Please provide Debug console output, with:

            "showDebugOutput": true,
            "trace": true

in launch.json.

Also, it would be helpful to provide simple script that reproduces this, unless it is reproducing in simple one-liner.

Also, paste here your launch.json config.

It gives this error with every bash script. I tested also with a trivial "Hello world" bash script.
Note: I start code with a bash function shown below in comment of launch.json.
Everything works fine with the previous Visual Studio Code, but not with the latest.

launch.json:

{
    // Assume 'code' is started with this bash function:
    //     code() { command code --folder-uri "$PWD" "$@" ; }
    //
    // 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": [
        {
            "type": "bashdb",
            "request": "launch",
            "name": "Bash-Debug (/usr/bin/mytest1)",
            "program": "/usr/bin/mytest1",
            "terminalKind": "integrated",
            "showDebugOutput": true,
            "trace": true
        }
    ]
}

Debug console output:

From client: initialize({"clientID":"vscode","clientName":"Code - OSS","adapterID":"bashdb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us","supportsProgressReporting":true})
To client: {"seq":0,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":false,"supportsEvaluateForHovers":true,"supportsStepBack":false,"supportsSetVariable":false}}
From client: launch({"type":"bashdb","request":"launch","name":"Bash-Debug (/usr/bin/mytest1)","program":"/usr/bin/mytest1","terminalKind":"integrated","showDebugOutput":true,"trace":true,"args":[],"env":{},"cwd":"/home/user/Bash/_BUILD_/m-more2","pathBash":"bash","pathBashdb":"/home/user/.vscode-oss/extensions/rogalmic.bash-debug-0.3.7/bashdb_dir/bashdb","pathBashdbLib":"/home/user/.vscode-oss/extensions/rogalmic.bash-debug-0.3.7/bashdb_dir","pathCat":"cat","pathMkfifo":"mkfifo","pathPkill":"pkill","__sessionId":"4e83bfb5-a325-4654-9929-51471cfa8adb"})
To client: "runInTerminal"({"kind":"integrated","title":"Bash Debug Console","cwd":".","args":["bash","-c","cd \"/home/user/Bash/_BUILD_/m-more2\"; while [[ ! -p \"/tmp/vscode-bash-debug-fifo-19313\" ]]; do sleep 0.25; done; \"bash\" \"/home/user/.vscode-oss/extensions/rogalmic.bash-debug-0.3.7/bashdb_dir/bashdb\" --quiet --tty \"/tmp/vscode-bash-debug-fifo-19313\" --tty_in \"/tmp/vscode-bash-debug-fifo-19313_in\" --library \"/home/user/.vscode-oss/extensions/rogalmic.bash-debug-0.3.7/bashdb_dir\" -- \"/usr/bin/mytest1\" "]}), timeout: 10000
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stderr","output":"::PROXYID::23158\n"}}
::PROXYID::23158

Just a wild guess - are you sure the debugged script path is not ending with ".sh":

/usr/bin/mytest1.sh

It doesn't end with .sh.
And I have many tens of working bash scripts that all work as expected with vscode 1.43.2,
but not 1.44.0 nor 1.44.1.

Debugging a simple two-liner does not work with 1.44.x but works with 1.43.x:

#!/bin/bash
echo "Hello world!"

I've been using vscode with your bash debug extension for quite a while now (i.e. many months almost daily), and this is the first time debugging is no longer working.

OK, seems clear that there seems to be an issue. I just cannot reproduce it.

The problem is that debug console output is cutting just at the beginnig, no useful info there. Are you sure this is full output?

Have you tried option:

"terminalKind": "debugConsole",

instead of integrated?

@rogalmic I can confirm I'm experiencing the same behavior as the OP as well.
It happens only when using the integrated terminal kind.

My script ends with .sh and doesn't have any spaces in its' path. At first, I tried with arguments, then stripped them - the same behavior.

Yep, just installed this on linux and i see similar behaviour (only for integrated terminal, external terminal works fine).

The issue is that the command contains semicolons ";" , and newest VsCode seems to escape them "\;" in integrated terminal.

This does not happen on Windows.

Looking for root cause:
microsoft/vscode@1.43.2...1.44.0

Found something in prepareCommand()@src/vs/workbench/contrib/debug/node/terminals.ts:

s = s.replace(/(["';\\])/g, '\\$1'); // semicolon added

Related to:
microsoft/vscode#93166

This seems to me like VsCode issue.

Instead of escaping ";" or "&", or any other bash directive, the arguments from "type": "cppdbg" debugger should be passed escaped with '' (single quotes), which would prevent interpreting.

VsCode terminal api architecture is not that nice, it handles qouting/escaping by itself and has weird behaviour between shell/cmd/powershell while caller does not even know which shell interpreter will be used.

See:

    /** Arguments for 'runInTerminal' request. */
    interface RunInTerminalRequestArguments {
        /** What kind of terminal to launch. */
        kind?: 'integrated' | 'external';
        /** Optional title of the terminal. */
        title?: string;
        /** Working directory of the command. */
        cwd: string;
        /** List of arguments. The first argument is the command to run. */
        args: string[];
        /** Environment key-value pairs that are added to or removed from the default environment. */
        env?: {
            [key: string]: string | null;
        };
    }

Thanks for you both for taking time to examine this!
But does the external terminal allow keyboard input while debugging a bash program?

Yes, it should. It is basically same call, with terminal kind set to different value.

Thanks! I'll try that workaround. Hopefully the issue with the integrated terminal gets fixed.

The workaround using external terminal works, but is picky about which external terminal.
gnome-terminal, konsole, and xterm work.
terminator and xfce4-terminal fail.

Related to:
microsoft/vscode#93166

Looks like the latest comment in there just identified the change in VSCode that broke this and they will fix:

As a fix I plan to revert the previous fix and I will quote the string if it contains spaces or ';' instead.

Related to:
microsoft/vscode#93166

Looks like the latest comment in there just identified the change in VSCode that broke this and they will fix:

As a fix I plan to revert the previous fix and I will quote the string if it contains spaces or ';' instead.

Despite VSCode updating, it still seems to not be exacping correctly on V1.44.2

@angry-bender True, but I think that comment relates to a future update which hasn't been released yet

The vscode insider version (AUR pkgver 1587622013-1) works here!
Thanks for everyone, especially rogalmic who AFAIK found the issue!

I do confirm it is working on insiders from Snap store !!
image

image

Same here, Amazing the difference one day makes. I tried V1.4.4 yesterday with no luck

This is fixed in VS Code 1.45.0 which is released now. Tested and works for me.

This is fixed in VS Code 1.45.0 which is released now. Tested and works for me.

Yup, right on, I've just gone to the standard vscode version on snap, works a treat.

Thanks for following this. Closing...