[gdb][Linux] Sudo elevation not working with VSCode RunInTerminal
Type: Debugger Input information below
Please review existing issues and our documentation at https://github.com/Microsoft/vscode-cpptools/tree/master/Documentation prior to filing an issue.
Describe the bug
OS and Version: Ubuntu 18, 64bit VS Code Version: 1.28.2 C/C++ Extension Version: 0.20.0 Other extensions you installed (and if the issue persists after disabling them):
A clear and concise description of what the bug is.
The debugger in VS code does not work anymore after updating to Ubuntu 18 and also updating VS Code to the latest version.
Earlier behavior:
Starting the debugger would open xterm and prompt me my for my password and then i would be good to debug my application.
Current behavior:
Starting the debugger seems to be opening up the xfce4 terminal with the following output.
[1] + Stopped (tty output) /usr/bin/gdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-ongysklf.4yq 1>/tmp/Microsoft-MIEngine-Out-ybu9kjug.08a You have stopped jobs.
Press any key to continue...[sudo]
If i press any key to continue, the terminal just closes.
Anyone see the same issue ?
- A clear and concise description of what the bug is.
To Reproduce
Please include a code sample and launch.json configuration.
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Additional context
If applicable, please include logging by adding "logging": { "engineLogging": true, "trace": true, "traceResponse": true } in your launch.json
Add any other context about the problem here including log or error messages in your Debug Console or Output windows.
@sean-mcmanus , @pieandcakes : Could you guys help me with this ?
I rebooted my machine and tried debugging from VSCode. It still opens up a terminal with a different message now.
nied
[1] + Done(126) /usr/bin/sgdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-dvq9gn3l.eth 1>/tmp/Microsoft-MIEngine-Out-p0fhame1.28t
Press any key to continue...
This is my launch.json
{
"name": "(gdb) my-debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/myproj,
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}/myproj",
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/sgdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Have gdb ignore SIGUSR1",
"text": "handle SIGUSR1 nostop noprint",
"ignoreFailures": true
},
{
"description": "Have gdb ignore SIGUSR2",
"text": "handle SIGUSR2 nostop noprint",
"ignoreFailures": true
}
]
},
sgdb is simply a script which opens gdb using sudo.
I see the same behavior if i attempt to run vs code using sudo.
We changed over to using VSCode's debugProtocol to handle terminal launching. This is now using the RunInTerminalRequest message for VS Code. Can you try changing externalConsole to false and see if it works? I don't know if they are blocking any other UI from spawning.
This is the message i see in the integrated terminal after setting "externalConsole" to false.
[1] + Done(126) /usr/bin/sgdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-2zw8gvpe.arx 1>/tmp/Microsoft-MIEngine-Out-y60x1n13.mis
Is there any way for me to revert to the old VSCode behavior ? Will downgrading to a previous version help ?
Update : I tried downgrading to version 1.26 but still see the same behavior. I dont think it is a problem with the Ubuntu upgrade to 18.0.4. One of my friends is seeing the same problem with Ubuntu 16.04 as well. Everything used to work but he recently did a "sudo apt-get update" and "sudo apt-get upgrade" and also upgraded VSCode to the latest version. That is when things stopped working for him.
we made the change in 0.20.0 so anything before that has the old behavior.
To be clear, this is the C++ extension that made the transition due to customer requests. You will need to roll back our extension and not VS Code.
Okay. How do i do that ?
Where can i find the ".vsix" file for version 0.19.0 ?
I managed to get the ".vsix" file for the older version from here (https://github.com/Microsoft/vscode-cpptools/releases)
I tried to install it and it warned me that a newer version is avaiable and whether i still wanted to over-ride it. I chose yes and VSCode prompted me to reload the windows which i did.
Now when i try to debug, it says :
"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information"
Closing and opening the workspace brings the extension back to version 0.20.1 .
So, what is the correct way to downgrade the C++ extension to version 0.19.0 ?
- Uninstall the current version.
- Reload VS Code
- Go to File -> Preferences -> Settings and disable Extension: Auto Update

- Install the older version of the .vsix
Did that but still see this error :
"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information"
My bad. My sgdb script did not have execute permissions.
@pieandcakes : So it is confirmed that this issue does not exist in version 0.19 of the C++ extension.
Is there anyway you guys can add a new setting to toggle this new 'VSCode's debugProtocol behavior' that was introduced in version 0.20 and beyond ? This way users can toggle it as needed.
Maybe add that to the next version of the C/C++ extension ?
What say ?
@princehektor the code is in MIEngine although we removed the old behavior. I think the right way would be to either A) figure out what the issue is and have VS Code fix it or B) figure out a workaround for the problem that works.
This is on my list of items to investigate but I don't have time currently. If you want to include some logging and see if you can repro it in a VS Code console window, we can file a bug with them to fix it.
The workaround for me currently is to downgrade to version 0.19 of the extension. But with this i am missing out on all the fixes and improvements in later versions.
So the workaround is okay for now but i would prefer a better long term solution.
How do i enable logging and get you the information that you needed? Please help me out here.
Instructions are located in our FAQ Specifically, you probably want trace and traceResponse set to see what we send to VS Code and what you get back.
@pieandcakes :This is the output from the debug console with trace, traceResponse and enableLogging set to to true. Let me know if this is what you wanted.
--> E (output): {"event":"output","body":{"category":"console","output":"1: (93) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'\n"},"seq":2,"type":"event"}
1: (93) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (100) LaunchOptions ExePath='my_proj_path'\n"},"seq":4,"type":"event"}
1: (100) LaunchOptions ExePath='my_proj_path'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (100) LaunchOptions WorkingDirectory='my_proj_path'\n"},"seq":6,"type":"event"}
1: (100) LaunchOptions WorkingDirectory='my_proj_path'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (100) LaunchOptions ExeArguments=''\n"},"seq":8,"type":"event"}
1: (100) LaunchOptions ExeArguments=''
--> E (output): {"event":"output","body":{"category":"console","output":"1: (100) LaunchOptions MIMode='gdb'\n"},"seq":10,"type":"event"}
1: (100) LaunchOptions MIMode='gdb'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (101) LaunchOptions MIDebuggerPath='/usr/bin/sgdb'\n"},"seq":12,"type":"event"}
1: (101) LaunchOptions MIDebuggerPath='/usr/bin/sgdb'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (101) LaunchOptions WaitDynamicLibLoad='false'\n"},"seq":14,"type":"event"}
1: (101) LaunchOptions WaitDynamicLibLoad='false'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (101) LaunchOptions ExternalConsole='true'\n"},"seq":16,"type":"event"}
1: (101) LaunchOptions ExternalConsole='true'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (101) LaunchOptions>\n"},"seq":18,"type":"event"}
1: (101) LaunchOptions>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (102) LaunchOptions tty ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-lv16n8e0.bi5 /tmp/Microsoft-MIEngine-Out-9lkjodby.rqn /tmp/Microsoft-MIEngine-Pid-cmtgz3u3.nin /tmp/Microsoft-MIEngine-Cmd-7jpdxvw9.jzv' EXIT ; /usr/bin/sgdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-lv16n8e0.bi5 > /tmp/Microsoft-MIEngine-Out-9lkjodby.rqn & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-cmtgz3u3.nin ; wait $pid; \n"},"seq":32,"type":"event"}
1: (193) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-cmtgz3u3.nin ; cd my_proj_path ; DbgTerm=tty ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-lv16n8e0.bi5 /tmp/Microsoft-MIEngine-Out-9lkjodby.rqn /tmp/Microsoft-MIEngine-Pid-cmtgz3u3.nin /tmp/Microsoft-MIEngine-Cmd-7jpdxvw9.jzv' EXIT ; /usr/bin/sgdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-lv16n8e0.bi5 > /tmp/Microsoft-MIEngine-Out-9lkjodby.rqn & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-cmtgz3u3.nin ; wait $pid;
--> C (runInTerminal-34): {"command":"runInTerminal","arguments":{"kind":"external","title":"cppdbg: foo","cwd":"","args":["sh","/tmp/Microsoft-MIEngine-Cmd-7jpdxvw9.jzv"],"env":{}},"seq":34,"type":"request"}
--> E (output): {"event":"output","body":{"category":"console","output":"1: (203) Wait for connection completion.\n"},"seq":36,"type":"event"}
1: (203) Wait for connection completion.
Thanks. If you go to the terminal window in VS Code and just try and run /usr/bin/sgdb --interpreter=mi what do you get?
/usr/bin/sgdb --interpreter=mi =thread-group-added,id="i1" ~"GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git\n" ~"Copyright (C) 2018 Free Software Foundation, Inc.\n" ~"License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type "show copying"\nand "show warranty" for details.\n"~"This GDB was configured as "x86_64-linux-gnu".\nType "show configuration" for configuration details."~"\nFor bug reporting instructions, please see:\n" ~"http://www.gnu.org/software/gdb/bugs/.\n" ~"Find the GDB manual and other documentation resources online at:\nhttp://www.gnu.org/software/gdb/documentation/.\n"~"For help, type "help".\n" ~"Type "apropos word" to search for commands related to "word".\n" (gdb)
so does that ask you for a password in a pop up box?
Not in a pop up box. I was asked for the password in the integrated terminal itself.
FYI - I am getting the exact same error: "Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information" on Windows 10.
A colleague with an extremely similar desktop/environment to mine is using the same launch.json and tasks.json without error.
@ssctx66 : I am guessing that your colleague probably hasnt reloaded VSCode after the C/C++ plugin update.I could be wrong though.
For me, i got the error when my sgdb file did not have execute permissions which i fixed with a chmod.