debug symbols switch

This commit is contained in:
Li Jie
2024-09-13 17:15:36 +08:00
parent 3e5338c902
commit 4c5f37db0f
7 changed files with 76 additions and 28 deletions

View File

@@ -55,7 +55,7 @@ type aCompilationUnit struct {
type CompilationUnit = *aCompilationUnit
func (b diBuilder) CreateCompileUnit(filename, dir string) CompilationUnit {
func (b diBuilder) createCompileUnit(filename, dir string) CompilationUnit {
return &aCompilationUnit{ll: b.di.CreateCompileUnit(llvm.DICompileUnit{
Language: llvm.DW_LANG_Go,
File: filename,
@@ -121,7 +121,6 @@ type aDIType struct {
type DIType = *aDIType
func (b diBuilder) createType(ty Type, pos token.Position) DIType {
fmt.Printf("Create type: %T, %v\n", ty.RawType(), ty.RawType())
var typ llvm.Metadata
switch t := ty.RawType().(type) {
case *types.Basic:
@@ -179,6 +178,8 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType {
return b.createBasicType(ty)
case *types.Array:
return b.createBasicType(ty)
case *types.Chan:
return b.createBasicType(ty)
default:
panic(fmt.Errorf("can't create debug info of type: %v, %T", ty.RawType(), ty.RawType()))
}

View File

@@ -338,8 +338,6 @@ func (p Program) tyComplex128() llvm.Type {
// NewPackage creates a new package.
func (p Program) NewPackage(name, pkgPath string) Package {
mod := p.ctx.NewModule(pkgPath)
di := newDIBuilder(p, mod)
cu := di.CreateCompileUnit(name, pkgPath)
// TODO(xsw): Finalize may cause panic, so comment it.
// mod.Finalize()
gbls := make(map[string]Global)
@@ -354,7 +352,7 @@ func (p Program) NewPackage(name, pkgPath string) Package {
// p.needPyInit = false
ret := &aPackage{
mod: mod, vars: gbls, fns: fns, stubs: stubs,
pyobjs: pyobjs, pymods: pymods, strs: strs, named: named, Prog: p, di: di, cu: cu}
pyobjs: pyobjs, pymods: pymods, strs: strs, named: named, Prog: p, di: nil, cu: nil}
ret.abi.Init(pkgPath)
return ret
}
@@ -711,13 +709,20 @@ func (p Package) AfterInit(b Builder, ret BasicBlock) {
}
func (p Package) Finalize() {
p.di.Finalize()
if p.di != nil {
p.di.Finalize()
}
}
func (p Package) DIBuilder() diBuilder {
return p.di
}
func (p Package) EnableDebugSymbols(name, pkgPath string) {
p.di = newDIBuilder(p.Prog, p.mod)
p.cu = p.di.createCompileUnit(name, pkgPath)
}
// -----------------------------------------------------------------------------
/*