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,
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,
// 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,
}
}
-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)
}
// 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