ssa: fix function and global var debug info scope

This commit is contained in:
Li Jie
2024-09-20 12:22:08 +08:00
parent d89b68a279
commit f71e34fd9f
6 changed files with 38 additions and 10 deletions

View File

@@ -309,12 +309,15 @@ def parse_expected_values(source_files):
return test_cases
def execute_tests(executable_path, test_cases, interactive, plugin_path):
def execute_tests(executable_path, test_cases, verbose, interactive, plugin_path):
results = TestResults()
for test_case in test_cases:
debugger = LLDBDebugger(executable_path, plugin_path)
try:
if verbose:
log(f"Setting breakpoint at {
test_case.source_file}:{test_case.end_line}")
debugger.setup()
debugger.set_breakpoint(
test_case.source_file, test_case.end_line)
@@ -356,7 +359,7 @@ def run_tests(executable_path, source_files, verbose, interactive, plugin_path):
', '.join(source_files)} with {executable_path}")
log(f"Found {len(test_cases)} test cases")
results = execute_tests(executable_path, test_cases,
results = execute_tests(executable_path, test_cases, verbose,
interactive, plugin_path)
if not interactive:
print_test_results(results, verbose)

View File

@@ -5,5 +5,5 @@
# lldb -S _lldbtest/runmain.lldb
command script import _lldbtest/main.py
script main.run_tests("cl/_testdata/debug/out", ["cl/_testdata/debug/in.go"], True, True, None)
script main.run_tests("cl/_testdata/debug/out", ["cl/_testdata/debug/in.go"], True, False, None)
quit

View File

@@ -78,7 +78,10 @@ func FuncWithAllTypeStructParam(s StructWithAllTypeFields) {
// s.e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 30}
// s.pad1: 100
// s.pad2: 200
println(len(s.s))
s.i8 = 8
// Expected:
// s.i8: '\x08'
println(len(s.s), s.i8)
}
// Params is a function with all types of parameters.
@@ -125,7 +128,7 @@ func FuncWithAllTypeParams(
fn,
)
// Expected:
// all variables: i8 i16 i32 i64 i u8 u16 u32 u64 u f32 f64 b c64 c128 slice arr arr2 s e f pf pi intr m c err fn globalInt globalStruct globalStructPtr
// all variables: i8 i16 i32 i64 i u8 u16 u32 u64 u f32 f64 b c64 c128 slice arr arr2 s e f pf pi intr m c err fn
// i8: '\x01'
// i16: 2
// i32: 3
@@ -146,6 +149,10 @@ func FuncWithAllTypeParams(
// arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}}
// s: hello
// e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 30}
i8 = 9
// Expected:
// i8: '\x09'
println(i8)
return 1, errors.New("some error")
}
@@ -214,8 +221,17 @@ func main() {
// all variables: globalInt globalStruct globalStructPtr s i err
// s.i8: '\x01'
// s.i16: 2
s.i8 = 0x12
println(s.i8)
// Expected:
// all variables: globalInt globalStruct globalStructPtr s i err
// s.i8: '\x12'
// globalStruct.i8: '\x01'
println((*globalStructPtr).i8)
println("done")
println("")
println(&s, &globalStruct, globalStructPtr.i16, globalStructPtr)
globalStructPtr = nil
}
var globalInt int = 301

View File

@@ -730,15 +730,20 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
// Not a local variable.
return
}
if v.IsAddr {
// skip *ssa.Alloc or *ssa.FieldAddr
if variable.IsField() {
// skip *ssa.FieldAddr
return
}
pos := p.goProg.Fset.Position(v.Pos())
value := p.compileValue(b, v.X)
fn := v.Parent()
dbgVar := p.getLocalVariable(b, fn, variable)
b.DIValue(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
if v.IsAddr {
// *ssa.Alloc
b.DIDeclare(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
} else {
b.DIValue(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
}
}
default:
panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr))

View File

@@ -339,7 +339,7 @@ func (p Function) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
})
p.diFunc = &aDIFunction{
b.di.CreateFunction(
p.Pkg.cu.ll,
b.file(pos.Filename).ll,
llvm.DIFunction{
Type: diFuncType,
Name: p.Name(),

View File

@@ -56,6 +56,10 @@ type aCompilationUnit struct {
type CompilationUnit = *aCompilationUnit
func (c CompilationUnit) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
return &aDIScopeMeta{c.ll}
}
var DWARF_LANG_C llvm.DwarfLang = 0x2
var DWARF_LANG_GO llvm.DwarfLang = 0x16
@@ -576,7 +580,7 @@ func (b Builder) DIGlobal(v Expr, name string, pos token.Position) {
return
}
gv := b.di().createGlobalVariableExpression(
b.di().file(pos.Filename),
b.Pkg.cu,
pos,
name,
name,