Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode, MacOS Catalina - doesn't stop on breakpoints on C/C++ debug

I'm trying to make breakpoints work on C code developed using VSCode on Mac.

My code seems to compile and run just fine (thanks to 'openssl/crypto.h' file not found on vscode B.T.W) but I don't get any breakpoints, not even on start using "stopAtEntry": true or by attaching to a running process.

My tasks.json and launch.json are very standard:

{
    "tasks": [
        {
            "type": "shell",
            "label": "clang build active file",
            "command": "/usr/bin/clang",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-I/usr/local/opt/openssl/include",
                "-L/usr/local/opt/openssl/lib",
                "-lssl",
                "-lcrypto"
            ],
            "options": {
               "cwd": "/usr/bin"
            }
        }
    ],
    "version": "2.0.0"
}

And:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/test2",
            "processId": "${command:pickProcess}",
            "MIMode": "lldb"
        },
        {
            "name": "clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "clang build active file",
            "logging": {
                "trace": false,
                "traceResponse": false,
                "engineLogging": false
              }
        }
    ]
}

I'm aware of VS code is ignoring the breakpoint in c++ debugging and all of the similar discussions here.

My setup is: MacOS Catalina (10.15, production) alongside XCode 11.1, Visual Studio Code 1.39.0 and C/C++ extension 0.26.0-insiders3.

Has anyone had better luck than me?

like image 839
Vaiden Avatar asked Oct 10 '19 19:10

Vaiden


2 Answers

So apparently it's a known issue with Catalina and XCode 11.x support: https://github.com/microsoft/vscode-cpptools/issues/3829 caused by lldb-mi.

lldb-mi is the driver that sits between the IDE and the lldb API itself.

It appears that the version of lldb-mi that comes bundled with the plugin isn't compatible with Catalina, and XCode 11.x doesn't have lldb-mi anymore.

The github thread offers 2 temporary solutions:

lldb-mi

The first solution is to use the lldb-mi that comes bundled with previous versions of XCode, by setting the miDebuggerPath property of launch.json.

I happened to have XCode 10.1 lying around so my configuration is:

"miDebuggerPath":"/Applications/Xcode 10.1.app/Contents/Developer/usr/bin/lldb-mi",

I managed to get basic debugging working but there are compatibility issues to be expected. However this turned out to be good enough for my needs (yay!).

A replacement lldb frontend

The second solution is to use the VSCode-lldb extension.

Updates come here

I will keep this answer and this post updated with a permanent solution once it comes up.

like image 63
Vaiden Avatar answered Sep 28 '22 02:09

Vaiden


Follow on @Vaiden solution 2, which I carry on with my C++ vscode debugging. I supplement how on use it on my debugging configuration.

  1. Install CodeLLDB vscode extension

  2. Modify launch.json configuration file

{
  "version": "0.2.0",
  "configurations": [
      {
          //...other configuration
          "type": "lldb", // change this one from cppdbg to lldb
      }
  ]
}
  1. F5 to start debug your code, and it should fix your lldm-mi issue
like image 32
Brady Huang Avatar answered Sep 28 '22 02:09

Brady Huang