From 02caf915a5d1474b52095cb0c455f222cde58914 Mon Sep 17 00:00:00 2001 From: beejeebus Date: Mon, 10 Feb 2025 08:43:31 -0500 Subject: [PATCH] Don't remove DWARF info from Go binaries in dev (#100328) Only ask the linker to strip DWARF information if we're not in dev, to avoid seeing stuff like this when using delve: ~ $ dlv attach $(pgrep grafana) (dlv) l main.main Command failed: location "main.main" not found After this change: ~ $ dlv attach $(pgrep grafana) Type 'help' for list of commands. (dlv) l main.main Showing /home/justin/code/grafana/pkg/cmd/grafana/main.go:23 (PC: 0xac93533) 18: var commit = gcli.DefaultCommitValue 19: var enterpriseCommit = gcli.DefaultCommitValue 20: var buildBranch = "main" 21: var buildstamp string 22: 23: func main() { 24: app := MainApp() 25: 26: if err := app.Run(os.Args); err != nil { --- pkg/build/cmd.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/build/cmd.go b/pkg/build/cmd.go index 7b775ad0f44..9796a1428da 100644 --- a/pkg/build/cmd.go +++ b/pkg/build/cmd.go @@ -243,7 +243,16 @@ func ldflags(opts BuildOpts) (string, error) { buildBranch = v } var b bytes.Buffer - b.WriteString("-w") + if !opts.isDev { + // Only ask the linker to strip DWARF information if we're not in + // dev, to avoid seeing stuff like this when using delve: + // + // ~ $ dlv attach $(pgrep grafana) + // (dlv) l main.main + // Command failed: location "main.main" not found + // + b.WriteString("-w") + } b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version)) b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha)) if enterpriseCommitSha != "" {