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: DWARF Incorrect and missing location expressions #47605

Closed
mahdi-hm opened this issue Aug 9, 2021 · 3 comments
Closed

cmd/compile: DWARF Incorrect and missing location expressions #47605

mahdi-hm opened this issue Aug 9, 2021 · 3 comments

Comments

@mahdi-hm
Copy link

mahdi-hm commented Aug 9, 2021

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

$ go version
go version go1.16.7 linux/amd64

Does this issue reproduce with the latest release?

It was working on 1.14.9 but not after that

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mahdi/.cache/go-build"
GOENV="/home/mahdi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mahdi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mahdi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3567533659=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Using standards debugger (Delve for instance) I tried to read some variable inside a function below is the sample code

package main

import "fmt"

type Day int

const (
	MONDAY Day = 1 + iota
	TUESDAY
	WEDNESDAY
	THURSDAY
	FRIDAY
	SATURDAY
	SUNDAY
)

var i int = 100
var f float64 = 100.1
var s string = "Hello world!"
var a [5]int = [5]int{1, 2, 3, 4, 5}
var d Day = TUESDAY
var c complex64 = 1 + 1i

func printParams(i int, f float64, s string, a [5]int, b []int, p *int, d Day, c complex64) {
	fmt.Println("Entering printParams")
	fmt.Println(i)
	fmt.Println(f)
	fmt.Println(s)
	fmt.Println(d)
	fmt.Println(c)
	for _, ai := range a {
		fmt.Println(ai)
	}
	for i := 0; i < len(b); i++ {
		fmt.Println(b[i])
	}
	b = append(b, 11)
	b = append(b, 12)
	b[0] = 14
	for i := 0; i < len(b); i++ {
		fmt.Println(b[i])
	}
	fmt.Println(*p)
	fmt.Println("Exiting printParams")
}

func main() {
	printParams(i, f, s, a, a[1:4], &i, d, 1i)
}

Also I tried to read DWARF section using readelf

What did you expect to see?

I expect to get below result while stepping into printParams function line 13 and 20:

(dlv) args
i = 100
f = 100.1
s = "Hello world!"
a = [5]int [...]
b = []int len: 3, cap: 4, [...]
p = (*int)(0x553120)
d = TUESDAY (2)
c = (0 + 1i)

And in DWARF:

<1><794f2>: Abbrev Number: 3 (DW_TAG_subprogram)
    <794f3>   DW_AT_name        : main.printParams
    <79504>   DW_AT_low_pc      : 0x491d70
    <7950c>   DW_AT_high_pc     : 0x492450
    <79514>   DW_AT_frame_base  : 1 byte block: 9c 	(DW_OP_call_frame_cfa)
    <79516>   DW_AT_decl_file   : 0x2
    <7951a>   DW_AT_external    : 1
 <2><7951b>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7951c>   DW_AT_name        : i
    <7951e>   DW_AT_variable_parameter: 0
    <7951f>   DW_AT_decl_line   : 31
    <79520>   DW_AT_type        : <0x3b10e>
    <79524>   DW_AT_location    : 0x82ce9 (location list)
 <2><79528>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <79529>   DW_AT_name        : f
    <7952b>   DW_AT_variable_parameter: 0
    <7952c>   DW_AT_decl_line   : 31
    <7952d>   DW_AT_type        : <0x3d1a1>
    <79531>   DW_AT_location    : 0x82d1c (location list)
 <2><79535>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <79536>   DW_AT_name        : s
    <79538>   DW_AT_variable_parameter: 0
    <79539>   DW_AT_decl_line   : 31
    <7953a>   DW_AT_type        : <0x3b11e>
     <7953e>   DW_AT_location    : 0x82d50 (location list) 
<2><79542>: Abbrev Number: 15 (DW_TAG_formal_parameter)
    <79543>   DW_AT_name        : a
    <79545>   DW_AT_variable_parameter: 0
    <79546>   DW_AT_decl_line   : 31
    <79547>   DW_AT_type        : <0x49bba>
    <7954b>   DW_AT_location    : 2 byte block: 91 20 	(DW_OP_fbreg: 32)
 <2><7954e>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7954f>   DW_AT_name        : b
    <79551>   DW_AT_variable_parameter: 0
    <79552>   DW_AT_decl_line   : 31
    <79553>   DW_AT_type        : <0x4849f>
    <79557>   DW_AT_location    : 0x82d8a (location list)
 <2><7955b>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7955c>   DW_AT_name        : p
    <7955e>   DW_AT_variable_parameter: 0
    <7955f>   DW_AT_decl_line   : 31
    <79560>   DW_AT_type        : <0x416c0>
    <79564>   DW_AT_location    : 0x82dcb (location list)
 <2><79568>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <79569>   DW_AT_name        : d
    <7956b>   DW_AT_variable_parameter: 0
    <7956c>   DW_AT_decl_line   : 31
    <7956d>   DW_AT_type        : <0x49ba5>
    <79571>   DW_AT_location    : 0x82e00 (location list)
 <2><79575>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <79576>   DW_AT_name        : c
    <79578>   DW_AT_variable_parameter: 0
    <79579>   DW_AT_decl_line   : 31
    <7957a>   DW_AT_type        : <0x3e2bb>
    <7957e>   DW_AT_location    : 0x82e35 (location list) 

