summaryrefslogtreecommitdiff
path: root/src/pkg/debug/dwarf/const.go
blob: 9d32a0af2a6fd3d64b4354b8fbffe81af0149549 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
// 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.

// Constants

package dwarf

import "strconv"

// An Attr identifies the attribute type in a DWARF Entry's Field.
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
)

var attrNames = [...]string{
	AttrSibling:        "Sibling",
	AttrLocation:       "Location",
	AttrName:           "Name",
	AttrOrdering:       "Ordering",
	AttrByteSize:       "ByteSize",
	AttrBitOffset:      "BitOffset",
	AttrBitSize:        "BitSize",
	AttrStmtList:       "StmtList",
	AttrLowpc:          "Lowpc",
	AttrHighpc:         "Highpc",
	AttrLanguage:       "Language",
	AttrDiscr:          "Discr",
	AttrDiscrValue:     "DiscrValue",
	AttrVisibility:     "Visibility",
	AttrImport:         "Import",
	AttrStringLength:   "StringLength",
	AttrCommonRef:      "CommonRef",
	AttrCompDir:        "CompDir",
	AttrConstValue:     "ConstValue",
	AttrContainingType: "ContainingType",
	AttrDefaultValue:   "DefaultValue",
	AttrInline:         "Inline",
	AttrIsOptional:     "IsOptional",
	AttrLowerBound:     "LowerBound",
	AttrProducer:       "Producer",
	AttrPrototyped:     "Prototyped",
	AttrReturnAddr:     "ReturnAddr",
	AttrStartScope:     "StartScope",
	AttrStrideSize:     "StrideSize",
	AttrUpperBound:     "UpperBound",
	AttrAbstractOrigin: "AbstractOrigin",
	AttrAccessibility:  "Accessibility",
	AttrAddrClass:      "AddrClass",
	AttrArtificial:     "Artificial",
	AttrBaseTypes:      "BaseTypes",
	AttrCalling:        "Calling",
	AttrCount:          "Count",
	AttrDataMemberLoc:  "DataMemberLoc",
	AttrDeclColumn:     "DeclColumn",
	AttrDeclFile:       "DeclFile",
	AttrDeclLine:       "DeclLine",
	AttrDeclaration:    "Declaration",
	AttrDiscrList:      "DiscrList",
	AttrEncoding:       "Encoding",
	AttrExternal:       "External",
	AttrFrameBase:      "FrameBase",
	AttrFriend:         "Friend",
	AttrIdentifierCase: "IdentifierCase",
	AttrMacroInfo:      "MacroInfo",
	AttrNamelistItem:   "NamelistItem",
	AttrPriority:       "Priority",
	AttrSegment:        "Segment",
	AttrSpecification:  "Specification",
	AttrStaticLink:     "StaticLink",
	AttrType:           "Type",
	AttrUseLocation:    "UseLocation",
	AttrVarParam:       "VarParam",
	AttrVirtuality:     "Virtuality",
	AttrVtableElemLoc:  "VtableElemLoc",
	AttrAllocated:      "Allocated",
	AttrAssociated:     "Associated",
	AttrDataLocation:   "DataLocation",
	AttrStride:         "Stride",
	AttrEntrypc:        "Entrypc",
	AttrUseUTF8:        "UseUTF8",
	AttrExtension:      "Extension",
	AttrRanges:         "Ranges",
	AttrTrampoline:     "Trampoline",
	AttrCallColumn:     "CallColumn",
	AttrCallFile:       "CallFile",
	AttrCallLine:       "CallLine",
	AttrDescription:    "Description",
}

func (a Attr) String() string {
	if int(a) < len(attrNames) {
		s := attrNames[a]
		if s != "" {
			return s
		}
	}
	return strconv.Itoa(int(a))
}

