我用VSCode寫了一個程式,專案路徑在D:\myapp. 而我“ F5”來除錯。
通常,我會__debug_bin在我的專案檔案夾中得到一個檔案名“ ”。
上周,我更新了 VSC 并重新安裝了所有工具(dlv或其他東西)。
我得到了一個新的除錯檔案“ __debug_bin1167246115.exe”。
但是我的專案檔案夾中沒有輸出檔案,絕對路徑是“ C:\Users\xxx\AppData\Local\Temp\__debug_bin1167246115.exe”。
問題是:
我需要除錯檔案輸出并在我的專案根檔案夾中運行;我怎樣才能做到這一點?
- VS 代碼版本:1.62.3(用戶設定)
- Golang 版本:1.17.3
- 啟動.json :
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/",
"cwd": "${workspaceFolder}/",
}
]
}
uj5u.com熱心網友回復:
上周(2021 年 11 月結束),我更新了 VSC 并重新安裝了所有工具(
dlv或其他東西)。
我得到了一個新的除錯檔案“__debug_bin1167246115.exe”。

我們稱這個中介為 Debug Adapter(簡稱 DA),DA 和 VS Code 之間使用的抽象協議是 Debug Adapter Protocol(簡稱 DAP)。
由于除錯配接器協議獨立于 VS Code,它有自己的網站,您可以在其中找到介紹和概述、詳細規范以及一些已知實作和支持工具的串列。
這篇博文解釋了 DAP 的歷史和背后的動機。
作為這種新 DAP 支持的一部分,您提交了 fa10cec,它首先嘗試創建一個臨時檔案,然后再回到您所知道的:
// Default output file pathname for the compiled binary in debug or test modes
// when temporary debug binary creation fails.
// This is relative to the current working directory of the server.
const defaultDebugBinary string = "./__debug_bin"
func (s *Session) tempDebugBinary() string {
binaryPattern := "__debug_bin"
if runtime.GOOS == "windows" {
binaryPattern = "__debug_bin*.exe"
}
f, err := ioutil.TempFile("", binaryPattern)
if err != nil {
s.config.log.Errorf("failed to create a temporary binary (%v), falling back to %q", err, defaultDebugBinary)
return cleanExeName(defaultDebugBinary)
}
...
}
This is [called by][6]:
```go
// Prepare the debug executable filename, building it if necessary
debugbinary := args.Program
if args.Mode == "debug" || args.Mode == "test" {
if args.Output == "" {
args.Output = s.tempDebugBinary()
} else {
args.Output = cleanExeName(args.Output)
}
args.Output, err = filepath.Abs(args.Output)
因此,請嘗試output在launch.json 屬性中或dlvFlags使用output鍵值設定標志。
將其設定為./__debug_bin。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/371085.html
