summaryrefslogtreecommitdiff
path: root/src/pkg/debug/gosym/pclntab_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/debug/gosym/pclntab_test.go')
-rw-r--r--src/pkg/debug/gosym/pclntab_test.go110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/pkg/debug/gosym/pclntab_test.go b/src/pkg/debug/gosym/pclntab_test.go
index 66609d9cf..9ab493d59 100644
--- a/src/pkg/debug/gosym/pclntab_test.go
+++ b/src/pkg/debug/gosym/pclntab_test.go
@@ -5,10 +5,10 @@
package gosym
import (
- "debug/elf";
- "os";
- "testing";
- "syscall";
+ "debug/elf"
+ "os"
+ "testing"
+ "syscall"
)
func dotest() bool {
@@ -17,40 +17,40 @@ func dotest() bool {
}
func getTable(t *testing.T) *Table {
- f, tab := crack(os.Args[0], t);
- f.Close();
- return tab;
+ f, tab := crack(os.Args[0], t)
+ f.Close()
+ return tab
}
func crack(file string, t *testing.T) (*elf.File, *Table) {
// Open self
- f, err := elf.Open(file);
+ f, err := elf.Open(file)
if err != nil {
t.Fatal(err)
}
- return parse(file, f, t);
+ return parse(file, f, t)
}
func parse(file string, f *elf.File, t *testing.T) (*elf.File, *Table) {
- symdat, err := f.Section(".gosymtab").Data();
+ symdat, err := f.Section(".gosymtab").Data()
if err != nil {
- f.Close();
- t.Fatalf("reading %s gosymtab: %v", file, err);
+ f.Close()
+ t.Fatalf("reading %s gosymtab: %v", file, err)
}
- pclndat, err := f.Section(".gopclntab").Data();
+ pclndat, err := f.Section(".gopclntab").Data()
if err != nil {
- f.Close();
- t.Fatalf("reading %s gopclntab: %v", file, err);
+ f.Close()
+ t.Fatalf("reading %s gopclntab: %v", file, err)
}
- pcln := NewLineTable(pclndat, f.Section(".text").Addr);
- tab, err := NewTable(symdat, pcln);
+ pcln := NewLineTable(pclndat, f.Section(".text").Addr)
+ tab, err := NewTable(symdat, pcln)
if err != nil {
- f.Close();
- t.Fatalf("parsing %s gosymtab: %v", file, err);
+ f.Close()
+ t.Fatalf("parsing %s gosymtab: %v", file, err)
}
- return f, tab;
+ return f, tab
}
var goarch = os.Getenv("O")
@@ -60,42 +60,42 @@ func TestLineFromAline(t *testing.T) {
return
}
- tab := getTable(t);
+ tab := getTable(t)
// Find the sym package
- pkg := tab.LookupFunc("gosym.TestLineFromAline").Obj;
+ pkg := tab.LookupFunc("gosym.TestLineFromAline").Obj
if pkg == nil {
t.Fatalf("nil pkg")
}
// Walk every absolute line and ensure that we hit every
// source line monotonically
- lastline := make(map[string]int);
- final := -1;
+ lastline := make(map[string]int)
+ final := -1
for i := 0; i < 10000; i++ {
- path, line := pkg.lineFromAline(i);
+ path, line := pkg.lineFromAline(i)
// Check for end of object
if path == "" {
if final == -1 {
final = i - 1
}
- continue;
+ continue
} else if final != -1 {
t.Fatalf("reached end of package at absolute line %d, but absolute line %d mapped to %s:%d", final, i, path, line)
}
// It's okay to see files multiple times (e.g., sys.a)
if line == 1 {
- lastline[path] = 1;
- continue;
+ lastline[path] = 1
+ continue
}
// Check that the is the next line in path
- ll, ok := lastline[path];
+ ll, ok := lastline[path]
if !ok {
t.Errorf("file %s starts on line %d", path, line)
} else if line != ll+1 {
t.Errorf("expected next line of file %s to be %d, got %d", path, ll+1, line)
}
- lastline[path] = line;
+ lastline[path] = line
}
if final == -1 {
t.Errorf("never reached end of object")
@@ -107,15 +107,15 @@ func TestLineAline(t *testing.T) {
return
}
- tab := getTable(t);
+ tab := getTable(t)
for _, o := range tab.Files {
// A source file can appear multiple times in a
// object. alineFromLine will always return alines in
// the first file, so track which lines we've seen.
- found := make(map[string]int);
+ found := make(map[string]int)
for i := 0; i < 1000; i++ {
- path, line := o.lineFromAline(i);
+ path, line := o.lineFromAline(i)
if path == "" {
break
}
@@ -131,9 +131,9 @@ func TestLineAline(t *testing.T) {
continue
}
}
- found[path] = line;
+ found[path] = line
- a, err := o.alineFromLine(path, line);
+ a, err := o.alineFromLine(path, line)
if err != nil {
t.Errorf("absolute line %d in object %s maps to %s:%d, but mapping that back gives error %s", i, o.Paths[0].Name, path, line, err)
} else if a != i {
@@ -151,20 +151,20 @@ func TestPCLine(t *testing.T) {
return
}
- f, tab := crack("_test/pclinetest", t);
- text := f.Section(".text");
- textdat, err := text.Data();
+ f, tab := crack("_test/pclinetest", t)
+ text := f.Section(".text")
+ textdat, err := text.Data()
if err != nil {
t.Fatalf("reading .text: %v", err)
}
// Test PCToLine
- sym := tab.LookupFunc("linefrompc");
- wantLine := 0;
+ sym := tab.LookupFunc("linefrompc")
+ wantLine := 0
for pc := sym.Entry; pc < sym.End; pc++ {
- file, line, fn := tab.PCToLine(pc);
- off := pc - text.Addr; // TODO(rsc): should not need off; bug in 8g
- wantLine += int(textdat[off]);
+ file, line, fn := tab.PCToLine(pc)
+ off := pc - text.Addr // TODO(rsc): should not need off; bug in 8g
+ wantLine += int(textdat[off])
if fn == nil {
t.Errorf("failed to get line of PC %#x", pc)
} else if len(file) < 12 || file[len(file)-12:] != "pclinetest.s" || line != wantLine || fn != sym {
@@ -173,24 +173,24 @@ func TestPCLine(t *testing.T) {
}
// Test LineToPC
- sym = tab.LookupFunc("pcfromline");
- lookupline := -1;
- wantLine = 0;
- off := uint64(0); // TODO(rsc): should not need off; bug in 8g
+ sym = tab.LookupFunc("pcfromline")
+ lookupline := -1
+ wantLine = 0
+ off := uint64(0) // TODO(rsc): should not need off; bug in 8g
for pc := sym.Value; pc < sym.End; pc += 2 + uint64(textdat[off]) {
- file, line, fn := tab.PCToLine(pc);
- off = pc - text.Addr;
- wantLine += int(textdat[off]);
+ file, line, fn := tab.PCToLine(pc)
+ off = pc - text.Addr
+ wantLine += int(textdat[off])
if line != wantLine {
- t.Errorf("expected line %d at PC %#x in pcfromline, got %d", wantLine, pc, line);
- off = pc + 1 - text.Addr;
- continue;
+ t.Errorf("expected line %d at PC %#x in pcfromline, got %d", wantLine, pc, line)
+ off = pc + 1 - text.Addr
+ continue
}
if lookupline == -1 {
lookupline = line
}
for ; lookupline <= line; lookupline++ {
- pc2, fn2, err := tab.LineToPC(file, lookupline);
+ pc2, fn2, err := tab.LineToPC(file, lookupline)
if lookupline != line {
// Should be nothing on this line
if err == nil {
@@ -202,6 +202,6 @@ func TestPCLine(t *testing.T) {
t.Errorf("expected PC %#x (%s) at line %d, got PC %#x (%s)", pc, fn.Name, line, pc2, fn2.Name)
}
}
- off = pc + 1 - text.Addr;
+ off = pc + 1 - text.Addr
}
}