microsoft / microsoft/vscode-cpptools
Debugging on WSL - Must kill the integrated terminal after each debugging session, or gdb will not launch.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and version: Window 11 (Build 22631.3447)
- VS Code: 1.88.1
- C/C++ extension: 1.19.9
- OS and version of remote machine (if applicable): WSL / Debian bookworm
- GDB / LLDB version: GDB 13.1
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:
- In this environment: as mentioned above.
- With this config: launch.json included.
- Start debugging (F5) for the first time after you launch vscode.
- Debugger runs fine and everything works, and there is output in the integrated terminal.
- Stop debugging (Shift + F5), or maybe the program exists normally. (integrated terminal still open)
- Hit F5 to start debugging again, and nothing happens. Just the clock icon on the debug icon on sidebar and nothing happens.
- Stop debugging (Shift + F5).
- Kill the old terminal (from the last debugging session).
- Now if you press F5 everything works again normally.
- 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
kill terminal
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the launch.json configuration and the engine log, especially the command that launches GDB through the integrated terminal. Reproduce the second F5 attempt on WSL with externalConsole set to false, then compare it with externalConsole set to true. Done means repeated debugging sessions launch successfully without manually killing the integrated terminal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, debian, linux, vscode
- Domain
- operating-systems, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100