microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

c++ debugger doesn't run #11533

Open zmrocze opened 1 year ago

zmrocze commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

Launching a c++ debugger from vscode doesn't launch debugger. For a moment the debugging icons show up, but quickly thedDebugger quits doesn't stopping on breakpoints. No error messages show anywhere in vscode console/problems/output.

Steps to reproduce:

  1. Use the default debugger configuration called "g++: build and debug" or configure launch.json like below:
// launch.json
"configurations": [
    {
      "name": "(gdb) Launch 1",
      "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
          },
          {
              "description": "Set Disassembly Flavor to Intel",
              "text": "-gdb-set disassembly-flavor intel",
              "ignoreFailures": true
          }
      ]
    },
 ]
}
  1. From withing vs code debugger tab start the debugger (in the example a configuration "(gdb) Launch 1"
  2. Observe how debugger seemingly starts, icons (start/continue/stop) show up for a moment but then disappear and nothing more happens.
  3. Inspect how nothing shows up in problems/output/debug console.

Debugger Configurations

{ "configurations": [
    {
      "name": "(gdb) Launch 1",
      "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
          },
          {
              "description": "Set Disassembly Flavor to Intel",
              "text": "-gdb-set disassembly-flavor intel",
              "ignoreFailures": true
          }
      ]
    },
  ]
}

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++ build active file",
      "command": "/home/zmrocze/.nix-profile/bin/g++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ],
  "version": "2.0.0"
}

Debugger Logs

Nothing shows up anywhere after I enabled logging like hinted ^ above.

Other Extensions

No response

Additional Information

I'm using nixos so it might be bit weirder with the linker, I've hit problems before when the linker couldn't find something during compilation. BUT here this is irrelevant: 1) I can compile succesfully with these compilers, also from within vscode. 2) there's no indication whatsover from vscode that anything failed.

Versions:

$ which gdb
/home/zmrocze/.nix-profile/bin/gdb
$ which g++
/home/zmrocze/.nix-profile/bin/g++
$ g++ (GCC) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
sean-mcmanus commented 1 year ago

Can you provide a screenshot of the button you're clicking to start debugging? Does it run without debugging?

zmrocze commented 1 year ago

The button: "Run and Debug" section on the left -> "Start debugging (F5)" green play button. Choosing the "(gdb) Launch 1" configuration.

sean-mcmanus commented 1 year ago

@zmrocze Sorry for the delayed response. I'm not sure what could be going wrong.

@WardenGnaw Do you know what could be going wrong?

hwangs12 commented 8 months ago

I had the same issue and debugger started working again when I downgraded version to 1.6.2.

hifigraz commented 7 months ago

same here.

[proc] Executing command: gdb --version

Is the last info, then nothing more happens.

As far as I can see, it does not try to start any gdb process after the version check to get the path.

fzakaria commented 3 months ago

This is because there is an unpatched binary in the extension. Please see https://discourse.nixos.org/t/cant-run-c-debugger-in-vscode/33609/6

I made really good progress on this using strace

I did:

strace -f -s99999 -e trace=clone,execve code --wait .

Then I tried to click the debugger:

[pid 193326] execve("/home/fmzakari/.vscode/extensions/ms-vscode.cpptools-1.20.5-linux-x64/debugAdapters/bin/OpenDebugAD7", ["/home/fmzakari/.vscode/extensions/ms-vscode.cpptools-1.20.5-linux-x64/debugAdapters/bin/OpenDebugAD7"], 0x2aec0357bc00 /* 92 vars */) = 0
[pid 193326] +++ exited with 127 +++

It tries to run a binary OpenDebugAD7 which is not compatible with NixOS :(

This needs to be rebuilt using NixO