Ubuntu 16.04 中 VS Code 如何斷點調試C語言程式
問題:環境是 Ubuntu16.04,如何使用 Vscode 斷點調試C語言程式。
寫代碼沒有調試環境是不能忍受的,所以折騰了一下,最後成功了。折騰的過程是這樣的:
1、 首先安裝 C/C++ 擴充,直接搜尋第一個就是,或者點此 連結 查看其協助文檔進行安裝。
2、然後開啟當前項目目錄,左邊點調試選項,點擊添加配置,產生了一個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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/LearnC/bin/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
所有內容都是預設產生的配置,我只是修改了"program"這一行,指定為編譯後的可執行檔。這樣,調試的時候預設調試這個檔案。
相關操作:
選擇 add configuration
選擇 C++(GDB/LLDB)
3、編輯代碼,完成後,首先要編譯,命令如下:
$ gcc -g -o /path/LearnC/bin/a.out [[SOURCE_FILE]]
第一個路徑指定產生後的檔案,一定要是之前program參數指定的檔案路徑,SOURCE_FILE表示C語言檔案路徑。
4、然後開啟調試,我的快速鍵是F5,開啟之後,就能直接運行到斷點處了,效果如下:
Ubuntu 14.04 安裝Visual Studio Code https://www.bkjia.com/Linux/2016-03/129052.htm
使用Visual Studio Code開發TypeScript https://www.bkjia.com/Linux/2015-07/119456.htm
Visual Studio Code 簡單試用體驗 https://www.bkjia.com/Linux/2015-05/116887.htm
Visual Studio Code試用體驗 https://www.bkjia.com/Linux/2015-07/120378.htm
Visual Studio調試技巧分享 https://www.bkjia.com/Linux/2017-11/148700.htm
Ubuntu上配置VTK開發環境——基於Visual Studio Code 與 GCC https://www.bkjia.com/Linux/2017-09/147169.htm
在Ubuntu中用Visual Studio Code編譯調試C\C++ https://www.bkjia.com/Linux/2017-09/147171.htm
Ubuntu 14.04如何安裝Visual studio Code https://www.bkjia.com/Linux/2016-07/132886.htm
Visual Studio Code 1.18 發布 (Ubuntu如何下安裝) https://www.bkjia.com/Linux/2017-11/148946.htm
Visual Studio 的詳細介紹:請點這裡
Visual Studio 的:請點這裡
本文永久更新連結地址:https://www.bkjia.com/Linux/2018-03/151602.htm