Search code examples
c++visual-studio-codelldbvscode-debugger

Visual Studio Code LLDB on macOS error when starting debugging session


I'm trying to configure Visual Studio Code for compiling/debugging C++ programs on macOS. I am using the following launch.json file:

Enter image description here

When I try and start a debugging session, I get the following error:

Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process
exited with status -1 (attach failed ((os/kern) invalid argument))
The program '/path/to/Development/C++/helloworld/main' has exited with code 42
(0x0000002a).

It is worth mentioning that I am using an MacBook (M1), so x86_64 is not the correct architecture. I'm assuming that this is the reason for the error.

I can't seem to find any reference to this error anywhere online. How can I solve this?

Adding "targetArchitecture": "ARM64" removed the warning, but it does not fix the error.


Solution

  • I had the same problem and I found that Visual Studio Code does not support a debugger for ARM64 binaries yet. Here is the issue link.

    However, it works if you use another extension. Install CodeLLDB and set "type": "lldb" in launch.json like below.

    {
        // 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": "clang++ - Build and debug active file",
            "type": "lldb",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "clang++ build active file"
          }
        ]
      }
    

    You can check quick start guide of vscode-lldb repository.

    Note that preLaunchTask's value should be the same as the label's value in your task.json file.