x/debug: update dwarf tests.
Change-Id: I191f4bf193be966673a1b96592fe2b864549dfa8
Reviewed-on: https://go-review.googlesource.com/24244
Reviewed-by: Dave Day <djd@golang.org>
diff --git a/dwarf/frame_test.go b/dwarf/frame_test.go
index 6a997a6..2bf41f5 100644
--- a/dwarf/frame_test.go
+++ b/dwarf/frame_test.go
@@ -13,6 +13,8 @@
"runtime"
"strings"
"testing"
+
+ "golang.org/x/debug/dwarf"
)
var (
@@ -48,7 +50,7 @@
}
// This command builds pcsptest from testdata/pcsptest.go.
pcsptestBinary = filepath.Join(pcspTempDir, "pcsptest")
- command := fmt.Sprintf("go tool 6g -o %s.6 testdata/pcsptest.go && go tool 6l -H %s -o %s %s.6",
+ command := fmt.Sprintf("go tool compile -o %s.6 testdata/pcsptest.go && go tool link -H %s -o %s %s.6",
pcsptestBinary, runtime.GOOS, pcsptestBinary, pcsptestBinary)
cmd := exec.Command("sh", "-c", command)
cmd.Stdout = os.Stdout
@@ -77,13 +79,17 @@
if err != nil {
t.Fatal(err)
}
- startPC, err := data.LookupFunction("main.test")
+ entry, err := data.LookupFunction("main.test")
if err != nil {
t.Fatal("lookup startPC:", err)
}
- endPC, err := data.LookupFunction("main.afterTest")
- if err != nil {
- t.Fatal("lookup endPC:", err)
+ startPC, ok := entry.Val(dwarf.AttrLowpc).(uint64)
+ if !ok {
+ t.Fatal(`DWARF data for function "main.test" has no low PC`)
+ }
+ endPC, ok := entry.Val(dwarf.AttrHighpc).(uint64)
+ if !ok {
+ t.Fatal(`DWARF data for function "main.test" has no high PC`)
}
const addrSize = 8 // TODO: Assumes amd64.
diff --git a/dwarf/pclntab_test.go b/dwarf/pclntab_test.go
index d07e632..31ceb78 100644
--- a/dwarf/pclntab_test.go
+++ b/dwarf/pclntab_test.go
@@ -56,7 +56,7 @@
// the resulting binary looks like it was built from pclinetest.s,
// but we have renamed it to keep it away from the go tool.
pclinetestBinary = filepath.Join(pclineTempDir, "pclinetest")
- command := fmt.Sprintf("go tool 6a -o %s.6 ../../gosym/pclinetest.asm && go tool 6l -H %s -E main -o %s %s.6",
+ command := fmt.Sprintf("go tool asm -o %s.6 ../gosym/pclinetest.asm && go tool link -H %s -E main -o %s %s.6",
pclinetestBinary, runtime.GOOS, pclinetestBinary, pclinetestBinary)
cmd := exec.Command("sh", "-c", command)
cmd.Stdout = os.Stdout
@@ -115,20 +115,42 @@
}
// Test PCToLine.
- // TODO: Do much more than this.
- pc, err := data.LookupFunction("linefrompc")
+ entry, err := data.LookupFunction("linefrompc")
if err != nil {
t.Fatal(err)
}
- file, line, err := data.PCToLine(pc)
- if err != nil {
- t.Fatal(err)
+ pc, ok := entry.Val(AttrLowpc).(uint64)
+ if !ok {
+ t.Fatal(`DWARF data for function "linefrompc" has no PC`)
}
- // We expect <longpath>/pclinetest.asm, line 13.
- if !strings.HasSuffix(file, "/pclinetest.asm") {
- t.Errorf("got %s; want %s", file, ".../pclinetest.asm")
- }
- if line != 13 {
- t.Errorf("got %d; want %d", line, 13)
+ for _, tt := range []struct {
+ offset, want uint64
+ }{
+ {0, 2},
+ {1, 3},
+ {2, 4},
+ {3, 4},
+ {4, 5},
+ {6, 5},
+ {7, 6},
+ {11, 6},
+ {12, 7},
+ {19, 7},
+ {20, 8},
+ {32, 8},
+ {33, 9},
+ {53, 9},
+ {54, 10},
+ } {
+ file, line, err := data.PCToLine(pc + tt.offset)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.HasSuffix(file, "/pclinetest.asm") {
+ t.Errorf("got %s; want %s", file, ".../pclinetest.asm")
+ }
+ if line != tt.want {
+ t.Errorf("line for offset %d: got %d; want %d", tt.offset, line, tt.want)
+ }
}
}