rename debug info class/funcs

This commit is contained in:
Li Jie
2024-09-13 19:52:36 +08:00
parent 4c5f37db0f
commit d6f87a8254
6 changed files with 63 additions and 74 deletions

View File

@@ -238,9 +238,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
sig = types.NewSignatureType(nil, nil, nil, params, results, false)
}
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, f.Origin() != nil)
if debugSymbols {
p.pkg.DIBuilder().DebugFunction(fn, p.goProg.Fset.Position(f.Pos()))
}
}
if nblk := len(f.Blocks); nblk > 0 {
@@ -263,7 +260,8 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
}
b := fn.NewBuilder()
if debugSymbols {
b.SetCurrentDebugLocation(p.fn, p.goProg.Fset.Position(f.Pos()))
b.DebugFunction(fn, p.goProg.Fset.Position(f.Pos()))
b.DISetCurrentDebugLocation(p.fn, p.goProg.Fset.Position(f.Pos()))
}
p.bvals = make(map[ssa.Value]llssa.Expr)
off := make([]int, len(f.Blocks))
@@ -298,13 +296,11 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
func (p *context) debugParams(b llssa.Builder, f *ssa.Function) {
for argNo, param := range f.Params {
blk := p.fn.Block(0)
pos := p.goProg.Fset.Position(param.Pos())
v := p.compileValue(b, param)
ty := param.Type()
t := b.Pkg.DIBuilder().DIType(p.prog.Type(ty, llssa.InGo), pos)
div := b.Pkg.DIBuilder().DIVarParam(p.fn, p.goProg.Fset.Position(param.Pos()), param.Name(), t, argNo)
b.Pkg.DIBuilder().DebugValue(v, div, p.fn, pos, blk)
div := b.DIVarParam(p.fn, pos, param.Name(), b.Prog.Type(ty, llssa.InGo), argNo)
b.DIValue(v, div, p.fn, pos, p.fn.Block(0))
}
}
@@ -487,7 +483,7 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
}
if debugSymbols {
if v, ok := iv.(ssa.Instruction); ok {
b.SetCurrentDebugLocation(p.fn, p.goProg.Fset.Position(v.Pos()))
b.DISetCurrentDebugLocation(p.fn, p.goProg.Fset.Position(v.Pos()))
}
}
switch v := iv.(type) {
@@ -735,7 +731,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
// dbgVar := p.getLocalVariable(b, fn, variable)
// pos := p.goProg.Fset.Position(getPos(v))
// value := p.compileValue(b, v.X)
// b.Pkg.DIBuilder().Debug(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
// b.Debug(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
default:
panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr))
}
@@ -781,13 +777,12 @@ func getPos(v poser) token.Pos {
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)
vt := b.Pkg.DIBuilder().DIType(t, pos)
for i, param := range fn.Params {
if param.Object().(*types.Var) == v {
return b.DIVarParam(p.fn, pos, v.Name(), vt, i)
return b.DIVarParam(p.fn, pos, v.Name(), t, i)
}
}
return b.DIVarAuto(p.fn, pos, v.Name(), vt)
return b.DIVarAuto(p.fn, pos, v.Name(), t)
}
func (p *context) compileFunction(v *ssa.Function) (goFn llssa.Function, pyFn llssa.PyObjRef, kind int) {

View File

@@ -267,7 +267,6 @@ func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObj
}
sig := fn.Signature
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false, fn.Origin() != nil)
// p.pkg.DIBuilder().DebugFunction(aFn, p.goProg.Fset.Position(fn.Pos()))
}
}
return

View File

