Commit 1c729599 authored by Robert Griesemer's avatar Robert Griesemer

1) Change default gofmt default settings for

                  parsing and printing to new syntax.

                  Use -oldparser to parse the old syntax,
                  use -oldprinter to print the old syntax.

               2) Change default gofmt formatting settings
                  to use tabs for indentation only and to use
                  spaces for alignment. This will make the code
                  alignment insensitive to an editor's tabwidth.

                  Use -spaces=false to use tabs for alignment.

               3) Manually changed src/exp/parser/parser_test.go
                  so that it doesn't try to parse the parser's
                  source files using the old syntax (they have
                  new syntax now).

               4) gofmt -w src misc test/bench

	       2nd set of files.

R=rsc
CC=golang-dev
https://golang.org/cl/179067
parent d122bb21
......@@ -7,20 +7,20 @@
package dwarf
import (
"encoding/binary";
"os";
"strconv";
"encoding/binary"
"os"
"strconv"
)
// Data buffer being decoded.
type buf struct {
dwarf *Data;
order binary.ByteOrder;
name string;
off Offset;
data []byte;
addrsize int;
err os.Error;
dwarf *Data
order binary.ByteOrder
name string
off Offset
data []byte
addrsize int
err os.Error
}
func makeBuf(d *Data, name string, off Offset, data []byte, addrsize int) buf {
......@@ -29,95 +29,95 @@ func makeBuf(d *Data, name string, off Offset, data []byte, addrsize int) buf {
func (b *buf) uint8() uint8 {
if len(b.data) < 1 {
b.error("underflow");
return 0;
b.error("underflow")
return 0
}
val := b.data[0];
b.data = b.data[1:];
b.off++;
return val;
val := b.data[0]
b.data = b.data[1:]
b.off++
return val
}
func (b *buf) bytes(n int) []byte {
if len(b.data) < n {
b.error("underflow");
return nil;
b.error("underflow")
return nil
}
data := b.data[0:n];
b.data = b.data[n:];
b.off += Offset(n);
return data;
data := b.data[0:n]
b.data = b.data[n:]
b.off += Offset(n)
return data
}
func (b *buf) skip(n int) { b.bytes(n) }
func (b *buf) skip(n int) { b.bytes(n) }
func (b *buf) string() string {
for i := 0; i < len(b.data); i++ {
if b.data[i] == 0 {
s := string(b.data[0:i]);
b.data = b.data[i+1:];
b.off += Offset(i + 1);
return s;
s := string(b.data[0:i])
b.data = b.data[i+1:]
b.off += Offset(i + 1)
return s
}
}
b.error("underflow");
return "";
b.error("underflow")
return ""
}
func (b *buf) uint16() uint16 {
a := b.bytes(2);
a := b.bytes(2)
if a == nil {
return 0
}
return b.order.Uint16(a);
return b.order.Uint16(a)
}
func (b *buf) uint32() uint32 {
a := b.bytes(4);
a := b.bytes(4)
if a == nil {
return 0
}
return b.order.Uint32(a);
return b.order.Uint32(a)
}
func (b *buf) uint64() uint64 {
a := b.bytes(8);
a := b.bytes(8)
if a == nil {
return 0
}
return b.order.Uint64(a);
return b.order.Uint64(a)
}
// Read a varint, which is 7 bits per byte, little endian.
// the 0x80 bit means read another byte.
func (b *buf) varint() (c uint64, bits uint) {
for i := 0; i < len(b.data); i++ {
byte := b.data[i];
c |= uint64(byte&0x7F) << bits;
bits += 7;
byte := b.data[i]
c |= uint64(byte&0x7F) << bits
bits += 7
if byte&0x80 == 0 {
b.off += Offset(i + 1);
b.data = b.data[i+1:];
return c, bits;
b.off += Offset(i + 1)
b.data = b.data[i+1:]
return c, bits
}
}
return 0, 0;
return 0, 0
}
// Unsigned int is just a varint.
func (b *buf) uint() uint64 {
x, _ := b.varint();
return x;
x, _ := b.varint()
return x
}
// Signed int is a sign-extended varint.
func (b *buf) int() int64 {
ux, bits := b.varint();
x := int64(ux);
ux, bits := b.varint()
x := int64(ux)
if x&(1<<(bits-1)) != 0 {
x |= -1 << bits
}
return x;
return x
}
// Address-sized uint.
......@@ -132,21 +132,21 @@ func (b *buf) addr() uint64 {
case 8:
return uint64(b.uint64())
}
b.error("unknown address size");
return 0;
b.error("unknown address size")
return 0
}
func (b *buf) error(s string) {
if b.err == nil {
b.data = nil;
b.err = DecodeError{b.name, b.off, s};
b.data = nil
b.err = DecodeError{b.name, b.off, s}
}
}
type DecodeError struct {
Name string;
Offset Offset;
Error string;
Name string
Offset Offset
Error string
}
func (e DecodeError) String() string {
......
This diff is collapsed.
......@@ -14,14 +14,14 @@ import "os"
// a single entry's description: a sequence of attributes
type abbrev struct {
tag Tag;
children bool;
field []afield;
tag Tag
children bool
field []afield
}
type afield struct {
attr Attr;
fmt format;
attr Attr
fmt format
}
// a map from entry format ids to their descriptions
......@@ -34,74 +34,74 @@ func (d *Data) parseAbbrev(off uint32) (abbrevTable, os.Error) {
return m, nil
}
data := d.abbrev;
data := d.abbrev
if off > uint32(len(data)) {
data = nil
} else {
data = data[off:]
}
b := makeBuf(d, "abbrev", 0, data, 0);
b := makeBuf(d, "abbrev", 0, data, 0)
// Error handling is simplified by the buf getters
// returning an endless stream of 0s after an error.
m := make(abbrevTable);
m := make(abbrevTable)
for {
// Table ends with id == 0.
id := uint32(b.uint());
id := uint32(b.uint())
if id == 0 {
break
}
// Walk over attributes, counting.
n := 0;
b1 := b; // Read from copy of b.
b1.uint();
b1.uint8();
n := 0
b1 := b // Read from copy of b.
b1.uint()
b1.uint8()
for {
tag := b1.uint();
fmt := b1.uint();
tag := b1.uint()
fmt := b1.uint()
if tag == 0 && fmt == 0 {
break
}
n++;
n++
}
if b1.err != nil {
return nil, b1.err
}
// Walk over attributes again, this time writing them down.
var a abbrev;
a.tag = Tag(b.uint());
a.children = b.uint8() != 0;
a.field = make([]afield, n);
var a abbrev
a.tag = Tag(b.uint())
a.children = b.uint8() != 0
a.field = make([]afield, n)
for i := range a.field {
a.field[i].attr = Attr(b.uint());
a.field[i].fmt = format(b.uint());
a.field[i].attr = Attr(b.uint())
a.field[i].fmt = format(b.uint())
}
b.uint();
b.uint();
b.uint()
b.uint()
m[id] = a;
m[id] = a
}
if b.err != nil {
return nil, b.err
}
d.abbrevCache[off] = m;
return m, nil;
d.abbrevCache[off] = m
return m, nil
}
// An entry is a sequence of attribute/value pairs.
type Entry struct {
Offset Offset; // offset of Entry in DWARF info
Tag Tag; // tag (kind of Entry)
Children bool; // whether Entry is followed by children
Field []Field;
Offset Offset // offset of Entry in DWARF info
Tag Tag // tag (kind of Entry)
Children bool // whether Entry is followed by children
Field []Field
}
// A Field is a single attribute/value pair in an Entry.
type Field struct {
Attr Attr;
Val interface{};
Attr Attr
Val interface{}
}
// Val returns the value associated with attribute Attr in Entry,
......@@ -117,7 +117,7 @@ func (e *Entry) Val(a Attr) interface{} {
return f.Val
}
}
return nil;
return nil
}
// An Offset represents the location of an Entry within the DWARF info.
......@@ -127,25 +127,25 @@ type Offset uint32
// Entry reads a single entry from buf, decoding
// according to the given abbreviation table.
func (b *buf) entry(atab abbrevTable, ubase Offset) *Entry {
off := b.off;
id := uint32(b.uint());
off := b.off
id := uint32(b.uint())
if id == 0 {
return &Entry{}
}
a, ok := atab[id];
a, ok := atab[id]
if !ok {
b.error("unknown abbreviation table index");
return nil;
b.error("unknown abbreviation table index")
return nil
}
e := &Entry{
Offset: off,
Tag: a.tag,
Children: a.children,
Field: make([]Field, len(a.field)),
};
}
for i := range e.Field {
e.Field[i].Attr = a.field[i].attr;
fmt := a.field[i].fmt;
e.Field[i].Attr = a.field[i].attr
fmt := a.field[i].fmt
if fmt == formIndirect {
fmt = format(b.uint())
}
......@@ -204,24 +204,24 @@ func (b *buf) entry(atab abbrevTable, ubase Offset) *Entry {
case formString:
val = b.string()
case formStrp:
off := b.uint32(); // offset into .debug_str
off := b.uint32() // offset into .debug_str
if b.err != nil {
return nil
}
b1 := makeBuf(b.dwarf, "str", 0, b.dwarf.str, 0);
b1.skip(int(off));
val = b1.string();
b1 := makeBuf(b.dwarf, "str", 0, b.dwarf.str, 0)
b1.skip(int(off))
val = b1.string()
if b1.err != nil {
b.err = b1.err;
return nil;
b.err = b1.err
return nil
}
}
e.Field[i].Val = val;
e.Field[i].Val = val
}
if b.err != nil {
return nil
}
return e;
return e
}
// A Reader allows reading Entry structures from a DWARF ``info'' section.
......@@ -230,58 +230,58 @@ func (b *buf) entry(atab abbrevTable, ubase Offset) *Entry {
// If an entry has children, its Children field will be true, and the children
// follow, terminated by an Entry with Tag 0.
type Reader struct {
b buf;
d *Data;
err os.Error;
unit int;
lastChildren bool; // .Children of last entry returned by Next
lastSibling Offset; // .Val(AttrSibling) of last entry returned by Next
b buf
d *Data
err os.Error
unit int
lastChildren bool // .Children of last entry returned by Next
lastSibling Offset // .Val(AttrSibling) of last entry returned by Next
}
// Reader returns a new Reader for Data.
// The reader is positioned at byte offset 0 in the DWARF ``info'' section.
func (d *Data) Reader() *Reader {
r := &Reader{d: d};
r.Seek(0);
return r;
r := &Reader{d: d}
r.Seek(0)
return r
}
// Seek positions the Reader at offset off in the encoded entry stream.
// Offset 0 can be used to denote the first entry.
func (r *Reader) Seek(off Offset) {
d := r.d;
r.err = nil;
r.lastChildren = false;
d := r.d
r.err = nil
r.lastChildren = false
if off == 0 {
if len(d.unit) == 0 {
return
}
u := &d.unit[0];
r.unit = 0;
r.b = makeBuf(r.d, "info", u.off, u.data, u.addrsize);
return;
u := &d.unit[0]
r.unit = 0
r.b = makeBuf(r.d, "info", u.off, u.data, u.addrsize)
return
}
// TODO(rsc): binary search (maybe a new package)
var i int;
var u *unit;
var i int
var u *unit
for i = range d.unit {
u = &d.unit[i];
u = &d.unit[i]
if u.off <= off && off < u.off+Offset(len(u.data)) {
r.unit = i;
r.b = makeBuf(r.d, "info", off, u.data[off-u.off:], u.addrsize);
return;
r.unit = i
r.b = makeBuf(r.d, "info", off, u.data[off-u.off:], u.addrsize)
return
}
}
r.err = os.NewError("offset out of range");
r.err = os.NewError("offset out of range")
}
// maybeNextUnit advances to the next unit if this one is finished.
func (r *Reader) maybeNextUnit() {
for len(r.b.data) == 0 && r.unit+1 < len(r.d.unit) {
r.unit++;
u := &r.d.unit[r.unit];
r.b = makeBuf(r.d, "info", u.off, u.data, u.addrsize);
r.unit++
u := &r.d.unit[r.unit]
r.b = makeBuf(r.d, "info", u.off, u.data, u.addrsize)
}
}
......@@ -293,25 +293,25 @@ func (r *Reader) Next() (*Entry, os.Error) {
if r.err != nil {
return nil, r.err
}
r.maybeNextUnit();
r.maybeNextUnit()
if len(r.b.data) == 0 {
return nil, nil
}
u := &r.d.unit[r.unit];
e := r.b.entry(u.atable, u.base);
u := &r.d.unit[r.unit]
e := r.b.entry(u.atable, u.base)
if r.b.err != nil {
r.err = r.b.err;
return nil, r.err;
r.err = r.b.err
return nil, r.err
}
if e != nil {
r.lastChildren = e.Children;
r.lastChildren = e.Children
if r.lastChildren {
r.lastSibling, _ = e.Val(AttrSibling).(Offset)
}
} else {
r.lastChildren = false
}
return e, nil;
return e, nil
}
// SkipChildren skips over the child entries associated with
......@@ -327,12 +327,12 @@ func (r *Reader) SkipChildren() {
// sibling, so we can avoid decoding the
// child subtrees.
if r.lastSibling >= r.b.off {
r.Seek(r.lastSibling);
return;
r.Seek(r.lastSibling)
return
}
for {
e, err := r.Next();
e, err := r.Next()
if err != nil || e == nil || e.Tag == 0 {
break
}
......
......@@ -8,29 +8,29 @@
package dwarf
import (
"encoding/binary";
"os";
"encoding/binary"
"os"
)
// Data represents the DWARF debugging information
// loaded from an executable file (for example, an ELF or Mach-O executable).
type Data struct {
// raw data
abbrev []byte;
aranges []byte;
frame []byte;
info []byte;
line []byte;
pubnames []byte;
ranges []byte;
str []byte;
abbrev []byte
aranges []byte
frame []byte
info []byte
line []byte
pubnames []byte
ranges []byte
str []byte
// parsed data
abbrevCache map[uint32]abbrevTable;
addrsize int;
order binary.ByteOrder;
typeCache map[Offset]Type;
unit []unit;
abbrevCache map[uint32]abbrevTable
addrsize int
order binary.ByteOrder
typeCache map[Offset]Type
unit []unit
}
// New returns a new Data object initialized from the given parameters.
......@@ -52,14 +52,14 @@ func New(abbrev, aranges, frame, info, line, pubnames, ranges, str []byte) (*Dat
str: str,
abbrevCache: make(map[uint32]abbrevTable),
typeCache: make(map[Offset]Type),
};
}
// Sniff .debug_info to figure out byte order.
// bytes 4:6 are the version, a tiny 16-bit number (1, 2, 3).
if len(d.info) < 6 {
return nil, DecodeError{"info", Offset(len(d.info)), "too short"}
}
x, y := d.info[4], d.info[5];
x, y := d.info[4], d.info[5]
switch {
case x == 0 && y == 0:
return nil, DecodeError{"info", 4, "unsupported version 0"}
......@@ -71,10 +71,10 @@ func New(abbrev, aranges, frame, info, line, pubnames, ranges, str []byte) (*Dat
return nil, DecodeError{"info", 4, "cannot determine byte order"}
}
u, err := d.parseUnits();
u, err := d.parseUnits()
if err != nil {
return nil, err
}
d.unit = u;
return d, nil;
d.unit = u
return d, nil
}
This diff is collapsed.
......@@ -5,10 +5,10 @@
package dwarf_test
import (
. "debug/dwarf";
"debug/elf";
"debug/macho";
"testing";
. "debug/dwarf"
"debug/elf"
"debug/macho"
"testing"
)
var typedefTests = map[string]string{
......@@ -30,43 +30,43 @@ var typedefTests = map[string]string{
}
func elfData(t *testing.T, name string) *Data {
f, err := elf.Open(name);
f, err := elf.Open(name)
if err != nil {
t.Fatal(err)
}
d, err := f.DWARF();
d, err := f.DWARF()
if err != nil {
t.Fatal(err)
}
return d;
return d
}
func machoData(t *testing.T, name string) *Data {
f, err := macho.Open(name);
f, err := macho.Open(name)
if err != nil {
t.Fatal(err)
}
d, err := f.DWARF();
d, err := f.DWARF()
if err != nil {
t.Fatal(err)
}
return d;
return d
}
func TestTypedefsELF(t *testing.T) { testTypedefs(t, elfData(t, "testdata/typedef.elf")) }
func TestTypedefsELF(t *testing.T) { testTypedefs(t, elfData(t, "testdata/typedef.elf")) }
func TestTypedefsMachO(t *testing.T) {
testTypedefs(t, machoData(t, "testdata/typedef.macho"))
}
func testTypedefs(t *testing.T, d *Data) {
r := d.Reader();
seen := make(map[string]bool);
r := d.Reader()
seen := make(map[string]bool)
for {
e, err := r.Next();
e, err := r.Next()
if err != nil {
t.Fatal("r.Next:", err)
}
......@@ -74,12 +74,12 @@ func testTypedefs(t *testing.T, d *Data) {
break
}
if e.Tag == TagTypedef {
typ, err := d.Type(e.Offset);
typ, err := d.Type(e.Offset)
if err != nil {
t.Fatal("d.Type:", err)
}
t1 := typ.(*TypedefType);
var typstr string;
t1 := typ.(*TypedefType)
var typstr string
if ts, ok := t1.Type.(*StructType); ok {
typstr = ts.Defn()
} else {
......@@ -90,7 +90,7 @@ func testTypedefs(t *testing.T, d *Data) {
if _, ok := seen[t1.Name]; ok {
t.Errorf("multiple definitions for %s", t1.Name)
}
seen[t1.Name] = true;
seen[t1.Name] = true
if typstr != want {
t.Errorf("%s:\n\thave %s\n\twant %s", t1.Name, typstr, want)
}
......
......@@ -5,58 +5,58 @@
package dwarf
import (
"os";
"strconv";
"os"
"strconv"
)
// DWARF debug info is split into a sequence of compilation units.
// Each unit has its own abbreviation table and address size.
type unit struct {
base Offset; // byte offset of header within the aggregate info
off Offset; // byte offset of data within the aggregate info
data []byte;
atable abbrevTable;
addrsize int;
base Offset // byte offset of header within the aggregate info
off Offset // byte offset of data within the aggregate info
data []byte
atable abbrevTable
addrsize int
}
func (d *Data) parseUnits() ([]unit, os.Error) {
// Count units.
nunit := 0;
b := makeBuf(d, "info", 0, d.info, 0);
nunit := 0
b := makeBuf(d, "info", 0, d.info, 0)
for len(b.data) > 0 {
b.skip(int(b.uint32()));
nunit++;
b.skip(int(b.uint32()))
nunit++
}
if b.err != nil {
return nil, b.err
}
// Again, this time writing them down.
b = makeBuf(d, "info", 0, d.info, 0);
units := make([]unit, nunit);
b = makeBuf(d, "info", 0, d.info, 0)
units := make([]unit, nunit)
for i := range units {
u := &units[i];
u.base = b.off;
n := b.uint32();
u := &units[i]
u.base = b.off
n := b.uint32()
if vers := b.uint16(); vers != 2 {
b.error("unsupported DWARF version " + strconv.Itoa(int(vers)));
break;
b.error("unsupported DWARF version " + strconv.Itoa(int(vers)))
break
}
atable, err := d.parseAbbrev(b.uint32());
atable, err := d.parseAbbrev(b.uint32())
if err != nil {
if b.err == nil {
b.err = err
}
break;
break
}
u.atable = atable;
u.addrsize = int(b.uint8());
u.off = b.off;
u.data = b.bytes(int(n - (2 + 4 + 1)));
u.atable = atable
u.addrsize = int(b.uint8())
u.off = b.off
u.data = b.bytes(int(n - (2 + 4 + 1)))
}
if b.err != nil {
return nil, b.err
}
return units, nil;
return units, nil
}
This diff is collapsed.
......@@ -5,13 +5,13 @@
package elf
import (
"fmt";
"testing";
"fmt"
"testing"
)
type nameTest struct {
val interface{};
str string;
val interface{}
str string
}
var nameTests = []nameTest{
......@@ -41,7 +41,7 @@ var nameTests = []nameTest{
func TestNames(t *testing.T) {
for i, tt := range nameTests {
s := fmt.Sprint(tt.val);
s := fmt.Sprint(tt.val)
if s != tt.str {
t.Errorf("#%d: want %q have %q", i, s, tt.str)
}
......
This diff is collapsed.
......@@ -5,16 +5,16 @@
package elf
import (
"debug/dwarf";
"encoding/binary";
"reflect";
"testing";
"debug/dwarf"
"encoding/binary"
"reflect"
"testing"
)
type fileTest struct {
file string;
hdr FileHeader;
sections []SectionHeader;
file string
hdr FileHeader
sections []SectionHeader
}
var fileTests = []fileTest{
......@@ -101,28 +101,28 @@ var fileTests = []fileTest{
func TestOpen(t *testing.T) {
for i := range fileTests {
tt := &fileTests[i];
tt := &fileTests[i]
f, err := Open(tt.file);
f, err := Open(tt.file)
if err != nil {
t.Error(err);
continue;
t.Error(err)
continue
}
if !reflect.DeepEqual(f.FileHeader, tt.hdr) {
t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr);
continue;
t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr)
continue
}
for i, s := range f.Sections {
if i >= len(tt.sections) {
break
}
sh := &tt.sections[i];
sh := &tt.sections[i]
if !reflect.DeepEqual(&s.SectionHeader, sh) {
t.Errorf("open %s, section %d:\n\thave %#v\n\twant %#v\n", tt.file, i, &s.SectionHeader, sh)
}
}
tn := len(tt.sections);
fn := len(f.Sections);
tn := len(tt.sections)
fn := len(f.Sections)
if tn != fn {
t.Errorf("open %s: len(Sections) = %d, want %d", tt.file, fn, tn)
}
......@@ -130,8 +130,8 @@ func TestOpen(t *testing.T) {
}
type relocationTest struct {
file string;
firstEntry *dwarf.Entry;
file string
firstEntry *dwarf.Entry
}
var relocationTests = []relocationTest{
......@@ -151,30 +151,30 @@ var relocationTests = []relocationTest{
func TestDWARFRelocations(t *testing.T) {
for i, test := range relocationTests {
f, err := Open(test.file);
f, err := Open(test.file)
if err != nil {
t.Error(err);
continue;
t.Error(err)
continue
}
dwarf, err := f.DWARF();
dwarf, err := f.DWARF()
if err != nil {
t.Error(err);
continue;
t.Error(err)
continue
}
reader := dwarf.Reader();
reader := dwarf.Reader()
// Checking only the first entry is sufficient since it has
// many different strings. If the relocation had failed, all
// the string offsets would be zero and all the strings would
// end up being the same.
firstEntry, err := reader.Next();
firstEntry, err := reader.Next()
if err != nil {
t.Error(err);
continue;
t.Error(err)
continue
}
if !reflect.DeepEqual(test.firstEntry, firstEntry) {
t.Errorf("#%d: mismatch: got:%#v want:%#v", i, firstEntry, test.firstEntry);
continue;
t.Errorf("#%d: mismatch: got:%#v want:%#v", i, firstEntry, test.firstEntry)
continue
}
}
}
......@@ -11,9 +11,9 @@ package gosym
import "encoding/binary"
type LineTable struct {
Data []byte;
PC uint64;
Line int;
Data []byte
PC uint64
Line int
}
// TODO(rsc): Need to pull in quantum from architecture definition.
......@@ -28,49 +28,49 @@ func (t *LineTable) parse(targetPC uint64, targetLine int) (b []byte, pc uint64,
//
// Here we process each update individually, which simplifies
// the code, but makes the corner cases more confusing.
b, pc, line = t.Data, t.PC, t.Line;
b, pc, line = t.Data, t.PC, t.Line
for pc <= targetPC && line != targetLine && len(b) > 0 {
code := b[0];
b = b[1:];
code := b[0]
b = b[1:]
switch {
case code == 0:
if len(b) < 4 {
b = b[0:0];
break;
b = b[0:0]
break
}
val := binary.BigEndian.Uint32(b);
b = b[4:];
line += int(val);
val := binary.BigEndian.Uint32(b)
b = b[4:]
line += int(val)
case code <= 64:
line += int(code)
case code <= 128:
line -= int(code - 64)
default:
pc += quantum * uint64(code-128);
continue;
pc += quantum * uint64(code-128)
continue
}
pc += quantum;
pc += quantum
}
return b, pc, line;
return b, pc, line
}
func (t *LineTable) slice(pc uint64) *LineTable {
data, pc, line := t.parse(pc, -1);
return &LineTable{data, pc, line};
data, pc, line := t.parse(pc, -1)
return &LineTable{data, pc, line}
}
func (t *LineTable) PCToLine(pc uint64) int {
_, _, line := t.parse(pc, -1);
return line;
_, _, line := t.parse(pc, -1)
return line
}
func (t *LineTable) LineToPC(line int, maxpc uint64) uint64 {
_, pc, line1 := t.parse(maxpc, line);
_, pc, line1 := t.parse(maxpc, line)
if line1 != line {
return 0
}
// Subtract quantum from PC to account for post-line increment
return pc - quantum;
return pc - quantum
}
// NewLineTable returns a new PC/line table
......
......@@ -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
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -5,15 +5,15 @@
package macho
import (
"reflect";
"testing";
"reflect"
"testing"
)
type fileTest struct {
file string;
hdr FileHeader;
segments []*SegmentHeader;
sections []*SectionHeader;
file string
hdr FileHeader
segments []*SegmentHeader
sections []*SectionHeader
}
var fileTests = []fileTest{
......@@ -100,41 +100,41 @@ var fileTests = []fileTest{
func TestOpen(t *testing.T) {
for i := range fileTests {
tt := &fileTests[i];
tt := &fileTests[i]
f, err := Open(tt.file);
f, err := Open(tt.file)
if err != nil {
t.Error(err);
continue;
t.Error(err)
continue
}
if !reflect.DeepEqual(f.FileHeader, tt.hdr) {
t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr);
continue;
t.Errorf("open %s:\n\thave %#v\n\twant %#v\n", tt.file, f.FileHeader, tt.hdr)
continue
}
for i, l := range f.Loads {
if i >= len(tt.segments) {
break
}
sh := tt.segments[i];
s, ok := l.(*Segment);
sh := tt.segments[i]
s, ok := l.(*Segment)
if sh == nil {
if ok {
t.Errorf("open %s, section %d: skipping %#v\n", tt.file, i, &s.SegmentHeader)
}
continue;
continue
}
if !ok {
t.Errorf("open %s, section %d: not *Segment\n", tt.file, i);
continue;
t.Errorf("open %s, section %d: not *Segment\n", tt.file, i)
continue
}
have := &s.SegmentHeader;
want := sh;
have := &s.SegmentHeader
want := sh
if !reflect.DeepEqual(have, want) {
t.Errorf("open %s, segment %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
}
}
tn := len(tt.segments);
fn := len(f.Loads);
tn := len(tt.segments)
fn := len(f.Loads)
if tn != fn {
t.Errorf("open %s: len(Loads) = %d, want %d", tt.file, fn, tn)
}
......@@ -143,14 +143,14 @@ func TestOpen(t *testing.T) {
if i >= len(tt.sections) {
break
}
have := &sh.SectionHeader;
want := tt.sections[i];
have := &sh.SectionHeader
want := tt.sections[i]
if !reflect.DeepEqual(have, want) {
t.Errorf("open %s, section %d:\n\thave %#v\n\twant %#v\n", tt.file, i, have, want)
}
}
tn = len(tt.sections);
fn = len(f.Sections);
tn = len(tt.sections)
fn = len(f.Sections)
if tn != fn {
t.Errorf("open %s: len(Sections) = %d, want %d", tt.file, fn, tn)
}
......
This diff is collapsed.
......@@ -13,22 +13,22 @@ package proc
// and proc_darwin.go do, because deps.bash only looks at
// this file.
import (
_ "container/vector";
_ "fmt";
_ "io";
"os";
_ "runtime";
"strconv";
_ "strings";
_ "sync";
_ "syscall";
_ "container/vector"
_ "fmt"
_ "io"
"os"
_ "runtime"
"strconv"
_ "strings"
_ "sync"
_ "syscall"
)
type Word uint64
// A Cause explains why a thread is stopped.
type Cause interface {
String() string;
String() string
}
// Regs is a set of named machine registers, including a program
......@@ -42,33 +42,33 @@ type Cause interface {
// other per-register information like how to print it.
type Regs interface {
// PC returns the value of the program counter.
PC() Word;
PC() Word
// SetPC sets the program counter to val.
SetPC(val Word) os.Error;
SetPC(val Word) os.Error
// Link returns the link register, if any.
Link() Word;
Link() Word
// SetLink sets the link register to val.
SetLink(val Word) os.Error;
SetLink(val Word) os.Error
// SP returns the value of the stack pointer.
SP() Word;
SP() Word
// SetSP sets the stack pointer register to val.
SetSP(val Word) os.Error;
SetSP(val Word) os.Error
// Names returns the names of all of the registers.
Names() []string;
Names() []string
// Get returns the value of a register, where i corresponds to
// the index of the register's name in the array returned by
// Names.
Get(i int) Word;
Get(i int) Word
// Set sets the value of a register.
Set(i int, val Word) os.Error;
Set(i int, val Word) os.Error
}
// Thread is a thread in the process being traced.
......@@ -78,15 +78,15 @@ type Thread interface {
// breakpoint, this will step over the breakpoint.
//
// XXX What if it's stopped because of a signal?
Step() os.Error;
Step() os.Error
// Stopped returns the reason that this thread is stopped. It
// is an error is the thread not stopped.
Stopped() (Cause, os.Error);
Stopped() (Cause, os.Error)
// Regs retrieves the current register values from this
// thread. The thread must be stopped.
Regs() (Regs, os.Error);
Regs() (Regs, os.Error)
// Peek reads len(out) bytes from the address addr in this
// thread into out. The thread must be stopped. It returns
......@@ -95,7 +95,7 @@ type Thread interface {
// could be short and an error will be returned. If this does
// encounter unmapped memory, it will read up to the byte
// preceding the unmapped area.
Peek(addr Word, out []byte) (int, os.Error);
Peek(addr Word, out []byte) (int, os.Error)
// Poke writes b to the address addr in this thread. The
// thread must be stopped. It returns the number of bytes
......@@ -104,7 +104,7 @@ type Thread interface {
// short and an error will be returned. If this does
// encounter unmapped memory, it will write up to the byte
// preceding the unmapped area.
Poke(addr Word, b []byte) (int, os.Error);
Poke(addr Word, b []byte) (int, os.Error)
}
// Process is a process being traced. It consists of a set of
......@@ -112,37 +112,37 @@ type Thread interface {
// process's state extends to all of its threads.
type Process interface {
// Threads returns an array of all threads in this process.
Threads() []Thread;
Threads() []Thread
// AddBreakpoint creates a new breakpoint at program counter
// pc. Breakpoints can only be created when the process is
// stopped. It is an error if a breakpoint already exists at
// pc.
AddBreakpoint(pc Word) os.Error;
AddBreakpoint(pc Word) os.Error
// RemoveBreakpoint removes the breakpoint at the program
// counter pc. It is an error if no breakpoint exists at pc.
RemoveBreakpoint(pc Word) os.Error;
RemoveBreakpoint(pc Word) os.Error
// Stop stops all running threads in this process before
// returning.
Stop() os.Error;
Stop() os.Error
// Continue resumes execution of all threads in this process.
// Any thread that is stopped on a breakpoint will be stepped
// over that breakpoint. Any thread that is stopped because
// of a signal (other than SIGSTOP or SIGTRAP) will receive
// the pending signal.
Continue() os.Error;
Continue() os.Error
// WaitStop waits until all threads in process p are stopped
// as a result of some thread hitting a breakpoint, receiving
// a signal, creating a new thread, or exiting.
WaitStop() os.Error;
WaitStop() os.Error
// Detach detaches from this process. All stopped threads
// will be resumed.
Detach() os.Error;
Detach() os.Error
}
// Stopped is a stop cause used for threads that are stopped either by
......@@ -151,14 +151,14 @@ type Process interface {
// stop.
type Stopped struct{}
func (c Stopped) String() string { return "stopped" }
func (c Stopped) String() string { return "stopped" }
// Breakpoint is a stop cause resulting from a thread reaching a set
// breakpoint.
type Breakpoint Word
// PC returns the program counter that the program is stopped at.
func (c Breakpoint) PC() Word { return Word(c) }
func (c Breakpoint) PC() Word { return Word(c) }
func (c Breakpoint) String() string {
return "breakpoint at 0x" + strconv.Uitob64(uint64(c.PC()), 16)
......@@ -169,47 +169,47 @@ func (c Breakpoint) String() string {
type Signal string
// Signal returns the signal being delivered to the thread.
func (c Signal) Name() string { return string(c) }
func (c Signal) Name() string { return string(c) }
func (c Signal) String() string { return c.Name() }
func (c Signal) String() string { return c.Name() }
// ThreadCreate is a stop cause returned from an existing thread when
// it creates a new thread. The new thread exists in a primordial
// form at this point and will begin executing in earnest when the
// process is continued.
type ThreadCreate struct {
thread Thread;
thread Thread
}
func (c *ThreadCreate) NewThread() Thread { return c.thread }
func (c *ThreadCreate) NewThread() Thread { return c.thread }
func (c *ThreadCreate) String() string { return "thread create" }
func (c *ThreadCreate) String() string { return "thread create" }
// ThreadExit is a stop cause resulting from a thread exiting. When
// this cause first arises, the thread will still be in the list of
// process threads and its registers and memory will still be
// accessible.
type ThreadExit struct {
exitStatus int;
signal string;
exitStatus int
signal string
}
// Exited returns true if the thread exited normally.
func (c *ThreadExit) Exited() bool { return c.exitStatus != -1 }
func (c *ThreadExit) Exited() bool { return c.exitStatus != -1 }
// ExitStatus returns the exit status of the thread if it exited
// normally or -1 otherwise.
func (c *ThreadExit) ExitStatus() int { return c.exitStatus }
func (c *ThreadExit) ExitStatus() int { return c.exitStatus }
// Signaled returns true if the thread was terminated by a signal.
func (c *ThreadExit) Signaled() bool { return c.exitStatus == -1 }
func (c *ThreadExit) Signaled() bool { return c.exitStatus == -1 }
// StopSignal returns the signal that terminated the thread, or "" if
// it was not terminated by a signal.
func (c *ThreadExit) StopSignal() string { return c.signal }
func (c *ThreadExit) StopSignal() string { return c.signal }
func (c *ThreadExit) String() string {
res := "thread exited ";
res := "thread exited "
switch {
case c.Exited():
res += "with status " + strconv.Itoa(c.ExitStatus())
......@@ -218,5 +218,5 @@ func (c *ThreadExit) String() string {
default:
res += "from unknown cause"
}
return res;
return res
}
This diff is collapsed.
......@@ -5,8 +5,8 @@
package proc
import (
"os";
"syscall";
"os"
"syscall"
)
// Process tracing is not supported on Native Client.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -6,4 +6,4 @@
package main
func init() { pieces4 = pieces5 }
func init() { pieces4 = pieces5 }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -344,4 +344,4 @@ var stmtTests = []test{
Run2("func f1(){}", "f1()"),
}
func TestStmt(t *testing.T) { runTests(t, "stmtTests", stmtTests) }
func TestStmt(t *testing.T) { runTests(t, "stmtTests", stmtTests) }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -6,4 +6,4 @@ package main
import "exp/ogle"
func main() { ogle.Main() }
func main() { ogle.Main() }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment