cmd/compile: output DWARF lexical blocks for local variables

Change compiler and linker to emit DWARF lexical blocks in debug_info.
Version of debug_info is updated from DWARF v.2 to DWARF v.3 since version 2
does not allow lexical blocks with discontinuous ranges.

Second attempt at https://go-review.googlesource.com/#/c/29591/

Remaining open problems:
- scope information is removed from inlined functions
- variables in debug_info do not have DW_AT_start_scope attributes so a
variable will shadow other variables with the same name as soon as its
containing scope begins, before its declaration.

Updates golang/go#12899, golang/go#6913

Change-Id: I0e260a45b564d14a87b88974eb16c5387cb410a5
Reviewed-on: https://go-review.googlesource.com/36879
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Alessandro Arzilli 2017-03-07 18:59:14 +01:00 committed by Matthew Dempsky
parent 7165bcc6ba
commit c8b889cc48
21 changed files with 890 additions and 110 deletions

View file

@ -6,6 +6,7 @@ package gc
import (
"cmd/compile/internal/types"
"cmd/internal/src"
"fmt"
)
@ -17,7 +18,7 @@ func closurehdr(ntype *Node) {
n.Func.Depth = funcdepth
n.Func.Outerfunc = Curfn
funchdr(n)
funchdr(n, src.NoPos)
// steal ntype's argument names and
// leave a fresh copy in their place.
@ -58,7 +59,7 @@ func closurebody(body []*Node) *Node {
func_ := Curfn
func_.Nbody.Set(body)
func_.Func.Endlineno = lineno
funcbody(func_)
funcbody(func_, src.NoPos)
// closure-specific variables are hanging off the
// ordinary ones in the symbol table; see oldname.
@ -226,8 +227,10 @@ func makeclosure(func_ *Node) *Node {
}
xfunc.Nbody.Set(func_.Nbody.Slice())
xfunc.Func.scopes = func_.Func.scopes
xfunc.Func.Dcl = append(func_.Func.Dcl, xfunc.Func.Dcl...)
func_.Func.Dcl = nil
func_.Func.scopes.Scopes = nil
if xfunc.Nbody.Len() == 0 {
Fatalf("empty body - won't generate any code")
}
@ -609,6 +612,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
xfunc.Func.Nname.Sym.SetExported(true) // disable export
xfunc.Func.Nname.Name.Param.Ntype = xtype
xfunc.Func.Nname.Name.Defn = xfunc
xfunc.Func.scopes.Scopes = []src.Scope{src.Scope{}}
declare(xfunc.Func.Nname, PFUNC)
// Declare and initialize variable holding receiver.