Skip to content

Commit 87f83ea

Browse files
committed
cmd/compile: include non-decomposed vars for -dwarflocationlists
When enhanced DWARF location list generation is enabled (via internal option -dwarflocationlists), variable entries were missing for "large" (non-decomposable) locals and formals. From the debugging perspective, this makes it appear that the variable doesn't exist, which is probably not what we want. This change insures that a formal/local DIE is created for these vars (with correct type, line, etc) but with a conservative ("no info") location. Change-Id: I10b2e9a51a60c7b4c748e987cdec5f2d8b2837d5 Reviewed-on: https://go-review.googlesource.com/72630 Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 0316d66 commit 87f83ea

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func debuginfo(fnsym *obj.LSym, curfn interface{}) []dwarf.Scope {
338338
var dwarfVars []*dwarf.Var
339339
var decls []*Node
340340
if Ctxt.Flag_locationlists && Ctxt.Flag_optimize {
341-
decls, dwarfVars = createComplexVars(fnsym, debugInfo)
341+
decls, dwarfVars = createComplexVars(fnsym, debugInfo, automDecls)
342342
} else {
343343
decls, dwarfVars = createSimpleVars(automDecls)
344344
}
@@ -416,7 +416,7 @@ type varPart struct {
416416
slot ssa.SlotID
417417
}
418418

419-
func createComplexVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug) ([]*Node, []*dwarf.Var) {
419+
func createComplexVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug, automDecls []*Node) ([]*Node, []*dwarf.Var) {
420420
for _, blockDebug := range debugInfo.Blocks {
421421
for _, locList := range blockDebug.Variables {
422422
for _, loc := range locList.Locations {
@@ -438,11 +438,13 @@ func createComplexVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug) ([]*Node, []*d
438438

439439
// Group SSA variables by the user variable they were decomposed from.
440440
varParts := map[*Node][]varPart{}
441+
ssaVars := make(map[*Node]bool)
441442
for slotID, slot := range debugInfo.VarSlots {
442443
for slot.SplitOf != nil {
443444
slot = slot.SplitOf
444445
}
445446
n := slot.N.(*Node)
447+
ssaVars[n] = true
446448
varParts[n] = append(varParts[n], varPart{varOffset(slot), ssa.SlotID(slotID)})
447449
}
448450

@@ -472,6 +474,39 @@ func createComplexVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug) ([]*Node, []*d
472474
vars = append(vars, dvar)
473475
}
474476
}
477+
478+
// The machinery above will create a dwarf.Var for only those
479+
// variables that are decomposed into SSA names. Fill in the list
480+
// with entries for the remaining variables (including things too
481+
// big to decompose). Since optimization is enabled, the recipe
482+
// below creates a conservative location. The idea here is that we
483+
// want to communicate to the user that "yes, there is a variable
484+
// named X in this function, but no, I don't have enough
485+
// information to reliably report its contents."
486+
for _, n := range automDecls {
487+
if _, found := ssaVars[n]; !found {
488+
continue
489+
}
490+
c := n.Sym.Name[0]
491+
if c == '~' || c == '.' {
492+
continue
493+
}
494+
typename := dwarf.InfoPrefix + typesymname(n.Type)
495+
decls = append(decls, n)
496+
abbrev := dwarf.DW_ABRV_AUTO_LOCLIST
497+
if n.Class() == PPARAM || n.Class() == PPARAMOUT {
498+
abbrev = dwarf.DW_ABRV_PARAM_LOCLIST
499+
}
500+
vars = append(vars, &dwarf.Var{
501+
Name: n.Sym.Name,
502+
IsReturnValue: n.Class() == PPARAMOUT,
503+
Abbrev: abbrev,
504+
StackOffset: int32(n.Xoffset),
505+
Type: Ctxt.Lookup(typename),
506+
DeclLine: n.Pos.Line(),
507+
})
508+
}
509+
475510
return decls, vars
476511
}
477512

0 commit comments

Comments
 (0)