Vscode-cpptools: [Linux] Debug launch command shows up in terminal window

Created on 15 Mar 2019  路  34Comments  路  Source: microsoft/vscode-cpptools

Type: Debugger

Computer Details

  • OS and Version: Ubuntu, 18.04
  • VS Code Version: 1.31.1
  • C/C++ Extension Version: 0.21.0
  • Compiler Version: G++-8

After debugging my C++ code and stopping it(by pressing the red button) a string of random characters are printed on the screen. Here are the exact words:

[1] + Done /usr/bin/gdb --interpreter=mi --tty=${DbgTerm} 0/tmp/Microsoft-MIEngine-Out-9278nini.hzx

This happens everytime I close the debug session, and if I go to the terminal and press the up arrow key(to view the previous commands I used), these commands seem to have been run:

env sh /tmp/Microsoft-MIEngine-Cmd-ecbdhibq.wek

env sh /tmp/Microsoft-MIEngine-Cmd-bhx2btll.wux

env sh /tmp/Microsoft-MIEngine-Cmd-99w9hl15.1xc

To Reproduce

  1. Start a C++ debug process on Ubuntu Linux, and break it by pressing the red button.
  2. Go to the terminal(In my case the integrated one, tho the same string is printed on the external terminal if used in place of the internal) in which the debug code was run.

DeepinScreenshot_select-area_20190315163944

