Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

481 rinda
15 KiB

  1. // Copyright 2018 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Constants
  15. package dwarf
  16. import "strconv"
  17. // An Attr identifies the attribute type in a DWARF Entry's Field.
  18. type Attr uint32
  19. const (
  20. AttrSibling Attr = 0x01
  21. AttrLocation Attr = 0x02
  22. AttrName Attr = 0x03
  23. AttrOrdering Attr = 0x09
  24. AttrByteSize Attr = 0x0B
  25. AttrBitOffset Attr = 0x0C
  26. AttrBitSize Attr = 0x0D
  27. AttrStmtList Attr = 0x10
  28. AttrLowpc Attr = 0x11
  29. AttrHighpc Attr = 0x12
  30. AttrLanguage Attr = 0x13
  31. AttrDiscr Attr = 0x15
  32. AttrDiscrValue Attr = 0x16
  33. AttrVisibility Attr = 0x17
  34. AttrImport Attr = 0x18
  35. AttrStringLength Attr = 0x19
  36. AttrCommonRef Attr = 0x1A
  37. AttrCompDir Attr = 0x1B
  38. AttrConstValue Attr = 0x1C
  39. AttrContainingType Attr = 0x1D
  40. AttrDefaultValue Attr = 0x1E
  41. AttrInline Attr = 0x20
  42. AttrIsOptional Attr = 0x21
  43. AttrLowerBound Attr = 0x22
  44. AttrProducer Attr = 0x25
  45. AttrPrototyped Attr = 0x27
  46. AttrReturnAddr Attr = 0x2A
  47. AttrStartScope Attr = 0x2C
  48. AttrStrideSize Attr = 0x2E
  49. AttrUpperBound Attr = 0x2F
  50. AttrAbstractOrigin Attr = 0x31
  51. AttrAccessibility Attr = 0x32
  52. AttrAddrClass Attr = 0x33
  53. AttrArtificial Attr = 0x34
  54. AttrBaseTypes Attr = 0x35
  55. AttrCalling Attr = 0x36
  56. AttrCount Attr = 0x37
  57. AttrDataMemberLoc Attr = 0x38
  58. AttrDeclColumn Attr = 0x39
  59. AttrDeclFile Attr = 0x3A
  60. AttrDeclLine Attr = 0x3B
  61. AttrDeclaration Attr = 0x3C
  62. AttrDiscrList Attr = 0x3D
  63. AttrEncoding Attr = 0x3E
  64. AttrExternal Attr = 0x3F
  65. AttrFrameBase Attr = 0x40
  66. AttrFriend Attr = 0x41
  67. AttrIdentifierCase Attr = 0x42
  68. AttrMacroInfo Attr = 0x43
  69. AttrNamelistItem Attr = 0x44
  70. AttrPriority Attr = 0x45
  71. AttrSegment Attr = 0x46
  72. AttrSpecification Attr = 0x47
  73. AttrStaticLink Attr = 0x48
  74. AttrType Attr = 0x49
  75. AttrUseLocation Attr = 0x4A
  76. AttrVarParam Attr = 0x4B
  77. AttrVirtuality Attr = 0x4C
  78. AttrVtableElemLoc Attr = 0x4D
  79. AttrAllocated Attr = 0x4E
  80. AttrAssociated Attr = 0x4F
  81. AttrDataLocation Attr = 0x50
  82. AttrStride Attr = 0x51
  83. AttrEntrypc Attr = 0x52
  84. AttrUseUTF8 Attr = 0x53
  85. AttrExtension Attr = 0x54
  86. AttrRanges Attr = 0x55
  87. AttrTrampoline Attr = 0x56
  88. AttrCallColumn Attr = 0x57
  89. AttrCallFile Attr = 0x58
  90. AttrCallLine Attr = 0x59
  91. AttrDescription Attr = 0x5A
  92. // Go-specific attributes.
  93. AttrGoKind Attr = 0x2900
  94. AttrGoKey Attr = 0x2901
  95. AttrGoElem Attr = 0x2902
  96. AttrGoEmbeddedField Attr = 0x2903
  97. )
  98. var attrNames = [...]string{
  99. AttrSibling: "Sibling",
  100. AttrLocation: "Location",
  101. AttrName: "Name",
  102. AttrOrdering: "Ordering",
  103. AttrByteSize: "ByteSize",
  104. AttrBitOffset: "BitOffset",
  105. AttrBitSize: "BitSize",
  106. AttrStmtList: "StmtList",
  107. AttrLowpc: "Lowpc",
  108. AttrHighpc: "Highpc",
  109. AttrLanguage: "Language",
  110. AttrDiscr: "Discr",
  111. AttrDiscrValue: "DiscrValue",
  112. AttrVisibility: "Visibility",
  113. AttrImport: "Import",
  114. AttrStringLength: "StringLength",
  115. AttrCommonRef: "CommonRef",
  116. AttrCompDir: "CompDir",
  117. AttrConstValue: "ConstValue",
  118. AttrContainingType: "ContainingType",
  119. AttrDefaultValue: "DefaultValue",
  120. AttrInline: "Inline",
  121. AttrIsOptional: "IsOptional",
  122. AttrLowerBound: "LowerBound",
  123. AttrProducer: "Producer",
  124. AttrPrototyped: "Prototyped",
  125. AttrReturnAddr: "ReturnAddr",
  126. AttrStartScope: "StartScope",
  127. AttrStrideSize: "StrideSize",
  128. AttrUpperBound: "UpperBound",
  129. AttrAbstractOrigin: "AbstractOrigin",
  130. AttrAccessibility: "Accessibility",
  131. AttrAddrClass: "AddrClass",
  132. AttrArtificial: "Artificial",
  133. AttrBaseTypes: "BaseTypes",
  134. AttrCalling: "Calling",
  135. AttrCount: "Count",
  136. AttrDataMemberLoc: "DataMemberLoc",
  137. AttrDeclColumn: "DeclColumn",
  138. AttrDeclFile: "DeclFile",
  139. AttrDeclLine: "DeclLine",
  140. AttrDeclaration: "Declaration",
  141. AttrDiscrList: "DiscrList",
  142. AttrEncoding: "Encoding",
  143. AttrExternal: "External",
  144. AttrFrameBase: "FrameBase",
  145. AttrFriend: "Friend",
  146. AttrIdentifierCase: "IdentifierCase",
  147. AttrMacroInfo: "MacroInfo",
  148. AttrNamelistItem: "NamelistItem",
  149. AttrPriority: "Priority",
  150. AttrSegment: "Segment",
  151. AttrSpecification: "Specification",
  152. AttrStaticLink: "StaticLink",
  153. AttrType: "Type",
  154. AttrUseLocation: "UseLocation",
  155. AttrVarParam: "VarParam",
  156. AttrVirtuality: "Virtuality",
  157. AttrVtableElemLoc: "VtableElemLoc",
  158. AttrAllocated: "Allocated",
  159. AttrAssociated: "Associated",
  160. AttrDataLocation: "DataLocation",
  161. AttrStride: "Stride",
  162. AttrEntrypc: "Entrypc",
  163. AttrUseUTF8: "UseUTF8",
  164. AttrExtension: "Extension",
  165. AttrRanges: "Ranges",
  166. AttrTrampoline: "Trampoline",
  167. AttrCallColumn: "CallColumn",
  168. AttrCallFile: "CallFile",
  169. AttrCallLine: "CallLine",
  170. AttrDescription: "Description",
  171. }
  172. func (a Attr) String() string {
  173. if int(a) < len(attrNames) {
  174. s := attrNames[a]
  175. if s != "" {
  176. return s
  177. }
  178. }
  179. switch a {
  180. case AttrGoKind:
  181. return "GoKind"
  182. case AttrGoKey:
  183. return "GoKey"
  184. case AttrGoElem:
  185. return "GoElem"
  186. case AttrGoEmbeddedField:
  187. return "GoEmbeddedField"
  188. }
  189. return strconv.Itoa(int(a))
  190. }
  191. func (a Attr) GoString() string {
  192. if int(a) < len(attrNames) {
  193. s := attrNames[a]
  194. if s != "" {
  195. return "dwarf.Attr" + s
  196. }
  197. }
  198. return "dwarf.Attr(" + strconv.FormatInt(int64(a), 10) + ")"
  199. }
  200. // A format is a DWARF data encoding format.
  201. type format uint32
  202. const (
  203. // value formats
  204. formAddr format = 0x01
  205. formDwarfBlock2 format = 0x03
  206. formDwarfBlock4 format = 0x04
  207. formData2 format = 0x05
  208. formData4 format = 0x06
  209. formData8 format = 0x07
  210. formString format = 0x08
  211. formDwarfBlock format = 0x09
  212. formDwarfBlock1 format = 0x0A
  213. formData1 format = 0x0B
  214. formFlag format = 0x0C
  215. formSdata format = 0x0D
  216. formStrp format = 0x0E
  217. formUdata format = 0x0F
  218. formRefAddr format = 0x10
  219. formRef1 format = 0x11
  220. formRef2 format = 0x12
  221. formRef4 format = 0x13
  222. formRef8 format = 0x14
  223. formRefUdata format = 0x15
  224. formIndirect format = 0x16
  225. // The following are new in DWARF 4.
  226. formSecOffset format = 0x17
  227. formExprloc format = 0x18
  228. formFlagPresent format = 0x19
  229. formRefSig8 format = 0x20
  230. // Extensions for multi-file compression (.dwz)
  231. // http://www.dwarfstd.org/ShowIssue.php?issue=120604.1
  232. formGnuRefAlt format = 0x1f20
  233. formGnuStrpAlt format = 0x1f21
  234. )
  235. // A Tag is the classification (the type) of an Entry.
  236. type Tag uint32
  237. const (
  238. TagArrayType Tag = 0x01
  239. TagClassType Tag = 0x02
  240. TagEntryPoint Tag = 0x03
  241. TagEnumerationType Tag = 0x04
  242. TagFormalParameter Tag = 0x05
  243. TagImportedDeclaration Tag = 0x08
  244. TagLabel Tag = 0x0A
  245. TagLexDwarfBlock Tag = 0x0B
  246. TagMember Tag = 0x0D
  247. TagPointerType Tag = 0x0F
  248. TagReferenceType Tag = 0x10
  249. TagCompileUnit Tag = 0x11
  250. TagStringType Tag = 0x12
  251. TagStructType Tag = 0x13
  252. TagSubroutineType Tag = 0x15
  253. TagTypedef Tag = 0x16
  254. TagUnionType Tag = 0x17
  255. TagUnspecifiedParameters Tag = 0x18
  256. TagVariant Tag = 0x19
  257. TagCommonDwarfBlock Tag = 0x1A
  258. TagCommonInclusion Tag = 0x1B
  259. TagInheritance Tag = 0x1C
  260. TagInlinedSubroutine Tag = 0x1D
  261. TagModule Tag = 0x1E
  262. TagPtrToMemberType Tag = 0x1F
  263. TagSetType Tag = 0x20
  264. TagSubrangeType Tag = 0x21
  265. TagWithStmt Tag = 0x22
  266. TagAccessDeclaration Tag = 0x23
  267. TagBaseType Tag = 0x24
  268. TagCatchDwarfBlock Tag = 0x25
  269. TagConstType Tag = 0x26
  270. TagConstant Tag = 0x27
  271. TagEnumerator Tag = 0x28
  272. TagFileType Tag = 0x29
  273. TagFriend Tag = 0x2A
  274. TagNamelist Tag = 0x2B
  275. TagNamelistItem Tag = 0x2C
  276. TagPackedType Tag = 0x2D
  277. TagSubprogram Tag = 0x2E
  278. TagTemplateTypeParameter Tag = 0x2F
  279. TagTemplateValueParameter Tag = 0x30
  280. TagThrownType Tag = 0x31
  281. TagTryDwarfBlock Tag = 0x32
  282. TagVariantPart Tag = 0x33
  283. TagVariable Tag = 0x34
  284. TagVolatileType Tag = 0x35
  285. // The following are new in DWARF 3.
  286. TagDwarfProcedure Tag = 0x36
  287. TagRestrictType Tag = 0x37
  288. TagInterfaceType Tag = 0x38
  289. TagNamespace Tag = 0x39
  290. TagImportedModule Tag = 0x3A
  291. TagUnspecifiedType Tag = 0x3B
  292. TagPartialUnit Tag = 0x3C
  293. TagImportedUnit Tag = 0x3D
  294. TagMutableType Tag = 0x3E // Later removed from DWARF.
  295. TagCondition Tag = 0x3F
  296. TagSharedType Tag = 0x40
  297. // The following are new in DWARF 4.
  298. TagTypeUnit Tag = 0x41
  299. TagRvalueReferenceType Tag = 0x42
  300. TagTemplateAlias Tag = 0x43
  301. )
  302. var tagNames = [...]string{
  303. TagArrayType: "ArrayType",
  304. TagClassType: "ClassType",
  305. TagEntryPoint: "EntryPoint",
  306. TagEnumerationType: "EnumerationType",
  307. TagFormalParameter: "FormalParameter",
  308. TagImportedDeclaration: "ImportedDeclaration",
  309. TagLabel: "Label",
  310. TagLexDwarfBlock: "LexDwarfBlock",
  311. TagMember: "Member",
  312. TagPointerType: "PointerType",
  313. TagReferenceType: "ReferenceType",
  314. TagCompileUnit: "CompileUnit",
  315. TagStringType: "StringType",
  316. TagStructType: "StructType",
  317. TagSubroutineType: "SubroutineType",
  318. TagTypedef: "Typedef",
  319. TagUnionType: "UnionType",
  320. TagUnspecifiedParameters: "UnspecifiedParameters",
  321. TagVariant: "Variant",
  322. TagCommonDwarfBlock: "CommonDwarfBlock",
  323. TagCommonInclusion: "CommonInclusion",
  324. TagInheritance: "Inheritance",
  325. TagInlinedSubroutine: "InlinedSubroutine",
  326. TagModule: "Module",
  327. TagPtrToMemberType: "PtrToMemberType",
  328. TagSetType: "SetType",
  329. TagSubrangeType: "SubrangeType",
  330. TagWithStmt: "WithStmt",
  331. TagAccessDeclaration: "AccessDeclaration",
  332. TagBaseType: "BaseType",
  333. TagCatchDwarfBlock: "CatchDwarfBlock",
  334. TagConstType: "ConstType",
  335. TagConstant: "Constant",
  336. TagEnumerator: "Enumerator",
  337. TagFileType: "FileType",
  338. TagFriend: "Friend",
  339. TagNamelist: "Namelist",
  340. TagNamelistItem: "NamelistItem",
  341. TagPackedType: "PackedType",
  342. TagSubprogram: "Subprogram",
  343. TagTemplateTypeParameter: "TemplateTypeParameter",
  344. TagTemplateValueParameter: "TemplateValueParameter",
  345. TagThrownType: "ThrownType",
  346. TagTryDwarfBlock: "TryDwarfBlock",
  347. TagVariantPart: "VariantPart",
  348. TagVariable: "Variable",
  349. TagVolatileType: "VolatileType",
  350. TagDwarfProcedure: "DwarfProcedure",
  351. TagRestrictType: "RestrictType",
  352. TagInterfaceType: "InterfaceType",
  353. TagNamespace: "Namespace",
  354. TagImportedModule: "ImportedModule",
  355. TagUnspecifiedType: "UnspecifiedType",
  356. TagPartialUnit: "PartialUnit",
  357. TagImportedUnit: "ImportedUnit",
  358. TagMutableType: "MutableType",
  359. TagCondition: "Condition",
  360. TagSharedType: "SharedType",
  361. TagTypeUnit: "TypeUnit",
  362. TagRvalueReferenceType: "RvalueReferenceType",
  363. TagTemplateAlias: "TemplateAlias",
  364. }
  365. func (t Tag) String() string {
  366. if int(t) < len(tagNames) {
  367. s := tagNames[t]
  368. if s != "" {
  369. return s
  370. }
  371. }
  372. return strconv.Itoa(int(t))
  373. }
  374. func (t Tag) GoString() string {
  375. if int(t) < len(tagNames) {
  376. s := tagNames[t]
  377. if s != "" {
  378. return "dwarf.Tag" + s
  379. }
  380. }
  381. return "dwarf.Tag(" + strconv.FormatInt(int64(t), 10) + ")"
  382. }
  383. // Location expression operators.
  384. // The debug info encodes value locations like 8(R3)
  385. // as a sequence of these op codes.
  386. // This package does not implement full expressions;
  387. // the opPlusUconst operator is expected by the type parser.
  388. const (
  389. opAddr = 0x03 /* 1 op, const addr */
  390. opDeref = 0x06
  391. opConst1u = 0x08 /* 1 op, 1 byte const */
  392. opConst1s = 0x09 /* " signed */
  393. opConst2u = 0x0A /* 1 op, 2 byte const */
  394. opConst2s = 0x0B /* " signed */
  395. opConst4u = 0x0C /* 1 op, 4 byte const */
  396. opConst4s = 0x0D /* " signed */
  397. opConst8u = 0x0E /* 1 op, 8 byte const */
  398. opConst8s = 0x0F /* " signed */
  399. opConstu = 0x10 /* 1 op, LEB128 const */
  400. opConsts = 0x11 /* " signed */
  401. opDup = 0x12
  402. opDrop = 0x13
  403. opOver = 0x14
  404. opPick = 0x15 /* 1 op, 1 byte stack index */
  405. opSwap = 0x16
  406. opRot = 0x17
  407. opXderef = 0x18
  408. opAbs = 0x19
  409. opAnd = 0x1A
  410. opDiv = 0x1B
  411. opMinus = 0x1C
  412. opMod = 0x1D
  413. opMul = 0x1E
  414. opNeg = 0x1F
  415. opNot = 0x20
  416. opOr = 0x21
  417. opPlus = 0x22
  418. opPlusUconst = 0x23 /* 1 op, ULEB128 addend */
  419. opShl = 0x24
  420. opShr = 0x25
  421. opShra = 0x26
  422. opXor = 0x27
  423. opSkip = 0x2F /* 1 op, signed 2-byte constant */
  424. opBra = 0x28 /* 1 op, signed 2-byte constant */
  425. opEq = 0x29
  426. opGe = 0x2A
  427. opGt = 0x2B
  428. opLe = 0x2C
  429. opLt = 0x2D
  430. opNe = 0x2E
  431. opLit0 = 0x30
  432. /* OpLitN = OpLit0 + N for N = 0..31 */
  433. opReg0 = 0x50
  434. /* OpRegN = OpReg0 + N for N = 0..31 */
  435. opBreg0 = 0x70 /* 1 op, signed LEB128 constant */
  436. /* OpBregN = OpBreg0 + N for N = 0..31 */
  437. opRegx = 0x90 /* 1 op, ULEB128 register */
  438. opFbreg = 0x91 /* 1 op, SLEB128 offset */
  439. opBregx = 0x92 /* 2 op, ULEB128 reg; SLEB128 off */
  440. opPiece = 0x93 /* 1 op, ULEB128 size of piece */
  441. opDerefSize = 0x94 /* 1-byte size of data retrieved */
  442. opXderefSize = 0x95 /* 1-byte size of data retrieved */
  443. opNop = 0x96
  444. /* next four new in Dwarf v3 */
  445. opPushObjAddr = 0x97
  446. opCall2 = 0x98 /* 2-byte offset of DIE */
  447. opCall4 = 0x99 /* 4-byte offset of DIE */
  448. opCallRef = 0x9A /* 4- or 8- byte offset of DIE */
  449. /* 0xE0-0xFF reserved for user-specific */
  450. )
  451. // Basic type encodings -- the value for AttrEncoding in a TagBaseType Entry.
  452. const (
  453. encAddress = 0x01
  454. encBoolean = 0x02
  455. encComplexFloat = 0x03
  456. encFloat = 0x04
  457. encSigned = 0x05
  458. encSignedChar = 0x06
  459. encUnsigned = 0x07
  460. encUnsignedChar = 0x08
  461. encImaginaryFloat = 0x09
  462. )