Merge pull request #806 from cpunion/llvm-debug

Debug: fix struct vars debug, params modication, supports expressions, lexical scope/lifecycle
This commit is contained in:
xushiwei
2024-10-29 11:09:00 +08:00
committed by GitHub
19 changed files with 861 additions and 293 deletions

View File

@@ -187,7 +187,14 @@ func Do(args []string, conf *Config) {
return dedup.Check(llssa.PkgPython).Types
})
progSSA := ssa.NewProgram(initial[0].Fset, ssaBuildMode)
buildMode := ssaBuildMode
if cl.DebugSymbols() {
buildMode |= ssa.GlobalDebug
}
if !IsOptimizeEnabled() {
buildMode |= ssa.NaiveForm
}
progSSA := ssa.NewProgram(initial[0].Fset, buildMode)
patches := make(cl.Patches, len(altPkgPaths))
altSSAPkgs(progSSA, patches, altPkgs[1:], verbose)
@@ -237,7 +244,7 @@ func isNeedRuntimeOrPyInit(pkg *packages.Package) (needRuntime, needPyInit bool)
}
const (
ssaBuildMode = ssa.SanityCheckFunctions | ssa.InstantiateGenerics | ssa.GlobalDebug
ssaBuildMode = ssa.SanityCheckFunctions | ssa.InstantiateGenerics
)
type context struct {
@@ -438,7 +445,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, llFiles
}
args = append(args, exargs...)
if cl.DebugSymbols() {
args = append(args, "-gdwarf-5")
args = append(args, "-gdwarf-4")
}
// TODO(xsw): show work
@@ -609,10 +616,22 @@ var (
)
const llgoDebug = "LLGO_DEBUG"
const llgoOptimize = "LLGO_OPTIMIZE"
func isEnvOn(env string, defVal bool) bool {
envVal := strings.ToLower(os.Getenv(env))
if envVal == "" {
return defVal
}
return envVal == "1" || envVal == "true" || envVal == "on"
}
func IsDebugEnabled() bool {
llgoDbgVal := strings.ToLower(os.Getenv(llgoDebug))
return llgoDbgVal == "1" || llgoDbgVal == "true" || llgoDbgVal == "on"
return isEnvOn(llgoDebug, false)
}
func IsOptimizeEnabled() bool {
return isEnvOn(llgoOptimize, true)
}
func ParseArgs(args []string, swflags map[string]bool) (flags, patterns []string, verbose bool) {

View File

@@ -20,16 +20,17 @@ import (
"os"
"github.com/goplus/llgo/cl"
"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/mod"
llssa "github.com/goplus/llgo/ssa"
)
func Init(enableDbg bool) {
func Init() {
llssa.Initialize(llssa.InitAll)
llssa.SetDebug(llssa.DbgFlagAll)
cl.SetDebug(cl.DbgFlagAll)
cl.EnableDebugSymbols(enableDbg)
cl.EnableDebugSymbols(build.IsDebugEnabled())
}
func PkgPath(dir string) string {

View File

@@ -25,6 +25,7 @@ import (
"strings"
"github.com/goplus/llgo/cl"
"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/packages"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
@@ -90,7 +91,14 @@ func genFrom(fileOrPkg string, pkgPath string) string {
initial, err := packages.LoadEx(dedup, prog.TypeSizes, cfg, fileOrPkg)
check(err)
_, pkgs := ssautil.AllPackages(initial, ssa.SanityCheckFunctions|ssa.InstantiateGenerics|ssa.GlobalDebug)
buildMode := ssa.SanityCheckFunctions | ssa.InstantiateGenerics
if build.IsDebugEnabled() {
buildMode |= ssa.GlobalDebug
}
if !build.IsOptimizeEnabled() {
buildMode |= ssa.NaiveForm
}
_, pkgs := ssautil.AllPackages(initial, buildMode)
pkg := initial[0]
ssaPkg := pkgs[0]