I got above result from 1.14.9 version

What did you see instead?

From the debugger I got this part instead:

(dlv) args
i = 100
f = 100.1
s = (unreadable empty OP stack) 
a = [5]int [...]
b = (unreadable could not find loclist entry at 0x8648e for address 0x497a9e) 
p = (*int)(0x535118)
d = TUESDAY (2)
c = (unreadable empty OP stack) 

And the DWARF section is like this:

<1><7d39d>: Abbrev Number: 3 (DW_TAG_subprogram)
    <7d39e>   DW_AT_name        : main.printParams
    <7d3af>   DW_AT_low_pc      : 0x497a00
    <7d3b7>   DW_AT_high_pc     : 0x4980f0
    <7d3bf>   DW_AT_frame_base  : 1 byte block: 9c 	(DW_OP_call_frame_cfa)
    <7d3c1>   DW_AT_decl_file   : 0x2
    <7d3c5>   DW_AT_external    : 1
 <2><7d3c6>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7d3c7>   DW_AT_name        : i
    <7d3c9>   DW_AT_variable_parameter: 0
    <7d3ca>   DW_AT_decl_line   : 31
    <7d3cb>   DW_AT_type        : <0x49bde>
    <7d3cf>   DW_AT_location    : 0x8645a (location list)
 <2><7d3d3>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7d3d4>   DW_AT_name        : f
    <7d3d6>   DW_AT_variable_parameter: 0
    <7d3d7>   DW_AT_decl_line   : 31
    <7d3d8>   DW_AT_type        : <0x4b5f2>
    <7d3dc>   DW_AT_location    : 0x8648d (location list)
 <2><7d3e0>: Abbrev Number: 15 (DW_TAG_formal_parameter)
    <7d3e1>   DW_AT_name        : s
    <7d3e3>   DW_AT_variable_parameter: 0
    <7d3e4>   DW_AT_decl_line   : 31
    <7d3e5>   DW_AT_type        : <0x49bee>
    <7d3e9>   DW_AT_location    : 0 byte block: 	() 
<2><7d3ea>: Abbrev Number: 15 (DW_TAG_formal_parameter)
    <7d3eb>   DW_AT_name        : a
    <7d3ed>   DW_AT_variable_parameter: 0
    <7d3ee>   DW_AT_decl_line   : 31
    <7d3ef>   DW_AT_type        : <0x5b0e8>
    <7d3f3>   DW_AT_location    : 2 byte block: 91 20 	(DW_OP_fbreg: 32)
 <2><7d3f6>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7d3f7>   DW_AT_name        : b
    <7d3f9>   DW_AT_variable_parameter: 0
    <7d3fa>   DW_AT_decl_line   : 31
    <7d3fb>   DW_AT_type        : <0x5917d>
    <7d3ff>   DW_AT_location    : 0x864c1 (location list)
 <2><7d403>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7d404>   DW_AT_name        : p
    <7d406>   DW_AT_variable_parameter: 0
    <7d407>   DW_AT_decl_line   : 31
    <7d408>   DW_AT_type        : <0x52251>
    <7d40c>   DW_AT_location    : 0x865cf (location list)
 <2><7d410>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <7d411>   DW_AT_name        : d
    <7d413>   DW_AT_variable_parameter: 0
    <7d414>   DW_AT_decl_line   : 31
    <7d415>   DW_AT_type        : <0x5b0ad>
    <7d419>   DW_AT_location    : 0x86604 (location list)
 <2><7d41d>: Abbrev Number: 15 (DW_TAG_formal_parameter)
    <7d41e>   DW_AT_name        : c
    <7d420>   DW_AT_variable_parameter: 0
    <7d421>   DW_AT_decl_line   : 31
    <7d422>   DW_AT_type        : <0x4d604>
    <7d426>   DW_AT_location    : 0 byte block: 	() 

I created another issue (#45680) before not sure whether that one cover this one or no

@cherrymui
Copy link
Member

@mahdi-hm Could you try Go 1.17RC2 (or tip) and see if it makes any difference? Thanks.

cc @thanm

@mahdi-hm
Copy link
Author

mahdi-hm commented Aug 9, 2021

@cherrymui I can confirm that Go 1.17 RC2 is fine and I can not reproduce the same error using that

@ianlancetaylor
Copy link
Contributor

Thanks for trying the release candidate. Sounds like this will be fixed in 1.17, and it's not the sort of thing we normally backport to earlier releases, so closing.

@golang golang locked and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants