VScode M1芯片 报错:ERROR: Unable to start debugging. Unexpected LLDB output from command “-exec-run“.

VScode 报错:ERROR: Unable to start debugging. Unexpected LLDB output from command “-exec-run”.

1. 背景介绍

  1. 新手 VScode 使用者,使用系统是:MacOS Big Sur 11.4,使用的是Apple M1 芯片。
  2. 利用 Vscode 编译 c++ 代码,按照标准流程, 进行了配置。标准配置链接为:https://code.visualstudio.com/docs/cpp/config-clang-mac

debug 之后出现的问题是:

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 ‘/Users/Desktop/test/test’ has exited with code 42 (0x0000002a).

2. 问题分析以及解决方法

tasks.json 中代码为:

    {
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ 生成活动文件",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: /usr/bin/clang++"
        },
    ]
}

其中 args 中的参数代表编译器会执行:

clang++ -g test.cpp -o test

在此之后,生成的结果为:
在这里插入图片描述
然后,下一步是需要执行 ./test 操作,这一步需要用扩展来完成:CodeLLDB,具体是在 launch.json 中写入 launch 的操作,具体是操作 ./test 的步骤,使结果输出:

        {
            "name": "Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": ["-arg1", "-arg2"],
        }

其中 ${fileBasenameNoExtension} 代表 test 的文件。之后,在cpp文件中执行 F5 操作,无报错。
在这里插入图片描述

3. 重点

CodeLLDB 扩展的引入以及 launch 中写入了

"program": "${workspaceFolder}/${fileBasenameNoExtension}", 

命令。

参考:
  1. lldb 使用: https://blog.csdn.net/Vinsuan1993/article/details/103983520
  2. 思路指向:https://github.com/microsoft/vscode-cpptools/issues/6779

2022.2.4 更新

新添加配置成功之后的json参数:
launch.json

{
    // 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": "(lldb) 启动",
      "type": "lldb",
      "request": "launch",
      "program": "${workspaceFolder}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb"
    }
    ]
  }

task.json

{
    "version": "2.0.0",
    "tasks": [
          {
            "type": "cppbuild",
            "label": "C/C++: clang 生成活动文件",
            "command": "/usr/bin/clang",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: /usr/bin/clang"
        }
    ]
}

此外,安装了插件:
CodeLLDB

C/C++

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值