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

GDB Launch is automatically adding the breakpoint to `main` function

Open AmeyaVS opened this issue 4 years ago • 9 comments

Bug type: Debugger

Describe the bug

  • OS and Version: Fedora 34
  • VS Code Version: 1.59.0
  • C/C++ Extension Version: v1.5.1 and v1.6.0-insiders3
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is.

I am developing/debugging C/C++ plugins for a large framework. Where I don't have access to the source of main function. It seems the C++ debug interface automatically configures the main function as a breakpoint in GDB. How can I disable the main function from being added to the debugger by default? Basically I want to remove the default breakpoint being added to the debugger: Here is the snapshot from the Debug Console in VSCode attached document for reference trace.txt:

...
1: (208) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (208) 1009: elapsed time 0\n"},"seq":112}
1: (208) 1009: elapsed time 0
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (209) <-1010-break-insert -f main\n"},"seq":114}
1: (209) <-1010-break-insert -f main
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (211) ->1010^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x00000000004012e3\",func=\"main(int, char**)\",file=\"/home/ameyavs/apps/src/test/test.cpp\",fullname=\"/home/ameyavs/apps/src/test/test.cpp\",line=\"11\",thread-groups=[\"i1\"],times=\"0\",original-location=\"main\"}\n"},"seq":116}
1: (211) ->1010^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000000004012e3",func="main(int, char**)",file="/home/ameyavs/apps/src/test/test.cpp",fullname="/home/ameyavs/apps/src/test/test.cpp",line="11",thread-groups=["i1"],times="0",original-location="main"}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (211) ->(gdb)\n"},"seq":118}
1: (211) ->(gdb)
...
1: (484) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (485) 1020: elapsed time 1\n"},"seq":338}
1: (485) 1020: elapsed time 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (490) <-1021-break-delete 1\n"},"seq":340}
1: (490) <-1021-break-delete 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (490) ->1021^done\n"},"seq":342}
1: (490) ->1021^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (490) ->(gdb)\n"},"seq":344}
1: (490) ->(gdb)
...

To Reproduce

  • Code sample which captures the said behavior and launch.json configuration.*

Sample Code: test.cpp

#include <iostream>
#include <string>

using namespace std;

void print(const string& message) {
    cout << message << "\n";
}

int main(int argc, char* argv[]) {
    print("Hello");
    return 0;
}

Sample launch.json configuration

{
    // 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 active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb",
            "logging": {
                "engineLogging": true,
                "trace": true,
                "traceResponse": true
            }
        }
    ]
}

Steps to reproduce the behavior:

  1. Add a breakpoint in line 7 or print function on the code.
  2. Start debugging
  3. Observe the DEBUG CONSOLE in VSCode for following lines: -break-insert -f main: Inserts the very first breakpoint even when the json config: stopAtEntry is set to false. -break-delete 1: Deletes breakpoint after loading.

Additional context In actual development environment(source unavailable) receiving the following error from GDB due to this behavior in VSCode.

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Warning:
Cannot insert breakpoint 1.
Cannot access memory at address <0x30c0>.
  • For now, using the attach debugging capability to work around this issue by first starting the application from another terminal, then attaching VSCode to the process for debugging.
  • Also, while setting up gdb on the console no such behavior is observed.

AmeyaVS avatar Aug 19 '21 13:08 AmeyaVS