問題
表題の通り、以下のエラーによりVSCodeでGolangのデバッグ実行に失敗するという問題に直面しました。
2022-02-12T08:26:42+09:00 error layer=debugger can't find build-id note on binary
panic: runtime error: slice bounds out of range [:2] with length 0
---(省略)
解決
go-delve/delveのissueによると
@latest
でインストールされるdelve@1.8.2
(2022/02/13時点)ではこの問題に対処されていないため
VSCodeの拡張機能などによるインストールではなく手動でdelveをインストールします。
# Install at tree head:
$ go install github.com/go-delve/delve/cmd/dlv@master
もし、以下のエラーによりインストールに失敗する場合は、
go: github.com/go-delve/delve/cmd/dlv@master (in github.com/go-delve/delve@v1.8.2-0.20220210175055-dee4437bd088):
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause
it to be interpreted differently than if it were the main module.
次のコマンドを実行してください。
$ git clone https://github.com/go-delve/delve
$ cd delve
$ go install github.com/go-delve/delve/cmd/dlv
delve@v1.8.2
のインストールが完了後、ブレークポイントを設定してデバッグ実行します。