diff options
Diffstat (limited to 'src/pkg/debug/dwarf')
-rw-r--r-- | src/pkg/debug/dwarf/buf.go | 108 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/const.go | 444 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/entry.go | 172 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/open.go | 40 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/type.go | 370 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/type_test.go | 36 | ||||
-rw-r--r-- | src/pkg/debug/dwarf/unit.go | 50 |
7 files changed, 610 insertions, 610 deletions
diff --git a/src/pkg/debug/dwarf/buf.go b/src/pkg/debug/dwarf/buf.go index 2ece903a0..2d29cebdd 100644 --- a/src/pkg/debug/dwarf/buf.go +++ b/src/pkg/debug/dwarf/buf.go @@ -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 { diff --git a/src/pkg/debug/dwarf/const.go b/src/pkg/debug/dwarf/const.go index 808a80c8a..d73480cb2 100644 --- a/src/pkg/debug/dwarf/const.go +++ b/src/pkg/debug/dwarf/const.go @@ -12,78 +12,78 @@ import "strconv" type Attr uint32 const ( - AttrSibling Attr = 0x01; - AttrLocation Attr = 0x02; - AttrName Attr = 0x03; - AttrOrdering Attr = 0x09; - AttrByteSize Attr = 0x0B; - AttrBitOffset Attr = 0x0C; - AttrBitSize Attr = 0x0D; - AttrStmtList Attr = 0x10; - AttrLowpc Attr = 0x11; - AttrHighpc Attr = 0x12; - AttrLanguage Attr = 0x13; - AttrDiscr Attr = 0x15; - AttrDiscrValue Attr = 0x16; - AttrVisibility Attr = 0x17; - AttrImport Attr = 0x18; - AttrStringLength Attr = 0x19; - AttrCommonRef Attr = 0x1A; - AttrCompDir Attr = 0x1B; - AttrConstValue Attr = 0x1C; - AttrContainingType Attr = 0x1D; - AttrDefaultValue Attr = 0x1E; - AttrInline Attr = 0x20; - AttrIsOptional Attr = 0x21; - AttrLowerBound Attr = 0x22; - AttrProducer Attr = 0x25; - AttrPrototyped Attr = 0x27; - AttrReturnAddr Attr = 0x2A; - AttrStartScope Attr = 0x2C; - AttrStrideSize Attr = 0x2E; - AttrUpperBound Attr = 0x2F; - AttrAbstractOrigin Attr = 0x31; - AttrAccessibility Attr = 0x32; - AttrAddrClass Attr = 0x33; - AttrArtificial Attr = 0x34; - AttrBaseTypes Attr = 0x35; - AttrCalling Attr = 0x36; - AttrCount Attr = 0x37; - AttrDataMemberLoc Attr = 0x38; - AttrDeclColumn Attr = 0x39; - AttrDeclFile Attr = 0x3A; - AttrDeclLine Attr = 0x3B; - AttrDeclaration Attr = 0x3C; - AttrDiscrList Attr = 0x3D; - AttrEncoding Attr = 0x3E; - AttrExternal Attr = 0x3F; - AttrFrameBase Attr = 0x40; - AttrFriend Attr = 0x41; - AttrIdentifierCase Attr = 0x42; - AttrMacroInfo Attr = 0x43; - AttrNamelistItem Attr = 0x44; - AttrPriority Attr = 0x45; - AttrSegment Attr = 0x46; - AttrSpecification Attr = 0x47; - AttrStaticLink Attr = 0x48; - AttrType Attr = 0x49; - AttrUseLocation Attr = 0x4A; - AttrVarParam Attr = 0x4B; - AttrVirtuality Attr = 0x4C; - AttrVtableElemLoc Attr = 0x4D; - AttrAllocated Attr = 0x4E; - AttrAssociated Attr = 0x4F; - AttrDataLocation Attr = 0x50; - AttrStride Attr = 0x51; - AttrEntrypc Attr = 0x52; - AttrUseUTF8 Attr = 0x53; - AttrExtension Attr = 0x54; - AttrRanges Attr = 0x55; - AttrTrampoline Attr = 0x56; - AttrCallColumn Attr = 0x57; - AttrCallFile Attr = 0x58; - AttrCallLine Attr = 0x59; - AttrDescription Attr = 0x5A; + AttrSibling Attr = 0x01 + AttrLocation Attr = 0x02 + AttrName Attr = 0x03 + AttrOrdering Attr = 0x09 + AttrByteSize Attr = 0x0B + AttrBitOffset Attr = 0x0C + AttrBitSize Attr = 0x0D + AttrStmtList Attr = 0x10 + AttrLowpc Attr = 0x11 + AttrHighpc Attr = 0x12 + AttrLanguage Attr = 0x13 + AttrDiscr Attr = 0x15 + AttrDiscrValue Attr = 0x16 + AttrVisibility Attr = 0x17 + AttrImport Attr = 0x18 + AttrStringLength Attr = 0x19 + AttrCommonRef Attr = 0x1A + AttrCompDir Attr = 0x1B + AttrConstValue Attr = 0x1C + AttrContainingType Attr = 0x1D + AttrDefaultValue Attr = 0x1E + AttrInline Attr = 0x20 + AttrIsOptional Attr = 0x21 + AttrLowerBound Attr = 0x22 + AttrProducer Attr = 0x25 + AttrPrototyped Attr = 0x27 + AttrReturnAddr Attr = 0x2A + AttrStartScope Attr = 0x2C + AttrStrideSize Attr = 0x2E + AttrUpperBound Attr = 0x2F + AttrAbstractOrigin Attr = 0x31 + AttrAccessibility Attr = 0x32 + AttrAddrClass Attr = 0x33 + AttrArtificial Attr = 0x34 + AttrBaseTypes Attr = 0x35 + AttrCalling Attr = 0x36 + AttrCount Attr = 0x37 + AttrDataMemberLoc Attr = 0x38 + AttrDeclColumn Attr = 0x39 + AttrDeclFile Attr = 0x3A + AttrDeclLine Attr = 0x3B + AttrDeclaration Attr = 0x3C + AttrDiscrList Attr = 0x3D + AttrEncoding Attr = 0x3E + AttrExternal Attr = 0x3F + AttrFrameBase Attr = 0x40 + AttrFriend Attr = 0x41 + AttrIdentifierCase Attr = 0x42 + AttrMacroInfo Attr = 0x43 + AttrNamelistItem Attr = 0x44 + AttrPriority Attr = 0x45 + AttrSegment Attr = 0x46 + AttrSpecification Attr = 0x47 + AttrStaticLink Attr = 0x48 + AttrType Attr = 0x49 + AttrUseLocation Attr = 0x4A + AttrVarParam Attr = 0x4B + AttrVirtuality Attr = 0x4C + AttrVtableElemLoc Attr = 0x4D + AttrAllocated Attr = 0x4E + AttrAssociated Attr = 0x4F + AttrDataLocation Attr = 0x50 + AttrStride Attr = 0x51 + AttrEntrypc Attr = 0x52 + AttrUseUTF8 Attr = 0x53 + AttrExtension Attr = 0x54 + AttrRanges Attr = 0x55 + AttrTrampoline Attr = 0x56 + AttrCallColumn Attr = 0x57 + AttrCallFile Attr = 0x58 + AttrCallLine Attr = 0x59 + AttrDescription Attr = 0x5A ) var attrNames = [...]string{ @@ -163,22 +163,22 @@ var attrNames = [...]string{ func (a Attr) String() string { if int(a) < len(attrNames) { - s := attrNames[a]; + s := attrNames[a] if s != "" { return s } } - return strconv.Itoa(int(a)); + return strconv.Itoa(int(a)) } func (a Attr) GoString() string { if int(a) < len(attrNames) { - s := attrNames[a]; + s := attrNames[a] if s != "" { return "dwarf.Attr" + s } } - return "dwarf.Attr(" + strconv.Itoa64(int64(a)) + ")"; + return "dwarf.Attr(" + strconv.Itoa64(int64(a)) + ")" } // A format is a DWARF data encoding format. @@ -186,89 +186,89 @@ type format uint32 const ( // value formats - formAddr format = 0x01; - formDwarfBlock2 format = 0x03; - formDwarfBlock4 format = 0x04; - formData2 format = 0x05; - formData4 format = 0x06; - formData8 format = 0x07; - formString format = 0x08; - formDwarfBlock format = 0x09; - formDwarfBlock1 format = 0x0A; - formData1 format = 0x0B; - formFlag format = 0x0C; - formSdata format = 0x0D; - formStrp format = 0x0E; - formUdata format = 0x0F; - formRefAddr format = 0x10; - formRef1 format = 0x11; - formRef2 format = 0x12; - formRef4 format = 0x13; - formRef8 format = 0x14; - formRefUdata format = 0x15; - formIndirect format = 0x16; + formAddr format = 0x01 + formDwarfBlock2 format = 0x03 + formDwarfBlock4 format = 0x04 + formData2 format = 0x05 + formData4 format = 0x06 + formData8 format = 0x07 + formString format = 0x08 + formDwarfBlock format = 0x09 + formDwarfBlock1 format = 0x0A + formData1 format = 0x0B + formFlag format = 0x0C + formSdata format = 0x0D + formStrp format = 0x0E + formUdata format = 0x0F + formRefAddr format = 0x10 + formRef1 format = 0x11 + formRef2 format = 0x12 + formRef4 format = 0x13 + formRef8 format = 0x14 + formRefUdata format = 0x15 + formIndirect format = 0x16 ) // A Tag is the classification (the type) of an Entry. type Tag uint32 const ( - TagArrayType Tag = 0x01; - TagClassType Tag = 0x02; - TagEntryPoint Tag = 0x03; - TagEnumerationType Tag = 0x04; - TagFormalParameter Tag = 0x05; - TagImportedDeclaration Tag = 0x08; - TagLabel Tag = 0x0A; - TagLexDwarfBlock Tag = 0x0B; - TagMember Tag = 0x0D; - TagPointerType Tag = 0x0F; - TagReferenceType Tag = 0x10; - TagCompileUnit Tag = 0x11; - TagStringType Tag = 0x12; - TagStructType Tag = 0x13; - TagSubroutineType Tag = 0x15; - TagTypedef Tag = 0x16; - TagUnionType Tag = 0x17; - TagUnspecifiedParameters Tag = 0x18; - TagVariant Tag = 0x19; - TagCommonDwarfBlock Tag = 0x1A; - TagCommonInclusion Tag = 0x1B; - TagInheritance Tag = 0x1C; - TagInlinedSubroutine Tag = 0x1D; - TagModule Tag = 0x1E; - TagPtrToMemberType Tag = 0x1F; - TagSetType Tag = 0x20; - TagSubrangeType Tag = 0x21; - TagWithStmt Tag = 0x22; - TagAccessDeclaration Tag = 0x23; - TagBaseType Tag = 0x24; - TagCatchDwarfBlock Tag = 0x25; - TagConstType Tag = 0x26; - TagConstant Tag = 0x27; - TagEnumerator Tag = 0x28; - TagFileType Tag = 0x29; - TagFriend Tag = 0x2A; - TagNamelist Tag = 0x2B; - TagNamelistItem Tag = 0x2C; - TagPackedType Tag = 0x2D; - TagSubprogram Tag = 0x2E; - TagTemplateTypeParameter Tag = 0x2F; - TagTemplateValueParameter Tag = 0x30; - TagThrownType Tag = 0x31; - TagTryDwarfBlock Tag = 0x32; - TagVariantPart Tag = 0x33; - TagVariable Tag = 0x34; - TagVolatileType Tag = 0x35; - TagDwarfProcedure Tag = 0x36; - TagRestrictType Tag = 0x37; - TagInterfaceType Tag = 0x38; - TagNamespace Tag = 0x39; - TagImportedModule Tag = 0x3A; - TagUnspecifiedType Tag = 0x3B; - TagPartialUnit Tag = 0x3C; - TagImportedUnit Tag = 0x3D; - TagMutableType Tag = 0x3E; + TagArrayType Tag = 0x01 + TagClassType Tag = 0x02 + TagEntryPoint Tag = 0x03 + TagEnumerationType Tag = 0x04 + TagFormalParameter Tag = 0x05 + TagImportedDeclaration Tag = 0x08 + TagLabel Tag = 0x0A + TagLexDwarfBlock Tag = 0x0B + TagMember Tag = 0x0D + TagPointerType Tag = 0x0F + TagReferenceType Tag = 0x10 + TagCompileUnit Tag = 0x11 + TagStringType Tag = 0x12 + TagStructType Tag = 0x13 + TagSubroutineType Tag = 0x15 + TagTypedef Tag = 0x16 + TagUnionType Tag = 0x17 + TagUnspecifiedParameters Tag = 0x18 + TagVariant Tag = 0x19 + TagCommonDwarfBlock Tag = 0x1A + TagCommonInclusion Tag = 0x1B + TagInheritance Tag = 0x1C + TagInlinedSubroutine Tag = 0x1D + TagModule Tag = 0x1E + TagPtrToMemberType Tag = 0x1F + TagSetType Tag = 0x20 + TagSubrangeType Tag = 0x21 + TagWithStmt Tag = 0x22 + TagAccessDeclaration Tag = 0x23 + TagBaseType Tag = 0x24 + TagCatchDwarfBlock Tag = 0x25 + TagConstType Tag = 0x26 + TagConstant Tag = 0x27 + TagEnumerator Tag = 0x28 + TagFileType Tag = 0x29 + TagFriend Tag = 0x2A + TagNamelist Tag = 0x2B + TagNamelistItem Tag = 0x2C + TagPackedType Tag = 0x2D + TagSubprogram Tag = 0x2E + TagTemplateTypeParameter Tag = 0x2F + TagTemplateValueParameter Tag = 0x30 + TagThrownType Tag = 0x31 + TagTryDwarfBlock Tag = 0x32 + TagVariantPart Tag = 0x33 + TagVariable Tag = 0x34 + TagVolatileType Tag = 0x35 + TagDwarfProcedure Tag = 0x36 + TagRestrictType Tag = 0x37 + TagInterfaceType Tag = 0x38 + TagNamespace Tag = 0x39 + TagImportedModule Tag = 0x3A + TagUnspecifiedType Tag = 0x3B + TagPartialUnit Tag = 0x3C + TagImportedUnit Tag = 0x3D + TagMutableType Tag = 0x3E ) var tagNames = [...]string{ @@ -332,22 +332,22 @@ var tagNames = [...]string{ func (t Tag) String() string { if int(t) < len(tagNames) { - s := tagNames[t]; + s := tagNames[t] if s != "" { return s } } - return strconv.Itoa(int(t)); + return strconv.Itoa(int(t)) } func (t Tag) GoString() string { if int(t) < len(tagNames) { - s := tagNames[t]; + s := tagNames[t] if s != "" { return "dwarf.Tag" + s } } - return "dwarf.Tag(" + strconv.Itoa64(int64(t)) + ")"; + return "dwarf.Tag(" + strconv.Itoa64(int64(t)) + ")" } // Location expression operators. @@ -356,78 +356,78 @@ func (t Tag) GoString() string { // This package does not implement full expressions; // the opPlusUconst operator is expected by the type parser. const ( - opAddr = 0x03; /* 1 op, const addr */ - opDeref = 0x06; - opConst1u = 0x08; /* 1 op, 1 byte const */ - opConst1s = 0x09; /* " signed */ - opConst2u = 0x0A; /* 1 op, 2 byte const */ - opConst2s = 0x0B; /* " signed */ - opConst4u = 0x0C; /* 1 op, 4 byte const */ - opConst4s = 0x0D; /* " signed */ - opConst8u = 0x0E; /* 1 op, 8 byte const */ - opConst8s = 0x0F; /* " signed */ - opConstu = 0x10; /* 1 op, LEB128 const */ - opConsts = 0x11; /* " signed */ - opDup = 0x12; - opDrop = 0x13; - opOver = 0x14; - opPick = 0x15; /* 1 op, 1 byte stack index */ - opSwap = 0x16; - opRot = 0x17; - opXderef = 0x18; - opAbs = 0x19; - opAnd = 0x1A; - opDiv = 0x1B; - opMinus = 0x1C; - opMod = 0x1D; - opMul = 0x1E; - opNeg = 0x1F; - opNot = 0x20; - opOr = 0x21; - opPlus = 0x22; - opPlusUconst = 0x23; /* 1 op, ULEB128 addend */ - opShl = 0x24; - opShr = 0x25; - opShra = 0x26; - opXor = 0x27; - opSkip = 0x2F; /* 1 op, signed 2-byte constant */ - opBra = 0x28; /* 1 op, signed 2-byte constant */ - opEq = 0x29; - opGe = 0x2A; - opGt = 0x2B; - opLe = 0x2C; - opLt = 0x2D; - opNe = 0x2E; - opLit0 = 0x30; + opAddr = 0x03 /* 1 op, const addr */ + opDeref = 0x06 + opConst1u = 0x08 /* 1 op, 1 byte const */ + opConst1s = 0x09 /* " signed */ + opConst2u = 0x0A /* 1 op, 2 byte const */ + opConst2s = 0x0B /* " signed */ + opConst4u = 0x0C /* 1 op, 4 byte const */ + opConst4s = 0x0D /* " signed */ + opConst8u = 0x0E /* 1 op, 8 byte const */ + opConst8s = 0x0F /* " signed */ + opConstu = 0x10 /* 1 op, LEB128 const */ + opConsts = 0x11 /* " signed */ + opDup = 0x12 + opDrop = 0x13 + opOver = 0x14 + opPick = 0x15 /* 1 op, 1 byte stack index */ + opSwap = 0x16 + opRot = 0x17 + opXderef = 0x18 + opAbs = 0x19 + opAnd = 0x1A + opDiv = 0x1B + opMinus = 0x1C + opMod = 0x1D + opMul = 0x1E + opNeg = 0x1F + opNot = 0x20 + opOr = 0x21 + opPlus = 0x22 + opPlusUconst = 0x23 /* 1 op, ULEB128 addend */ + opShl = 0x24 + opShr = 0x25 + opShra = 0x26 + opXor = 0x27 + opSkip = 0x2F /* 1 op, signed 2-byte constant */ + opBra = 0x28 /* 1 op, signed 2-byte constant */ + opEq = 0x29 + opGe = 0x2A + opGt = 0x2B + opLe = 0x2C + opLt = 0x2D + opNe = 0x2E + opLit0 = 0x30 /* OpLitN = OpLit0 + N for N = 0..31 */ - opReg0 = 0x50; + opReg0 = 0x50 /* OpRegN = OpReg0 + N for N = 0..31 */ - opBreg0 = 0x70; /* 1 op, signed LEB128 constant */ + opBreg0 = 0x70 /* 1 op, signed LEB128 constant */ /* OpBregN = OpBreg0 + N for N = 0..31 */ - opRegx = 0x90; /* 1 op, ULEB128 register */ - opFbreg = 0x91; /* 1 op, SLEB128 offset */ - opBregx = 0x92; /* 2 op, ULEB128 reg; SLEB128 off */ - opPiece = 0x93; /* 1 op, ULEB128 size of piece */ - opDerefSize = 0x94; /* 1-byte size of data retrieved */ - opXderefSize = 0x95; /* 1-byte size of data retrieved */ - opNop = 0x96; + opRegx = 0x90 /* 1 op, ULEB128 register */ + opFbreg = 0x91 /* 1 op, SLEB128 offset */ + opBregx = 0x92 /* 2 op, ULEB128 reg; SLEB128 off */ + opPiece = 0x93 /* 1 op, ULEB128 size of piece */ + opDerefSize = 0x94 /* 1-byte size of data retrieved */ + opXderefSize = 0x95 /* 1-byte size of data retrieved */ + opNop = 0x96 /* next four new in Dwarf v3 */ - opPushObjAddr = 0x97; - opCall2 = 0x98; /* 2-byte offset of DIE */ - opCall4 = 0x99; /* 4-byte offset of DIE */ - opCallRef = 0x9A; /* 4- or 8- byte offset of DIE */ + opPushObjAddr = 0x97 + opCall2 = 0x98 /* 2-byte offset of DIE */ + opCall4 = 0x99 /* 4-byte offset of DIE */ + opCallRef = 0x9A /* 4- or 8- byte offset of DIE */ /* 0xE0-0xFF reserved for user-specific */ ) // Basic type encodings -- the value for AttrEncoding in a TagBaseType Entry. const ( - encAddress = 0x01; - encBoolean = 0x02; - encComplexFloat = 0x03; - encFloat = 0x04; - encSigned = 0x05; - encSignedChar = 0x06; - encUnsigned = 0x07; - encUnsignedChar = 0x08; - encImaginaryFloat = 0x09; + encAddress = 0x01 + encBoolean = 0x02 + encComplexFloat = 0x03 + encFloat = 0x04 + encSigned = 0x05 + encSignedChar = 0x06 + encUnsigned = 0x07 + encUnsignedChar = 0x08 + encImaginaryFloat = 0x09 ) diff --git a/src/pkg/debug/dwarf/entry.go b/src/pkg/debug/dwarf/entry.go index a4f013c39..5f739c426 100644 --- a/src/pkg/debug/dwarf/entry.go +++ b/src/pkg/debug/dwarf/entry.go @@ -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 } diff --git a/src/pkg/debug/dwarf/open.go b/src/pkg/debug/dwarf/open.go index a5cb1a103..3a1b00311 100644 --- a/src/pkg/debug/dwarf/open.go +++ b/src/pkg/debug/dwarf/open.go @@ -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 } diff --git a/src/pkg/debug/dwarf/type.go b/src/pkg/debug/dwarf/type.go index bf57fd4bf..5d4a51653 100644 --- a/src/pkg/debug/dwarf/type.go +++ b/src/pkg/debug/dwarf/type.go @@ -9,259 +9,259 @@ package dwarf import ( - "os"; - "strconv"; + "os" + "strconv" ) // A Type conventionally represents a pointer to any of the // specific Type structures (CharType, StructType, etc.). type Type interface { - Common() *CommonType; - String() string; - Size() int64; + Common() *CommonType + String() string + Size() int64 } // A CommonType holds fields common to multiple types. // If a field is not known or not applicable for a given type, // the zero value is used. type CommonType struct { - ByteSize int64; // size of value of this type, in bytes - Name string; // name that can be used to refer to type + ByteSize int64 // size of value of this type, in bytes + Name string // name that can be used to refer to type } -func (c *CommonType) Common() *CommonType { return c } +func (c *CommonType) Common() *CommonType { return c } -func (c *CommonType) Size() int64 { return c.ByteSize } +func (c *CommonType) Size() int64 { return c.ByteSize } // Basic types // A BasicType holds fields common to all basic types. type BasicType struct { - CommonType; - BitSize int64; - BitOffset int64; + CommonType + BitSize int64 + BitOffset int64 } -func (b *BasicType) Basic() *BasicType { return b } +func (b *BasicType) Basic() *BasicType { return b } func (t *BasicType) String() string { if t.Name != "" { return t.Name } - return "?"; + return "?" } // A CharType represents a signed character type. type CharType struct { - BasicType; + BasicType } // A UcharType represents an unsigned character type. type UcharType struct { - BasicType; + BasicType } // An IntType represents a signed integer type. type IntType struct { - BasicType; + BasicType } // A UintType represents an unsigned integer type. type UintType struct { - BasicType; + BasicType } // A FloatType represents a floating point type. type FloatType struct { - BasicType; + BasicType } // A ComplexType represents a complex floating point type. type ComplexType struct { - BasicType; + BasicType } // A BoolType represents a boolean type. type BoolType struct { - BasicType; + BasicType } // An AddrType represents a machine address type. type AddrType struct { - BasicType; + BasicType } // qualifiers // A QualType represents a type that has the C/C++ "const", "restrict", or "volatile" qualifier. type QualType struct { - CommonType; - Qual string; - Type Type; + CommonType + Qual string + Type Type } -func (t *QualType) String() string { return t.Qual + " " + t.Type.String() } +func (t *QualType) String() string { return t.Qual + " " + t.Type.String() } -func (t *QualType) Size() int64 { return t.Type.Size() } +func (t *QualType) Size() int64 { return t.Type.Size() } // An ArrayType represents a fixed size array type. type ArrayType struct { - CommonType; - Type Type; - StrideBitSize int64; // if > 0, number of bits to hold each element - Count int64; // if == -1, an incomplete array, like char x[]. + CommonType + Type Type + StrideBitSize int64 // if > 0, number of bits to hold each element + Count int64 // if == -1, an incomplete array, like char x[]. } func (t *ArrayType) String() string { return "[" + strconv.Itoa64(t.Count) + "]" + t.Type.String() } -func (t *ArrayType) Size() int64 { return t.Count * t.Type.Size() } +func (t *ArrayType) Size() int64 { return t.Count * t.Type.Size() } // A VoidType represents the C void type. type VoidType struct { - CommonType; + CommonType } -func (t *VoidType) String() string { return "void" } +func (t *VoidType) String() string { return "void" } // A PtrType represents a pointer type. type PtrType struct { - CommonType; - Type Type; + CommonType + Type Type } -func (t *PtrType) String() string { return "*" + t.Type.String() } +func (t *PtrType) String() string { return "*" + t.Type.String() } // A StructType represents a struct, union, or C++ class type. type StructType struct { - CommonType; - StructName string; - Kind string; // "struct", "union", or "class". - Field []*StructField; - Incomplete bool; // if true, struct, union, class is declared but not defined + CommonType + StructName string + Kind string // "struct", "union", or "class". + Field []*StructField + Incomplete bool // if true, struct, union, class is declared but not defined } // A StructField represents a field in a struct, union, or C++ class type. type StructField struct { - Name string; - Type Type; - ByteOffset int64; - ByteSize int64; - BitOffset int64; // within the ByteSize bytes at ByteOffset - BitSize int64; // zero if not a bit field + Name string + Type Type + ByteOffset int64 + ByteSize int64 + BitOffset int64 // within the ByteSize bytes at ByteOffset + BitSize int64 // zero if not a bit field } func (t *StructType) String() string { if t.StructName != "" { return t.Kind + " " + t.StructName } - return t.Defn(); + return t.Defn() } func (t *StructType) Defn() string { - s := t.Kind; + s := t.Kind if t.StructName != "" { s += " " + t.StructName } if t.Incomplete { - s += " /*incomplete*/"; - return s; + s += " /*incomplete*/" + return s } - s += " {"; + s += " {" for i, f := range t.Field { if i > 0 { s += "; " } - s += f.Name + " " + f.Type.String(); - s += "@" + strconv.Itoa64(f.ByteOffset); + s += f.Name + " " + f.Type.String() + s += "@" + strconv.Itoa64(f.ByteOffset) if f.BitSize > 0 { - s += " : " + strconv.Itoa64(f.BitSize); - s += "@" + strconv.Itoa64(f.BitOffset); + s += " : " + strconv.Itoa64(f.BitSize) + s += "@" + strconv.Itoa64(f.BitOffset) } } - s += "}"; - return s; + s += "}" + return s } // An EnumType represents an enumerated type. // The only indication of its native integer type is its ByteSize // (inside CommonType). type EnumType struct { - CommonType; - EnumName string; - Val []*EnumValue; + CommonType + EnumName string + Val []*EnumValue } // An EnumValue represents a single enumeration value. type EnumValue struct { - Name string; - Val int64; + Name string + Val int64 } func (t *EnumType) String() string { - s := "enum"; + s := "enum" if t.EnumName != "" { s += " " + t.EnumName } - s += " {"; + s += " {" for i, v := range t.Val { if i > 0 { s += "; " } - s += v.Name + "=" + strconv.Itoa64(v.Val); + s += v.Name + "=" + strconv.Itoa64(v.Val) } - s += "}"; - return s; + s += "}" + return s } // A FuncType represents a function type. type FuncType struct { - CommonType; - ReturnType Type; - ParamType []Type; + CommonType + ReturnType Type + ParamType []Type } func (t *FuncType) String() string { - s := "func("; + s := "func(" for i, t := range t.ParamType { if i > 0 { s += ", " } - s += t.String(); + s += t.String() } - s += ")"; + s += ")" if t.ReturnType != nil { s += " " + t.ReturnType.String() } - return s; + return s } // A DotDotDotType represents the variadic ... function parameter. type DotDotDotType struct { - CommonType; + CommonType } -func (t *DotDotDotType) String() string { return "..." } +func (t *DotDotDotType) String() string { return "..." } // A TypedefType represents a named type. type TypedefType struct { - CommonType; - Type Type; + CommonType + Type Type } -func (t *TypedefType) String() string { return t.Name } +func (t *TypedefType) String() string { return t.Name } -func (t *TypedefType) Size() int64 { return t.Type.Size() } +func (t *TypedefType) Size() int64 { return t.Type.Size() } func (d *Data) Type(off Offset) (Type, os.Error) { if t, ok := d.typeCache[off]; ok { return t, nil } - r := d.Reader(); - r.Seek(off); - e, err := r.Next(); + r := d.Reader() + r.Seek(off) + e, err := r.Next() if err != nil { return nil, err } @@ -272,42 +272,42 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Parse type from Entry. // Must always set d.typeCache[off] before calling // d.Type recursively, to handle circular types correctly. - var typ Type; + var typ Type // Get next child; set err if error happens. next := func() *Entry { if !e.Children { return nil } - kid, err1 := r.Next(); + kid, err1 := r.Next() if err1 != nil { - err = err1; - return nil; + err = err1 + return nil } if kid == nil { - err = DecodeError{"info", r.b.off, "unexpected end of DWARF entries"}; - return nil; + err = DecodeError{"info", r.b.off, "unexpected end of DWARF entries"} + return nil } if kid.Tag == 0 { return nil } - return kid; - }; + return kid + } // Get Type referred to by Entry's AttrType field. // Set err if error happens. Not having a type is an error. typeOf := func(e *Entry) Type { - toff, ok := e.Val(AttrType).(Offset); + toff, ok := e.Val(AttrType).(Offset) if !ok { // It appears that no Type means "void". return new(VoidType) } - var t Type; + var t Type if t, err = d.Type(toff); err != nil { return nil } - return t; - }; + return t + } switch e.Tag { case TagArrayType: @@ -319,24 +319,24 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Children: // TagSubrangeType or TagEnumerationType giving one dimension. // dimensions are in left to right order. - t := new(ArrayType); - typ = t; - d.typeCache[off] = t; + t := new(ArrayType) + typ = t + d.typeCache[off] = t if t.Type = typeOf(e); err != nil { goto Error } - t.StrideBitSize, _ = e.Val(AttrStrideSize).(int64); + t.StrideBitSize, _ = e.Val(AttrStrideSize).(int64) // Accumulate dimensions, - ndim := 0; + ndim := 0 for kid := next(); kid != nil; kid = next() { // TODO(rsc): Can also be TagEnumerationType // but haven't seen that in the wild yet. switch kid.Tag { case TagSubrangeType: - max, ok := kid.Val(AttrUpperBound).(int64); + max, ok := kid.Val(AttrUpperBound).(int64) if !ok { - max = -2 // Count == -1, as in x[]. + max = -2 // Count == -1, as in x[]. } if ndim == 0 { t.Count = max + 1 @@ -345,15 +345,15 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Create new array type underneath this one. t.Type = &ArrayType{Type: t.Type, Count: max + 1} } - ndim++; + ndim++ case TagEnumerationType: - err = DecodeError{"info", kid.Offset, "cannot handle enumeration type as array bound"}; - goto Error; + err = DecodeError{"info", kid.Offset, "cannot handle enumeration type as array bound"} + goto Error } } if ndim == 0 { - err = DecodeError{"info", e.Offset, "missing dimension for array"}; - goto Error; + err = DecodeError{"info", e.Offset, "missing dimension for array"} + goto Error } case TagBaseType: @@ -364,16 +364,16 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // AttrByteSize: size of type in bytes [required] // AttrBitOffset: for sub-byte types, size in bits // AttrBitSize: for sub-byte types, bit offset of high order bit in the AttrByteSize bytes - name, _ := e.Val(AttrName).(string); - enc, ok := e.Val(AttrEncoding).(int64); + name, _ := e.Val(AttrName).(string) + enc, ok := e.Val(AttrEncoding).(int64) if !ok { - err = DecodeError{"info", e.Offset, "missing encoding attribute for " + name}; - goto Error; + err = DecodeError{"info", e.Offset, "missing encoding attribute for " + name} + goto Error } switch enc { default: - err = DecodeError{"info", e.Offset, "unrecognized encoding attribute value"}; - goto Error; + err = DecodeError{"info", e.Offset, "unrecognized encoding attribute value"} + goto Error case encAddress: typ = new(AddrType) @@ -392,13 +392,13 @@ func (d *Data) Type(off Offset) (Type, os.Error) { case encUnsignedChar: typ = new(UcharType) } - d.typeCache[off] = typ; + d.typeCache[off] = typ t := typ.(interface { - Basic() *BasicType; - }).Basic(); - t.Name = name; - t.BitSize, _ = e.Val(AttrBitSize).(int64); - t.BitOffset, _ = e.Val(AttrBitOffset).(int64); + Basic() *BasicType + }).Basic() + t.Name = name + t.BitSize, _ = e.Val(AttrBitSize).(int64) + t.BitOffset, _ = e.Val(AttrBitOffset).(int64) case TagClassType, TagStructType, TagUnionType: // Structure, union, or class type. (DWARF v2 §5.5) @@ -415,9 +415,9 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // AttrBitSize: bit size for bit fields // AttrDataMemberLoc: location within struct [required for struct, class] // There is much more to handle C++, all ignored for now. - t := new(StructType); - typ = t; - d.typeCache[off] = t; + t := new(StructType) + typ = t + d.typeCache[off] = t switch e.Tag { case TagClassType: t.Kind = "class" @@ -426,41 +426,41 @@ func (d *Data) Type(off Offset) (Type, os.Error) { case TagUnionType: t.Kind = "union" } - t.StructName, _ = e.Val(AttrName).(string); - t.Incomplete = e.Val(AttrDeclaration) != nil; - t.Field = make([]*StructField, 0, 8); + t.StructName, _ = e.Val(AttrName).(string) + t.Incomplete = e.Val(AttrDeclaration) != nil + t.Field = make([]*StructField, 0, 8) for kid := next(); kid != nil; kid = next() { if kid.Tag == TagMember { - f := new(StructField); + f := new(StructField) if f.Type = typeOf(kid); err != nil { goto Error } if loc, ok := kid.Val(AttrDataMemberLoc).([]byte); ok { - b := makeBuf(d, "location", 0, loc, d.addrsize); + b := makeBuf(d, "location", 0, loc, d.addrsize) if b.uint8() != opPlusUconst { - err = DecodeError{"info", kid.Offset, "unexpected opcode"}; - goto Error; + err = DecodeError{"info", kid.Offset, "unexpected opcode"} + goto Error } - f.ByteOffset = int64(b.uint()); + f.ByteOffset = int64(b.uint()) if b.err != nil { - err = b.err; - goto Error; + err = b.err + goto Error } } - f.Name, _ = kid.Val(AttrName).(string); - f.ByteSize, _ = kid.Val(AttrByteSize).(int64); - f.BitOffset, _ = kid.Val(AttrBitOffset).(int64); - f.BitSize, _ = kid.Val(AttrBitSize).(int64); - n := len(t.Field); + f.Name, _ = kid.Val(AttrName).(string) + f.ByteSize, _ = kid.Val(AttrByteSize).(int64) + f.BitOffset, _ = kid.Val(AttrBitOffset).(int64) + f.BitSize, _ = kid.Val(AttrBitSize).(int64) + n := len(t.Field) if n >= cap(t.Field) { - fld := make([]*StructField, n, n*2); + fld := make([]*StructField, n, n*2) for i, f := range t.Field { fld[i] = f } - t.Field = fld; + t.Field = fld } - t.Field = t.Field[0 : n+1]; - t.Field[n] = f; + t.Field = t.Field[0 : n+1] + t.Field[n] = f } } @@ -468,9 +468,9 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Type modifier (DWARF v2 §5.2) // Attributes: // AttrType: subtype - t := new(QualType); - typ = t; - d.typeCache[off] = t; + t := new(QualType) + typ = t + d.typeCache[off] = t if t.Type = typeOf(e); err != nil { goto Error } @@ -492,26 +492,26 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // TagEnumerator: // AttrName: name of constant // AttrConstValue: value of constant - t := new(EnumType); - typ = t; - d.typeCache[off] = t; - t.EnumName, _ = e.Val(AttrName).(string); - t.Val = make([]*EnumValue, 0, 8); + t := new(EnumType) + typ = t + d.typeCache[off] = t + t.EnumName, _ = e.Val(AttrName).(string) + t.Val = make([]*EnumValue, 0, 8) for kid := next(); kid != nil; kid = next() { if kid.Tag == TagEnumerator { - f := new(EnumValue); - f.Name, _ = kid.Val(AttrName).(string); - f.Val, _ = kid.Val(AttrConstValue).(int64); - n := len(t.Val); + f := new(EnumValue) + f.Name, _ = kid.Val(AttrName).(string) + f.Val, _ = kid.Val(AttrConstValue).(int64) + n := len(t.Val) if n >= cap(t.Val) { - val := make([]*EnumValue, n, n*2); + val := make([]*EnumValue, n, n*2) for i, f := range t.Val { val[i] = f } - t.Val = val; + t.Val = val } - t.Val = t.Val[0 : n+1]; - t.Val[n] = f; + t.Val = t.Val[0 : n+1] + t.Val[n] = f } } @@ -520,14 +520,14 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Attributes: // AttrType: subtype [not required! void* has no AttrType] // AttrAddrClass: address class [ignored] - t := new(PtrType); - typ = t; - d.typeCache[off] = t; + t := new(PtrType) + typ = t + d.typeCache[off] = t if e.Val(AttrType) == nil { - t.Type = &VoidType{}; - break; + t.Type = &VoidType{} + break } - t.Type = typeOf(e); + t.Type = typeOf(e) case TagSubroutineType: // Subroutine type. (DWARF v2 §5.7) @@ -539,15 +539,15 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // TagFormalParameter: typed parameter // AttrType: type of parameter // TagUnspecifiedParameter: final ... - t := new(FuncType); - typ = t; - d.typeCache[off] = t; + t := new(FuncType) + typ = t + d.typeCache[off] = t if t.ReturnType = typeOf(e); err != nil { goto Error } - t.ParamType = make([]Type, 0, 8); + t.ParamType = make([]Type, 0, 8) for kid := next(); kid != nil; kid = next() { - var tkid Type; + var tkid Type switch kid.Tag { default: continue @@ -558,16 +558,16 @@ func (d *Data) Type(off Offset) (Type, os.Error) { case TagUnspecifiedParameters: tkid = &DotDotDotType{} } - n := len(t.ParamType); + n := len(t.ParamType) if n >= cap(t.ParamType) { - param := make([]Type, n, n*2); + param := make([]Type, n, n*2) for i, t := range t.ParamType { param[i] = t } - t.ParamType = param; + t.ParamType = param } - t.ParamType = t.ParamType[0 : n+1]; - t.ParamType[n] = tkid; + t.ParamType = t.ParamType[0 : n+1] + t.ParamType[n] = tkid } case TagTypedef: @@ -575,29 +575,29 @@ func (d *Data) Type(off Offset) (Type, os.Error) { // Attributes: // AttrName: name [required] // AttrType: type definition [required] - t := new(TypedefType); - typ = t; - d.typeCache[off] = t; - t.Name, _ = e.Val(AttrName).(string); - t.Type = typeOf(e); + t := new(TypedefType) + typ = t + d.typeCache[off] = t + t.Name, _ = e.Val(AttrName).(string) + t.Type = typeOf(e) } if err != nil { goto Error } - b, ok := e.Val(AttrByteSize).(int64); + b, ok := e.Val(AttrByteSize).(int64) if !ok { b = -1 } - typ.Common().ByteSize = b; + typ.Common().ByteSize = b - return typ, nil; + return typ, nil Error: // If the parse fails, take the type out of the cache // so that the next call with this offset doesn't hit // the cache and return success. - d.typeCache[off] = nil, false; - return nil, err; + d.typeCache[off] = nil, false + return nil, err } diff --git a/src/pkg/debug/dwarf/type_test.go b/src/pkg/debug/dwarf/type_test.go index 629f0fb16..2c5aabd39 100644 --- a/src/pkg/debug/dwarf/type_test.go +++ b/src/pkg/debug/dwarf/type_test.go @@ -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) } diff --git a/src/pkg/debug/dwarf/unit.go b/src/pkg/debug/dwarf/unit.go index eb4e7656e..02cb363b4 100644 --- a/src/pkg/debug/dwarf/unit.go +++ b/src/pkg/debug/dwarf/unit.go @@ -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 } |