@@ -277,10 +277,6 @@ func (p Function) NewBuilder() Builder {
return &aBuilder{b, nil, p, p.Pkg, prog}
}
func (p Function) NewDIBuilder() *llvm.DIBuilder {
return llvm.NewDIBuilder(p.Pkg.mod)
}
// HasBody reports whether the function has a body.
func (p Function) HasBody() bool {
return len(p.blks) > 0
@@ -335,10 +331,10 @@ func (p Function) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
if p.diFunc == nil {
paramTypes := make([]llvm.Metadata, len(p.params))
for i, t := range p.params {
paramTypes[i] = b.DIType(t, pos).ll
paramTypes[i] = b.diType(t, pos).ll
}
diFuncType := b.di.CreateSubroutineType(llvm.DISubroutineType{
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Parameters: paramTypes,
})
p.diFunc = &aDIFunction{
@@ -348,7 +344,7 @@ func (p Function) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
Type: diFuncType,
Name: p.Name(),
LinkageName: p.Name(),
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
IsDefinition: true,
Optimized: false,

View File

@@ -92,7 +92,7 @@ func (b diBuilder) createFile(filename string) DIFile {
}
func (f DIFile) scopeMeta(b diBuilder, cu CompilationUnit, pos token.Position) DIScopeMeta {
return &aDIScopeMeta{b.DIFile(pos.Filename).ll}
return &aDIScopeMeta{b.file(pos.Filename).ll}
}
// ----------------------------------------------------------------------------
@@ -105,7 +105,7 @@ type DILexicalBlock = *aDILexicalBlock
func (b diBuilder) createLexicalBlock(scope DIScope, pos token.Position) DILexicalBlock {
block := llvm.DILexicalBlock{
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
Column: pos.Column,
}
@@ -165,7 +165,7 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType {
case *types.Pointer:
return b.createPointerType(b.prog.rawType(t.Elem()), pos)
case *types.Named:
return b.DIType(b.prog.rawType(t.Underlying()), pos)
return b.diType(b.prog.rawType(t.Underlying()), pos)
case *types.Interface:
return b.createBasicType(ty)
case *types.Slice:
@@ -194,7 +194,7 @@ type aDIFunction struct {
type DIFunction = *aDIFunction
func (b diBuilder) CreateFunction(scope DIScope, pos token.Position, name, linkageName string, ty DIType, isLocalToUnit, isDefinition, isOptimized bool) DIFunction {
func (b diBuilder) createFunction(scope DIScope, pos token.Position, name, linkageName string, ty DIType, isLocalToUnit, isDefinition, isOptimized bool) DIFunction {
return &aDIFunction{ll: scope.scopeMeta(b, pos).ll}
}
@@ -206,14 +206,14 @@ type aDIGlobalVariableExpression struct {
type DIGlobalVariableExpression = *aDIGlobalVariableExpression
func (b diBuilder) CreateGlobalVariableExpression(scope DIScope, pos token.Position, name, linkageName string, ty DIType, isLocalToUnit bool) DIGlobalVariableExpression {
func (b diBuilder) createGlobalVariableExpression(scope DIScope, pos token.Position, name, linkageName string, ty DIType, isLocalToUnit bool) DIGlobalVariableExpression {
return &aDIGlobalVariableExpression{
ll: b.di.CreateGlobalVariableExpression(
scope.scopeMeta(b, pos).ll,
llvm.DIGlobalVariableExpression{
Name: name,
LinkageName: linkageName,
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
Type: ty.ll,
LocalToUnit: isLocalToUnit,
@@ -234,13 +234,13 @@ type aDIVar struct {
type DIVar = *aDIVar
func (b diBuilder) CreateParameterVariable(scope DIScope, pos token.Position, name string, argNo int, ty DIType) DIVar {
func (b diBuilder) createParameterVariable(scope DIScope, pos token.Position, name string, argNo int, ty DIType) DIVar {
return &aDIVar{
ll: b.di.CreateParameterVariable(
scope.scopeMeta(b, pos).ll,
llvm.DIParameterVariable{
Name: name,
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
ArgNo: argNo,
Type: ty.ll,
@@ -250,13 +250,13 @@ func (b diBuilder) CreateParameterVariable(scope DIScope, pos token.Position, na
}
}
func (b diBuilder) CreateAutoVariable(scope DIScope, pos token.Position, name string, ty DIType) DIVar {
func (b diBuilder) createAutoVariable(scope DIScope, pos token.Position, name string, ty DIType) DIVar {
return &aDIVar{
ll: b.di.CreateAutoVariable(
scope.scopeMeta(b, pos).ll,
llvm.DIAutoVariable{
Name: name,
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
Type: ty.ll,
AlwaysPreserve: true,
@@ -265,8 +265,6 @@ func (b diBuilder) CreateAutoVariable(scope DIScope, pos token.Position, name st
}
}
// ----------------------------------------------------------------------------
func (b diBuilder) createBasicType(t Type) DIType {
return &aDIType{ll: b.di.CreateBasicType(llvm.DIBasicType{
Name: t.RawType().String(),
@@ -277,7 +275,7 @@ func (b diBuilder) createBasicType(t Type) DIType {
func (b diBuilder) createPointerType(ty Type, pos token.Position) DIType {
return &aDIType{ll: b.di.CreatePointerType(llvm.DIPointerType{
Pointee: b.DIType(ty, pos).ll,
Pointee: b.diType(ty, pos).ll,
SizeInBits: b.prog.SizeOf(ty) * 8,
AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType())) * 8,
AddressSpace: 0,
@@ -285,7 +283,7 @@ func (b diBuilder) createPointerType(ty Type, pos token.Position) DIType {
}
func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) {
scope := b.DIFile(pos.Filename)
scope := b.file(pos.Filename)
ret = &aDIType{b.di.CreateReplaceableCompositeType(
scope.ll,
llvm.DIReplaceableCompositeType{
@@ -305,12 +303,12 @@ func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) {
scope.ll,
llvm.DIMemberType{
Name: field.Name(),
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
SizeInBits: b.prog.SizeOf(b.prog.rawType(field.Type())) * 8,
AlignInBits: 8,
OffsetInBits: b.prog.OffsetOf(ty, i) * 8,
Type: b.DIType(b.prog.rawType(field.Type()), pos).ll,
Type: b.diType(b.prog.rawType(field.Type()), pos).ll,
},
)
}
@@ -318,7 +316,7 @@ func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) {
scope.ll,
llvm.DIStructType{
Name: ty.RawType().String(),
File: b.DIFile(pos.Filename).ll,
File: b.file(pos.Filename).ll,
Line: pos.Line,
SizeInBits: b.prog.SizeOf(ty) * 8,
AlignInBits: uint32(b.prog.sizes.Alignof(structType) * 8),
@@ -332,12 +330,12 @@ func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) {
func (b diBuilder) createFuncPtrType(ty Type, pos token.Position) DIType {
sig := ty.RawType().(*types.Signature)
retTy := b.DIType(b.prog.rawType(sig.Results()), pos)
retTy := b.diType(b.prog.rawType(sig.Results()), pos)
paramTys := make([]DIType, sig.Params().Len())
for i := 0; i < sig.Params().Len(); i++ {
paramTys[i] = b.DIType(b.prog.rawType(sig.Params().At(i).Type()), pos)
paramTys[i] = b.diType(b.prog.rawType(sig.Params().At(i).Type()), pos)
}
rt := b.createSubroutineType(b.DIFile(pos.Filename), retTy, paramTys)
rt := b.createSubroutineType(b.file(pos.Filename), retTy, paramTys)
return &aDIType{ll: b.di.CreatePointerType(llvm.DIPointerType{
Pointee: rt.ll,
SizeInBits: b.prog.SizeOf(ty) * 8,
@@ -346,8 +344,6 @@ func (b diBuilder) createFuncPtrType(ty Type, pos token.Position) DIType {
})}
}
// ----------------------------------------------------------------------------
func (b diBuilder) createSubroutineType(file DIFile, retTy DIType, paramTys []DIType) DIType {
params := make([]llvm.Metadata, len(paramTys)+1)
params[0] = retTy.ll
@@ -363,7 +359,7 @@ func (b diBuilder) createSubroutineType(file DIFile, retTy DIType, paramTys []DI
// ----------------------------------------------------------------------------
func (b diBuilder) Debug(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
func (b diBuilder) dbgDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
loc := llvm.DebugLoc{
Line: uint(pos.Line),
Col: uint(pos.Column),
@@ -378,7 +374,7 @@ func (b diBuilder) Debug(v Expr, dv DIVar, scope DIScope, pos token.Position, bl
)
}
func (b diBuilder) DebugValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
func (b diBuilder) dbgValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
loc := llvm.DebugLoc{
Line: uint(pos.Line),
Col: uint(pos.Column),
@@ -393,7 +389,7 @@ func (b diBuilder) DebugValue(v Expr, dv DIVar, scope DIScope, pos token.Positio
)
}
func (b diBuilder) DIType(t Type, pos token.Position) DIType {
func (b diBuilder) diType(t Type, pos token.Position) DIType {
if ty, ok := b.diTypes[t]; ok {
return ty
}
@@ -402,8 +398,8 @@ func (b diBuilder) DIType(t Type, pos token.Position) DIType {
return ty
}
func (b diBuilder) DIVarParam(f Function, pos token.Position, varName string, vt DIType, argNo int) DIVar {
return b.CreateParameterVariable(
func (b diBuilder) varParam(f Function, pos token.Position, varName string, vt DIType, argNo int) DIVar {
return b.createParameterVariable(
f,
pos,
varName,
@@ -412,8 +408,8 @@ func (b diBuilder) DIVarParam(f Function, pos token.Position, varName string, vt
)
}
func (b diBuilder) DIVarAuto(f Function, pos token.Position, varName string, vt DIType) DIVar {
return b.CreateAutoVariable(
func (b diBuilder) varAuto(f Function, pos token.Position, varName string, vt DIType) DIVar {
return b.createAutoVariable(
f,
pos,
varName,
@@ -421,21 +417,42 @@ func (b diBuilder) DIVarAuto(f Function, pos token.Position, varName string, vt
)
}
func (b diBuilder) DIFile(filename string) DIFile {
func (b diBuilder) file(filename string) DIFile {
return b.createFile(filename)
}
// -----------------------------------------------------------------------------
func (b Builder) SetCurrentDebugLocation(f Function, pos token.Position) {
func (b Builder) DIDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
b.Pkg.diBuilder().dbgDeclare(v, dv, scope, pos, blk)
}
func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) {
b.Pkg.diBuilder().dbgValue(v, dv, scope, pos, blk)
}
func (b Builder) DIVarParam(f Function, pos token.Position, varName string, vt Type, argNo int) DIVar {
t := b.Pkg.diBuilder().diType(vt, pos)
return b.Pkg.diBuilder().varParam(f, pos, varName, t, argNo)
}
func (b Builder) DIVarAuto(f Function, pos token.Position, varName string, vt Type) DIVar {
t := b.Pkg.diBuilder().diType(vt, pos)
return b.Pkg.diBuilder().varAuto(f, pos, varName, t)
}
func (b Builder) DISetCurrentDebugLocation(f Function, pos token.Position) {
b.impl.SetCurrentDebugLocation(
uint(pos.Line),
uint(pos.Column),
f.scopeMeta(b.Pkg.DIBuilder(), pos).ll,
f.scopeMeta(b.Pkg.diBuilder(), pos).ll,
f.impl.InstructionDebugLoc(),
)
}
func (b diBuilder) DebugFunction(f Function, pos token.Position) {
func (b Builder) DebugFunction(f Function, pos token.Position) {
// attach debug info to function
f.scopeMeta(b, pos)
f.scopeMeta(b.Pkg.di, pos)
}
// -----------------------------------------------------------------------------

View File

@@ -714,7 +714,7 @@ func (p Package) Finalize() {
}
}
func (p Package) DIBuilder() diBuilder {
func (p Package) diBuilder() diBuilder {
return p.di
}

View File

@@ -287,24 +287,6 @@ func (b Builder) Times(n Expr, loop func(i Expr)) {
b.blk.last = blks[2].last
}
// -----------------------------------------------------------------------------
func (b Builder) Debug(v Expr, dv DIVar, scope DIScope, pos token.Position) {
b.Pkg.DIBuilder().Debug(v, dv, scope, pos, b.blk)
}
func (b Builder) DebugValue(v Expr, dv DIVar, scope DIScope, pos token.Position) {
b.Pkg.DIBuilder().DebugValue(v, dv, scope, pos, b.blk)
}
func (b Builder) DIVarParam(f Function, pos token.Position, varName string, vt DIType, argNo int) DIVar {
return b.Pkg.DIBuilder().DIVarParam(f, pos, varName, vt, argNo)
}
func (b Builder) DIVarAuto(f Function, pos token.Position, varName string, vt DIType) DIVar {
return b.Pkg.DIBuilder().DIVarAuto(f, pos, varName, vt)
}
// -----------------------------------------------------------------------------
/*
type caseStmt struct {