我正在嘗試從 launch.json 檔案運行,因此我可以使用 gdb 在 vscode 中除錯我的程式。
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "SourceFolder/test",
"args": [],
"stopAtEntry": false,
"cwd": "SourceFolder",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g compile active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
路徑正確,我可以在檔案夾中看到編譯后的檔案。我可以通過控制臺(bash)運行程式沒問題,它不會拋出任何錯誤,但是當我通過這種方法運行它時,我得到以下彈出視窗:
Unable to start debugging. Program path 'SourceFolder/test' is missing or invalid.
GDB failed with message: SourceFolder/test: File or directory not found.
...
除錯終端回傳:
The program 'SourceFolder/test' has exited with code 42 (0x0000002a).
"preLaunchTask": "g compile active file" 是否會導致此錯誤?
uj5u.com熱心網友回復:
preLaunchTask 名稱必須與.vscode 中默認構建label的tasks.json檔案的標簽匹配。檢查它們是否匹配。如果這還不夠,繼續你的源代碼檔案,按下Ctrl Shift B并查看預編譯器是否一切正常。您應該會看到如下內容:
> 執行任務:g build active file <
開始構建... /usr/bin/g -fdiagnostics-color=always -g "sourcefilename.extension" -o "sourcefilenameNoExtension" 構建成功完成。
終端將被任務重用,按任意鍵關閉它。
如果這碰巧沒問題,那么您應該準備好運行檔案“SourceFolder/test”。如果出現問題,您可以檢查您的tasks.json設定,或者簡單地將檔案名更改為test.extension并將其放入SourceFolder檔案夾中(如果您還沒有)。如果您的意思是 SourceFolder 是實際打開的檔案夾的默認值,那么您應該撰寫 ${workspaceFolder}。順便說一句,您可以在 VSCode 的本指南中找到此內容以及更多內容
https://code.visualstudio.com/docs/languages/cpp#_tutorials
在這里,您將找到在您的作業系統上使用 G 的鏈接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/381124.html
標籤:调试 视觉工作室代码 数据库 vscode 调试器 发射
上一篇:C 除錯-停止變數更改
