Breakpoints are set in all files with same name
When setting a breakpoint in a file with a particular name, breakpoints are set in all files with that file name at the same line.
I saw #977 where the same issue is reported, but the provided workaround does not work and there is no response anymore from the team.
This is a deal breaker for me as I cannot use the debugger at all in the current situation. The issue has been open for 3 years already. If there is no intent of providing a good fix for this, can you let us know so we can reconsider our options?
Can you fill out the debugger bug template?
**Describe the bug**
- OS and Version:
- VS Code Version:
- C/C++ Extension Version:
- Other extensions you installed (and if the issue persists after disabling them):
- 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:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. 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.
@WardenGnaw As I said in the description, this is the SAME issue as the one I referenced (#977). Maybe it's easier to reopen the other issue instead of me copy pasting stuff from there to here.
When setting a breakpoint in a file with a particular name, breakpoints are set in all files with that file name at the same line.
Reproduce
Create the following project layout:
src |- main.c |- folder |- main.cThat is, there are two
main.cfiles. One directly insrc:int foo(); int main(int argc, char *argv[]) { int a = 0; a += 3; a *= 4; foo(); return 0; }The other in
src/folder:int foo() { int b = 14; int d = 13; b += d - b * d; return b + d; }In both files, line 5 contains executable code.
Compile from within
src:gcc main.c folder/main.c -g -O0 -o a.exeAdd
launch.json:{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/src/a.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }Set breakpoint in
src/main.cat line 5. Launch debugger, it breaks in main, hit continue and it will break in foo (which it should not).The above setup:
Settings
"debug.allowBreakpointsEverywhere": true
c_cpp_properties.jsonis not in use and launch.json is given above.
cpptools version: 1.1.3 Version: 1.52.1 (user setup) Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523 Date: 2020-12-16T16:34:46.910Z Electron: 9.3.5 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Windows_NT x64 10.0.18363
As per the comments, the fix is to add:
"sourceFileMap":{
"C:\\path\\to\\project\\src": {
"editorPath": "C:\\path\\to\\project\\src",
"useForBreakpoints": true
}
},
With engineLogging enabled, you will see that the breakpoints are binding with the full path. E.g.
1: (298) <-1011-break-insert -f main
1: (350) <-1012-break-insert -f C:/path/to/project/src/main.c:5
1: (391) <-1014-break-insert -f C:/path/to/project/src/folder/main.c:5
If not, the breakpoints will be bound by filename:line number
1: (319) <-1011-break-insert -f main
1: (368) <-1012-break-insert -f main.c:5
1: (426) <-1015-break-insert -f main.c:5
@WardenGnaw I already tried that and it did not solve the issue for me. The logging you mention was also not present.
See https://github.com/microsoft/vscode-cpptools/issues/977#issuecomment-726325642 and https://github.com/microsoft/vscode-cpptools/issues/977#issuecomment-726346927.
Also as was mentioned in the other issue, this is a workaround and not a proper fix.
I have encountered this problem in VSC since 2016 when first starting to use VSC (MacOS and Ubuntu). I don't think I have ever seen it work properly in all that time.
@WardenGnaw the issue I mentioned here seems related to #4017, although I dont have relative paths.
Why the solution is so badly described?
- Edit launch.json
- Add the following entry
"sourceFileMap": {
"${workspaceFolder}": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": "true"
}
}
- If you want to add logs to confirm the configuration add this entry
"logging": {
"engineLogging": true
}
For reference this is my complete launch.json (sensitive data removed):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/app",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make",
"miDebuggerPath": "/usr/bin/gdb",
"sourceFileMap": {
"${workspaceFolder}": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": "true"
}
},
"logging": {
"engineLogging": true
}
}
]
}
I encountered the same issue and solved it as @josuegomes said, but I believe this is a bug and should be fixed elegantly.
@geekfivestart I tried what @josuegomes said but I still got the same error that I reported here. Maybe it's because I am running Windows?

This bug has been reported 4 years ago and it is still not fixed, and there is very little feedback from the team. It seems that they don't want to fix it.
@psclkhoury sorry to hear it didn't work for you on Windows.
@WardenGnaw Any update on this?
It was still happening to me yesterday.
@WardenGnaw any update?
same issue debugging with an elf built in a docker environment does not seem to find proper breakpoint
Same issue.
GNU gdb (GDB) 12.1
Name: C/C++
Id: ms-vscode.cpptools
Description: C/C++ IntelliSense, debugging, and code browsing.
Version: 1.12.4
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
Version: 1.73.1 (user setup)
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T04:27:29.066Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22000
Sandboxed: No

Adding
"sourceFileMap": {
"${workspaceFolder}": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": "true"
}
}
to my launch configuration, as mentioned in https://github.com/microsoft/vscode-cpptools/issues/977#issuecomment-767445913, fixes the issue for me (on Linux). Maybe #6754 could be resolved by making this the default setting.
Why the solution is so badly described?
- Edit launch.json
- Add the following entry
"sourceFileMap": { "${workspaceFolder}": { "editorPath": "${workspaceFolder}", "useForBreakpoints": "true" } }
- If you want to add logs to confirm the configuration add this entry
"logging": { "engineLogging": true }For reference this is my complete launch.json (sensitive data removed):
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/app", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "make", "miDebuggerPath": "/usr/bin/gdb", "sourceFileMap": { "${workspaceFolder}": { "editorPath": "${workspaceFolder}", "useForBreakpoints": "true" } }, "logging": { "engineLogging": true } } ] }
It works for me!
Doesn't work anymore, not sure what have changed. "${workspaceFolder}" used as a key isn't resolved anymore.
from the logs:
1: (733) <-1012-break-insert -f ${workspaceFolder}/src/main.cpp:28
1: (752) ->&"No source file named ${workspaceFolder}/src/main.cpp.\n"
it does work if I replace ${workspaceFolder} with the actual location.
Just confirmed: It's a regression from vscode 1.99. It does work with vscode 1.98.
Very glitched and annoying thing! Please, fix this
I'm running into this too. The cmake extension suffers from this too, and there's no launch configuration I can edit.
I can confirm that after adding the below snippet, it is working properly in vscode 1.101
"sourceFileMap": {
"${workspaceFolder}": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": "true"
}
},
"logging": {
"engineLogging": true
}
My GDB version:
gdb --version
GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
BUT THIS IS JUST A WORKAROUND and need users to modify lauch.json themselves.