My files:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++-8",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "setupCommands": [
                {
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "_runner": "terminal",
    "tasks": [
        {
            "label": "Build",
            "type": "shell",
            "command": "g++-8",
            "args": [
                "-g",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
by design debugger help wanted

Most helpful comment

As a super hackish solution one could exploit the fact that miDebuggerArgs is placed literally in the command to replace wait with fg >/dev/null. Just add the following to your launch.json:

"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi"

All 34 comments

Any fix for this yet? Why isn't there any progress? Anyone else facing the same issue?

@infixint943 this isn't random text. this is the command we send to gdb to allow integrated terminal to work with VS Code. unfortunately there isn't a way to hide it through shell commands so it is being displayed. If you have a workaround in Linux shell, let us know.

this is the command we send to gdb to allow integrated terminal to work with VS Code

The same message is displayed on the external terminal.
screenshot

This is why I switched from ext. to internal terminal, because in the former I would have to manually close the terminal. As far as I remember, this problem didn't exist on Ubuntu about a ~year back, and I was comfortable using the external terminal(since the terminal would close on break of the debugging.)
@pieandcakes Is there any setting to close the ext terminal automatically as described above?

@infixint943 The text you are seeing is the command we need to send to gdb to redirect its stdin/stdout/stderr so that we can communicate with it from the debug adapter. In changing to allow integratedTerminal, we also chose to allow VS Code to handle all the terminal launching for external console too due to a request by the community to support more than just xTerm and gnomeTerminal.

Unfortunately, *nix will show the launching command when debugging exits in the terminal. If you have a suggestion on how to remove it, that would be helpful but I've been unable to find a good way to do it.

Just installed 0.11.1 version of this extension and noticed that the problem doesn't exist here. Are you able to reproduce the same?

@infixint943 The change was introduced in version 0.20.0

@pieandcakes Since *nix users face this problem and this is an inconvenience, could this issue be opened so that a solution could be found?

@infixint943 I'll reopen with a better title.

Does anyone face the same issue? This seems to persist in every Linux OS I tried. Is there any short term fix for this?

@infixint943 This happens only on the Linux ones. If you use WIndows or macOs it won't show up.

Like I said above, this is something that we have as a requirement to support running in the integrated terminal and having VS Code launch our terminal.

@pieandcakes Any luck with this? This issue is really an inconvenience to me...

I haven't found a solution in Linux to not display the command.

I had an idea to evade this. clear command could be run automatically once the debug process is terminated.

@infixint943 we thought about that but you would also lose all the output from your application run which is why we did not do it.

I don't think the solution of launching a new terminal to launch the command will work. The whole point of this change was to allow VS Code to own the terminal launching experience and to not care which terminal application the user has on their machine.

Or a seperate terminal, like the one's build and test tasks have.

@infixint943 You can use "externalConsole": true if you want a separate terminal. If you are saying to run the command and create two terminals in VS Code, I can't find anything that supports it.

You are welcome to try and come up with a solution if you want to try and we take pull requests and features from the community. The code for our debug adapter is located at https://github.com/microsoft/MIEngine and the code to support RunInTerminal. Instructions on how to set it up are here.

@infixint943 ... If you have a workaround in Linux shell, let us know.
Since the text in question is just one line, how about removing that line from the output by filtering it out? something along this way: THE_DEBUGGING_COMMAND | head -n 1

@ahmed-ais our command sets a termination clause to clean up the fifo files we create. I will try the head -n 1 command but I suspect that won't get run until after termination which by that point it will be too late.

@ahmed-ais our command sets a termination clause to clean up the fifo files we create. I will try the head -n 1 command but I suspect that won't get run until after termination which by that point it will be too late.

Well, if this is going to work, then you should try this one instead: | head -n -1 since the previous one is wrong.

I am facing the same problem.
@pieandcakes
What if the command history -c is executed each time after integrated terminal debug operation is finished in order to clear the current command entered in the current terminal session?

I think it a feasible way to do so...

Screenshot from 2019-10-25 16-33-22
Screenshot from 2019-10-25 15-58-08

That would clear the entire command history, which is not intended.

That would clear the entire command history, which is not intended.

@infixint943
No, history -c does clear the entire command history, but only the current bash session (that is, everything that is still only in memory and not yet written to disk). Therefore, it does not affect the bash_history file.

It only clears the debug commands in the integrated terminal, which is what we want. In addition, it does not affect other currently open terminal bash sessions, so don't worry, because we only want to get rid of the history of debug launch commands, so this is a good way...

Don't confuse, some Internet sources indicate that history -c will clear the entire command history, but this does not mean clearing the bash_history file, please take note.

Reference - https://askubuntu.com/questions/903281/how-do-i-delete-bash-history-for-current-day-only

Short screencast on how history -c works - https://www.youtube.com/watch?v=lagsoJ8KVyY

That would clear the entire command history, which is not intended.

@infixint943
No, history -c does clear the entire command history, but only the current bash session (that is, everything that is still only in memory and not yet written to disk). Therefore, it does not affect the bash_history file.

It only clears the debug commands in the integrated terminal, which is what we want. In addition, it does not affect other currently open terminal bash sessions, so don't worry, because we only want to get rid of the history of debug launch commands, so this is a good way...

Don't confuse, some Internet sources indicate that history -c will clear the entire command history, but this does not mean clearing the bash_history file, please take note.

Reference - https://askubuntu.com/questions/903281/how-do-i-delete-bash-history-for-current-day-only

Short screencast on how history -c works - https://www.youtube.com/watch?v=lagsoJ8KVyY

catch the same issue, it's really annoying

[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-z83z61vp.ykf" 1>"/tmp/Microsoft-MIEngine-Out-aj59n6gk.muf"

catch the same issue, it's really annoying

[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-z83z61vp.ykf" 1>"/tmp/Microsoft-MIEngine-Out-aj59n6gk.muf"

I also face the same problem like yours. Have you solved it?

OS and Version: Ubuntu, 18.04
VS Code Version: 1.46
C/C++ Extension Version: 0.29.0
Compiler Version: G++-7

The results from my code is :
Hello C++ World from VS Code and the C++ extension! [1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-zb4lu5fo.f8t" 1>"/tmp/Microsoft-MIEngine-Out-a455v55d.vkm"

@Litreily
I seem to find reason why this happen.
VS Code need to start debugging when the target file (you want to be debugged) is opened in current tabs.
For exp, if you open launch.json file in current window, and you click the start debugging button, the error comes.
And if you open the file(such as yoursource.cpp which to be debugged) in current window, it works.

It was very annoing for me and i make this fix for me
May be it will be useful for someone..

I create file __~/.local/bin/bash__ with

```#!/bin/bash
[[ -z "$2" ]] && exec /bin/bash "$@"

if [[ -z "${2##Microsoft-MIEngine-Cmd}" ]]; then
NAME=$(echo "$2"|grep -oE '/tmp/Microsoft-MIEngine-Cmd[^ ]*')
sed 's|"/usr/bin/gdb"|("/usr/bin/gdb"|;s|wait $pid|wait $pid)|' -i $NAME
fi

exec /bin/bash "$@"
```

and make in execute
$ chmod +x ~/.local/bin/bash

This issue has been closed automatically because it's labeled as 'by design'.

I think microsoft/MIEngine#1089 suggests a fix.

As a super hackish solution one could exploit the fact that miDebuggerArgs is placed literally in the command to replace wait with fg >/dev/null. Just add the following to your launch.json:

"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi"

As a super hackish solution one could exploit the fact that miDebuggerArgs is placed literally in the command to replace wait with fg >/dev/null. Just add the following to your launch.json:

"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi"

This works perfectly, in internal terminal & external terminal
thanks

Thanks @cyrus-and ... The problem is fixed. However I'm facing another problem when compiling and running directly by pressing "ctrl+alt+n". Is there any way to hide this annoying message?
I can clean the log by writing system("clear"); in the beginning of my main function in the code. But is there any way to do it automatically?
image

Ctrl + Alt + n does nothing on my setup, you should see how it is defined and maybe place a clear right after the compilation(?).

Was this page helpful?
0 / 5 - 0 ratings