Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: Adding -gcflags "all=-N -l" does not add debugging information. #64082

Closed
aimuz opened this issue Nov 12, 2023 · 5 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@aimuz
Copy link
Contributor

aimuz commented Nov 12, 2023

What version of Go are you using (go version)?

$ go version
go version devel go1.22-f7b4f02ba0 Fri Aug 4 15:41:19 2023 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/aimuz/Library/Caches/go-build'
GOENV='/Users/aimuz/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=' -mod=mod'
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/aimuz/go/pkg/mod'
GONOPROXY='gitee.com/wisecloud,gitee.com/wisecloud-archive'
GONOSUMDB='gitee.com/wisecloud,gitee.com/wisecloud-archive'
GOOS='darwin'
GOPATH='/Users/aimuz/go'
GOPRIVATE='gitee.com/wisecloud,gitee.com/wisecloud-archive'
GOPROXY='https://goproxy.dev,https://goproxy.io,https://goproxy.cn,direct'
GOROOT='/Users/aimuz/workspace/go'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/aimuz/workspace/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='devel go1.22-f7b4f02ba0 Fri Aug 4 15:41:19 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/aimuz/workspace/go/src/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/pt/qtn3qrvs6n9b_944ggd01nj00000gn/T/go-build4175838830=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Master branch compilations cannot be debugged using dlv.

Programs built with the -gcflags "all=-N -l" parameter cannot be debugged.

After investigation, the problem was caused by changes to https://go-review.googlesource.com/c/go/+/461697

When I change back to the historical version of the code, I can debug it properly

func DefaultPIE(goos, goarch string, isRace bool) bool {
	switch goos {
	case "android", "ios":
		return true
	case "windows":
		if isRace {
			// PIE is not supported with -race on windows;
			// see https://go.dev/cl/416174.
			return false
		}
		return true
	case "darwin":
		return goarch == "arm64"
	}
	return false
}
ld -v
@(#)PROGRAM:ld  PROJECT:dyld-1015.7
BUILD 16:59:22 Oct  1 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
Library search paths:
Framework search paths:

What did you expect to see?

Be able to use dlv to debug programs properly

What did you see instead?

cannot be debugged

@aimuz aimuz changed the title internal/platform: Adding -gcflags all=-N -l does not add debugging information. internal/platform: Adding -gcflags "all=-N -l" does not add debugging information. Nov 12, 2023
@aimuz
Copy link
Contributor Author

aimuz commented Nov 12, 2023

When I add the -ldflags "-buildmode=exe" parameter, he works fine!

@aimuz aimuz changed the title internal/platform: Adding -gcflags "all=-N -l" does not add debugging information. compile: Adding -gcflags "all=-N -l" does not add debugging information. Nov 12, 2023
@aimuz aimuz changed the title compile: Adding -gcflags "all=-N -l" does not add debugging information. cmd/compile: Adding -gcflags "all=-N -l" does not add debugging information. Nov 12, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 12, 2023
@aarzilli
Copy link
Contributor

Debug info is always included in the executable, -N -l just disables optimizations. Your problem is different: probably an just old version of delve, but it's hard to tell for sure because you haven't really described what's happening.

@aimuz
Copy link
Contributor Author

aimuz commented Nov 12, 2023

You are right, when I use the latest version of dlv he works fine, maybe older versions of dlv don't support PIE format executables?

@aarzilli
Copy link
Contributor

It was probably this go-delve/delve#3467

@aimuz
Copy link
Contributor Author

aimuz commented Nov 12, 2023

thank you

@aimuz aimuz closed this as completed Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants