Skip to content

cmd/compile: add string constants to DWARF #67744

Open
@Benoit12345

Description

@Benoit12345

Go version

go version go1.22.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/.cache/go-build'
GOENV='/home/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/user/1000/go-build3235747414=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I tried to view the value of different types of const values with dlv.
Code:

package main

import "fmt"

const myValueStr = "try"
const myValueInt = 12
const myValueFloat = 1.2

func main() {
fmt.Println(myValueStr, myValueInt, myValueFloat)
}

What did you see happen?

I obtain a different behavior depending of the type of the constant.

Debug:

dlv exec main
(dlv) print main.constValueInt
12
(dlv) print main.constValueStr
Command failed: could not find symbol value for main
(dlv) print main.constValueFloat
Command failed: could not find symbol value for main

Analyze:

objdump -W main | grep -i constV
<2547> DW_AT_name : main.constValueInt

By analyzing Go ompiler code, we can see into src/cmd/compile/internal/gc/obj.go:163 that's the func dumpGlobalConst exports only integer const "for now" (ie. comment line 172).

What did you expect to see?

I expect to see all const values.

Debug:

dlv exec main
(dlv) print main.constValueInt
12
(dlv) print main.constValueStr
"try"
(dlv) print main.constValueFloat
1.2

Analyze:

objdump -W main | grep -i constV
<2547> DW_AT_name : main.constValueInt
<2547> DW_AT_name : main.constValueStr
<2547> DW_AT_name : main.constValueFloat

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions