microsoft / microsoft/vscode-cpptools

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

Open
#8,011 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugger Feature Request
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with test.cpp and the provided launch.json, focusing on stopAtEntry and the traced GDB commands -break-insert -f main and -break-delete 1. Compare this with the attach-debugging workaround; done means launching does not leave an invalid breakpoint that prevents debugging when stopAtEntry is false.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.