Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB Breakpoints are set in all files with same name #977

Closed
ZobyTwo opened this issue Aug 16, 2017 · 40 comments
Closed

GDB Breakpoints are set in all files with same name #977

ZobyTwo opened this issue Aug 16, 2017 · 40 comments

Comments

@ZobyTwo
Copy link

ZobyTwo commented Aug 16, 2017

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.

Environment

Win 10
VSCode 1.15 stable build
C/C++ 0.12.2
No other extension installed.
Gdb 7.6.1 is from mingw32
Gcc 5.3.0 is from mingw32

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.

@ZobyTwo
Copy link
Author

ZobyTwo commented Aug 18, 2017

@pieandcakes Could you please elaborate on why this is considered a request for a feature?

From my perspective, this looks like a bug, really. I have a project with a few hundred *.c files with the same name (they are mostly generated by another tool) and this makes it very hard to debug them because the debugger breaks at seemingly random places - additional to the line where I did set a breakpoint.

@pieandcakes
Copy link
Contributor

@ZobyTwo When we send the bindings for the breakpoints we are currently only sending the filename. As such, it is "by design" even though it is unintended. There have been changes in MIEngine to allow support of this. I'll mark it as a bug also but either way it will require work on my part to get it to work.

@ZobyTwo
Copy link
Author

ZobyTwo commented Aug 19, 2017

@pieandcakes I see, thanks for the explanation.

@tobiaskohlbau
Copy link

tobiaskohlbau commented Aug 28, 2017

I've the same bug/lack of feature as I use cpptools to debug an ARM Processor with multiple cores. As each core gets it's own main.cpp (entrypoint) vscode breaks on every line. Would be nice if this feature/bug could be implemented/resolved.

@ghost
Copy link

ghost commented May 30, 2018

Is the bug has been resolved ?

@mpups
Copy link

mpups commented Jun 20, 2018

Seems to still be a problem (at least in 8.1-0ubuntu3). I tried to get round this by setting the full path name of the file but GDB doesn't like this either. I guess it is not using realpath internally to disambiguate files.

@Ju57iCe
Copy link

Ju57iCe commented Oct 12, 2018

Any ETA or roadmap on this? The breakpoint features seem frozen for so long - data breakpoints, log points.

@rsbondi
Copy link

rsbondi commented Mar 19, 2019

When we send the bindings for the breakpoints we are currently only sending the filename

I have a possibly related issue based on the quote, the object file is built with prefix_filename so it is missing the breakpoint in filename.c(red, looks set but not hit), is this a symptom of the same issue? Is there a workaround?

@psclkhoury
Copy link

psclkhoury commented Apr 10, 2019

I am having the same issue but with the vs debugger and it's quite annoying.

We have a big repository and some files have the same name but in a different path.

When I put a breakpoint in Folder1/Folder2/Util.cpp, all the Util.cpp will break regardless of their paths. This makes the debugger unusable.

This is my launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Loader",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "c:/SomeExecutable.exe",
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "externalConsole": true,
    }
  ]
}

@pieandcakes
Copy link
Contributor

@psclkhoury It is on our list for current work planning.

@ghost
Copy link

ghost commented Mar 6, 2020

Any updates on this bug?
Thanks!

@Yuri6037
Copy link

Hello, I also have this problem under Ubuntu Server 18.04. I hope this will be fixed very soon as it's getting really annoying...
However I don't get it under Windows MSVC.

@Trass3r
Copy link

Trass3r commented Oct 22, 2020

Also got bitten by this on v1.0.1

@psclkhoury
Copy link

3 years later still no fix? @pieandcakes Will you accept a PR for this or is it in the closed source part of the code?

@Trass3r
Copy link

Trass3r commented Oct 27, 2020

I think it's all open source by now.

@WardenGnaw
Copy link
Member

You can now specify breakpoints to use full path in v1.1.0 via sourceFileMap.

Example:

"sourceFileMap": {
   "<compiler-path>": {
      "editorPath": "<source-path>",
      "useForBreakpoints": true
   }
}

@psclkhoury
Copy link

psclkhoury commented Nov 12, 2020

@WardenGnaw Can you give a better example on how to use this? Do I have to do this for each breakpoint I set or what? What are <compiler-path> and <source-path>?

I don't agree with the solution. By default I should be able to set a breakpoint and the full path should be sent to the debug engine without any extra action.

