aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2022-12-14 13:36:19 -0500
committerGopher Robot <gobot@golang.org>2023-01-30 15:19:41 +0000
commit9e45b1d53e4f4c19863bb36276e019b96b8764c0 (patch)
treeb4434fedbae944479764f2efbb8229347c65c038 /src/cmd/internal
parentee5ce77c62483933ae4d5dbdbcbadf6f82dd3f6c (diff)
downloadgo-9e45b1d53e4f4c19863bb36276e019b96b8764c0.tar.xz
cmd/compile,cmd/link: set DW_AT_decl_line for function declarations
DW_AT_decl_line provides the line number of function declarations (the line containing the func keyword). This is the equivalent to CL 429638, but provided via DWARF. Note that the file of declarations (DW_AT_decl_file) is already provided for non-inlined functions. It is omitted for inlined functions because those DWARF subprograms may be generated outside of their source compilation unit, where referencing the file table is difficult. Fixes #57308. Change-Id: I3ad12e1f366c4465c2a588297988a5825ef7efec Reviewed-on: https://go-review.googlesource.com/c/go/+/458195 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/dwarf/dwarf.go7
-rw-r--r--src/cmd/internal/obj/dwarf.go12
-rw-r--r--src/cmd/internal/obj/link.go2
3 files changed, 18 insertions, 3 deletions
diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go
index a6d19c61d1..d4a4e33652 100644
--- a/src/cmd/internal/dwarf/dwarf.go
+++ b/src/cmd/internal/dwarf/dwarf.go
@@ -94,6 +94,7 @@ type FnState struct {
Absfn Sym
StartPC Sym
Size int64
+ StartLine int32
External bool
Scopes []Scope
InlCalls InlCalls
@@ -458,6 +459,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_high_pc, DW_FORM_addr},
{DW_AT_frame_base, DW_FORM_block1},
{DW_AT_decl_file, DW_FORM_data4},
+ {DW_AT_decl_line, DW_FORM_udata},
{DW_AT_external, DW_FORM_flag},
},
},
@@ -482,6 +484,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
[]dwAttrForm{
{DW_AT_name, DW_FORM_string},
{DW_AT_inline, DW_FORM_data1},
+ {DW_AT_decl_line, DW_FORM_udata},
{DW_AT_external, DW_FORM_flag},
},
},
@@ -1254,6 +1257,8 @@ func PutAbstractFunc(ctxt Context, s *FnState) error {
// DW_AT_inlined value
putattr(ctxt, s.Absfn, abbrev, DW_FORM_data1, DW_CLS_CONSTANT, int64(DW_INL_inlined), nil)
+ putattr(ctxt, s.Absfn, abbrev, DW_FORM_udata, DW_CLS_CONSTANT, int64(s.StartLine), nil)
+
var ev int64
if s.External {
ev = 1
@@ -1446,6 +1451,8 @@ func PutDefaultFunc(ctxt Context, s *FnState, isWrapper bool) error {
putattr(ctxt, s.Info, abbrev, DW_FORM_flag, DW_CLS_FLAG, int64(1), 0)
} else {
ctxt.AddFileRef(s.Info, s.Filesym)
+ putattr(ctxt, s.Info, abbrev, DW_FORM_udata, DW_CLS_CONSTANT, int64(s.StartLine), nil)
+
var ev int64
if s.External {
ev = 1
diff --git a/src/cmd/internal/obj/dwarf.go b/src/cmd/internal/obj/dwarf.go
index a9c13fdc8c..121a9f6ee9 100644
--- a/src/cmd/internal/obj/dwarf.go
+++ b/src/cmd/internal/obj/dwarf.go
@@ -353,7 +353,9 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym, myimportpath string)
var scopes []dwarf.Scope
var inlcalls dwarf.InlCalls
if ctxt.DebugInfo != nil {
- scopes, inlcalls = ctxt.DebugInfo(s, info, curfn)
+ // Don't need startPos because s.Func().StartLine is populated,
+ // as s is in this package.
+ scopes, inlcalls, _ = ctxt.DebugInfo(s, info, curfn)
}
var err error
dwctxt := dwCtxt{ctxt}
@@ -368,6 +370,7 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym, myimportpath string)
Absfn: absfunc,
StartPC: s,
Size: s.Size,
+ StartLine: s.Func().StartLine,
External: !s.Static(),
Scopes: scopes,
InlCalls: inlcalls,
@@ -427,8 +430,12 @@ func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym, myimportpath str
if s.Func() == nil {
s.NewFuncInfo()
}
- scopes, _ := ctxt.DebugInfo(s, absfn, curfn)
+ scopes, _, startPos := ctxt.DebugInfo(s, absfn, curfn)
+ _, startLine := ctxt.getFileSymbolAndLine(startPos)
dwctxt := dwCtxt{ctxt}
+ // TODO(prattmic): this returns nil for symbols outside of the current
+ // package because s.Func() is empty. This doesn't matter because
+ // PutAbstractFunc doesn't use Filesym. Use startPos or remove.
filesym := ctxt.fileSymbol(s)
fnstate := dwarf.FnState{
Name: s.Name,
@@ -436,6 +443,7 @@ func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym, myimportpath str
Info: absfn,
Filesym: filesym,
Absfn: absfn,
+ StartLine: startLine,
External: !s.Static(),
Scopes: scopes,
UseBASEntries: ctxt.UseBASEntries,
diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index 80370173af..6d40b334af 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -916,7 +916,7 @@ type Link struct {
Imports []goobj.ImportedPkg
DiagFunc func(string, ...interface{})
DiagFlush func()
- DebugInfo func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls) // if non-nil, curfn is a *gc.Node
+ DebugInfo func(fn *LSym, info *LSym, curfn interface{}) ([]dwarf.Scope, dwarf.InlCalls, src.XPos) // if non-nil, curfn is a *ir.Func
GenAbstractFunc func(fn *LSym)
Errors int