From c8b889cc4824f4dbd64a51a3f7b5b6dce4b87ed2 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 7 Mar 2017 18:59:14 +0100 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/internal/obj/data.go | 2 +- src/cmd/internal/obj/link.go | 3 ++- src/cmd/internal/obj/objfile.go | 31 +++++++++++++++++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src/cmd/internal/obj') diff --git a/src/cmd/internal/obj/data.go b/src/cmd/internal/obj/data.go index 114841dedb..7a19e3a38c 100644 --- a/src/cmd/internal/obj/data.go +++ b/src/cmd/internal/obj/data.go @@ -114,7 +114,7 @@ func (s *LSym) WriteInt(ctxt *Link, off int64, siz int, i int64) { // WriteAddr writes an address of size siz into s at offset off. // rsym and roff specify the relocation for the address. func (s *LSym) WriteAddr(ctxt *Link, off int64, siz int, rsym *LSym, roff int64) { - if siz != ctxt.Arch.PtrSize { + if siz != ctxt.Arch.PtrSize && siz != 4 { ctxt.Diag("WriteAddr: bad address size %d in %s", siz, s.Name) } s.prepwrite(ctxt, off, siz) diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index fd07851f3b..e08d7a0340 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -483,6 +483,7 @@ const ( SHOSTOBJ SDWARFSECT SDWARFINFO + SDWARFRANGE SSUB = SymKind(1 << 8) SMASK = SymKind(SSUB - 1) SHIDDEN = SymKind(1 << 9) @@ -739,7 +740,7 @@ type Link struct { Armsize int32 Pc int64 DiagFunc func(string, ...interface{}) - DebugInfo func(fn *LSym, curfn interface{}) []*dwarf.Var // if non-nil, curfn is a *gc.Node + DebugInfo func(fn *LSym, curfn interface{}) []dwarf.Scope // if non-nil, curfn is a *gc.Node Cursym *LSym Version int Errors int diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 6858143674..314c7a9de6 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -542,10 +542,14 @@ func (c dwCtxt) SymValue(s dwarf.Sym) int64 { return 0 } func (c dwCtxt) AddAddress(s dwarf.Sym, data interface{}, value int64) { - rsym := data.(*LSym) ls := s.(*LSym) size := c.PtrSize() - ls.WriteAddr(c.Link, ls.Size, size, rsym, value) + if data != nil { + rsym := data.(*LSym) + ls.WriteAddr(c.Link, ls.Size, size, rsym, value) + } else { + ls.WriteInt(c.Link, ls.Size, size, value) + } } func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64) { ls := s.(*LSym) @@ -555,6 +559,10 @@ func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64 r.Type = R_DWARFREF } +func (s *LSym) Len() int64 { + return s.Size +} + // makeFuncDebugEntry makes a DWARF Debugging Information Entry // for TEXT symbol s. func makeFuncDebugEntry(ctxt *Link, curfn interface{}, s *LSym) { @@ -564,10 +572,21 @@ func makeFuncDebugEntry(ctxt *Link, curfn interface{}, s *LSym) { } dsym.Type = SDWARFINFO dsym.Set(AttrDuplicateOK, s.DuplicateOK()) - var vars []*dwarf.Var + + drsym := ctxt.Lookup(dwarf.RangePrefix+s.Name, int(s.Version)) + if drsym.Size != 0 { + return + } + drsym.Type = SDWARFRANGE + drsym.Set(AttrDuplicateOK, s.DuplicateOK()) + + var scopes []dwarf.Scope if ctxt.DebugInfo != nil { - vars = ctxt.DebugInfo(s, curfn) + scopes = ctxt.DebugInfo(s, curfn) + } + err := dwarf.PutFunc(dwCtxt{ctxt}, dsym, drsym, s.Name, s.Version == 0, s, s.Size, scopes) + if err != nil { + ctxt.Diag("emitting DWARF for %s failed: %v", s.Name, err) } - dwarf.PutFunc(dwCtxt{ctxt}, dsym, s.Name, s.Version == 0, s, s.Size, vars) - ctxt.Data = append(ctxt.Data, dsym) + ctxt.Data = append(ctxt.Data, dsym, drsym) } -- cgit v1.3-5-g9baa