// Progs accumulates Progs for a function and converts them into machine code.
type Progs struct {
- Text *obj.Prog // ATEXT Prog for this function
- next *obj.Prog // next Prog
- pc int64 // virtual PC; count of Progs
- pos src.XPos // position to use for new Progs
+ Text *obj.Prog // ATEXT Prog for this function
+ next *obj.Prog // next Prog
+ pc int64 // virtual PC; count of Progs
+ pos src.XPos // position to use for new Progs
+ curfn *Node // fn these Progs are for
}
// newProgs returns a new Progs for fn.
func newProgs(fn *Node) *Progs {
pp := new(Progs)
+ pp.curfn = fn
// prime the pump
pp.next = Ctxt.NewProg()
// Flush converts from pp to machine code.
func (pp *Progs) Flush() {
- plist := &obj.Plist{Firstpc: pp.Text}
+ plist := &obj.Plist{Firstpc: pp.Text, Curfn: pp.curfn}
obj.Flushplist(Ctxt, plist)
// Clear pp to enable GC and avoid abuse.
*pp = Progs{}
pp.Flush()
}
-func debuginfo(fnsym *obj.LSym) []*dwarf.Var {
- if expect := Linksym(Curfn.Func.Nname.Sym); fnsym != expect {
+func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
+ fn := curfn.(*Node)
+ if expect := Linksym(fn.Func.Nname.Sym); fnsym != expect {
Fatalf("unexpected fnsym: %v != %v", fnsym, expect)
}
var vars []*dwarf.Var
- for _, n := range Curfn.Func.Dcl {
+ for _, n := range fn.Func.Dcl {
if n.Op != ONAME { // might be OTYPE or OLITERAL
continue
}
Armsize int32
Pc int64
DiagFunc func(string, ...interface{})
- DebugInfo func(fn *LSym) []*dwarf.Var
+ DebugInfo func(fn *LSym, curfn interface{}) []*dwarf.Var // if non-nil, curfn is a *gc.Node
Cursym *LSym
Version int
Errors int
// makeFuncDebugEntry makes a DWARF Debugging Information Entry
// for TEXT symbol s.
-func makeFuncDebugEntry(ctxt *Link, s *LSym) {
+func makeFuncDebugEntry(ctxt *Link, curfn interface{}, s *LSym) {
dsym := Linklookup(ctxt, dwarf.InfoPrefix+s.Name, int(s.Version))
if dsym.Size != 0 {
return
dsym.Set(AttrDuplicateOK, s.DuplicateOK())
var vars []*dwarf.Var
if ctxt.DebugInfo != nil {
- vars = ctxt.DebugInfo(s)
+ vars = ctxt.DebugInfo(s, curfn)
}
dwarf.PutFunc(dwCtxt{ctxt}, dsym, s.Name, s.Version == 0, s, s.Size, vars)
ctxt.Data = append(ctxt.Data, dsym)
type Plist struct {
Firstpc *Prog
+ Curfn interface{} // holds a *gc.Node, if non-nil
}
func Flushplist(ctxt *Link, plist *Plist) {
ctxt.Arch.Preprocess(ctxt, s)
ctxt.Arch.Assemble(ctxt, s)
linkpcln(ctxt, s)
- makeFuncDebugEntry(ctxt, s)
+ makeFuncDebugEntry(ctxt, plist.Curfn, s)
if freeProgs {
s.Text = nil
}