ssa: fix debug info of local vars
This commit is contained in:
39
ssa/di.go
39
ssa/di.go
@@ -501,8 +501,16 @@ func (b Builder) constructDebugAddr(v Expr) (dbgPtr Expr, dbgVal Expr, deref boo
|
|||||||
return v.ptr, v.val, v.deref
|
return v.ptr, v.val, v.deref
|
||||||
}
|
}
|
||||||
t := v.Type.RawType().Underlying()
|
t := v.Type.RawType().Underlying()
|
||||||
|
dbgPtr, dbgVal, deref = b.doConstructDebugAddr(v, t)
|
||||||
|
b.dbgVars[v] = dbgExpr{dbgPtr, dbgVal, deref}
|
||||||
|
return dbgPtr, dbgVal, deref
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Builder) doConstructDebugAddr(v Expr, t types.Type) (dbgPtr Expr, dbgVal Expr, deref bool) {
|
||||||
var ty Type
|
var ty Type
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
|
case *types.Pointer:
|
||||||
|
return v, v, false
|
||||||
case *types.Basic:
|
case *types.Basic:
|
||||||
if t.Info()&types.IsComplex != 0 {
|
if t.Info()&types.IsComplex != 0 {
|
||||||
if t.Kind() == types.Complex128 {
|
if t.Kind() == types.Complex128 {
|
||||||
@@ -532,34 +540,40 @@ func (b Builder) constructDebugAddr(v Expr) (dbgPtr Expr, dbgVal Expr, deref boo
|
|||||||
dbgPtr.Type = b.Prog.Pointer(v.Type)
|
dbgPtr.Type = b.Prog.Pointer(v.Type)
|
||||||
b.Store(dbgPtr, v)
|
b.Store(dbgPtr, v)
|
||||||
dbgVal = b.Load(dbgPtr)
|
dbgVal = b.Load(dbgPtr)
|
||||||
b.dbgVars[v] = dbgExpr{dbgPtr, dbgVal, deref}
|
|
||||||
return dbgPtr, dbgVal, deref
|
return dbgPtr, dbgVal, deref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b Builder) di() diBuilder {
|
||||||
|
return b.Pkg.di
|
||||||
|
}
|
||||||
|
|
||||||
func (b Builder) DIDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
|
func (b Builder) DIDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
|
||||||
dbgPtr, _, _ := b.constructDebugAddr(v)
|
dbgPtr, _, _ := b.constructDebugAddr(v)
|
||||||
expr := b.Pkg.diBuilder().createExpression(nil)
|
expr := b.di().createExpression(nil)
|
||||||
b.Pkg.diBuilder().dbgDeclare(dbgPtr, dv, scope, pos, expr, blk)
|
b.di().dbgDeclare(dbgPtr, dv, scope, pos, expr, blk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
|
func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
|
||||||
expr := b.Pkg.diBuilder().createExpression(nil)
|
expr := b.di().createExpression(nil)
|
||||||
b.Pkg.diBuilder().dbgValue(v, dv, scope, pos, expr, blk)
|
b.di().dbgValue(v, dv, scope, pos, expr, blk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Builder) DIVarParam(f Function, pos token.Position, varName string, vt Type, argNo int) DIVar {
|
func (b Builder) DIVarParam(f Function, pos token.Position, varName string, vt Type, argNo int) DIVar {
|
||||||
t := b.Pkg.diBuilder().diType(vt, pos)
|
t := b.di().diType(vt, pos)
|
||||||
return b.Pkg.diBuilder().varParam(f, pos, varName, t, argNo)
|
return b.di().varParam(f, pos, varName, t, argNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Builder) DIVarAuto(f Function, pos token.Position, varName string, vt Type) DIVar {
|
func (b Builder) DIVarAuto(f Function, pos token.Position, varName string, vt Type) DIVar {
|
||||||
t := b.Pkg.diBuilder().diType(vt, pos)
|
t := b.di().diType(vt, pos)
|
||||||
return b.Pkg.diBuilder().varAuto(f, pos, varName, t)
|
return b.di().varAuto(f, pos, varName, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Builder) DIGlobal(v Expr, name string, pos token.Position) {
|
func (b Builder) DIGlobal(v Expr, name string, pos token.Position) {
|
||||||
gv := b.Pkg.diBuilder().createGlobalVariableExpression(
|
if _, ok := b.Pkg.glbDbgVars[v]; ok {
|
||||||
b.Pkg.diBuilder().file(pos.Filename),
|
return
|
||||||
|
}
|
||||||
|
gv := b.di().createGlobalVariableExpression(
|
||||||
|
b.di().file(pos.Filename),
|
||||||
pos,
|
pos,
|
||||||
name,
|
name,
|
||||||
name,
|
name,
|
||||||
@@ -567,13 +581,14 @@ func (b Builder) DIGlobal(v Expr, name string, pos token.Position) {
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
v.impl.AddMetadata(0, gv.ll)
|
v.impl.AddMetadata(0, gv.ll)
|
||||||
|
b.Pkg.glbDbgVars[v] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Builder) DISetCurrentDebugLocation(f Function, pos token.Position) {
|
func (b Builder) DISetCurrentDebugLocation(f Function, pos token.Position) {
|
||||||
b.impl.SetCurrentDebugLocation(
|
b.impl.SetCurrentDebugLocation(
|
||||||
uint(pos.Line),
|
uint(pos.Line),
|
||||||
uint(pos.Column),
|
uint(pos.Column),
|
||||||
f.scopeMeta(b.Pkg.diBuilder(), pos).ll,
|
f.scopeMeta(b.di(), pos).ll,
|
||||||
f.impl.InstructionDebugLoc(),
|
f.impl.InstructionDebugLoc(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,12 +347,15 @@ func (p Program) NewPackage(name, pkgPath string) Package {
|
|||||||
pymods := make(map[string]Global)
|
pymods := make(map[string]Global)
|
||||||
strs := make(map[string]llvm.Value)
|
strs := make(map[string]llvm.Value)
|
||||||
named := make(map[types.Type]Expr)
|
named := make(map[types.Type]Expr)
|
||||||
|
glbDbgVars := make(map[Expr]bool)
|
||||||
p.NeedRuntime = false
|
p.NeedRuntime = false
|
||||||
// Don't need reset p.needPyInit here
|
// Don't need reset p.needPyInit here
|
||||||
// p.needPyInit = false
|
// p.needPyInit = false
|
||||||
ret := &aPackage{
|
ret := &aPackage{
|
||||||
mod: mod, vars: gbls, fns: fns, stubs: stubs,
|
mod: mod, vars: gbls, fns: fns, stubs: stubs,
|
||||||
pyobjs: pyobjs, pymods: pymods, strs: strs, named: named, Prog: p, di: nil, cu: nil}
|
pyobjs: pyobjs, pymods: pymods, strs: strs, named: named, Prog: p,
|
||||||
|
di: nil, cu: nil, glbDbgVars: glbDbgVars,
|
||||||
|
}
|
||||||
ret.abi.Init(pkgPath)
|
ret.abi.Init(pkgPath)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -592,6 +595,7 @@ type aPackage struct {
|
|||||||
di diBuilder
|
di diBuilder
|
||||||
cu CompilationUnit
|
cu CompilationUnit
|
||||||
|
|
||||||
|
glbDbgVars map[Expr]bool
|
||||||
vars map[string]Global
|
vars map[string]Global
|
||||||
fns map[string]Function
|
fns map[string]Function
|
||||||
stubs map[string]Function
|
stubs map[string]Function
|
||||||
|
|||||||
Reference in New Issue
Block a user