Skip to content

Commit 04bfb7c

Browse files
committed
internal/gocore: fixes for DWARF5 support
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 <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 6e46839 commit 04bfb7c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

internal/gocore/dwarf.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"reflect"
1212
"strings"
1313

14+
"golang.org/x/debug/dwtest"
1415
"golang.org/x/debug/internal/core"
1516

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

397398
if e.Tag == dwarf.TagSubprogram {
398-
lowpc := e.AttrField(dwarf.AttrLowpc)
399-
highpc := e.AttrField(dwarf.AttrHighpc)
400-
if lowpc == nil || highpc == nil {
399+
if e.AttrField(dwarf.AttrLowpc) == nil ||
400+
e.AttrField(dwarf.AttrHighpc) == nil {
401401
continue
402402
}
403-
min := core.Address(lowpc.Val.(uint64) + p.StaticBase())
404-
max := core.Address(highpc.Val.(uint64) + p.StaticBase())
405-
f := fns.find(min)
403+
404+
// Collect the start/end PC for the func. The format/class of
405+
// the high PC attr may vary depending on which DWARF version
406+
// we're generating; invoke a helper to handle the various
407+
// possibilities.
408+
lowpc, highpc, perr := dwtest.SubprogLoAndHighPc(e)
409+
if perr != nil {
410+
return nil, fmt.Errorf("subprog die malformed: %v", perr)
411+
}
412+
fmin := core.Address(lowpc + p.StaticBase())
413+
fmax := core.Address(highpc + p.StaticBase())
414+
f := fns.find(fmin)
406415
if f == nil {
407416
// some func Go doesn't know about. C?
408417
curfn = nil
409418
} else {
410-
if f.entry != min {
419+
if f.entry != fmin {
411420
return nil, errors.New("dwarf and runtime don't agree about start of " + f.name)
412421
}
413-
if fns.find(max-1) != f {
422+
if fns.find(fmax-1) != f {
414423
return nil, errors.New("function ranges don't match for " + f.name)
415424
}
416425
curfn = f

0 commit comments

Comments
 (0)