Skip to content

cmd/compile: bad DWARF location for variable #58813

Open
@aarzilli

Description

@aarzilli
$ go version
go version go1.20.1 linux/amd64

Given the following code:

package main

import "fmt"

func cul(row int64) bool {
	id := int((row >> 32) & 0x3fffffff)
	
	return id != 0
}

func main() {
	fmt.Println(cul(0))
}

Compiled with `-gcflags='all=-N -l', main.cul function compiles into:

  test.go:5		0x49c8c0		4883ec18		SUBQ $0x18, SP		
  test.go:5		0x49c8c4		48896c2410		MOVQ BP, 0x10(SP)	
  test.go:5		0x49c8c9		488d6c2410		LEAQ 0x10(SP), BP	
  test.go:5		0x49c8ce		4889442420		MOVQ AX, 0x20(SP)	
  test.go:5		0x49c8d3		c644240700		MOVB $0x0, 0x7(SP)	
  test.go:6		0x49c8d8		488b4c2420		MOVQ 0x20(SP), CX	
  test.go:6		0x49c8dd		48c1f920		SARQ $0x20, CX		
  test.go:6		0x49c8e1		81e1ffffff3f		ANDL $0x3fffffff, CX	
  test.go:8		0x49c8e7		4885c9			TESTQ CX, CX		
  test.go:8		0x49c8ea		0f95c0			SETNE AL		
  test.go:6		0x49c8ed		48894c2408		MOVQ CX, 0x8(SP)	
  test.go:8		0x49c8f2		88442407		MOVB AL, 0x7(SP)	
  test.go:8		0x49c8f6		488b6c2410		MOVQ 0x10(SP), BP	
  test.go:8		0x49c8fb		4883c418		ADDQ $0x18, SP		
  test.go:8		0x49c8ff		90			NOPL			
  test.go:8		0x49c900		c3			RET			

and the variable id has DW_OP_fbreg -0x18 has its location, however at instruction 0x49c8ea, which is the instruction picked for a breakpoint on line :8, the variable is stored on register rcx, not in its stack location (where it gets moved only later at instruction 0x49c8ed).
Originally reported as go-delve/delve#3290.

cc @dr2chase.

Metadata

Metadata

Assignees

Labels

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

Relationships

None yet

Development

No branches or pull requests

Issue actions