Unable to start debugging. Failed to initialize debugger terminal.
I am trying to debug a simple "Hello world!" application with VSCode on a 64 bit Arch Linux machine. Compiling is done without a problem, but when I go to debug it, about 10 seconds pass and it spits out this error: Unable to start debugging. Failed to initialize debugger terminal. I am using the default GDB/LLDB environment for launch.json.
Things I've tried:
- Changing "externalConsole" to false.
- Changing "terminal.external.linuxExec" to a different shell.
- Changing "terminal.integrated.shell.linux" to a different shell.
It would be our debug adapter layer, not VS Code. I wonder why it isn't elevated, but I'd have to setup a test machine to verify. Like I said above we use pkexec and fall back to a call to sudo to try and elevate but it seems like it isn't happening in this instance and I don't know why.
The other workaround would be to set ptrace_scope to 0 which would allow you to attach to any process, which should get you past this problem, but this seems like a different error compared to the first problem you are running into. AFAIK VS Code also says they don't support running under root but I don't know what issues you would run into when doing that.
Any update on either scenario?
I'm having the exact same issue running VS code 1.21.1 on Centos 7. I have an executable that needs to be run as root, so I've launched the VS Code application as a Superuser using sudo. I've been able to get the executable to successfully build, but when I try to run and debug it I get the error "Unable to start debugging. Failed to initialize debugger terminal." Because of what @puchodr said, I opened up the exact same workspace (with the exact same launch.json file) in VS Code launched as a normal user, and the debugger worked without a problem (the code failed very shortly in because it wasn't being run as root, but the debugger did function properly and hit the first breakpoint I specified).
So, it does appear there may be an issue of VS Code having difficulty launching a debugger with root privileges? To my understanding this should be supported, I didn't see anything in the docs saying this functionality doesn't exist but of course I could be mistaken.
It seems this issue is at least being looked into which is great, but I figured it couldn't hurt to share that I'm experiencing a similar problem. Thanks for the help!
In case it's needed, here is the copy of my launch.json file:

I’m still experiencing the same thing as well. I’ve basically given up trying things until there’s some solution to this.
@puchodr have you ever opened a new issue regarding this topic or looked around github to see if anyone else has had this same problem? I'm wondering if @pieandcakes lost track of this thread since he was initially incredibly responsive and it appears we're following up under an issue that's marked as closed.
@bboudrea @puchodr VS Code itself doesn't support running in sudo mode. If that is a requirement, they need to make changes to VS Code first to fix any issues there. I've been busy with other work and haven't had a chance to debug this yet to see what the problem might be but it is on the list of items to look at when I have free time but I suspect that there will need to be work on their side to support the scenario before we can get much further.
Running VS Code in sudo would be a workaround if it worked. But the real issue is that I can't debug a root-process with VS Code running as a user-process. I have two different setups, Ubuntu and RHEL. Ubuntu seems to handle this scenario properly but VS Code running in RHEL fails to create a terminal.
@puchodr I'll have to see if between @WardenGnaw and I we can try this out on RHEL. That isn't a distro that I've tried the extension on recently.
I have the same issue. I tried already every solution described here unsuccessfully. I am on RHEL, which is offline because I am on a military site. I should be root on VSCode (Insiders) as the commands (freeipmi c librairie) are used as root. any help will be graceful Francine
I also had this problem on ubuntu 18.04. I had installed it with snap, but then I uninstalled it and reinstalled with the .deb package.
Any updates on this matter? Still not working for RHEL7.4. sudo is not an option for me, as I am working on a cluster.
I'd vote for reopening this issue as this does not seem to be fixed.
this used to work but I forgot how far back that was, obviously earlier than the oldest 17.3 version that is available from releases. also using Centos/RHEL 7.xx
I'm using Arch Linux updated to date, and I'm having the same issues described above.
Can any of you who are not running into the RHEL sudo issue see if this comment fixes your problem?
For the RHEL/Centos problem, I filed a new issue: #2493
Can any of you who are not running into the RHEL sudo issue see if this comment fixes your problem?
Nope. At least I do not have the .real.
That gnome-real thing is like super weird, I've been using gnome since ages and never saw another gnome-terminal besides the default one :/. Also, modifying system applications like that in order to fix something else does not seem the correct way to deal with it.
I also cannot attach via gdb to a running process when running visual studio code in a vnc session on linux at display :1 . gnome-terminal and xterm apps are located in /usr/bin and can be launched (there is no .real file). I assume visual studio code is tryting to launch the terminal at the wrong display. Setting the DISPLAY variable to :1 doesn't help. Any suggestions?
@tobiasmelcher your scenario sounds a bit different. You are VNCing into a Linux machine and then launching VS Code and it can't debug? Attaching should not be using a terminal at all since the terminal is where you ran the program you are attaching to. Can you help clarify what you are asking?
Yes, exactly. I connect to a remote Linux machine via vncviewer and launch then VS code inside the vnc session. C++ toolingis working great, but gdb debugging inside VS code is not working for me. I get the here mentioned error message "failed to initialize debugger terminal". As workaround, I can debug using lldb like described here; but I would prefer using gdb.