Commit 6652572b authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: thread Curfn through to debuginfo

Updates #15756

Change-Id: I860dd45cae9d851c7844654621bbc99efe7c7f03
Reviewed-on: https://go-review.googlesource.com/38591
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 3a1ce108
...@@ -37,15 +37,17 @@ import ( ...@@ -37,15 +37,17 @@ import (
// Progs accumulates Progs for a function and converts them into machine code. // Progs accumulates Progs for a function and converts them into machine code.
type Progs struct { type Progs struct {
Text *obj.Prog // ATEXT Prog for this function Text *obj.Prog // ATEXT Prog for this function
next *obj.Prog // next Prog next *obj.Prog // next Prog
pc int64 // virtual PC; count of Progs pc int64 // virtual PC; count of Progs
pos src.XPos // position to use for new Progs pos src.XPos // position to use for new Progs
curfn *Node // fn these Progs are for
} }
// newProgs returns a new Progs for fn. // newProgs returns a new Progs for fn.
func newProgs(fn *Node) *Progs { func newProgs(fn *Node) *Progs {
pp := new(Progs) pp := new(Progs)
pp.curfn = fn
// prime the pump // prime the pump
pp.next = Ctxt.NewProg() pp.next = Ctxt.NewProg()
...@@ -58,7 +60,7 @@ func newProgs(fn *Node) *Progs { ...@@ -58,7 +60,7 @@ func newProgs(fn *Node) *Progs {
// Flush converts from pp to machine code. // Flush converts from pp to machine code.
func (pp *Progs) Flush() { func (pp *Progs) Flush() {
plist := &obj.Plist{Firstpc: pp.Text} plist := &obj.Plist{Firstpc: pp.Text, Curfn: pp.curfn}
obj.Flushplist(Ctxt, plist) obj.Flushplist(Ctxt, plist)
// Clear pp to enable GC and avoid abuse. // Clear pp to enable GC and avoid abuse.
*pp = Progs{} *pp = Progs{}
......
...@@ -310,13 +310,14 @@ func compile(fn *Node) { ...@@ -310,13 +310,14 @@ func compile(fn *Node) {
pp.Flush() pp.Flush()
} }
func debuginfo(fnsym *obj.LSym) []*dwarf.Var { func debuginfo(fnsym *obj.LSym, curfn interface{}) []*dwarf.Var {
if expect := Linksym(Curfn.Func.Nname.Sym); fnsym != expect { fn := curfn.(*Node)
if expect := Linksym(fn.Func.Nname.Sym); fnsym != expect {
Fatalf("unexpected fnsym: %v != %v", fnsym, expect) Fatalf("unexpected fnsym: %v != %v", fnsym, expect)
} }
var vars []*dwarf.Var 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 if n.Op != ONAME { // might be OTYPE or OLITERAL
continue continue
} }
......
...@@ -746,7 +746,7 @@ type Link struct { ...@@ -746,7 +746,7 @@ type Link struct {
Armsize int32 Armsize int32
Pc int64 Pc int64
DiagFunc func(string, ...interface{}) 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 Cursym *LSym
Version int Version int
Errors int Errors int
......
...@@ -553,7 +553,7 @@ func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64 ...@@ -553,7 +553,7 @@ func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64
// makeFuncDebugEntry makes a DWARF Debugging Information Entry // makeFuncDebugEntry makes a DWARF Debugging Information Entry
// for TEXT symbol s. // 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)) dsym := Linklookup(ctxt, dwarf.InfoPrefix+s.Name, int(s.Version))
if dsym.Size != 0 { if dsym.Size != 0 {
return return
...@@ -562,7 +562,7 @@ func makeFuncDebugEntry(ctxt *Link, s *LSym) { ...@@ -562,7 +562,7 @@ func makeFuncDebugEntry(ctxt *Link, s *LSym) {
dsym.Set(AttrDuplicateOK, s.DuplicateOK()) dsym.Set(AttrDuplicateOK, s.DuplicateOK())
var vars []*dwarf.Var var vars []*dwarf.Var
if ctxt.DebugInfo != nil { 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) dwarf.PutFunc(dwCtxt{ctxt}, dsym, s.Name, s.Version == 0, s, s.Size, vars)
ctxt.Data = append(ctxt.Data, dsym) ctxt.Data = append(ctxt.Data, dsym)
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
type Plist struct { type Plist struct {
Firstpc *Prog Firstpc *Prog
Curfn interface{} // holds a *gc.Node, if non-nil
} }
func Flushplist(ctxt *Link, plist *Plist) { func Flushplist(ctxt *Link, plist *Plist) {
...@@ -127,7 +128,7 @@ func flushplist(ctxt *Link, plist *Plist, freeProgs bool) { ...@@ -127,7 +128,7 @@ func flushplist(ctxt *Link, plist *Plist, freeProgs bool) {
ctxt.Arch.Preprocess(ctxt, s) ctxt.Arch.Preprocess(ctxt, s)
ctxt.Arch.Assemble(ctxt, s) ctxt.Arch.Assemble(ctxt, s)
linkpcln(ctxt, s) linkpcln(ctxt, s)
makeFuncDebugEntry(ctxt, s) makeFuncDebugEntry(ctxt, plist.Curfn, s)
if freeProgs { if freeProgs {
s.Text = nil s.Text = nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment