Skip to content

Commit

Permalink
dwtest: fixes for DWARF5 support
Browse files Browse the repository at this point in the history
Fix the var location test harness 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). Also add "-trimpath" to a number of the builds to make it
easier to diff good/bad DWARF.

Updates golang/go#26379.

Change-Id: I708e14e5bb60ba4ebd668e616c4ca37f8d998efc
Reviewed-on: https://go-review.googlesource.com/c/debug/+/636518
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
thanm committed Feb 23, 2025
1 parent 4c9cba1 commit 6e46839
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions dwtest/dwloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func buildHarness(t *testing.T, dir string) (string, string) {

// Run builds.
harnessPath := filepath.Join(dir, "dumpdwloc.exe")
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", harnessPath)
cmd := exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-o", harnessPath)
cmd.Dir = bd
if b, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed (%v): %s", err, b)
}

nooptHarnessPath := filepath.Join(dir, "dumpdwloc.exe")
cmd = exec.Command(testenv.GoToolPath(t), "build", "-gcflags=all=-l -N", "-o", nooptHarnessPath)
cmd = exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-gcflags=all=-l -N", "-o", nooptHarnessPath)
cmd.Dir = bd
if b, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed (%v): %s", err, b)
Expand Down Expand Up @@ -129,7 +129,7 @@ func gobuild(t *testing.T, sourceCode string, pname string, dir string) string {
// A note on this build: Delve currently has problems digesting
// PIE binaries on Windows; until this can be straightened out,
// default to "exe" buildmode.
cmd := exec.Command(testenv.GoToolPath(t), "build", "-buildmode=exe", "-o", epath, spath)
cmd := exec.Command(testenv.GoToolPath(t), "build", "-trimpath", "-buildmode=exe", "-o", epath, spath)
if b, err := cmd.CombinedOutput(); err != nil {
t.Logf("%% build output: %s\n", b)
t.Fatalf("build failed: %s", err)
Expand Down
19 changes: 10 additions & 9 deletions dwtest/testdata/dwdumploc.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,17 @@ func locateFuncDetails(executable string, fcn string) (finfo, error) {

verb(1, "found function %s at offset %x", fcn, off)
rrv.dwOffset = off
if lopc, ok := die.Val(dwarf.AttrLowpc).(uint64); ok {
rrv.dwLoPC = lopc
} else {
return finfo{}, fmt.Errorf("target function seems to be missing LowPC attribute")
}
if hipc, ok := die.Val(dwarf.AttrHighpc).(uint64); ok {
rrv.dwHiPC = hipc
} else {
return finfo{}, fmt.Errorf("target function seems to be missing HighPC attribute")

// 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(die)
if perr != nil {
return finfo{}, fmt.Errorf("sibprog die malformed: %v", perr)
}
rrv.dwLoPC = lowpc
rrv.dwHiPC = highpc
rrv.dwx = &dwx
rrv.name = fcn
rrv.valid = true
Expand Down

0 comments on commit 6e46839

Please sign in to comment.