compiler: split LLGO_DEBUG into LLGO_DEBUG, LLGO_DBG_SYMBOLS, disableInline
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
### Build with debug info
|
### Build with debug info
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
LLGO_DEBUG=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
|
LLGO_DEBUG_SYMBOLS=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debug with lldb
|
### Debug with lldb
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ build_project() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LLGO_DEBUG=1 llgo build -o "debug.out" . || {
|
LLGO_DEBUG_SYMBOLS=1 llgo build -o "debug.out" . || {
|
||||||
local ret=$?
|
local ret=$?
|
||||||
cd "$current_dir" || return
|
cd "$current_dir" || return
|
||||||
return $ret
|
return $ret
|
||||||
|
|||||||
@@ -46,10 +46,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
debugInstr bool
|
debugInstr bool
|
||||||
debugGoSSA bool
|
debugGoSSA bool
|
||||||
debugSymbols bool
|
|
||||||
debugTrace bool
|
enableCallTracing bool
|
||||||
|
enableDbg bool
|
||||||
|
enableDbgSyms bool
|
||||||
|
disableInline bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetDebug sets debug flags.
|
// SetDebug sets debug flags.
|
||||||
@@ -58,12 +61,16 @@ func SetDebug(dbgFlags dbgFlags) {
|
|||||||
debugGoSSA = (dbgFlags & DbgFlagGoSSA) != 0
|
debugGoSSA = (dbgFlags & DbgFlagGoSSA) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnableDebugSymbols(b bool) {
|
func EnableDebug(b bool) {
|
||||||
debugSymbols = b
|
enableDbg = b
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnableDbgSyms(b bool) {
|
||||||
|
enableDbgSyms = b
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnableTrace(b bool) {
|
func EnableTrace(b bool) {
|
||||||
debugTrace = b
|
enableCallTracing = b
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -246,7 +253,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
}
|
}
|
||||||
if fn == nil {
|
if fn == nil {
|
||||||
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, f.Origin() != nil)
|
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, f.Origin() != nil)
|
||||||
if debugSymbols {
|
if disableInline {
|
||||||
fn.Inline(llssa.NoInline)
|
fn.Inline(llssa.NoInline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,7 +285,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
log.Println("==> FuncBody", name)
|
log.Println("==> FuncBody", name)
|
||||||
}
|
}
|
||||||
b := fn.NewBuilder()
|
b := fn.NewBuilder()
|
||||||
if debugSymbols {
|
if enableDbg {
|
||||||
pos := p.goProg.Fset.Position(f.Pos())
|
pos := p.goProg.Fset.Position(f.Pos())
|
||||||
bodyPos := p.getFuncBodyPos(f)
|
bodyPos := p.getFuncBodyPos(f)
|
||||||
b.DebugFunction(fn, pos, bodyPos)
|
b.DebugFunction(fn, pos, bodyPos)
|
||||||
@@ -385,11 +392,11 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
|||||||
var instrs = block.Instrs[n:]
|
var instrs = block.Instrs[n:]
|
||||||
var ret = fn.Block(block.Index)
|
var ret = fn.Block(block.Index)
|
||||||
b.SetBlock(ret)
|
b.SetBlock(ret)
|
||||||
if block.Index == 0 && debugTrace && !strings.HasPrefix(fn.Name(), "github.com/goplus/llgo/runtime/internal/runtime.Print") {
|
if block.Index == 0 && enableCallTracing && !strings.HasPrefix(fn.Name(), "github.com/goplus/llgo/runtime/internal/runtime.Print") {
|
||||||
b.Printf("call " + fn.Name() + "\n\x00")
|
b.Printf("call " + fn.Name() + "\n\x00")
|
||||||
}
|
}
|
||||||
// place here to avoid wrong current-block
|
// place here to avoid wrong current-block
|
||||||
if debugSymbols && block.Index == 0 {
|
if enableDbgSyms && block.Index == 0 {
|
||||||
p.debugParams(b, block.Parent())
|
p.debugParams(b, block.Parent())
|
||||||
}
|
}
|
||||||
if doModInit {
|
if doModInit {
|
||||||
@@ -781,7 +788,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
|||||||
p.compileInstrOrValue(b, iv, false)
|
p.compileInstrOrValue(b, iv, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if debugSymbols {
|
if enableDbg {
|
||||||
scope := p.getDebugLocScope(instr.Parent(), instr.Pos())
|
scope := p.getDebugLocScope(instr.Parent(), instr.Pos())
|
||||||
if scope != nil {
|
if scope != nil {
|
||||||
diScope := b.DIScope(p.fn, scope)
|
diScope := b.DIScope(p.fn, scope)
|
||||||
@@ -844,7 +851,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
|||||||
x := p.compileValue(b, v.X)
|
x := p.compileValue(b, v.X)
|
||||||
b.Send(ch, x)
|
b.Send(ch, x)
|
||||||
case *ssa.DebugRef:
|
case *ssa.DebugRef:
|
||||||
if debugSymbols {
|
if enableDbgSyms {
|
||||||
p.debugRef(b, v)
|
p.debugRef(b, v)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -901,7 +908,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
|
|||||||
if isCgoVar(varName) {
|
if isCgoVar(varName) {
|
||||||
p.cgoSymbols = append(p.cgoSymbols, val.Name())
|
p.cgoSymbols = append(p.cgoSymbols, val.Name())
|
||||||
}
|
}
|
||||||
if debugSymbols {
|
if enableDbgSyms {
|
||||||
pos := p.fset.Position(v.Pos())
|
pos := p.fset.Position(v.Pos())
|
||||||
b.DIGlobal(val, v.Name(), pos)
|
b.DIGlobal(val, v.Name(), pos)
|
||||||
}
|
}
|
||||||
@@ -984,8 +991,8 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
|
|||||||
prog.SetRuntime(pkgTypes)
|
prog.SetRuntime(pkgTypes)
|
||||||
}
|
}
|
||||||
ret = prog.NewPackage(pkgName, pkgPath)
|
ret = prog.NewPackage(pkgName, pkgPath)
|
||||||
if debugSymbols {
|
if enableDbg {
|
||||||
ret.InitDebugSymbols(pkgName, pkgPath, pkgProg.Fset)
|
ret.InitDebug(pkgName, pkgPath, pkgProg.Fset)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := &context{
|
ctx := &context{
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObj
|
|||||||
}
|
}
|
||||||
sig := fn.Signature
|
sig := fn.Signature
|
||||||
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false, fn.Origin() != nil)
|
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false, fn.Origin() != nil)
|
||||||
if debugSymbols {
|
if disableInline {
|
||||||
aFn.Inline(llssa.NoInline)
|
aFn.Inline(llssa.NoInline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,8 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.EnableDebugSymbols(IsDebugEnabled())
|
cl.EnableDebug(IsDbgEnabled())
|
||||||
|
cl.EnableDbgSyms(IsDbgSymsEnabled())
|
||||||
cl.EnableTrace(IsTraceEnabled())
|
cl.EnableTrace(IsTraceEnabled())
|
||||||
llssa.Initialize(llssa.InitAll)
|
llssa.Initialize(llssa.InitAll)
|
||||||
|
|
||||||
@@ -201,7 +202,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
buildMode := ssaBuildMode
|
buildMode := ssaBuildMode
|
||||||
if IsDebugEnabled() {
|
if IsDbgEnabled() {
|
||||||
buildMode |= ssa.GlobalDebug
|
buildMode |= ssa.GlobalDebug
|
||||||
}
|
}
|
||||||
if !IsOptimizeEnabled() {
|
if !IsOptimizeEnabled() {
|
||||||
@@ -451,7 +452,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer os.Remove(entryLLFile)
|
// defer os.Remove(entryLLFile)
|
||||||
args = append(args, entryLLFile)
|
args = append(args, entryLLFile)
|
||||||
|
|
||||||
var aPkg *aPackage
|
var aPkg *aPackage
|
||||||
@@ -480,7 +481,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args = append(args, exargs...)
|
args = append(args, exargs...)
|
||||||
if IsDebugEnabled() {
|
if IsDbgSymsEnabled() {
|
||||||
args = append(args, "-gdwarf-4")
|
args = append(args, "-gdwarf-4")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,6 +752,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const llgoDebug = "LLGO_DEBUG"
|
const llgoDebug = "LLGO_DEBUG"
|
||||||
|
const llgoDbgSyms = "LLGO_DEBUG_SYMBOLS"
|
||||||
const llgoTrace = "LLGO_TRACE"
|
const llgoTrace = "LLGO_TRACE"
|
||||||
const llgoOptimize = "LLGO_OPTIMIZE"
|
const llgoOptimize = "LLGO_OPTIMIZE"
|
||||||
const llgoCheck = "LLGO_CHECK"
|
const llgoCheck = "LLGO_CHECK"
|
||||||
@@ -768,8 +770,12 @@ func IsTraceEnabled() bool {
|
|||||||
return isEnvOn(llgoTrace, false)
|
return isEnvOn(llgoTrace, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsDebugEnabled() bool {
|
func IsDbgEnabled() bool {
|
||||||
return isEnvOn(llgoDebug, false)
|
return isEnvOn(llgoDebug, false) || isEnvOn(llgoDbgSyms, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsDbgSymsEnabled() bool {
|
||||||
|
return isEnvOn(llgoDbgSyms, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsOptimizeEnabled() bool {
|
func IsOptimizeEnabled() bool {
|
||||||
|
|||||||
@@ -33,11 +33,16 @@ func GenFrom(fileOrPkg string) string {
|
|||||||
|
|
||||||
func genFrom(pkgPath string) (build.Package, error) {
|
func genFrom(pkgPath string) (build.Package, error) {
|
||||||
oldDbg := os.Getenv("LLGO_DEBUG")
|
oldDbg := os.Getenv("LLGO_DEBUG")
|
||||||
|
oldDbgSyms := os.Getenv("LLGO_DEBUG_SYMBOLS")
|
||||||
dbg := isDbgSymEnabled(filepath.Join(pkgPath, "flags.txt"))
|
dbg := isDbgSymEnabled(filepath.Join(pkgPath, "flags.txt"))
|
||||||
if dbg {
|
if dbg {
|
||||||
os.Setenv("LLGO_DEBUG", "1")
|
os.Setenv("LLGO_DEBUG", "1")
|
||||||
|
os.Setenv("LLGO_DEBUG_SYMBOLS", "1")
|
||||||
}
|
}
|
||||||
defer os.Setenv("LLGO_DEBUG", oldDbg)
|
defer func() {
|
||||||
|
os.Setenv("LLGO_DEBUG", oldDbg)
|
||||||
|
os.Setenv("LLGO_DEBUG_SYMBOLS", oldDbgSyms)
|
||||||
|
}()
|
||||||
|
|
||||||
conf := &build.Config{
|
conf := &build.Config{
|
||||||
Mode: build.ModeGen,
|
Mode: build.ModeGen,
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ func (p Package) AfterInit(b Builder, ret BasicBlock) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Package) InitDebugSymbols(name, pkgPath string, positioner Positioner) {
|
func (p Package) InitDebug(name, pkgPath string, positioner Positioner) {
|
||||||
p.di = newDIBuilder(p.Prog, p, positioner)
|
p.di = newDIBuilder(p.Prog, p, positioner)
|
||||||
p.cu = p.di.createCompileUnit(name, pkgPath)
|
p.cu = p.di.createCompileUnit(name, pkgPath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user