ssa: debug info of global variable

This commit is contained in:
Li Jie
2024-09-18 22:05:41 +08:00
parent 90a83c8f11
commit 87f6c8087f
3 changed files with 28 additions and 2 deletions

View File

@@ -140,6 +140,9 @@ func main() {
pad1: 100,
pad2: 200,
}
globalStructPtr = &s
globalStruct = s
println("globalInt:", globalInt)
println("s:", &s)
FuncWithAllTypeStructParam(s)
println("called function with struct")
@@ -159,5 +162,11 @@ func main() {
)
println(i, err)
println("called function with types")
println(globalStructPtr)
println(&globalStruct)
println("done")
}
var globalInt int = 301
var globalStruct StructWithAllTypeFields
var globalStructPtr *StructWithAllTypeFields

View File

@@ -797,7 +797,12 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
}
return pyFn.Expr
case *ssa.Global:
return p.varOf(b, v)
val := p.varOf(b, v)
if debugSymbols {
pos := p.fset.Position(v.Pos())
b.DIGlobal(val, v.Name(), pos)
}
return val
case *ssa.Const:
t := types.Default(v.Type())
bg := llssa.InGo

View File

@@ -90,7 +90,7 @@ func (b diBuilder) createFile(filename string) DIFile {
return &aDIFile{ll: b.di.CreateFile(file, dir)}
}
func (f DIFile) scopeMeta(b diBuilder, cu CompilationUnit, pos token.Position) DIScopeMeta {
func (f DIFile) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
return &aDIScopeMeta{b.file(pos.Filename).ll}
}
@@ -633,6 +633,18 @@ func (b Builder) DIVarAuto(f Function, pos token.Position, varName string, vt Ty
return b.Pkg.diBuilder().varAuto(f, pos, varName, t)
}
func (b Builder) DIGlobal(v Expr, name string, pos token.Position) {
gv := b.Pkg.diBuilder().createGlobalVariableExpression(
b.Pkg.diBuilder().file(pos.Filename),
pos,
name,
name,
b.Pkg.diBuilder().diType(v.Type, pos),
false,
)
v.impl.AddMetadata(0, gv.ll)
}
func (b Builder) DISetCurrentDebugLocation(f Function, pos token.Position) {
b.impl.SetCurrentDebugLocation(
uint(pos.Line),