ssa: debug info of function/closure
This commit is contained in:
@@ -37,7 +37,9 @@ type StructWithAllTypeFields struct {
|
||||
m map[string]uint64
|
||||
c chan int
|
||||
err error
|
||||
// fn func(string) (int, error)
|
||||
fn func(string) (int, error)
|
||||
pad1 int
|
||||
pad2 int
|
||||
}
|
||||
|
||||
type Interface interface {
|
||||
@@ -84,7 +86,7 @@ func FuncWithAllTypeParams(
|
||||
m map[string]uint64,
|
||||
c chan int,
|
||||
err error,
|
||||
// fn func(string) (int, error),
|
||||
fn func(string) (int, error),
|
||||
) (int, error) {
|
||||
println(
|
||||
i8, i16, i32, i64, i, u8, u16, u32, u64, u,
|
||||
@@ -96,7 +98,7 @@ func FuncWithAllTypeParams(
|
||||
&f, pf, pi, intr, m,
|
||||
c,
|
||||
err,
|
||||
// fn,
|
||||
fn,
|
||||
)
|
||||
return 1, errors.New("Some error")
|
||||
}
|
||||
@@ -130,10 +132,13 @@ func main() {
|
||||
m: map[string]uint64{"a": 31, "b": 32},
|
||||
c: make(chan int),
|
||||
err: errors.New("Test error"),
|
||||
// fn: func(s string) (int, error) {
|
||||
// println("fn:", s)
|
||||
// return 1, errors.New("fn error")
|
||||
// },
|
||||
fn: func(s string) (int, error) {
|
||||
println("fn:", s)
|
||||
i = 201
|
||||
return 1, errors.New("fn error")
|
||||
},
|
||||
pad1: 100,
|
||||
pad2: 200,
|
||||
}
|
||||
println("s:", &s)
|
||||
FuncWithAllTypeStructParam(s)
|
||||
@@ -150,7 +155,7 @@ func main() {
|
||||
s.m,
|
||||
s.c,
|
||||
s.err,
|
||||
// s.fn,
|
||||
s.fn,
|
||||
)
|
||||
println(i, err)
|
||||
println("called function with types")
|
||||
|
||||
@@ -735,7 +735,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
||||
return
|
||||
}
|
||||
|
||||
pos := p.goProg.Fset.Position(getPos(v))
|
||||
pos := p.goProg.Fset.Position(v.Pos())
|
||||
value := p.compileValue(b, v.X)
|
||||
fn := v.Parent()
|
||||
dbgVar := p.getLocalVariable(b, fn, variable)
|
||||
@@ -754,40 +754,6 @@ type poser interface {
|
||||
Pos() token.Pos
|
||||
}
|
||||
|
||||
func getPos(v poser) token.Pos {
|
||||
pos := v.Pos()
|
||||
if pos.IsValid() {
|
||||
return pos
|
||||
}
|
||||
panic(fmt.Errorf("getPos: invalid position - %T", v))
|
||||
|
||||
// switch v := v.(type) {
|
||||
// case *ssa.MakeInterface:
|
||||
// return getPos(v.X)
|
||||
// case *ssa.MakeClosure:
|
||||
// return v.Fn.(*ssa.Function).Pos()
|
||||
// case *ssa.Return:
|
||||
// syntax := v.Parent().Syntax()
|
||||
// if syntax != nil {
|
||||
// return syntax.End()
|
||||
// }
|
||||
// return token.NoPos
|
||||
// case *ssa.FieldAddr:
|
||||
// return getPos(v.X)
|
||||
// case *ssa.IndexAddr:
|
||||
// return getPos(v.X)
|
||||
// case *ssa.Slice:
|
||||
// return getPos(v.X)
|
||||
// case *ssa.Store:
|
||||
// return getPos(v.Addr)
|
||||
// case *ssa.Extract:
|
||||
// return getPos(v.Tuple)
|
||||
// default:
|
||||
// fmt.Printf("getPos: unknown instr - %T\n", v)
|
||||
// return token.NoPos
|
||||
// }
|
||||
}
|
||||
|
||||
func (p *context) getLocalVariable(b llssa.Builder, fn *ssa.Function, v *types.Var) llssa.DIVar {
|
||||
pos := p.fset.Position(v.Pos())
|
||||
t := b.Prog.Type(v.Type(), llssa.InGo)
|
||||
|
||||
Reference in New Issue
Block a user