This seems more like a workaround than a fix.

@WardenGnaw
Copy link
Member

<compile-path> is the path that GDB returns when a breakpoint is hit.
<source-path> is the path that you want to see in the editor.

For scenarios where you do not build on a different machine or move the source files before compiling, <compile-path> and <source-path> will be exactly the same.

With the following, all breakpoints (except the first one the debug adapter uses to break at entry) will be fully qualified.
E.g.

"sourceFileMap": {
   "C:\Path\To\Project\Root": {
      "editorPath": "C:\Path\To\Project\Root",
      "useForBreakpoints": true
   }
}

By default I should be able to set a breakpoint and the full path should be sent to the debug engine without any extra action.

We decided not make this a default because there are projects that users have debug bits but do not have the source code. This would cause the breakpoint bind to fail.

Here is the related code in the Debug Adapter:
https://github.com/microsoft/MIEngine/blob/73db59d89b8f0fbfdaa3cee1423e674e092ffc0f/src/MIDebugEngine/Engine.Impl/Breakpoints.cs#L114-L118

@psclkhoury
Copy link

@WardenGnaw I tried:

"sourceFileMap": {
     "${workspaceFolder}": {
         "editorPath": "${workspaceFolder}",
         "useForBreakpoints": true
    }
}

And I got an error:
image

I then tried to put the real path instead of ${workspaceFolder} (so c:/path/to/root) and the breakpoint was set in all files with the same name.

We decided not make this a default because there are projects that users have debug bits but do not have the source code. This would cause the breakpoint bind to fail.

I think most users will never have to deal with that, so it do not understand why the default is chosen according to that very rare scenario.
If someone has debug bits then maybe they can change some setting or add something to the launch.json to make it work, and the normal use cases should work without any user configuration.

@WardenGnaw
Copy link
Member

Can you enable logging by adding the following to your launch.json and share the -break-insert logs in Debug Console?

"logging": {
   "engineLogging": true
}

When doing that, you can filter and check to see if MIEngine is telling GDB to bind with the specific path for files under that path.

Here's an example of two files with the same name foo.cpp in associated folders called A/B under the project D:/Projects/cpp
image

If it only shows something like -break-insert -f filename.cpp:15, then it could not resolve the path you provided in sourceFileMap.

@psclkhoury
Copy link

I do not see any logging with break-insert after enabling the engineLogging. I only see this which has the correct path.

image

@Trass3r
Copy link

Trass3r commented Nov 12, 2020

We decided not make this a default because there are projects that users have debug bits but do not have the source code. This would cause the breakpoint bind to fail.

I can't follow. If you don't have the source code you can't set a breakpoint from the code editor, only manually via the breakpoints view and that user input should be passed on as-is.

Anyway can't the debug adapter decide on its own if a full path is ok, like with File.Exists or whatever?

@psclkhoury
Copy link

@WardenGnaw Can we reopen this issue? The solution is not working for me.

@josuegomes
Copy link

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 addition 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
            }
        }
    ]
}

asialasr pushed a commit to asialasr/vscode-cpptools that referenced this issue Mar 12, 2021
* Allow consoleCommand to exec while process run

Added flag allowWhileRunning to consoleAsyncCmd since certain
commands
like 'version' do not require the process to be stopped in order to
work
@lp35
Copy link

lp35 commented Aug 30, 2021

Hi,

Bug has reappeared in the latest releases, as recently reported in #692 and #7913. Could you reopen this ticket?

@amih90
Copy link

amih90 commented Feb 16, 2022

any updates? still reproducing

@WardenGnaw
Copy link
Member

I am unable to reproduce this issue in v1.8.4, as mentioned in #977 (comment), you need the following to enable breakpoints as full paths instead of just filename.

            "sourceFileMap":{
                "${workspaceRoot}": {
                    "editorPath": "${workspaceRoot}",
                    "useForBreakpoints": true
                }
            }

@amih90 Can you share your launch.json if you do have the snippet above?

@psclkhoury
Copy link

I am unable to reproduce this issue in v1.8.4, as mentioned in #977 (comment), you need the following to enable breakpoints as full paths instead of just filename.

            "sourceFileMap":{
                "${workspaceRoot}": {
                    "editorPath": "${workspaceRoot}",
                    "useForBreakpoints": true
                }
            }

@amih90 Can you share your launch.json if you do have the snippet above?

@WardenGnaw @sean-mcmanus I tried the suggested solution but it doesn't work for me.
The ${workspaceFolder} is being replaced by the vscode editor path.

I also tried to enter the explicit ${workspaceFolder} (c:/path/to/repo) but also did not work. The breakpoints were still being attached in all files having the same name.

I still don't understand why this is not fixed on the extension side by sending the full path to the debugger, instead of on the user side with us having to fiddle with our launch.json. It would be a much better and more robust solution.
Can someone please clarify why?

This is the breakpoint I set:
image

It got transformed to that after I started debugging:
image

And of course the file was not found.

This is my launch.json:

"configurations": [
    {
      "name": "Start App",
      "type": "cppvsdbg",
      "request": "launch",
      "cwd": "some/dir",
      "program": "my/executable.exe",
      "stopAtEntry": false,
      "console": "newExternalWindow",
      "requireExactSource": true,
      "sourceFileMap": {
        "${workspaceRoot}": {
          "editorPath": "${workspaceRoot}",
          "useForBreakpoints": true
        }
      }
    },
]

@WardenGnaw
Copy link
Member

@psclkhoury I apologize since I did not read your initial message at #977 (comment) but only read your message starting at #977 (comment). I assumed that your issue was specifically for GDB not the vsdebugger.

I have re-opened this issue for cppvdbg at #9054

@pierrebai-adsk
Copy link

I'm getting the same problems with the latest VSCode and native Windows debugger.

@davidstone
Copy link

davidstone commented Mar 3, 2023

It seems pretty strange that I can use the VS Code UI to set a breakpoint by clicking on a line number in a specific file and that has the effect of setting a breakpoint in a different file by default. I feel like a better experience would not require a multi-line json configuration to do the thing that 100% of users using this interface are trying to do. It also looks like I need to modify the setting of every configuration I have in my launch.json

@pierrebai-adsk
Copy link

We have multiple projects, multiple libraries in multiple file repos. Having to list every single one in every entries in the launch.json is super-cumbersome. No single other IDE, development tools require such contortions just to properly set a breakpoint. As pointed out by someone else, the explanation why this is not the default behaviour makes no sense: if they don't have the source code, then they surely are not creating breakpoints in the editor!

@psclkhoury
Copy link

@WardenGnaw @pieandcakes can you guys at least respond and clarify why you don't want to fix it?
This issue is more than 6 years old and has been reported so many times already.
If you use the extension yourselves for any meaningful c++ work you would know how annoying it is, and you probably would have fixed it already.

@rongzha1
Copy link

@WardenGnaw @pieandcakes can you guys at least respond and clarify why you don't want to fix it? This issue is more than 6 years old and has been reported so many times already. If you use the extension yourselves for any meaningful c++ work you would know how annoying it is, and you probably would have fixed it already.

totally agree. Hope to fix it , not a work around.

@nussjo
Copy link

nussjo commented Oct 26, 2023

still experiencing the issue. Makes debugging virtually impossible because the breakpoint in the other file with the same name is hit periodically and roughly 1000 times more often. How such a behavior that is obviously a bug can exist for over 6 years and not be fixed is a mystery to me.

@coldav
Copy link

coldav commented Nov 7, 2023

I agree, this reduces the effectiveness of an otherwise really good system - although the workaround is helpful.

@eii-zhangsong
Copy link

I am also getting this problem these days. It really took me some time to find out it's a bug from the editor. Hope it could be fixed to save time of other developers. Thank you.

@coldav
Copy link

coldav commented Nov 13, 2023

I am also getting this problem these days. It really took me some time to find out it's a bug from the editor. Hope it could be fixed to save time of other developers. Thank you.

The SourceFileMap workaround does work though, so i'd recommend adding this to your config.

@tok101
Copy link

tok101 commented Aug 6, 2024

#977 (comment)

This method is OK for a workspace with only one directory, but not for a workspace with multiple directories. For a workspace with multiple directories, this error will be reported:

Variable ${workspaceFolder} can not be resolved in a multi folderworkspace.Scope this variable using ":" and a workspace folder name.

I tried my best to follow the instructions and make the changes, but it didn't work.
Is there any way to solve this?

@Turtwiggy
Copy link

If I use an alternative to launch.json e.g. vscode-cmake-tool , is my debugger forever broken on files named the same thing? Pls no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests