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.
@hengck23 we try and use gnone-terminal and fall back to xTerm for our debugger terminal. If those are not installed on your instance of Ubuntu, you get the below message. I don't know why switching to lldb would work and i'll take a look when I have time.
@pieandcakes Are there any plans to allow other terminal emulators? I have my current one (xfce4-terminal) configured exactly how I like it, and using a different one for VSCode debugging is very less than ideal.
@DougTy With the number of terminal emulators out there and the amount of different flags for each one we would need to support, it isn't something we support today. That being said, we have an issue filed here, #515 that is tracking the request for other terminal apps. We also take community contributions so if you feel like it would be something you'd want to contribute, the code in question isin that issue also
@Tomaszal i find out why it shows
Failed to initialize debugger terminal.
my OS version is ubuntu 16.04 LTS and i check the directory /usr/bin ,there are two files,one is the python file named gnome-terminal and another one is gnome-terminal.real ,the real file to lunch terminal is the second one (type gnome-terminal.real in a terminal to lunch a new terminal)—— gnome-terminal.real ,it means that you must use command
python /usr/bin/gnome-terminal to lunch the terminal.but this is a python file , i guess vscode just find the file gnome-terminal and do something.
root@vivjackPC:/usr/bin# mv ./gnome-terminal ./gnome-terminal.bak root@vivjackPC:/usr/bin# mv ./gnome-terminal.real ./gnome-terminal
then vscode works
I am using ubuntu 16.04 and gdb to debug.I find that when my folder is named "pro32" or "pro-32",vscode can debug successfully.But when my folder is named "pro(32)" or "pro(" or "pro)",I have the same problem.So I think is the matter of name.
@Yugata I think your issue is separate from the above comments about gnome-terminal and other terminal types
my working folder like "ham-serv (copy)" and debugging was giving the same error. then I changed folder name "hamservtest" and worked fine. I think a problem can be some characters at path .
I'm also having the same issue right now when trying to attach to a process. My Visual Studio Code version
Version 1.20.1 Commit f88bbf9137d24d36d968ea6b2911786bfe103002 Date 2018-02-13T15:31:21.019Z Shell 1.7.9 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64
Here is my launch.json: { // Use IntelliSense to learn about possible attributes.\n // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Attach", "type": "cppdbg", "request": "attach", "program": "~/builds/proj/bin/test", "processId": "${command:pickProcess}", "MIMode": "gdb", "logging": { "trace": true, "traceResponse": true } } ] }
Here is the output in the Debug Console with Logging enabled: E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/Attach","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.50106.1","VS.Diagnostics.Debugger.HostVersion":"1.0.40106.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Attach.Message":"Unable to start debugging. Failed to initialize debugger terminal.","VS.Diagnostics.Debugger.Attach.IsError":true},"type":"output"} R: {"success":false,"message":"Unable to start debugging. Failed to initialize debugger terminal.","request_seq":2,"command":"attach","body":{"error":{"id":1104,"format":"Unable to start debugging. Failed to initialize debugger terminal.","variables":null}},"running":false,"refs":null,"seq":0,"type":"response"} C disconnect: {"restart":false} R: {"success":true,"message":null,"request_seq":3,"command":"disconnect","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
I have both gnome-terminal and xterm installed, so I don't think that's the issue. I also tried to replace gdb with lldb which gives me a different error about the MiDebuggerPath. When I set the path lldb doesn't like the --interpreter argument. It doesn't recognize it. Thanks for the help.
@puchodr which Linux distribution are you on? Have you tried reinstalling the extension? When using lldb, you need to target the lldb-mi executable.
Linux distribution is: LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: RedHatEnterpriseWorkstation Description: Red Hat Enterprise Linux Workstation release 7.2 (Maipo) Release: 7.2 Codename: Maipo
So more specifically, this doesn't work when running as root. I just reinstalled the extension and was able to attach as a user not root. Unfortunately, we have a need to run as root so it would be ideal if we can figure out why this issue is specific to root. I also set the --user-data-dir argument to the directory of the user that installed the cpp extension and it still didn't work. The extension loaded correctly, but the console wouldn't launch.
If you are attempting to attach to a process running as root with an instance of VS Code running as a user, we try and determine that you are running as root and then attempt to ask the user to elevate. The relevant code is here. If we detect that the app is running under root, then we try and prompt the user for credentials using pkexec and falling back to sudo.
If you are also trying to run VS Code as root and not able to attach, I would try and run it as the user and see if you get the elevation prompts. We tested this back on Ubuntu 14.04 so there might be some fixes needed.
I'm running VS Code as root. The computer I'm moving to only has a root user and won't be having any non-root users. So I need to be able to debug as root while the process is running as root.
I don't think we've tried that. I'll have to give it a shot to see what about it doesn't work. Can you open another issue on this? it isn't the same issue as this one.
Also, please provide a log with just "logging" : { "engineLogging": true } enabled to see if we can tell what we get back from gdb, if anything.
1: (266) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014' 1: (279) LaunchOptions ExePath='~/builds/proj/bin/test' 1: (279) LaunchOptions ExeArguments='' 1: (279) LaunchOptions MIMode='gdb' 1: (279) LaunchOptions MIDebuggerPath='' 1: (279) LaunchOptions WaitDynamicLibLoad='false' 1: (279) LaunchOptions ProcessId='15527' 1: (279) LaunchOptions> 1: (279) LaunchOptions 1: (377) TempFile=/tmp/Microsoft-MIEngine-fifo-qd9jze0k.dvc 1: (377) TempFile=/tmp/Microsoft-MIEngine-fifo-qjn659bf.h5q 1: (377) TempFile=/tmp/Microsoft-MIEngine-fifo-5tb2e4ui.ai9
@puchodr Ah, it looks like it can't find gdb. Can you add the path to your gdb by specifying "miDebuggerPath": "<Path to gdb>" in your launch.json?
Only difference now is the debugger path. Same issue though 1: (227) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014' 1: (242) LaunchOptions ExePath='~/builds/proj/bin/test' 1: (243) LaunchOptions ExeArguments='' 1: (243) LaunchOptions MIMode='gdb' 1: (243) LaunchOptions MIDebuggerPath='/usr/bin/gdb' 1: (243) LaunchOptions WaitDynamicLibLoad='false' 1: (243) LaunchOptions ProcessId='15527' 1: (243) LaunchOptions> 1: (243) LaunchOptions 1: (319) TempFile=/tmp/Microsoft-MIEngine-fifo-4ynjzw8p.eok 1: (319) TempFile=/tmp/Microsoft-MIEngine-fifo-dz79ld2t.30u 1: (319) TempFile=/tmp/Microsoft-MIEngine-fifo-pch5xxuq.zgy
From your elevated terminal window can you run /usr/bin/gdb --interpreter=mi and see if it starts? If it does, then it might be our launch command, which i'll need to find it.
/usr/bin/gdb --interpreter=mi successfully launches gdb.
Btw, I really appreciate the help. You're going above and beyond. Thank you.
So just for science I reconfigured things to run vscode as a non-root user. I'm currently getting "Unable to start debugging. Attaching to process 13550 with GDB failed because of insufficient privileges with error message 'ptrace: Operation not permitted.'." when trying to attach to a process running as root. The user does have sudoers permissions. Sorry if it's too much but here's the log with engineLogging, trace, and traceResponse.
1: (293) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014' 1: (306) LaunchOptions ExePath='~/builds/proj/bin/test' 1: (306) LaunchOptions ExeArguments='' 1: (306) LaunchOptions MIMode='gdb' 1: (306) LaunchOptions MIDebuggerPath='' 1: (306) LaunchOptions WaitDynamicLibLoad='false' 1: (306) LaunchOptions ProcessId='13550' 1: (306) LaunchOptions> 1: (306) LaunchOptions 1: (381) TempFile=/tmp/Microsoft-MIEngine-fifo-tresny0l.g8q 1: (381) TempFile=/tmp/Microsoft-MIEngine-fifo-1bs8pc5m.i9q 1: (381) TempFile=/tmp/Microsoft-MIEngine-fifo-m5zmejry.421 1: (524) ShellPid=15376 1: (586) DebuggerPid=15379 1: (598) ->=thread-group-added,id="i1" 1: (599) ->~"GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7\n" 1: (599) ->~"Copyright (C) 2013 Free Software Foundation, Inc.\n" 1: (599) ->~"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" 1: (599) ->~"This GDB was configured as "x86_64-redhat-linux-gnu".\nFor bug reporting instructions, please see:\n" 1: (599) ->~"http://www.gnu.org/software/gdb/bugs/.\n" 1: (599) ->(gdb) 1: (605) <-1001-gdb-set target-async on 1: (606) ->1001^done 1: (606) ->(gdb) 1: (608) 1001: elapsed time 3 1: (614) <-1002-interpreter-exec console "set pagination off" 1: (618) ->=cmd-param-changed,param="pagination",value="off" 1: (618) ->1002^done 1: (618) ->(gdb) 1: (618) 1002: elapsed time 4 1: (618) <-1003-gdb-set solib-search-path ~/builds/proj/bin: 1: (619) ->1003^done 1: (619) ->(gdb) 1: (619) 1003: elapsed time 0 1: (619) <-1004-file-exec-and-symbols ~/builds/proj/bin/test 1: (620) ->1004^done 1: (620) ->(gdb) 1: (621) 1004: elapsed time 1 1: (623) <-1005-interpreter-exec console "show architecture" 1: (624) ->~"The target architecture is set automatically (currently i386)\n" 1: (624) ->1005^done 1: (624) ->(gdb) 1: (625) 1005: elapsed time 1 1: (628) <-1006-target-attach 13550 1: (629) ->1006^error,msg="ptrace: Operation not permitted." 1: (629) ->(gdb) 1: (631) 1006: elapsed time 3 1: (640) <--gdb-exit E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/Attach","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.50106.1","VS.Diagnostics.Debugger.HostVersion":"1.0.40106.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Attach.Message":"Unable to start debugging. Attaching to process 13550 with GDB failed because of insufficient privileges with error message 'ptrace: Operation not permitted.'.\r\n\r\nTo attach to an application on Linux, login as super user or set ptrace_scope to 0.\r\nSee https://aka.ms/miengine-gdb-troubleshooting for details.","VS.Diagnostics.Debugger.Attach.IsError":true},"type":"output"} R: {"success":false,"message":"Unable to start debugging. Attaching to process 13550 with GDB failed because of insufficient privileges with error message 'ptrace: Operation not permitted.'.\r\n\r\nTo attach to an application on Linux, login as super user or set ptrace_scope to 0.\r\nSee https://aka.ms/miengine-gdb-troubleshooting for details.","request_seq":2,"command":"attach","body":{"error":{"id":1104,"format":"Unable to start debugging. Attaching to process 13550 with GDB failed because of insufficient privileges with error message 'ptrace: Operation not permitted.'.\r\n\r\nTo attach to an application on Linux, login as super user or set ptrace_scope to 0.\r\nSee https://aka.ms/miengine-gdb-troubleshooting for details.","variables":null}},"running":false,"refs":null,"seq":0,"type":"response"} C disconnect: {"restart":false} R: {"success":true,"message":null,"request_seq":3,"command":"disconnect","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
That's a gdb error message. When I run sudo gdb --pid 13550 I'm able to debug my process. It seems like VS Code isn't falling back to using sudo for whatever reason.