vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Breakpoints are set in all files with same name

Open psclkhoury opened this issue 5 years ago • 22 comments

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?

psclkhoury avatar Jan 08 '21 09:01 psclkhoury

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 avatar Jan 08 '21 18:01 WardenGnaw

@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.c

That is, there are two main.c files. One directly in src:

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.exe

Add 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.c at line 5. Launch debugger, it breaks in main, hit continue and it will break in foo (which it should not).

The above setup:

Breakpoints.zip

Settings

    "debug.allowBreakpointsEverywhere": true

c_cpp_properties.json is 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

psclkhoury avatar Jan 08 '21 19:01 psclkhoury

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 avatar Jan 08 '21 19:01 WardenGnaw

@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.

psclkhoury avatar Jan 08 '21 20:01 psclkhoury

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.

diyessi avatar Jan 13 '21 04:01 diyessi

@WardenGnaw the issue I mentioned here seems related to #4017, although I dont have relative paths.

psclkhoury avatar Jan 14 '21 12:01 psclkhoury

Why the solution is so badly described?

  1. Edit launch.json
  2. Add the following entry
           "sourceFileMap": {
                "${workspaceFolder}": {
                    "editorPath": "${workspaceFolder}",
                    "useForBreakpoints": "true"
                }
            }
  1. 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
            }
        }
    ]
}

josuegomes avatar Jan 26 '21 10:01 josuegomes

I encountered the same issue and solved it as @josuegomes said, but I believe this is a bug and should be fixed elegantly.

geekfivestart avatar Mar 03 '21 10:03 geekfivestart

@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?

image

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 avatar Mar 03 '21 13:03 psclkhoury

@psclkhoury sorry to hear it didn't work for you on Windows.

josuegomes avatar Mar 03 '21 13:03 josuegomes

@WardenGnaw Any update on this?

psclkhoury avatar Apr 23 '21 12:04 psclkhoury

It was still happening to me yesterday.

diyessi avatar Apr 23 '21 15:04 diyessi

@WardenGnaw any update?

psclkhoury avatar Jul 13 '21 10:07 psclkhoury

same issue debugging with an elf built in a docker environment does not seem to find proper breakpoint

agosdahu avatar Sep 22 '21 09:09 agosdahu

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

image

sketch34 avatar Nov 16 '22 05:11 sketch34

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.

zrhoffman avatar Dec 20 '22 01:12 zrhoffman

Why the solution is so badly described?

  1. Edit launch.json
  2. Add the following entry
           "sourceFileMap": {
                "${workspaceFolder}": {
                    "editorPath": "${workspaceFolder}",
                    "useForBreakpoints": "true"
                }
            }
  1. 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!

buzhangjiuzhou avatar May 17 '23 02:05 buzhangjiuzhou

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.

Altyrost avatar Apr 09 '25 08:04 Altyrost

Just confirmed: It's a regression from vscode 1.99. It does work with vscode 1.98.

Altyrost avatar Apr 09 '25 08:04 Altyrost

Very glitched and annoying thing! Please, fix this

GulgDev avatar Jun 04 '25 14:06 GulgDev

I'm running into this too. The cmake extension suffers from this too, and there's no launch configuration I can edit.

jeremy-rifkin avatar Jun 10 '25 20:06 jeremy-rifkin

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.

khoand7 avatar Jun 17 '25 08:06 khoand7