continue
}
newStmt := p.Pos.IsStmt() != src.PosNotStmt
- newName, newLine := linkgetlineFromPos(ctxt, p.Pos)
+ newName, newLine := ctxt.getFileSymbolAndLine(p.Pos)
// Output debug info.
wrote := false
func (ctxt *Link) fileSymbol(fn *LSym) *LSym {
p := fn.Func().Text
if p != nil {
- f, _ := linkgetlineFromPos(ctxt, p.Pos)
+ f, _ := ctxt.getFileSymbolAndLine(p.Pos)
fsym := ctxt.Lookup(f)
return fsym
}
ctxt.Imports = append(ctxt.Imports, goobj.ImportedPkg{Pkg: pkg, Fingerprint: fingerprint})
}
-func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f string, l int32) {
- pos := ctxt.PosTable.Pos(xpos)
+// getFileSymbolAndLine returns the relative file symbol and relative line
+// number for a position (i.e., as adjusted by a //line directive). This is the
+// file/line visible in the final binary (pcfile, pcln, etc).
+func (ctxt *Link) getFileSymbolAndLine(xpos src.XPos) (f string, l int32) {
+ pos := ctxt.InnermostPos(xpos)
if !pos.IsKnown() {
pos = src.Pos{}
}
- // TODO(gri) Should this use relative or absolute line number?
return pos.SymFilename(), int32(pos.RelLine())
}
-// getFileIndexAndLine returns the file index (local to the CU), and the line number for a position.
-func getFileIndexAndLine(ctxt *Link, xpos src.XPos) (int, int32) {
- f, l := linkgetlineFromPos(ctxt, xpos)
+// getFileIndexAndLine returns the relative file index (local to the CU), and
+// the relative line number for a position (i.e., as adjusted by a //line
+// directive). This is the file/line visible in the final binary (pcfile, pcln,
+// etc).
+func (ctxt *Link) getFileIndexAndLine(xpos src.XPos) (int, int32) {
+ f, l := ctxt.getFileSymbolAndLine(xpos)
return ctxt.PosTable.FileIndex(f), l
}
"testing"
)
-func TestLinkgetlineFromPos(t *testing.T) {
+func TestGetFileSymbolAndLine(t *testing.T) {
ctxt := new(Link)
ctxt.hash = make(map[string]*LSym)
ctxt.statichash = make(map[string]*LSym)
}
for _, test := range tests {
- f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos))
+ f, l := ctxt.getFileSymbolAndLine(ctxt.PosTable.XPos(test.pos))
got := fmt.Sprintf("%s:%d", f, l)
if got != src.FileSymPrefix+test.want {
- t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
+ t.Errorf("ctxt.getFileSymbolAndLine(%v) = %q, want %q", test.pos, got, test.want)
}
}
}
sort.Slice(o.File, func(i, j int) bool { return o.File[i] < o.File[j] })
o.InlTree = make([]goobj.InlTreeNode, len(pc.InlTree.nodes))
for i, inl := range pc.InlTree.nodes {
- f, l := getFileIndexAndLine(ctxt, inl.Pos)
+ f, l := ctxt.getFileIndexAndLine(inl.Pos)
o.InlTree[i] = goobj.InlTreeNode{
Parent: int32(inl.Parent),
File: goobj.CUFileIndex(f),
if p.As == ATEXT || p.As == ANOP || p.Pos.Line() == 0 || phase == 1 {
return oldval
}
- f, l := getFileIndexAndLine(ctxt, p.Pos)
+ f, l := ctxt.getFileIndexAndLine(p.Pos)
if arg == nil {
return l
}
ctxt.Diag("symbol %s listed multiple times", s.Name)
}
- _, startLine := linkgetlineFromPos(ctxt, start)
+ // startLine should be the same line number that would be displayed via
+ // pcln, etc for the declaration (i.e., relative line number, as
+ // adjusted by //line).
+ _, startLine := ctxt.getFileSymbolAndLine(start)
// TODO(mdempsky): Remove once cmd/asm stops writing "" symbols.
name := strings.Replace(s.Name, "\"\"", ctxt.Pkgpath, -1)
if call.Func != nil {
fn(fsym, call.Func)
}
- f, _ := linkgetlineFromPos(ctxt, call.Pos)
+ f, _ := ctxt.getFileSymbolAndLine(call.Pos)
if filesym := ctxt.Lookup(f); filesym != nil {
fn(fsym, filesym)
}