compiler: add debug information for function parameters
Add 'optimized-out' parameters to functions. This might make debugging slightly easier by showing parameter names. Sadly I din't get setting variables to work. It might be a bug in CreateExpression.
Этот коммит содержится в:
родитель
43b8c24226
коммит
61e6f7cf5b
1 изменённых файлов: 22 добавлений и 3 удалений
25
compiler.go
25
compiler.go
|
@ -1182,11 +1182,30 @@ func (c *Compiler) parseFunc(frame *Frame) error {
|
||||||
frame.cleanupBlock = c.ctx.AddBasicBlock(frame.fn.llvmFn, "task.cleanup")
|
frame.cleanupBlock = c.ctx.AddBasicBlock(frame.fn.llvmFn, "task.cleanup")
|
||||||
frame.suspendBlock = c.ctx.AddBasicBlock(frame.fn.llvmFn, "task.suspend")
|
frame.suspendBlock = c.ctx.AddBasicBlock(frame.fn.llvmFn, "task.suspend")
|
||||||
}
|
}
|
||||||
|
entryBlock := frame.blocks[frame.fn.fn.Blocks[0]]
|
||||||
|
|
||||||
// Load function parameters
|
// Load function parameters
|
||||||
for _, param := range frame.fn.fn.Params {
|
for i, param := range frame.fn.fn.Params {
|
||||||
llvmParam := frame.fn.llvmFn.Param(frame.params[param])
|
llvmParam := frame.fn.llvmFn.Param(frame.params[param])
|
||||||
frame.locals[param] = llvmParam
|
frame.locals[param] = llvmParam
|
||||||
|
|
||||||
|
// Add debug information to this parameter (if available)
|
||||||
|
if c.debug && frame.fn.fn.Syntax() != nil {
|
||||||
|
pos := c.ir.program.Fset.Position(frame.fn.fn.Syntax().Pos())
|
||||||
|
dityp, err := c.getDIType(param.Type())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.dibuilder.CreateParameterVariable(frame.difunc, llvm.DIParameterVariable{
|
||||||
|
Name: param.Name(),
|
||||||
|
File: c.difiles[pos.Filename],
|
||||||
|
Line: pos.Line,
|
||||||
|
Type: dityp,
|
||||||
|
AlwaysPreserve: true,
|
||||||
|
ArgNo: i + 1,
|
||||||
|
})
|
||||||
|
// TODO: set the value of this parameter.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load free variables from the context. This is a closure (or bound
|
// Load free variables from the context. This is a closure (or bound
|
||||||
|
@ -1195,7 +1214,7 @@ func (c *Compiler) parseFunc(frame *Frame) error {
|
||||||
if !c.ir.FunctionNeedsContext(frame.fn) {
|
if !c.ir.FunctionNeedsContext(frame.fn) {
|
||||||
panic("free variables on function without context")
|
panic("free variables on function without context")
|
||||||
}
|
}
|
||||||
c.builder.SetInsertPointAtEnd(frame.blocks[frame.fn.fn.Blocks[0]])
|
c.builder.SetInsertPointAtEnd(entryBlock)
|
||||||
context := frame.fn.llvmFn.Param(len(frame.fn.fn.Params))
|
context := frame.fn.llvmFn.Param(len(frame.fn.fn.Params))
|
||||||
|
|
||||||
// Determine the context type. It's a struct containing all variables.
|
// Determine the context type. It's a struct containing all variables.
|
||||||
|
@ -1237,7 +1256,7 @@ func (c *Compiler) parseFunc(frame *Frame) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.builder.SetInsertPointAtEnd(frame.blocks[frame.fn.fn.Blocks[0]])
|
c.builder.SetInsertPointAtEnd(entryBlock)
|
||||||
|
|
||||||
if frame.fn.fn.Recover != nil {
|
if frame.fn.fn.Recover != nil {
|
||||||
// Create defer list pointer.
|
// Create defer list pointer.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче