Skip to content

Commit 3ba818c

Browse files
committed
cmd/compile: distinguish args and return values in DWARF
Set DW_AT_variable_parameter on DW_TAG_formal_parameters that are actually return values. variable_parameter is supposed to indicate inout parameters, but Go doesn't really have those, and DWARF doesn't have explicit support for multiple return values. This seems to be the best compromise, especially since the implementation of the two is very similar -- both are stack slots. Fixes #21100 Change-Id: Icebabc92b7b397e0aa00a7237478cce84ad1a670 Reviewed-on: https://go-review.googlesource.com/71670 Run-TryBot: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 77c041c commit 3ba818c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/cmd/compile/internal/gc/pgen.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ func createSimpleVars(automDecls []*Node) ([]*Node, []*dwarf.Var) {
400400
typename := dwarf.InfoPrefix + typesymname(n.Type)
401401
decls = append(decls, n)
402402
vars = append(vars, &dwarf.Var{
403-
Name: n.Sym.Name,
404-
Abbrev: abbrev,
405-
StackOffset: int32(offs),
406-
Type: Ctxt.Lookup(typename),
407-
DeclLine: n.Pos.Line(),
403+
Name: n.Sym.Name,
404+
IsReturnValue: n.Class() == PPARAMOUT,
405+
Abbrev: abbrev,
406+
StackOffset: int32(offs),
407+
Type: Ctxt.Lookup(typename),
408+
DeclLine: n.Pos.Line(),
408409
})
409410
}
410411
return decls, vars

src/cmd/internal/dwarf/dwarf.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ type Piece struct {
4949

5050
// A Var represents a local variable or a function parameter.
5151
type Var struct {
52-
Name string
53-
Abbrev int // Either DW_ABRV_AUTO or DW_ABRV_PARAM
54-
StackOffset int32
55-
LocationList []Location
56-
Scope int32
57-
Type Sym
58-
DeclLine uint
52+
Name string
53+
Abbrev int // Either DW_ABRV_AUTO[_LOCLIST] or DW_ABRV_PARAM[_LOCLIST]
54+
IsReturnValue bool
55+
StackOffset int32
56+
LocationList []Location
57+
Scope int32
58+
Type Sym
59+
DeclLine uint
5960
}
6061

6162
// A Scope represents a lexical scope. All variables declared within a
@@ -355,6 +356,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
355356
DW_CHILDREN_no,
356357
[]dwAttrForm{
357358
{DW_AT_name, DW_FORM_string},
359+
{DW_AT_variable_parameter, DW_FORM_flag},
358360
{DW_AT_decl_line, DW_FORM_udata},
359361
{DW_AT_location, DW_FORM_block1},
360362
{DW_AT_type, DW_FORM_ref_addr},
@@ -367,6 +369,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
367369
DW_CHILDREN_no,
368370
[]dwAttrForm{
369371
{DW_AT_name, DW_FORM_string},
372+
{DW_AT_variable_parameter, DW_FORM_flag},
370373
{DW_AT_decl_line, DW_FORM_udata},
371374
{DW_AT_location, DW_FORM_sec_offset},
372375
{DW_AT_type, DW_FORM_ref_addr},
@@ -833,8 +836,6 @@ func putscope(ctxt Context, info, loc, ranges, startPC Sym, curscope int32, scop
833836
}
834837

835838
func putvar(ctxt Context, info, loc Sym, v *Var, startPC Sym, encbuf []byte) {
836-
n := v.Name
837-
838839
// If the variable was entirely optimized out, don't emit a location list;
839840
// convert to an inline abbreviation and emit an empty location.
840841
missing := false
@@ -848,7 +849,14 @@ func putvar(ctxt Context, info, loc Sym, v *Var, startPC Sym, encbuf []byte) {
848849
}
849850

850851
Uleb128put(ctxt, info, int64(v.Abbrev))
851-
putattr(ctxt, info, v.Abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(n)), n)
852+
putattr(ctxt, info, v.Abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(v.Name)), v.Name)
853+
if v.Abbrev == DW_ABRV_PARAM || v.Abbrev == DW_ABRV_PARAM_LOCLIST {
854+
var isReturn int64
855+
if v.IsReturnValue {
856+
isReturn = 1
857+
}
858+
putattr(ctxt, info, v.Abbrev, DW_FORM_flag, DW_CLS_FLAG, isReturn, nil)
859+
}
852860
putattr(ctxt, info, v.Abbrev, DW_FORM_udata, DW_CLS_CONSTANT, int64(v.DeclLine), nil)
853861
if v.Abbrev == DW_ABRV_AUTO_LOCLIST || v.Abbrev == DW_ABRV_PARAM_LOCLIST {
854862
putattr(ctxt, info, v.Abbrev, DW_FORM_sec_offset, DW_CLS_PTR, int64(loc.Len()), loc)

0 commit comments

Comments
 (0)