summaryrefslogtreecommitdiff
path: root/src/pkg/debug
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/debug')
-rw-r--r--src/pkg/debug/binary/Makefile11
-rw-r--r--src/pkg/debug/binary/binary.go222
-rw-r--r--src/pkg/debug/binary/binary_test.go86
-rw-r--r--src/pkg/debug/dwarf/buf.go2
-rw-r--r--src/pkg/debug/dwarf/open.go2
-rw-r--r--src/pkg/debug/elf/file.go2
-rw-r--r--src/pkg/debug/elf/file_test.go2
-rw-r--r--src/pkg/debug/gosym/pclntab.go2
-rw-r--r--src/pkg/debug/gosym/symtab.go2
-rw-r--r--src/pkg/debug/macho/file.go2
10 files changed, 7 insertions, 326 deletions
diff --git a/src/pkg/debug/binary/Makefile b/src/pkg/debug/binary/Makefile
deleted file mode 100644
index 4d681e104..000000000
--- a/src/pkg/debug/binary/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.$(GOARCH)
-
-TARG=debug/binary
-GOFILES=\
- binary.go\
-
-include $(GOROOT)/src/Make.pkg
diff --git a/src/pkg/debug/binary/binary.go b/src/pkg/debug/binary/binary.go
deleted file mode 100644
index 836a43df0..000000000
--- a/src/pkg/debug/binary/binary.go
+++ /dev/null
@@ -1,222 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This package implements translation between
-// unsigned integer values and byte sequences.
-package binary
-
-import (
- "math";
- "io";
- "os";
- "reflect";
-)
-
-// A ByteOrder specifies how to convert byte sequences into
-// 16-, 32-, or 64-bit unsigned integers.
-type ByteOrder interface {
- Uint16(b []byte) uint16;
- Uint32(b []byte) uint32;
- Uint64(b []byte) uint64;
- String() string;
-}
-
-// This is byte instead of struct{} so that it can be compared,
-// allowing, e.g., order == binary.LittleEndian.
-type unused byte
-
-var LittleEndian ByteOrder = littleEndian(0)
-var BigEndian ByteOrder = bigEndian(0)
-
-type littleEndian unused
-
-func (littleEndian) Uint16(b []byte) uint16 {
- return uint16(b[0]) | uint16(b[1])<<8;
-}
-
-func (littleEndian) Uint32(b []byte) uint32 {
- return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24;
-}
-
-func (littleEndian) Uint64(b []byte) uint64 {
- return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
- uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56;
-}
-
-func (littleEndian) String() string {
- return "LittleEndian";
-}
-
-func (littleEndian) GoString() string {
- return "binary.LittleEndian";
-}
-
-type bigEndian unused
-
-func (bigEndian) Uint16(b []byte) uint16 {
- return uint16(b[1]) | uint16(b[0])<<8;
-}
-
-func (bigEndian) Uint32(b []byte) uint32 {
- return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24;
-}
-
-func (bigEndian) Uint64(b []byte) uint64 {
- return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
- uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56;
-}
-
-func (bigEndian) String() string {
- return "BigEndian";
-}
-
-func (bigEndian) GoString() string {
- return "binary.BigEndian";
-}
-
-// Read reads structured binary data from r into data.
-// Data must be a pointer to a fixed-size value.
-// A fixed-size value is either a fixed-size integer
-// (int8, uint8, int16, uint16, ...) or an array or struct
-// containing only fixed-size values. Bytes read from
-// r are decoded using order and written to successive
-// fields of the data.
-func Read(r io.Reader, order ByteOrder, data interface{}) os.Error {
- v := reflect.NewValue(data).(*reflect.PtrValue).Elem();
- size := sizeof(v.Type());
- if size < 0 {
- return os.NewError("binary.Read: invalid type " + v.Type().String());
- }
- d := &decoder{order: order, buf: make([]byte, size)};
- if _, err := io.ReadFull(r, d.buf); err != nil {
- return err;
- }
- d.value(v);
- return nil;
-}
-
-func sizeof(t reflect.Type) int {
- switch t := t.(type) {
- case *reflect.ArrayType:
- n := sizeof(t.Elem());
- if n < 0 {
- return -1;
- }
- return t.Len() * n;
-
- case *reflect.StructType:
- sum := 0;
- for i, n := 0, t.NumField(); i < n; i++ {
- s := sizeof(t.Field(i).Type);
- if s < 0 {
- return -1;
- }
- sum += s;
- }
- return sum;
-
- case *reflect.Uint8Type:
- return 1;
- case *reflect.Uint16Type:
- return 2;
- case *reflect.Uint32Type:
- return 4;
- case *reflect.Uint64Type:
- return 8;
- case *reflect.Int8Type:
- return 1;
- case *reflect.Int16Type:
- return 2;
- case *reflect.Int32Type:
- return 4;
- case *reflect.Int64Type:
- return 8;
- case *reflect.Float32Type:
- return 4;
- case *reflect.Float64Type:
- return 8;
- }
- return -1;
-}
-
-type decoder struct {
- order ByteOrder;
- buf []byte;
-}
-
-func (d *decoder) uint8() uint8 {
- x := d.buf[0];
- d.buf = d.buf[1:len(d.buf)];
- return x;
-}
-
-func (d *decoder) uint16() uint16 {
- x := d.order.Uint16(d.buf[0:2]);
- d.buf = d.buf[2:len(d.buf)];
- return x;
-}
-
-func (d *decoder) uint32() uint32 {
- x := d.order.Uint32(d.buf[0:4]);
- d.buf = d.buf[4:len(d.buf)];
- return x;
-}
-
-func (d *decoder) uint64() uint64 {
- x := d.order.Uint64(d.buf[0:8]);
- d.buf = d.buf[8:len(d.buf)];
- return x;
-}
-
-func (d *decoder) int8() int8 {
- return int8(d.uint8());
-}
-
-func (d *decoder) int16() int16 {
- return int16(d.uint16());
-}
-
-func (d *decoder) int32() int32 {
- return int32(d.uint32());
-}
-
-func (d *decoder) int64() int64 {
- return int64(d.uint64());
-}
-
-func (d *decoder) value(v reflect.Value) {
- switch v := v.(type) {
- case *reflect.ArrayValue:
- l := v.Len();
- for i := 0; i < l; i++ {
- d.value(v.Elem(i));
- }
- case *reflect.StructValue:
- l := v.NumField();
- for i := 0; i < l; i++ {
- d.value(v.Field(i));
- }
-
- case *reflect.Uint8Value:
- v.Set(d.uint8());
- case *reflect.Uint16Value:
- v.Set(d.uint16());
- case *reflect.Uint32Value:
- v.Set(d.uint32());
- case *reflect.Uint64Value:
- v.Set(d.uint64());
- case *reflect.Int8Value:
- v.Set(d.int8());
- case *reflect.Int16Value:
- v.Set(d.int16());
- case *reflect.Int32Value:
- v.Set(d.int32());
- case *reflect.Int64Value:
- v.Set(d.int64());
- case *reflect.Float32Value:
- v.Set(math.Float32frombits(d.uint32()));
- case *reflect.Float64Value:
- v.Set(math.Float64frombits(d.uint64()));
- }
-}
diff --git a/src/pkg/debug/binary/binary_test.go b/src/pkg/debug/binary/binary_test.go
deleted file mode 100644
index a04684b72..000000000
--- a/src/pkg/debug/binary/binary_test.go
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package binary
-
-import (
- "bytes";
- "math";
- "reflect";
- "testing";
-)
-
-type Struct struct {
- Int8 int8;
- Int16 int16;
- Int32 int32;
- Int64 int64;
- Uint8 uint8;
- Uint16 uint16;
- Uint32 uint32;
- Uint64 uint64;
- Float64 float64;
- Array [4]uint8;
-}
-
-var s = Struct{
- 0x01,
- 0x0203,
- 0x04050607,
- 0x08090a0b0c0d0e0f,
- 0x10,
- 0x1112,
- 0x13141516,
- 0x1718191a1b1c1d1e,
- math.Float64frombits(0x1f20212223242526),
- [4]uint8{0x27, 0x28, 0x29, 0x2a},
-}
-
-var big = []byte{
- 1,
- 2, 3,
- 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 16,
- 17, 18,
- 19, 20, 21, 22,
- 23, 24, 25, 26, 27, 28, 29, 30,
- 31, 32, 33, 34, 35, 36, 37, 38,
- 39, 40, 41, 42,
-}
-
-var little = []byte{
- 1,
- 3, 2,
- 7, 6, 5, 4,
- 15, 14, 13, 12, 11, 10, 9, 8,
- 16,
- 18, 17,
- 22, 21, 20, 19,
- 30, 29, 28, 27, 26, 25, 24, 23,
- 38, 37, 36, 35, 34, 33, 32, 31,
- 39, 40, 41, 42,
-}
-
-func TestRead(t *testing.T) {
- var sl, sb Struct;
-
- err := Read(bytes.NewBuffer(big), BigEndian, &sb);
- if err != nil {
- t.Errorf("Read big-endian: %v", err);
- goto little;
- }
- if !reflect.DeepEqual(sb, s) {
- t.Errorf("Read big-endian:\n\thave %+v\n\twant %+v", sb, s);
- }
-
-little:
- err = Read(bytes.NewBuffer(little), LittleEndian, &sl);
- if err != nil {
- t.Errorf("Read little-endian: %v", err);
- }
- if !reflect.DeepEqual(sl, s) {
- t.Errorf("Read big-endian:\n\thave %+v\n\twant %+v", sl, s);
- }
-}
diff --git a/src/pkg/debug/dwarf/buf.go b/src/pkg/debug/dwarf/buf.go
index 2d8211090..34880a5d5 100644
--- a/src/pkg/debug/dwarf/buf.go
+++ b/src/pkg/debug/dwarf/buf.go
@@ -7,7 +7,7 @@
package dwarf
import (
- "debug/binary";
+ "encoding/binary";
"os";
"strconv";
)
diff --git a/src/pkg/debug/dwarf/open.go b/src/pkg/debug/dwarf/open.go
index f2cfa4c93..6fc34fed3 100644
--- a/src/pkg/debug/dwarf/open.go
+++ b/src/pkg/debug/dwarf/open.go
@@ -8,7 +8,7 @@
package dwarf
import (
- "debug/binary";
+ "encoding/binary";
"os";
)
diff --git a/src/pkg/debug/elf/file.go b/src/pkg/debug/elf/file.go
index 0c5d6f317..0b5ff3fa1 100644
--- a/src/pkg/debug/elf/file.go
+++ b/src/pkg/debug/elf/file.go
@@ -6,8 +6,8 @@
package elf
import (
- "debug/binary";
"debug/dwarf";
+ "encoding/binary";
"fmt";
"io";
"os";
diff --git a/src/pkg/debug/elf/file_test.go b/src/pkg/debug/elf/file_test.go
index 01e638eea..9b756aea1 100644
--- a/src/pkg/debug/elf/file_test.go
+++ b/src/pkg/debug/elf/file_test.go
@@ -5,7 +5,7 @@
package elf
import (
- "debug/binary";
+ "encoding/binary";
"reflect";
"testing";
)
diff --git a/src/pkg/debug/gosym/pclntab.go b/src/pkg/debug/gosym/pclntab.go
index 24c368616..8008ada83 100644
--- a/src/pkg/debug/gosym/pclntab.go
+++ b/src/pkg/debug/gosym/pclntab.go
@@ -8,7 +8,7 @@
package gosym
-import "debug/binary"
+import "encoding/binary"
type LineTable struct {
Data []byte;
diff --git a/src/pkg/debug/gosym/symtab.go b/src/pkg/debug/gosym/symtab.go
index b531db6e0..7edbc0390 100644
--- a/src/pkg/debug/gosym/symtab.go
+++ b/src/pkg/debug/gosym/symtab.go
@@ -13,7 +13,7 @@ package gosym
// and the Go format is the runtime source, specifically ../../runtime/symtab.c.
import (
- "debug/binary";
+ "encoding/binary";
"fmt";
"os";
"strconv";
diff --git a/src/pkg/debug/macho/file.go b/src/pkg/debug/macho/file.go
index fee02fb27..67af39be5 100644
--- a/src/pkg/debug/macho/file.go
+++ b/src/pkg/debug/macho/file.go
@@ -10,8 +10,8 @@ package macho
import (
"bytes";
- "debug/binary";
"debug/dwarf";
+ "encoding/binary";
"fmt";
"io";
"os";