]> Cypherpunks repositories - gostls13.git/commitdiff
compiler: honor //line directives in DWARF variable file/line attrs
authorThan McIntosh <thanm@google.com>
Tue, 6 Feb 2018 14:36:13 +0000 (09:36 -0500)
committerThan McIntosh <thanm@google.com>
Thu, 15 Feb 2018 20:36:15 +0000 (20:36 +0000)
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>
src/cmd/compile/internal/gc/pgen.go
src/cmd/link/internal/ld/dwarf_test.go

index 315321b06de3307d94d2091fa357fe6092e9281d..dea4cf858121c85901420067d73511c7d2fbb29e 100644 (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,
index 391601acaf23ff0c7b3bd0e7ce3aec6565ef44c8..54e692865a2bac1e194eb523906f26e5a6fe4f6a 100644 (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")
-       }
-
-       const prog = `
-package main
+       prog := fmt.Sprintf("package main\n\nfunc main() {\n%s\nvar i int\ni = i\n}\n", directive)
 
-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,14 +362,35 @@ 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