1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:20:04 -07:00

compiler: honor //line directives in DWARF variable file/line attrs

During DWARF debug generation, the DW_AT_decl_line / DW_AT_decl_file
attributes for variable DIEs were being computed without taking into
account the possibility of "//line" directives. Fix things up to use
the correct src.Pos methods to pick up this info.

Fixes #23704.

Change-Id: I88c21a0e0a9602392be229252d856a6d665868e2
Reviewed-on: https://go-review.googlesource.com/92255
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Than McIntosh 2018-02-06 09:36:13 -05:00
parent 1ae22d8cfe
commit b3cb740be5
2 changed files with 33 additions and 23 deletions

View File

@ -424,8 +424,8 @@ func createSimpleVars(automDecls []*Node) ([]*Node, []*dwarf.Var, map[*Node]bool
Abbrev: abbrev,
StackOffset: int32(offs),
Type: Ctxt.Lookup(typename),
DeclFile: declpos.Base().SymFilename(),
DeclLine: declpos.Line(),
DeclFile: declpos.RelFilename(),
DeclLine: declpos.RelLine(),
DeclCol: declpos.Col(),
InlIndex: int32(inlIndex),
ChildIndex: -1,
@ -519,8 +519,8 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
Abbrev: abbrev,
StackOffset: int32(n.Xoffset),
Type: Ctxt.Lookup(typename),
DeclFile: declpos.Base().SymFilename(),
DeclLine: declpos.Line(),
DeclFile: declpos.RelFilename(),
DeclLine: declpos.RelLine(),
DeclCol: declpos.Col(),
InlIndex: int32(inlIndex),
ChildIndex: -1,
@ -651,8 +651,8 @@ func createComplexVar(fn *Func, varID ssa.VarID) *dwarf.Var {
// This won't work well if the first slot hasn't been assigned a stack
// location, but it's not obvious how to do better.
StackOffset: stackOffset(*debug.Slots[debug.VarSlots[varID][0]]),
DeclFile: declpos.Base().SymFilename(),
DeclLine: declpos.Line(),
DeclFile: declpos.RelFilename(),
DeclLine: declpos.RelLine(),
DeclCol: declpos.Col(),
InlIndex: int32(inlIndex),
ChildIndex: -1,

View File

@ -308,22 +308,11 @@ func main() {
}
}
func TestVarDeclCoordsAndSubrogramDeclFile(t *testing.T) {
testenv.MustHaveGoBuild(t)
func varDeclCoordsAndSubrogramDeclFile(t *testing.T, testpoint string, expectFile int, expectLine int, directive string) {
if runtime.GOOS == "plan9" {
t.Skip("skipping on plan9; no DWARF symbol table in executables")
}
prog := fmt.Sprintf("package main\n\nfunc main() {\n%s\nvar i int\ni = i\n}\n", directive)
const prog = `
package main
func main() {
var i int
i = i
}
`
dir, err := ioutil.TempDir("", "TestVarDeclCoords")
dir, err := ioutil.TempDir("", testpoint)
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
@ -373,16 +362,37 @@ func main() {
// Verify line/file attributes.
line := iEntry.Val(dwarf.AttrDeclLine)
if line == nil || line.(int64) != 5 {
t.Errorf("DW_AT_decl_line for i is %v, want 5", line)
if line == nil || line.(int64) != int64(expectLine) {
t.Errorf("DW_AT_decl_line for i is %v, want %d", line, expectLine)
}
file := maindie.Val(dwarf.AttrDeclFile)
if file == nil || file.(int64) != 1 {
t.Errorf("DW_AT_decl_file for main is %v, want 1", file)
t.Errorf("DW_AT_decl_file for main is %v, want %d", file, expectFile)
}
}
func TestVarDeclCoordsAndSubrogramDeclFile(t *testing.T) {
testenv.MustHaveGoBuild(t)
if runtime.GOOS == "plan9" {
t.Skip("skipping on plan9; no DWARF symbol table in executables")
}
varDeclCoordsAndSubrogramDeclFile(t, "TestVarDeclCoords", 1, 5, "")
}
func TestVarDeclCoordsWithLineDirective(t *testing.T) {
testenv.MustHaveGoBuild(t)
if runtime.GOOS == "plan9" {
t.Skip("skipping on plan9; no DWARF symbol table in executables")
}
varDeclCoordsAndSubrogramDeclFile(t, "TestVarDeclCoordsWithLineDirective",
2, 200, "//line /foobar.go:200")
}
// Helper class for supporting queries on DIEs within a DWARF .debug_info
// section. Invoke the populate() method below passing in a dwarf.Reader,
// which will read in all DIEs and keep track of parent/child