Skip to content

Commit

Permalink
internal/gocore: fixes for DWARF5 support
Browse files Browse the repository at this point in the history
Fix some DWARF-related test code to allow for subprogram DIE high_pc
attrs that are offsets from low_pc as opposed to addresses themselves
(this is what the Go compiler will be doing when it generates DWARF5).

Updates golang/go#26379.

Change-Id: I9d7bde7bbc305e01b0e8b61f3f2ed079c987274d
Reviewed-on: https://go-review.googlesource.com/c/debug/+/639177
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
thanm committed Feb 23, 2025
1 parent 6e46839 commit 04bfb7c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/gocore/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"strings"

"golang.org/x/debug/dwtest"
"golang.org/x/debug/internal/core"

"golang.org/x/debug/third_party/delve/dwarf/loclist"
Expand Down Expand Up @@ -395,22 +396,30 @@ func readDWARFVars(p *core.Process, fns *funcTab, dwarfTypeMap map[dwarf.Type]*T
}

if e.Tag == dwarf.TagSubprogram {
lowpc := e.AttrField(dwarf.AttrLowpc)
highpc := e.AttrField(dwarf.AttrHighpc)
if lowpc == nil || highpc == nil {
if e.AttrField(dwarf.AttrLowpc) == nil ||
e.AttrField(dwarf.AttrHighpc) == nil {
continue
}
min := core.Address(lowpc.Val.(uint64) + p.StaticBase())
max := core.Address(highpc.Val.(uint64) + p.StaticBase())
f := fns.find(min)

// Collect the start/end PC for the func. The format/class of
// the high PC attr may vary depending on which DWARF version
// we're generating; invoke a helper to handle the various
// possibilities.
lowpc, highpc, perr := dwtest.SubprogLoAndHighPc(e)
if perr != nil {
return nil, fmt.Errorf("subprog die malformed: %v", perr)
}
fmin := core.Address(lowpc + p.StaticBase())
fmax := core.Address(highpc + p.StaticBase())
f := fns.find(fmin)
if f == nil {
// some func Go doesn't know about. C?
curfn = nil
} else {
if f.entry != min {
if f.entry != fmin {
return nil, errors.New("dwarf and runtime don't agree about start of " + f.name)
}
if fns.find(max-1) != f {
if fns.find(fmax-1) != f {
return nil, errors.New("function ranges don't match for " + f.name)
}
curfn = f
Expand Down

0 comments on commit 04bfb7c

Please sign in to comment.