ctxt.Imports = append(ctxt.Imports, pkg)
}
-const FileSymPrefix = "gofile.."
-
func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f *LSym, l int32) {
pos := ctxt.PosTable.Pos(xpos)
- filename := pos.AbsFilename()
- if !pos.IsKnown() || filename == "" {
- return Linklookup(ctxt, FileSymPrefix+"??", 0), 0
+ if !pos.IsKnown() {
+ pos = src.Pos{}
}
// TODO(gri) Should this use relative or absolute line number?
- return Linklookup(ctxt, FileSymPrefix+filename, 0), int32(pos.RelLine())
+ return Linklookup(ctxt, pos.SymFilename(), 0), int32(pos.RelLine())
}
func fieldtrack(ctxt *Link, cursym *LSym) {
for _, test := range tests {
f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos))
got := fmt.Sprintf("%s:%d", f.Name, l)
- if got != FileSymPrefix+test.want {
+ if got != src.FileSymPrefix+test.want {
t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
}
}
// AbsFilename() returns the absolute filename recorded with the position's base.
func (p Pos) AbsFilename() string { return p.base.AbsFilename() }
+// SymFilename() returns the absolute filename recorded with the position's base,
+// prefixed by FileSymPrefix to make it appropriate for use as a linker symbol.
+func (p Pos) SymFilename() string { return p.base.SymFilename() }
+
func (p Pos) String() string {
if !p.IsKnown() {
return "<unknown line number>"
pos Pos
filename string // file name used to open source file, for error messages
absFilename string // absolute file name, for PC-Line tables
+ symFilename string // cached symbol file name, to avoid repeated string concatenation
line uint // relative line number at pos
inl int // inlining index (see cmd/internal/obj/inl.go)
}
// absolute) filenames.
func NewFileBase(filename, absFilename string) *PosBase {
if filename != "" {
- base := &PosBase{filename: filename, absFilename: absFilename, inl: -1}
+ base := &PosBase{
+ filename: filename,
+ absFilename: absFilename,
+ symFilename: FileSymPrefix + absFilename,
+ inl: -1,
+ }
base.pos = MakePos(base, 0, 0)
return base
}
// //line filename:line
// at position pos.
func NewLinePragmaBase(pos Pos, filename string, line uint) *PosBase {
- return &PosBase{pos, filename, filename, line - 1, -1}
+ return &PosBase{pos, filename, filename, FileSymPrefix + filename, line - 1, -1}
}
// NewInliningBase returns a copy of the old PosBase with the given inlining
return ""
}
+const FileSymPrefix = "gofile.."
+
+// SymFilename returns the absolute filename recorded with the base,
+// prefixed by FileSymPrefix to make it appropriate for use as a linker symbol.
+// If b is nil, SymFilename returns FileSymPrefix + "??".
+func (b *PosBase) SymFilename() string {
+ if b != nil {
+ return b.symFilename
+ }
+ return FileSymPrefix + "??"
+}
+
// Line returns the line number recorded with the base.
// If b == nil, the result is 0.
func (b *PosBase) Line() uint {