microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Debugging on WSL - Must kill the integrated terminal after each debugging session, or gdb will not launch. #12240

Open omsharp opened 6 months ago

omsharp commented 6 months ago

Environment

Bug Summary and Steps to Reproduce

I'm trying to debug on WSL with GDB. Debugger (gdb) runs only once per terminal instance, and I must kill the current terminal to start a new gdb session.

Steps to reproduce:

  1. In this environment: as mentioned above.
  2. With this config: launch.json included.
  3. Start debugging (F5) for the first time after you launch vscode.
  4. Debugger runs fine and everything works, and there is output in the integrated terminal.
  5. Stop debugging (Shift + F5), or maybe the program exists normally. (integrated terminal still open)
  6. Hit F5 to start debugging again, and nothing happens. Just the clock icon on the debug icon on sidebar and nothing happens.
  7. Stop debugging (Shift + F5).
  8. Kill the old terminal (from the last debugging session).
  9. Now if you press F5 everything works again normally.
  10. Each time you want to debug you'll have to make sure to kill the terminal used on that session before starting a new debugging session.

debugger hanging

image

kill terminal

image

Debugger Configurations

{
    "configurations": [
        {
            "name": "CMake: Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/main",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "logging": {
                "engineLogging": true
            },
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

Debugger Logs

1: (52) LaunchOptions{"name":"CMake: Debug","type":"cppdbg","request":"launch","program":"/home/omar/code/c_test/main","args":[],"stopAtEntry":false,"cwd":"/home/omar/code/c_test","logging":{"engineLogging":true},"externalConsole":false,"MIMode":"gdb","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"__configurationTarget":6,"__sessionId":"5954018f-1d5b-4025-9b02-11d0935a260e"}
1: (85) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-hwtp1kiq.zbu ; cd "/home/omar/code/c_test" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm "/tmp/Microsoft-MIEngine-In-bkwym34n.4jo" "/tmp/Microsoft-MIEngine-Out-35oyyhjc.0p5" "/tmp/Microsoft-MIEngine-Pid-hwtp1kiq.zbu" "/tmp/Microsoft-MIEngine-Cmd-0ciujqsx.thb"' EXIT ; "/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-bkwym34n.4jo" > "/tmp/Microsoft-MIEngine-Out-35oyyhjc.0p5" & clear; pid=$! ; echo $pid > "/tmp/Microsoft-MIEngine-Pid-hwtp1kiq.zbu" ; wait $pid;
1: (92) Wait for connection completion.

Other Extensions

CMake Tools: 1.17.17

Additional Information

1 - I installed xterm on my Debian/WSL and set { "externalConsole": true } in launch.json, and in that case debugging runs fine, and every time I press F5 a new external terminal (xterm) will launch even if the old one is not closed.

2 - The same setup works fine on Windows 11, with gcc, gdb, and source code all on Windows. The issue only happens if I'm trying to debug on WSL with gcc, gdb, and source code all on linux.

borjamunozf commented 6 months ago

Wondering if this could be linked somehow to this issue I'm facing https://github.com/microsoft/vscode-cpptools/issues/12120

I have to kill the process of OpenDAP a lot of times but only the first try, after launching a second one it finally starts.