[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.
Sorry, @princehektor, but I don't speak linux terribly well.
My colleague has left for the day but he did confirm that he was using v0.20.1 (as am I).
The last few lines of my "Debug Console" output:
1: (922) Starting: "C:\openOCD\openocd-0.10.0\bin\openocd.exe" -f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init"
1: (2275) Wait for connection completion.
Starting: "C:\openOCD\openocd-0.10.0\bin\openocd.exe" -f C:/OpenOCD/openocd-0.10.0/scripts/board/st_nucleo_f4.cfg -f C:/OpenOCD/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg -c init -c "reset init"
1: (7334) <-logout
This output is the same as before up until the last line. It's as though the GDB server is unable to launch. I can launch GDB from command prompt/terminal, though.
@ssctx66 Yours is on Windows which is a different implementation of what our problem is here on linux. Can you open a new issue with your launch.json so I can understand what it is you are passing?
@princehektor I think I have a workaround for you.
I created a new script called /usr/bin/sgdb which has the following line in it:
pkexec /usr/bin/gdb $*
and then it works (it pops up a window asking for credentials). Will this work for you?
@pieandcakes : So this is what i have in my gdb file right now.
#!/bin/sh sudo gdb $@
You want me to add the line(pkexec /usr/bin/gdb $*) at the end or instead of the sudo gdb line?
@princehektor Yes please. When I did that, it worked for me. I think instead of invoking sudo use pkexec and it should work for you. It is just another program to prompt for elevation and I think its a default on Ubuntu.
Okay i tried that. My sgdb file looks like this now
#!/bin/sh pkexec /usr/bin/gdb $*
Like you mentioned, it opens up a terminal and prompts for my password. But after i enter my password, i get this message :
"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information"
This is the output from the debug console.
1: (127) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (136) LaunchOptions ExePath='myproj'
1: (136) LaunchOptions WorkingDirectory='myproj'
1: (136) LaunchOptions ExeArguments=''
1: (136) LaunchOptions MIMode='gdb'
1: (136) LaunchOptions MIDebuggerPath='/usr/bin/sgdb'
1: (136) LaunchOptions WaitDynamicLibLoad='false'
1: (136) LaunchOptions ExternalConsole='true'
1: (136) LaunchOptions>
1: (136) LaunchOptions
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/MIEngine/DebuggerAborted","data":{"VS.Diagnostics.Debugger.MIEngine.DebuggerName":"GDB","VS.Diagnostics.Debugger.MIEngine.LastSentCommandName":""},"type":"output"} R: {"success":false,"message":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information.","request_seq":2,"command":"launch","body":{"error":{"id":1104,"format":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information.","variables":null}},"running":false,"refs":null,"seq":0,"type":"response"}
@princehektor did you close a window? I'm seeing Shell exited, stop debugging where it thinks the shell window was closed? Can you try with externalConsole set to false ?
@pieandcakes : My bad. I was trying out the new sgdb file changes without reloading VSCode. Therefore it will still using the old version of the C/C++ extension.
Once i reloaded, i get the same message as before :
Password: [1] + Stopped (tty output) /usr/bin/sgdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-4g0gtl2r.fvg 1>/tmp/Microsoft-MIEngine-Out-877qnd71.t7p
It doesnt even give me the option to enter my password.
Same thing with externalConsole set to false.
I don't know why I'm not seeing the same thing. my /usr/bin/sgdb is literally pkexec /usr/bin/gdb $@ and I ran a simple hello world with elevation. It prompts me to elevate and I enter my password and it works. I've tried it with both externalConsole true and false. Can you try a simple C++ program?
Same thing with a simple hello world program. It lets me enter the password in the terminal but then just shows me the "unable to start debugging" error.
Again, all this is with the C/C++ extension version 0.19. With the latest version, it is the same old tty problem the external terminal just closes when i enter any key.
Why was this changed in version 0.20 and above for everyone ? I mean why not a setting that could be toggled ? Was it something for security purposes ?
@princehektor If your sudo solution works with 0.19.0 don't change it. my suggestion for pkexec was with 0.20.1. I didn't try it with 0.19.0. I don't understand how you see a tty issue with 0.20.1 when using pkexec since it should be popping up to ask for UI.
Why was this changed in version 0.20 and above for everyone ? I mean why not a setting that could be toggled ? Was it something for security purposes ?
We have been asked by VS Code to support their way of launching terminals and to conform to what other extensions do.
@pieandcakes : Well that is unfortunate. For the time being i can continue using version 0.19.0 but i hope you guys can figure out a way to fix this so that we can get all the fixes you guys add with newer versions.
More and more people are going to run into similar issues i feel.
On my machine, with 0.20.1 I can use my pkexec solution and it works. If you want to dig into it, we can try and figure out why it doesn't work for you.
I setup a clean Ubuntu 18.04 VSCode and the 0.20.1 version of the extension and it works fine too, so I don't know if it has to do with some other configuration you have set within VS Code.
@pieandcakes : With version 0.20.1, it does open a new terminal and it looks like it is prompting for password but before i have a chance to enter the password, the tty problem hits.
Password: [1] + Stopped (tty output) /usr/bin/sgdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-iwzc6aiq.feu 1>/tmp/Microsoft-MIEngine-Out-r36u9ljh.zrr You have stopped jobs.
Press any key to continue...
I thought this is because i was using VNC to access my Ubuntu machine but it turns out the same thing happens when i try locally as well.
Are you using a custom terminal instead of the default terminal in VS Code? That's the only other thing I can think of. Also, with pkexec in your sgdb file it shouldn't show the password message in your output. That's what confuses me.
If you can give me something to repro this I'll debug it, but on my clean Ubuntu machine it is working.
Not using any custom terminal. I dont have gnome-terminal installed - only xterm and xfce terminal.
When i use version 0.19.0 and everything works, xterm opens up prompting for password and then i can continue on debugging.
I will ask my other colleagues to try it out as well and let you know the results.
@pieandcakes : I have some good news for you.
One of my colleagues updated the extension to version 0.20.1 and used "pkexec gdb" instead of "sudo gdb" in the sgdb file. Everything worked fine with no problems. He was also able to use the integrated terminal for debugging.
One of the differences between our setups is that my colleague was using the Ubuntu machine natively whereas i am using VNC to connect. So i tried the "pkexec" solution on my system locally (instead of VNC) and i was able to debug correctly. Only thing was that it showed this message on exit
[1] + Done /usr/bin/sgdb --interpreter=mi --tty=${DbgTerm} 0</tmp/Microsoft-MIEngine-In-o61b60mq.5vu 1>/tmp/Microsoft-MIEngine-Out-z9nqak38.zue
Press any key to continue...
Once i pressed a key, the external console closed correctly. This behavior does not exist if i use the integrated terminal
So it turns out that the problem is using my VNC setup. I can still use VNC and get everything to work if i open VSCode as sudo.
To summarize:
- No problems when using the Ubuntu system locally.
- No problems when opening VSCode using sudo.
I will try to use x11vnc instead and see what happens.
Thank you for investigating. I'll consider this resolved then.
Yeah sure. Thanks a lot for your help with this. Much appreciated.
please am having this error while running c++ code on VS, the output show up with some errors after it as you can see, i want only the output to be displayed without the error help me pls
