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: zero sized variables no longer have DIEs #54615

Closed
aarzilli opened this issue Aug 23, 2022 · 4 comments
Closed

cmd/compile: zero sized variables no longer have DIEs #54615

aarzilli opened this issue Aug 23, 2022 · 4 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Debugging FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aarzilli
Copy link
Contributor

aarzilli commented Aug 23, 2022

Given:

package main

import (
	"fmt"
	"runtime"
)

func main() {
	a0 := [0]int{}
	zsvar := struct{}{}
	runtime.Breakpoint()
	fmt.Printf("%v %v\n", a0, zsvar)
}

With go1.19 the DIE subtree for main.main was:

 <1><937>: Abbrev Number: 3 (DW_TAG_subprogram)
    <938>   DW_AT_name        : main.main
    <942>   DW_AT_low_pc      : 0x482520
    <94a>   DW_AT_high_pc     : 0x4825d9
    <952>   DW_AT_frame_base  : 1 byte block: 9c 	(DW_OP_call_frame_cfa)
    <954>   DW_AT_decl_file   : 0x2
    <958>   DW_AT_external    : 1
 <2><959>: Abbrev Number: 12 (DW_TAG_variable)
    <95a>   DW_AT_name        : a0
    <95d>   DW_AT_decl_line   : 9
    <95e>   DW_AT_type        : <0x6f384>
    <962>   DW_AT_location    : 3 byte block: 91 a8 7f 	(DW_OP_fbreg: -88)
 <2><966>: Abbrev Number: 12 (DW_TAG_variable)
    <967>   DW_AT_name        : zsvar
    <96d>   DW_AT_decl_line   : 10
    <96e>   DW_AT_type        : <0x6987c>
    <972>   DW_AT_location    : 3 byte block: 91 a8 7f 	(DW_OP_fbreg: -88)

Starting with a74e5f5 (reviewed as: https://go-review.googlesource.com/c/go/+/419320) it is:

 <1><5496>: Abbrev Number: 3 (DW_TAG_subprogram)
    <5497>   DW_AT_name        : main.main
    <54a1>   DW_AT_low_pc      : 0x481f80
    <54a9>   DW_AT_high_pc     : 0x482039
    <54b1>   DW_AT_frame_base  : 1 byte block: 9c       (DW_OP_call_frame_cfa)
    <54b3>   DW_AT_decl_file   : 0x2
    <54b7>   DW_AT_external    : 1
 <2><54b8>: Abbrev Number: 0

without the local variables (both of which have a size 0).

If the desire is to have zero-size variables not have addresses, even in non-optimized builds, then we could emit a location expression containing a single DW_OP_lit0 (0x30) followed by DW_OP_stack_value (0x9f) (or a different way to encode a constant value for a variable).

cc @randall77 @dr2chase based on bisect results

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 23, 2022
@aarzilli
Copy link
Contributor Author

We could also decide that zero sized variables are always optimized away and don't have DIEs, that would also be fine afaiac. Delve's test for zero sized variables was added by @polinasok, I don't know if she has stronger opinions in this regards.

@polinasok
Copy link

I don't have a strong opinion. Sg.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 24, 2022
@thanm
Copy link
Contributor

thanm commented Aug 25, 2022

Omitting them from DWARF entirely doesn't seem very consistent with the way we handle locals elsewhere. For example in this program

func main() {
	var willbedead int
	if false {
		println(willbedead)
	}
	fmt.Println("Hello, 世界")
}

https://go.dev/play/p/PbUYSz5Ww4Z

We at least indicate to the user that yes, there was a variable once, but it's not there any more, e.g.

(dlv) locals
willbedead = (unreadable empty OP stack)
(gdb) info locals
willbedead = <optimized out>

@seankhliao seankhliao added this to the Unplanned milestone Aug 27, 2022
@mknyszek mknyszek modified the milestones: Unplanned, Backlog Aug 31, 2022
@gopherbot
Copy link

Change https://go.dev/cl/433479 mentions this issue: cmd/compile: emit DIEs for zero sized variables

romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
Fixes the compiler to emit DIEs for zero sized variables.

Fixes golang#54615

Change-Id: I1e0c86a97f1abcc7edae516b6a7fe35bcb65ed0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/433479
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
@golang golang locked and limited conversation to collaborators Oct 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Debugging FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

8 participants