Skip to content

Commit d65d49f

Browse files
authored
Merge pull request #1036 from cpunion/split-debug-and-symbols
Split debug and symbols toggle environment variables
2 parents 9f38338 + 8cd5924 commit d65d49f

File tree

7 files changed

+45
-27
lines changed

7 files changed

+45
-27
lines changed

compiler/_lldb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### Build with debug info
44

55
```shell
6-
LLGO_DEBUG=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
6+
LLGO_DEBUG_SYMBOLS=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
77
```
88

99
### Debug with lldb

compiler/_lldb/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ build_project() {
4444
return 1
4545
fi
4646

47-
LLGO_DEBUG=1 llgo build -o "debug.out" . || {
47+
LLGO_DEBUG_SYMBOLS=1 llgo build -o "debug.out" . || {
4848
local ret=$?
4949
cd "$current_dir" || return
5050
return $ret

compiler/cl/compile.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ const (
4646
)
4747

4848
var (
49-
debugInstr bool
50-
debugGoSSA bool
51-
debugSymbols bool
52-
debugTrace bool
49+
debugInstr bool
50+
debugGoSSA bool
51+
52+
enableCallTracing bool
53+
enableDbg bool
54+
enableDbgSyms bool
55+
disableInline bool
5356
)
5457

5558
// SetDebug sets debug flags.
@@ -58,12 +61,16 @@ func SetDebug(dbgFlags dbgFlags) {
5861
debugGoSSA = (dbgFlags & DbgFlagGoSSA) != 0
5962
}
6063

61-
func EnableDebugSymbols(b bool) {
62-
debugSymbols = b
64+
func EnableDebug(b bool) {
65+
enableDbg = b
66+
}
67+
68+
func EnableDbgSyms(b bool) {
69+
enableDbgSyms = b
6370
}
6471

6572
func EnableTrace(b bool) {
66-
debugTrace = b
73+
enableCallTracing = b
6774
}
6875

6976
// -----------------------------------------------------------------------------
@@ -246,7 +253,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
246253
}
247254
if fn == nil {
248255
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, f.Origin() != nil)
249-
if debugSymbols {
256+
if disableInline {
250257
fn.Inline(llssa.NoInline)
251258
}
252259
}
@@ -278,7 +285,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
278285
log.Println("==> FuncBody", name)
279286
}
280287
b := fn.NewBuilder()
281-
if debugSymbols {
288+
if enableDbg {
282289
pos := p.goProg.Fset.Position(f.Pos())
283290
bodyPos := p.getFuncBodyPos(f)
284291
b.DebugFunction(fn, pos, bodyPos)
@@ -385,11 +392,11 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
385392
var instrs = block.Instrs[n:]
386393
var ret = fn.Block(block.Index)
387394
b.SetBlock(ret)
388-
if block.Index == 0 && debugTrace && !strings.HasPrefix(fn.Name(), "github.com/goplus/llgo/runtime/internal/runtime.Print") {
395+
if block.Index == 0 && enableCallTracing && !strings.HasPrefix(fn.Name(), "github.com/goplus/llgo/runtime/internal/runtime.Print") {
389396
b.Printf("call " + fn.Name() + "\n\x00")
390397
}
391398
// place here to avoid wrong current-block
392-
if debugSymbols && block.Index == 0 {
399+
if enableDbgSyms && block.Index == 0 {
393400
p.debugParams(b, block.Parent())
394401
}
395402
if doModInit {
@@ -781,7 +788,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
781788
p.compileInstrOrValue(b, iv, false)
782789
return
783790
}
784-
if debugSymbols {
791+
if enableDbg {
785792
scope := p.getDebugLocScope(instr.Parent(), instr.Pos())
786793
if scope != nil {
787794
diScope := b.DIScope(p.fn, scope)
@@ -844,7 +851,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
844851
x := p.compileValue(b, v.X)
845852
b.Send(ch, x)
846853
case *ssa.DebugRef:
847-
if debugSymbols {
854+
if enableDbgSyms {
848855
p.debugRef(b, v)
849856
}
850857
default:
@@ -901,7 +908,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
901908
if isCgoVar(varName) {
902909
p.cgoSymbols = append(p.cgoSymbols, val.Name())
903910
}
904-
if debugSymbols {
911+
if enableDbgSyms {
905912
pos := p.fset.Position(v.Pos())
906913
b.DIGlobal(val, v.Name(), pos)
907914
}
@@ -984,8 +991,8 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
984991
prog.SetRuntime(pkgTypes)
985992
}
986993
ret = prog.NewPackage(pkgName, pkgPath)
987-
if debugSymbols {
988-
ret.InitDebugSymbols(pkgName, pkgPath, pkgProg.Fset)
994+
if enableDbg {
995+
ret.InitDebug(pkgName, pkgPath, pkgProg.Fset)
989996
}
990997

991998
ctx := &context{

compiler/cl/instr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObj
348348
}
349349
sig := fn.Signature
350350
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false, fn.Origin() != nil)
351-
if debugSymbols {
351+
if disableInline {
352352
aFn.Inline(llssa.NoInline)
353353
}
354354
}

compiler/internal/build/build.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ func Do(args []string, conf *Config) ([]Package, error) {
142142
}
143143
}
144144

145-
cl.EnableDebugSymbols(IsDebugEnabled())
145+
cl.EnableDebug(IsDbgEnabled())
146+
cl.EnableDbgSyms(IsDbgSymsEnabled())
146147
cl.EnableTrace(IsTraceEnabled())
147148
llssa.Initialize(llssa.InitAll)
148149

@@ -201,7 +202,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
201202
})
202203

203204
buildMode := ssaBuildMode
204-
if IsDebugEnabled() {
205+
if IsDbgEnabled() {
205206
buildMode |= ssa.GlobalDebug
206207
}
207208
if !IsOptimizeEnabled() {
@@ -451,7 +452,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
451452
if err != nil {
452453
panic(err)
453454
}
454-
defer os.Remove(entryLLFile)
455+
// defer os.Remove(entryLLFile)
455456
args = append(args, entryLLFile)
456457

457458
var aPkg *aPackage
@@ -480,7 +481,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs
480481
}
481482
}
482483
args = append(args, exargs...)
483-
if IsDebugEnabled() {
484+
if IsDbgSymsEnabled() {
484485
args = append(args, "-gdwarf-4")
485486
}
486487

@@ -751,6 +752,7 @@ var (
751752
)
752753

753754
const llgoDebug = "LLGO_DEBUG"
755+
const llgoDbgSyms = "LLGO_DEBUG_SYMBOLS"
754756
const llgoTrace = "LLGO_TRACE"
755757
const llgoOptimize = "LLGO_OPTIMIZE"
756758
const llgoCheck = "LLGO_CHECK"
@@ -768,8 +770,12 @@ func IsTraceEnabled() bool {
768770
return isEnvOn(llgoTrace, false)
769771
}
770772

771-
func IsDebugEnabled() bool {
772-
return isEnvOn(llgoDebug, false)
773+
func IsDbgEnabled() bool {
774+
return isEnvOn(llgoDebug, false) || isEnvOn(llgoDbgSyms, false)
775+
}
776+
777+
func IsDbgSymsEnabled() bool {
778+
return isEnvOn(llgoDbgSyms, false)
773779
}
774780

775781
func IsOptimizeEnabled() bool {

compiler/internal/llgen/llgenf.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ func GenFrom(fileOrPkg string) string {
3333

3434
func genFrom(pkgPath string) (build.Package, error) {
3535
oldDbg := os.Getenv("LLGO_DEBUG")
36+
oldDbgSyms := os.Getenv("LLGO_DEBUG_SYMBOLS")
3637
dbg := isDbgSymEnabled(filepath.Join(pkgPath, "flags.txt"))
3738
if dbg {
3839
os.Setenv("LLGO_DEBUG", "1")
40+
os.Setenv("LLGO_DEBUG_SYMBOLS", "1")
3941
}
40-
defer os.Setenv("LLGO_DEBUG", oldDbg)
42+
defer func() {
43+
os.Setenv("LLGO_DEBUG", oldDbg)
44+
os.Setenv("LLGO_DEBUG_SYMBOLS", oldDbgSyms)
45+
}()
4146

4247
conf := &build.Config{
4348
Mode: build.ModeGen,

compiler/ssa/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ func (p Package) AfterInit(b Builder, ret BasicBlock) {
759759
}
760760
}
761761

762-
func (p Package) InitDebugSymbols(name, pkgPath string, positioner Positioner) {
762+
func (p Package) InitDebug(name, pkgPath string, positioner Positioner) {
763763
p.di = newDIBuilder(p.Prog, p, positioner)
764764
p.cu = p.di.createCompileUnit(name, pkgPath)
765765
}

0 commit comments

Comments
 (0)