compiler: set debug info when defining a function

Move attaching debug info to where the function is defined. As LLVM does
not allow setting debug info on declarations, this makes more sense and
is less error-prone.

This commit fixes debug info when using CGo.
Этот коммит содержится в:
Ayke van Laethem 2018-11-15 20:00:00 +01:00
родитель ae3535945c
коммит 1ed019771d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED

Просмотреть файл

@ -854,21 +854,6 @@ func (c *Compiler) parseFuncDecl(f *ir.Function) (*Frame, error) {
frame.fn.LLVMFn = llvm.AddFunction(c.mod, name, fnType)
}
if c.Debug && f.Synthetic == "package initializer" {
difunc, err := c.attachDebugInfoRaw(f, f.LLVMFn, "", "", 0)
if err != nil {
return nil, err
}
frame.difunc = difunc
} else if c.Debug && f.Syntax() != nil && len(f.Blocks) != 0 {
// Create debug info file if needed.
difunc, err := c.attachDebugInfo(f)
if err != nil {
return nil, err
}
frame.difunc = difunc
}
return frame, nil
}
@ -1217,7 +1202,24 @@ func (c *Compiler) parseFunc(frame *Frame) error {
frame.fn.LLVMFn.SetFunctionCallConv(85) // CallingConv::AVR_SIGNAL
}
// Add debug info, if needed.
if c.Debug {
if frame.fn.Synthetic == "package initializer" {
// Package initializers have no debug info. Create some fake debug
// info to at least have *something*.
difunc, err := c.attachDebugInfoRaw(frame.fn, frame.fn.LLVMFn, "", "", 0)
if err != nil {
return err
}
frame.difunc = difunc
} else if frame.fn.Syntax() != nil {
// Create debug info file if needed.
difunc, err := c.attachDebugInfo(frame.fn)
if err != nil {
return err
}
frame.difunc = difunc
}
pos := c.ir.Program.Fset.Position(frame.fn.Pos())
c.builder.SetCurrentDebugLocation(uint(pos.Line), uint(pos.Column), frame.difunc, llvm.Metadata{})
}