M1 Macbook vscode C++ debug調(diào)試實現(xiàn)
這里給出自己摸索的最基本的調(diào)試方式,需要進(jìn)階調(diào)試感覺還是需要一定的學(xué)習(xí)成本的,嘗試了幾個網(wǎng)上的博客,暫時沒遇到直接可以運(yùn)行的。所以這里記錄一下大概方法。
主要是需要在目錄文件下配置兩個 json 文件(tasks.json,launch.json)
版本說明
VS code 版本是在官網(wǎng)直接下載的 M1 版本的 February 2021 (version 1.54)
官方下載
擴(kuò)展
主要是要下載 codeLLDB 的下載,直接在 VS code 里面搜索下載就好了(可能需要從網(wǎng)上下載 VSIX,不過 VS code 會有提示)
配置文件
首先需要有一個文件目錄 demo:

選中我們需要調(diào)試的文件 test.cpp,然后按 F1,打開設(shè)置選項,選擇 Tasks:Configure Default Build Task,根據(jù)需要選擇對應(yīng)的編譯器,這里選擇 clang++:
之后 VS code 會在同級目錄下自動生成一個名為 `tasks.json` 的文件,正常這里是如果沒有其他需求直接使用默認(rèn)的即可,如果需要加入 std=c++11 還是 c++17 之類的,要在 `args` 的內(nèi)容里添加,這個可以額外學(xué)習(xí)一下 tasks.json 的配置教程,這里就不贅述了。默認(rèn)生成內(nèi)容如下:
{
"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": {
"kind": "build",
"isDefault": true
},
"detail": "編譯器: /usr/bin/clang++"
}
]
}
然后 選擇左邊第三個調(diào)試選項,再選擇create a launch.json file :

然后要選擇 LLDB 選項,這個才是我們下載的 codeLLDB 插件,VS code 會自動創(chuàng)建一個 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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
這里需要稍作修改,將 “program” 選項修改成與 tasks.json 的文件名一致,然后還需要加一個 preLaunchTask 的選項,將 tasks.json 的 label 名字粘貼過來,修改以后launch.json 內(nèi)容如下:
{
// 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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "C/C++: clang++ 生成活動文件"
}
]
}
運(yùn)行調(diào)試
上述配置完成以后,編譯項目(shift+command+B),在代碼中設(shè)置斷點(diǎn),然后直接點(diǎn)擊 F5,就可以正常斷點(diǎn)運(yùn)行調(diào)試了。

到此這篇關(guān)于M1 Macbook vscode C++ debug調(diào)試的文章就介紹到這了,更多相關(guān)M1 vscode C++ 調(diào)試內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C/C++?for?語句的要點(diǎn)與注意事項小結(jié)
C/C++ 中的?for?語句是一種常用的循環(huán)結(jié)構(gòu),用于重復(fù)執(zhí)行一段代碼,直到滿足某個條件為止,這篇文章主要介紹了C/C++?for?語句的要點(diǎn)與注意事項,需要的朋友可以參考下2024-06-06
VisualStudio2022不支持.NET Framework 4.0項目解決辦法
本文主要介紹了VisualStudio2022不支持.NET Framework 4.0項目解決辦法,文中通過圖文的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09