func (a Attr) GoString() string {
	if int(a) < len(attrNames) {
		s := attrNames[a]
		if s != "" {
			return "dwarf.Attr" + s
		}
	}
	return "dwarf.Attr(" + strconv.FormatInt(int64(a), 10) + ")"
}

// A format is a DWARF data encoding format.
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
	formSecOffset   format = 0x17
	formExprloc     format = 0x18
	formFlagPresent format = 0x19
	formRefSig8     format = 0x20
)

// 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
)

var tagNames = [...]string{
	TagArrayType:              "ArrayType",
	TagClassType:              "ClassType",
	TagEntryPoint:             "EntryPoint",
	TagEnumerationType:        "EnumerationType",
	TagFormalParameter:        "FormalParameter",
	TagImportedDeclaration:    "ImportedDeclaration",
	TagLabel:                  "Label",
	TagLexDwarfBlock:          "LexDwarfBlock",
	TagMember:                 "Member",
	TagPointerType:            "PointerType",
	TagReferenceType:          "ReferenceType",
	TagCompileUnit:            "CompileUnit",
	TagStringType:             "StringType",
	TagStructType:             "StructType",
	TagSubroutineType:         "SubroutineType",
	TagTypedef:                "Typedef",
	TagUnionType:              "UnionType",
	TagUnspecifiedParameters:  "UnspecifiedParameters",
	TagVariant:                "Variant",
	TagCommonDwarfBlock:       "CommonDwarfBlock",
	TagCommonInclusion:        "CommonInclusion",
	TagInheritance:            "Inheritance",
	TagInlinedSubroutine:      "InlinedSubroutine",
	TagModule:                 "Module",
	TagPtrToMemberType:        "PtrToMemberType",
	TagSetType:                "SetType",
	TagSubrangeType:           "SubrangeType",
	TagWithStmt:               "WithStmt",
	TagAccessDeclaration:      "AccessDeclaration",
	TagBaseType:               "BaseType",
	TagCatchDwarfBlock:        "CatchDwarfBlock",
	TagConstType:              "ConstType",
	TagConstant:               "Constant",
	TagEnumerator:             "Enumerator",
	TagFileType:               "FileType",
	TagFriend:                 "Friend",
	TagNamelist:               "Namelist",
	TagNamelistItem:           "NamelistItem",
	TagPackedType:             "PackedType",
	TagSubprogram:             "Subprogram",
	TagTemplateTypeParameter:  "TemplateTypeParameter",
	TagTemplateValueParameter: "TemplateValueParameter",
	TagThrownType:             "ThrownType",
	TagTryDwarfBlock:          "TryDwarfBlock",
	TagVariantPart:            "VariantPart",
	TagVariable:               "Variable",
	TagVolatileType:           "VolatileType",
	TagDwarfProcedure:         "DwarfProcedure",
	TagRestrictType:           "RestrictType",
	TagInterfaceType:          "InterfaceType",
	TagNamespace:              "Namespace",
	TagImportedModule:         "ImportedModule",
	TagUnspecifiedType:        "UnspecifiedType",
	TagPartialUnit:            "PartialUnit",
	TagImportedUnit:           "ImportedUnit",
	TagMutableType:            "MutableType",
}

func (t Tag) String() string {
	if int(t) < len(tagNames) {
		s := tagNames[t]
		if s != "" {
			return s
		}
	}
	return strconv.Itoa(int(t))
}

func (t Tag) GoString() string {
	if int(t) < len(tagNames) {
		s := tagNames[t]
		if s != "" {
			return "dwarf.Tag" + s
		}
	}
	return "dwarf.Tag(" + strconv.FormatInt(int64(t), 10) + ")"
}

// Location expression operators.
// The debug info encodes value locations like 8(R3)
// as a sequence of these op codes.
// 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
	/* OpLitN = OpLit0 + N for N = 0..31 */
	opReg0 = 0x50
	/* OpRegN = OpReg0 + N for N = 0..31 */
	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
	/* 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 */
	/* 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
)