dwarf.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. dwarf.h
  9. Abstract:
  10. This header contains definitions for the DWARF 2+ symbol format.
  11. Author:
  12. Evan Green 2-Dec-2015
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // Parser definitions.
  22. //
  23. //
  24. // Set this flag to print all the DWARF entities processed.
  25. //
  26. #define DWARF_CONTEXT_DEBUG 0x00000001
  27. //
  28. // Set this flag to print all the abbreviations.
  29. //
  30. #define DWARF_CONTEXT_DEBUG_ABBREVIATIONS 0x00000002
  31. //
  32. // Set this flag to print all the line number table information.
  33. //
  34. #define DWARF_CONTEXT_DEBUG_LINE_NUMBERS 0x00000004
  35. //
  36. // Set this flag to print unwinding information.
  37. //
  38. #define DWARF_CONTEXT_DEBUG_FRAMES 0x00000008
  39. //
  40. // Set this flag to print just the unwinding results.
  41. //
  42. #define DWARF_CONTEXT_VERBOSE_UNWINDING 0x00000010
  43. //
  44. // Define the maximum currently implemented depth of the stack. Bump this up if
  45. // applications seem to be heavily using the DWARF expression stack.
  46. //
  47. #define DWARF_EXPRESSION_STACK_SIZE 20
  48. //
  49. // ------------------------------------------------------ Data Type Definitions
  50. //
  51. typedef enum _DWARF_TAG {
  52. DwarfTagArrayType = 0x01,
  53. DwarfTagClassType = 0x02,
  54. DwarfTagEntryPoint = 0x03,
  55. DwarfTagEnumerationType = 0x04,
  56. DwarfTagFormalParameter = 0x05,
  57. DwarfTagImportedDeclaration = 0x08,
  58. DwarfTagLabel = 0x0A,
  59. DwarfTagLexicalBlock = 0x0B,
  60. DwarfTagMember = 0x0D,
  61. DwarfTagPointerType = 0x0F,
  62. DwarfTagReferenceType = 0x10,
  63. DwarfTagCompileUnit = 0x11,
  64. DwarfTagStringType = 0x12,
  65. DwarfTagStructureType = 0x13,
  66. DwarfTagSubroutineType = 0x15,
  67. DwarfTagTypedef = 0x16,
  68. DwarfTagUnionType = 0x17,
  69. DwarfTagUnspecifiedParameters = 0x18,
  70. DwarfTagVariant = 0x19,
  71. DwarfTagCommonBlock = 0x1A,
  72. DwarfTagCommonInclusion = 0x1B,
  73. DwarfTagInheritance = 0x1C,
  74. DwarfTagInlinedSubroutine = 0x1D,
  75. DwarfTagModule = 0x1E,
  76. DwarfTagPointerToMemberType = 0x1F,
  77. DwarfTagSetType = 0x20,
  78. DwarfTagSubrangeType = 0x21,
  79. DwarfTagWithStatement = 0x22,
  80. DwarfTagAccessDeclaration = 0x23,
  81. DwarfTagBaseType = 0x24,
  82. DwarfTagCatchBlock = 0x25,
  83. DwarfTagConstType = 0x26,
  84. DwarfTagConstant = 0x27,
  85. DwarfTagEnumerator = 0x28,
  86. DwarfTagFileType = 0x29,
  87. DwarfTagFriend = 0x2A,
  88. DwarfTagNameList = 0x2B,
  89. DwarfTagNameListItem = 0x2C,
  90. DwarfTagPackedType = 0x2D,
  91. DwarfTagSubprogram = 0x2E,
  92. DwarfTagTemplateTypeParameter = 0x2F,
  93. DwarfTagTemplateValueParameter = 0x30,
  94. DwarfTagThrownType = 0x31,
  95. DwarfTagTryBlock = 0x32,
  96. DwarfTagVariantPart = 0x33,
  97. DwarfTagVariable = 0x34,
  98. DwarfTagVolatileType = 0x35,
  99. DwarfTagDwarfProcedure = 0x36,
  100. DwarfTagRestrictType = 0x37,
  101. DwarfTagInterfaceType = 0x38,
  102. DwarfTagNamespace = 0x39,
  103. DwarfTagImportedModule = 0x3A,
  104. DwarfTagUnspecifiedType = 0x3B,
  105. DwarfTagPartialUnit = 0x3C,
  106. DwarfTagImportedUnit = 0x3D,
  107. DwarfTagCondition = 0x3F,
  108. DwarfTagSharedType = 0x40,
  109. DwarfTagTypeUnit = 0x41,
  110. DwarfTagRvalueReferenceType = 0x42,
  111. DwarfTagTemplateAlias = 0x43,
  112. DwarfTagLowUser = 0x4080,
  113. DwarfTagHighUser = 0xFFFF
  114. } DWARF_TAG, *PDWARF_TAG;
  115. typedef enum _DWARF_CHILDREN_VALUE {
  116. DwarfChildrenNo = 0x00,
  117. DwarfChildrenYes = 0x01
  118. } DWARF_CHILDREN_VALUE, *PDWARF_CHILDREN_VALUE;
  119. typedef enum _DWARF_ATTRIBUTE {
  120. DwarfAtSibling = 0x01,
  121. DwarfAtLocation = 0x02,
  122. DwarfAtName = 0x03,
  123. DwarfAtOrdering = 0x09,
  124. DwarfAtByteSize = 0x0B,
  125. DwarfAtBitOffset = 0x0C,
  126. DwarfAtBitSize = 0x0D,
  127. DwarfAtStatementList = 0x10,
  128. DwarfAtLowPc = 0x11,
  129. DwarfAtHighPc = 0x12,
  130. DwarfAtLanguage = 0x13,
  131. DwarfAtDiscr = 0x15,
  132. DwarfAtDiscrValue = 0x16,
  133. DwarfAtVisibility = 0x17,
  134. DwarfAtImport = 0x18,
  135. DwarfAtStringLength = 0x19,
  136. DwarfAtCommonReference = 0x1A,
  137. DwarfAtCompDir = 0x1B,
  138. DwarfAtConstValue = 0x1C,
  139. DwarfAtContainingType = 0x1D,
  140. DwarfAtDefaultValue = 0x1E,
  141. DwarfAtInline = 0x20,
  142. DwarfAtIsOptional = 0x21,
  143. DwarfAtLowerBound = 0x22,
  144. DwarfAtProducer = 0x25,
  145. DwarfAtPrototyped = 0x27,
  146. DwarfAtReturnAddress = 0x2A,
  147. DwarfAtStartScope = 0x2C,
  148. DwarfAtBitStride = 0x2E,
  149. DwarfAtUpperBound = 0x2F,
  150. DwarfAtAbstractOrigin = 0x31,
  151. DwarfAtAccessibility = 0x32,
  152. DwarfAtAddressClass = 0x33,
  153. DwarfAtArtificial = 0x34,
  154. DwarfAtBaseTypes = 0x35,
  155. DwarfAtCallingConvention = 0x36,
  156. DwarfAtCount = 0x37,
  157. DwarfAtDataMemberLocation = 0x38,
  158. DwarfAtDeclColumn = 0x39,
  159. DwarfAtDeclFile = 0x3A,
  160. DwarfAtDeclLine = 0x3B,
  161. DwarfAtDeclaration = 0x3C,
  162. DwarfAtDiscrList = 0x3D,
  163. DwarfAtEncoding = 0x3E,
  164. DwarfAtExternal = 0x3F,
  165. DwarfAtFrameBase = 0x40,
  166. DwarfAtFriend = 0x41,
  167. DwarfAtIdentifierCase = 0x42,
  168. DwarfAtMacroInfo = 0x43,
  169. DwarfAtNameListItem = 0x44,
  170. DwarfAtPriority = 0x45,
  171. DwarfAtSegment = 0x46,
  172. DwarfAtSpecification = 0x47,
  173. DwarfAtStaticLink = 0x48,
  174. DwarfAtType = 0x49,
  175. DwarfAtUseLocation = 0x4A,
  176. DwarfAtVariableParameter = 0x4B,
  177. DwarfAtVirtuality = 0x4C,
  178. DwarfAtVtableElementLocation = 0x4D,
  179. DwarfAtAllocated = 0x4E,
  180. DwarfAtAssociated = 0x4F,
  181. DwarfAtDataLocation = 0x50,
  182. DwarfAtByteStride = 0x51,
  183. DwarfAtEntryPc = 0x52,
  184. DwarfAtUseUtf8 = 0x53,
  185. DwarfAtExtension = 0x54,
  186. DwarfAtRanges = 0x55,
  187. DwarfAtTrampoline = 0x56,
  188. DwarfAtCallColumn = 0x57,
  189. DwarfAtCallFile = 0x58,
  190. DwarfAtCallLine = 0x59,
  191. DwarfAtDescription = 0x5A,
  192. DwarfAtBinaryScale = 0x5B,
  193. DwarfAtDecimalScale = 0x5C,
  194. DwarfAtSmall = 0x5D,
  195. DwarfAtDecimalSign = 0x5E,
  196. DwarfAtDigitCount = 0x5F,
  197. DwarfAtPictureString = 0x60,
  198. DwarfAtMutable = 0x61,
  199. DwarfAtThreadsScaled = 0x62,
  200. DwarfAtExplicit = 0x63,
  201. DwarfAtObjectPointer = 0x64,
  202. DwarfAtEndianity = 0x65,
  203. DwarfAtElemental = 0x66,
  204. DwarfAtPure = 0x67,
  205. DwarfAtRecursive = 0x68,
  206. DwarfAtSignature = 0x69,
  207. DwarfAtMainSubprogram = 0x6A,
  208. DwarfAtDataBitOffset = 0x6B,
  209. DwarfAtConstExpression = 0x6C,
  210. DwarfAtEnumClass = 0x6D,
  211. DwarfAtLinkageName = 0x6E,
  212. DwarfAtLowUser = 0x2000,
  213. DwarfAtHighUser = 0x3FFF
  214. } DWARF_ATTRIBUTE, *PDWARF_ATTRIBUTE;
  215. typedef enum _DWARF_FORM {
  216. DwarfFormAddress = 0x01,
  217. DwarfFormBlock2 = 0x03,
  218. DwarfFormBlock4 = 0x04,
  219. DwarfFormData2 = 0x05,
  220. DwarfFormData4 = 0x06,
  221. DwarfFormData8 = 0x07,
  222. DwarfFormString = 0x08,
  223. DwarfFormBlock = 0x09,
  224. DwarfFormBlock1 = 0x0A,
  225. DwarfFormData1 = 0x0B,
  226. DwarfFormFlag = 0x0C,
  227. DwarfFormSData = 0x0D,
  228. DwarfFormStringPointer = 0x0E,
  229. DwarfFormUData = 0x0F,
  230. DwarfFormRefAddress = 0x10,
  231. DwarfFormRef1 = 0x11,
  232. DwarfFormRef2 = 0x12,
  233. DwarfFormRef4 = 0x13,
  234. DwarfFormRef8 = 0x14,
  235. DwarfFormRefUData = 0x15,
  236. DwarfFormIndirect = 0x16,
  237. DwarfFormSecOffset = 0x17,
  238. DwarfFormExprLoc = 0x18,
  239. DwarfFormFlagPresent = 0x19,
  240. DwarfFormRefSig8 = 0x20
  241. } DWARF_FORM, *PDWARF_FORM;
  242. typedef enum _DWARF_OP {
  243. DwarfOpAddress = 0x03,
  244. DwarfOpDereference = 0x06,
  245. DwarfOpConst1U = 0x08,
  246. DwarfOpConst1S = 0x09,
  247. DwarfOpConst2U = 0x0A,
  248. DwarfOpConst2S = 0x0B,
  249. DwarfOpConst4U = 0x0C,
  250. DwarfOpConst4S = 0x0D,
  251. DwarfOpConst8U = 0x0E,
  252. DwarfOpConst8S = 0x0F,
  253. DwarfOpConstU = 0x10,
  254. DwarfOpConstS = 0x11,
  255. DwarfOpDup = 0x12,
  256. DwarfOpDrop = 0x13,
  257. DwarfOpOver = 0x14,
  258. DwarfOpPick = 0x15,
  259. DwarfOpSwap = 0x16,
  260. DwarfOpRot = 0x17,
  261. DwarfOpXDeref = 0x18,
  262. DwarfOpAbs = 0x19,
  263. DwarfOpAnd = 0x1A,
  264. DwarfOpDiv = 0x1B,
  265. DwarfOpMinus = 0x1C,
  266. DwarfOpMod = 0x1D,
  267. DwarfOpMul = 0x1E,
  268. DwarfOpNeg = 0x1F,
  269. DwarfOpNot = 0x20,
  270. DwarfOpOr = 0x21,
  271. DwarfOpPlus = 0x22,
  272. DwarfOpPlusUConst = 0x23,
  273. DwarfOpShl = 0x24,
  274. DwarfOpShr = 0x25,
  275. DwarfOpShra = 0x26,
  276. DwarfOpXor = 0x27,
  277. DwarfOpBra = 0x28,
  278. DwarfOpEq = 0x29,
  279. DwarfOpGe = 0x2A,
  280. DwarfOpGt = 0x2B,
  281. DwarfOpLe = 0x2C,
  282. DwarfOpLt = 0x2D,
  283. DwarfOpNe = 0x2E,
  284. DwarfOpSkip = 0x2F,
  285. DwarfOpLit0 = 0x30,
  286. DwarfOpLit31 = 0x4F,
  287. DwarfOpReg0 = 0x50,
  288. DwarfOpReg31 = 0x6F,
  289. DwarfOpBreg0 = 0x70,
  290. DwarfOpBreg31 = 0x8F,
  291. DwarfOpRegX = 0x90,
  292. DwarfOpFbreg = 0x91,
  293. DwarfOpBregX = 0x92,
  294. DwarfOpPiece = 0x93,
  295. DwarfOpDerefSize = 0x94,
  296. DwarfOpXDerefSize = 0x95,
  297. DwarfOpNop = 0x96,
  298. DwarfOpPushObjectAddress = 0x97,
  299. DwarfOpCall2 = 0x98,
  300. DwarfOpCall4 = 0x99,
  301. DwarfOpCallRef = 0x9A,
  302. DwarfOpFormTlsAddress = 0x9B,
  303. DwarfOpCallFrameCfa = 0x9C,
  304. DwarfOpBitPiece = 0x9D,
  305. DwarfOpImplicitValue = 0x9E,
  306. DwarfOpStackValue = 0x9F,
  307. DwarfOpLowUser = 0xE0,
  308. DwarfOpGnuPushTlsAddress = 0xE0,
  309. DwarfOpGnuUninit = 0xF0,
  310. DwarfOpGnuEncodedAddr = 0xF1,
  311. DwarfOpGnuImplicitPointer = 0xF2,
  312. DwarfOpGnuEntryValue = 0xF3,
  313. DwarfOpGnuConstType = 0xF4,
  314. DwarfOpGnuRegvalType = 0xF5,
  315. DwarfOpGnuDerefType = 0xF6,
  316. DwarfOpGnuConvert = 0xF7,
  317. DwarfOpGnuReinterpret = 0xF9,
  318. DwarfOpGnuParameterRef = 0xFA,
  319. DwarfOpGnuAddrIndex = 0xFB,
  320. DwarfOpGnuConstIndex = 0xFC,
  321. DwarfOpHighUser = 0xFF
  322. } DWARF_OP, *PDWARF_OP;
  323. typedef enum _DWARF_BASE_TYPE_ATTRIBUTE {
  324. DwarfAteAddress = 0x01,
  325. DwarfAteBoolean = 0x02,
  326. DwarfAteComplexFloat = 0x03,
  327. DwarfAteFloat = 0x04,
  328. DwarfAteSigned = 0x05,
  329. DwarfAteSignedChar = 0x06,
  330. DwarfAteUnsigned = 0x07,
  331. DwarfAteUnsignedChar = 0x08,
  332. DwarfAteImaginaryFloat = 0x09,
  333. DwarfAtePackedDecimal = 0x0A,
  334. DwarfAteNumericString = 0x0B,
  335. DwarfAteEdited = 0x0C,
  336. DwarfAteSignedFixed = 0x0D,
  337. DwarfAteUnsignedFixed = 0x0E,
  338. DwarfAteDecimalFloat = 0x0F,
  339. DwarfAteUtf = 0x10,
  340. DwarfAteLowUser = 0x80,
  341. DwarfAteHighUser = 0xFF
  342. } DWARF_BASE_TYPE_ATTRIBUTE, *PDWARF_BASE_TYPE_ATTRIBUTE;
  343. typedef enum _DWARF_DECIMAL_SIGN {
  344. DwarfDsUnsigned = 0x01,
  345. DwarfDsLeadingOverpunch = 0x02,
  346. DwarfDsTrailingOverpunch = 0x03,
  347. DwarfDsLeadingSeparate = 0x04,
  348. DwarfDsTrailingSeparate = 0x05,
  349. } DWARF_DECIMAL_SIGN, *PDWARF_DECIMAL_SIGN;
  350. typedef enum _DWARF_ENDIANITY {
  351. DwarfEndDefault = 0x00,
  352. DwarfEndBig = 0x01,
  353. DwarfEndLittle = 0x02,
  354. DwarfEndLowUser = 0x40,
  355. DwarfEndHighUser = 0xFF
  356. } DWARF_ENDIANITY, *PDWARF_ENDIANITY;
  357. typedef enum _DWARF_ACCESSIBILITY {
  358. DwarfAccessPublic = 0x01,
  359. DwarfAccessProtected = 0x02,
  360. DwarfAccessPrivate = 0x03,
  361. } DWARF_ACCESSIBILITY, *PDWARF_ACCESSIBILITY;
  362. typedef enum _DWARF_VISIBILITY {
  363. DwarfVisLocal = 0x01,
  364. DwarfVisExported = 0x02,
  365. DwarfVisQualified = 0x03
  366. } DWARF_VISIBILITY, *PDWARF_VISIBILITY;
  367. typedef enum _DWARF_VIRTUALITY {
  368. DwarfVirtualityNone = 0x00,
  369. DwarfVirtualityVirtual = 0x01,
  370. DwarfVirtualityPureVirtual = 0x02
  371. } DWARF_VIRTUALITY, *PDWARF_VIRTUALITY;
  372. typedef enum _DWARF_LANGUAGE {
  373. DwarfLanguageC89 = 0x0001,
  374. DwarfLanguageC = 0x0002,
  375. DwarfLanguageAda83 = 0x0003,
  376. DwarfLanguageCPlusPlus = 0x0004,
  377. DwarfLanguageCobol74 = 0x0005,
  378. DwarfLanguageCobol85 = 0x0006,
  379. DwarfLanguageFortran77 = 0x0007,
  380. DwarfLanguageFortran90 = 0x0008,
  381. DwarfLanguagePascal83 = 0x0009,
  382. DwarfLanguageModula2 = 0x000A,
  383. DwarfLanguageJava = 0x000B,
  384. DwarfLanguageC99 = 0x000C,
  385. DwarfLanguageAda95 = 0x000D,
  386. DwarfLanguageFortran95 = 0x000E,
  387. DwarfLanguagePli = 0x000F,
  388. DwarfLanguageObjC = 0x0010,
  389. DwarfLanguageObjCPlusPlus = 0x0011,
  390. DwarfLanguageUpc = 0x0012,
  391. DwarfLanguageD = 0x0013,
  392. DwarfLanguagePython = 0x0014,
  393. DwarfLanguageLowUser = 0x8000,
  394. DwarfLanguageHighUser = 0xFFFF
  395. } DWARF_LANGUAGE, *PDWARF_LANGUAGE;
  396. typedef enum _DWARF_IDENTIFIER_CASE {
  397. DwarfIdCaseSensitive = 0x00,
  398. DwarfIdUpCase = 0x01,
  399. DwarfIdDownCase = 0x02,
  400. DwarfIdCaseInsensitive = 0x03
  401. } DWARF_IDENTIFIER_CASE, *PDWARF_IDENTIFIER_CASE;
  402. typedef enum _DWARF_CALLING_CONVENTION {
  403. DwarfCcNormal = 0x01,
  404. DwarfCcProgram = 0x02,
  405. DwarfCcNoCall = 0x03,
  406. DwarfCcLowUser = 0x40,
  407. DwarfCcHighUser = 0xFF
  408. } DWARF_CALLING_CONVENTION, *PDWARF_CALLING_CONVENTION;
  409. typedef enum _DWARF_INLINE_CODE {
  410. DwarfInlNotInlined = 0x00,
  411. DwarfInlInlined = 0x01,
  412. DwarfInlDeclaredNotInlined = 0x02,
  413. DwarfInlDeclaredInlined = 0x03
  414. } DWARF_INLINE_CODE, *PDWARF_INLINE_CODE;
  415. typedef enum _DWARF_ARRAY_ORDERING {
  416. DwarfOrdRowMajor = 0x00,
  417. DwarfOrdColumnMajor = 0x01
  418. } DWARF_ARRAY_ORDERING, *PDWARF_ARRAY_ORDERING;
  419. typedef enum _DWARF_DISCRIMINANT_LIST {
  420. DwarfDscLabel = 0x00,
  421. DwarfDscRange = 0x01
  422. } DWARF_DISCRIMINANT_LIST, *PDWARF_DISCRIMINANT_LIST;
  423. typedef enum _DWARF_LINE_STANDARD_OP {
  424. DwarfLnsCopy = 0x01,
  425. DwarfLnsAdvancePc = 0x02,
  426. DwarfLnsAdvanceLine = 0x03,
  427. DwarfLnsSetFile = 0x04,
  428. DwarfLnsSetColumn = 0x05,
  429. DwarfLnsNegateStatement = 0x06,
  430. DwarfLnsSetBasicBlock = 0x07,
  431. DwarfLnsConstAddPc = 0x08,
  432. DwarfLnsFixedAdvancePc = 0x09,
  433. DwarfLnsSetPrologueEnd = 0x0A,
  434. DwarfLnsSetEpilogueBegin = 0x0B,
  435. DwarfLnsSetIsa = 0x0C,
  436. } DWARF_LINE_STANDARD_OP, *PDWARF_LINE_STANDARD_OP;
  437. typedef enum _DWARF_LINE_EXTENDED_OP {
  438. DwarfLneEndSequence = 0x01,
  439. DwarfLneSetAddress = 0x02,
  440. DwarfLneDefineFile = 0x03,
  441. DwarfLneSetDiscriminator = 0x04,
  442. DwarfLneLowUser = 0x80,
  443. DwarfLneHighUser = 0xFF
  444. } DWARF_LINE_EXTENDED_OP, *PDWARF_LINE_EXTENDED_OP;
  445. typedef enum _DWARF_MACRO_INFORMATION {
  446. DwarfMacInfoDefine = 0x01,
  447. DwarfMacInfoUndefine = 0x02,
  448. DwarfMacInfoStartFile = 0x03,
  449. DwarfMacInfoEndFile = 0x04,
  450. DwarfMacInfoVendorExt = 0xFF
  451. } DWARF_MACRO_INFORMATION, *PDWARF_MACRO_INFORMATION;
  452. typedef enum _DWARF_CALL_FRAME_ENCODING {
  453. DwarfCfaNop = 0x00,
  454. DwarfCfaSetLoc = 0x01,
  455. DwarfCfaAdvanceLoc1 = 0x02,
  456. DwarfCfaAdvanceLoc2 = 0x03,
  457. DwarfCfaAdvanceLoc4 = 0x04,
  458. DwarfCfaOffsetExtended = 0x05,
  459. DwarfCfaRestoreExtended = 0x06,
  460. DwarfCfaUndefined = 0x07,
  461. DwarfCfaSameValue = 0x08,
  462. DwarfCfaRegister = 0x09,
  463. DwarfCfaRememberState = 0x0A,
  464. DwarfCfaRestoreState = 0x0B,
  465. DwarfCfaDefCfa = 0x0C,
  466. DwarfCfaDefCfaRegister = 0x0D,
  467. DwarfCfaDefCfaOffset = 0x0E,
  468. DwarfCfaDefCfaExpression = 0x0F,
  469. DwarfCfaExpression = 0x10,
  470. DwarfCfaOffsetExtendedSf = 0x11,
  471. DwarfCfaDefCfaSf = 0x12,
  472. DwarfCfaDefCfaOffsetSf = 0x13,
  473. DwarfCfaValOffset = 0x14,
  474. DwarfCfaValOffsetSf = 0x15,
  475. DwarfCfaValExpression = 0x16,
  476. DwarfCfaLowUser = 0x1C,
  477. DwarfCfaHighUser = 0x3F,
  478. DwarfCfaAdvanceLoc = 0x40,
  479. DwarfCfaOffset = 0x80,
  480. DwarfCfaRestore = 0xC0,
  481. DwarfCfaHighMask = 0xC0
  482. } DWARF_CALL_FRAME_ENCODING, *PDWARF_CALL_FRAME_ENCODING;
  483. typedef enum _DWARF_ADDRESS_ENCODING {
  484. DwarfPeAbsolute = 0x00,
  485. DwarfPeLeb128 = 0x01,
  486. DwarfPeUdata2 = 0x02,
  487. DwarfPeUdata4 = 0x03,
  488. DwarfPeUdata8 = 0x04,
  489. DwarfPeSigned = 0x08,
  490. DwarfPeSleb128 = 0x09,
  491. DwarfPeSdata2 = 0x0A,
  492. DwarfPeSdata4 = 0x0B,
  493. DwarfPeSdata8 = 0x0C,
  494. DwarfPeTypeMask = 0x0F,
  495. DwarfPePcRelative = 0x10,
  496. DwarfPeTextRelative = 0x20,
  497. DwarfPeDataRelative = 0x30,
  498. DwarfPeFunctionRelative = 0x40,
  499. DwarfPeAligned = 0x50,
  500. DwarfPeModifierMask = 0x70,
  501. DwarfPeIndirect = 0x80,
  502. DwarfPeOmit = 0xFF,
  503. } DWARF_ADDRESS_ENCODING, *PDWARF_ADDRESS_ENCODING;
  504. //
  505. // Parser data types.
  506. //
  507. typedef enum _DWARF_LOCATION_TYPE {
  508. DwarfLocationInvalid,
  509. DwarfLocationMemory,
  510. DwarfLocationRegister,
  511. DwarfLocationKnownValue,
  512. DwarfLocationKnownData,
  513. DwarfLocationUndefined,
  514. } DWARF_LOCATION_TYPE, *PDWARF_LOCATION_TYPE;
  515. /*++
  516. Structure Description:
  517. This structure describes a single DWARF debug section.
  518. Members:
  519. Data - Stores a pointer to the data.
  520. Size - Stores the size of the section in bytes.
  521. --*/
  522. typedef struct _DWARF_SECTION {
  523. PVOID Data;
  524. ULONG Size;
  525. } DWARF_SECTION, *PDWARF_SECTION;
  526. /*++
  527. Structure Description:
  528. This structure contains the various debug sections used in DWARF symbols.
  529. Members:
  530. Info - Stores the primary .debug_info section.
  531. Abbreviations - Stores the .debug_abbrev abbreviations table.
  532. Strings - Stores the .debug_str string table.
  533. Locations - Stores the .debug_loc locations section.
  534. Aranges - Stores the .debug_aranges section.
  535. Ranges - Stores the .debug_ranges section.
  536. Macros - Stores the .debug_macinfo preprocessor macros information section.
  537. Lines - Stores the .debug_line line number information.
  538. PubNames - Store the .debug_pubnames name information.
  539. PubTypes - Stores the .debug_pubtypes type name information.
  540. Types - Stores the .debug_types type information, new in DWARF4.
  541. Frame - Stores the .debug_frame section.
  542. EhFrame - Stores the .eh_frame section.
  543. EhFrameAddress - Stores the virtual address of the .eh_frame section.
  544. --*/
  545. typedef struct _DWARF_DEBUG_SECTIONS {
  546. DWARF_SECTION Info;
  547. DWARF_SECTION Abbreviations;
  548. DWARF_SECTION Strings;
  549. DWARF_SECTION Locations;
  550. DWARF_SECTION Aranges;
  551. DWARF_SECTION Ranges;
  552. DWARF_SECTION Macros;
  553. DWARF_SECTION Lines;
  554. DWARF_SECTION PubNames;
  555. DWARF_SECTION PubTypes;
  556. DWARF_SECTION Types;
  557. DWARF_SECTION Frame;
  558. DWARF_SECTION EhFrame;
  559. ULONGLONG EhFrameAddress;
  560. } DWARF_DEBUG_SECTIONS, *PDWARF_DEBUG_SECTIONS;
  561. /*++
  562. Structure Description:
  563. This structure contains the context for a DWARF symbol table.
  564. Members:
  565. Flags - Stores a bitfield of flags. See DWARF_CONTEXT_* definitions.
  566. FileData - Stores a pointer to the file data.
  567. FileSize - Stores the size of the file data in bytes.
  568. Sections - Stores pointers to the various DWARF debug sections.
  569. UnitList - Stores the head of the list of Compilation Units.
  570. SourcesHead - Stores a pointer to the head of the list of source file
  571. symbols.
  572. LoadingContext - Stores a pointer to internal state used during the load of
  573. the module. This is of type DWARF_LOADING_CONTEXT.
  574. --*/
  575. typedef struct _DWARF_CONTEXT {
  576. ULONG Flags;
  577. PSTR FileData;
  578. UINTN FileSize;
  579. DWARF_DEBUG_SECTIONS Sections;
  580. LIST_ENTRY UnitList;
  581. PLIST_ENTRY SourcesHead;
  582. PVOID LoadingContext;
  583. } DWARF_CONTEXT, *PDWARF_CONTEXT;
  584. //
  585. // Location support stuctures
  586. //
  587. /*++
  588. Structure Description:
  589. This union contains the different forms of a DWARF location.
  590. Members:
  591. Address - Stores the target memory address location form.
  592. Register - Stores the register address form.
  593. Value - Stores the direct value, rather than the location.
  594. Buffer - Stores a pointer and size of a buffer that contains the direct
  595. value, rather than the location.
  596. --*/
  597. typedef union _DWARF_LOCATION_UNION {
  598. ULONGLONG Address;
  599. ULONG Register;
  600. ULONGLONG Value;
  601. DWARF_SECTION Buffer;
  602. } DWARF_LOCATION_UNION, *PDWARF_LOCATION_UNION;
  603. typedef struct _DWARF_LOCATION DWARF_LOCATION, *PDWARF_LOCATION;
  604. typedef struct _DWARF_COMPILATION_UNIT
  605. DWARF_COMPILATION_UNIT, *PDWARF_COMPILATION_UNIT;
  606. /*++
  607. Structure Description:
  608. This structure describes a DWARF location.
  609. Members:
  610. ListEntry - Stores pointers to the next and previous pieces of the
  611. complete location if this location is part of a list.
  612. Form - Stores the location form.
  613. Value - Stores the location value union.
  614. BitSize - Stores the size of this piece, or 0 if this describes the entire
  615. object.
  616. BitOffset - Stores the offset from the start of the source data in bits if
  617. this piece is offset in some way.
  618. NextPiece - Stores a pointer to the next piece of the object if it's a
  619. composite description.
  620. --*/
  621. struct _DWARF_LOCATION {
  622. DWARF_LOCATION_TYPE Form;
  623. DWARF_LOCATION_UNION Value;
  624. ULONG BitSize;
  625. ULONG BitOffset;
  626. PDWARF_LOCATION NextPiece;
  627. };
  628. /*++
  629. Structure Description:
  630. This structure describes the context needed to compute a DWARF location.
  631. Members:
  632. Stack - Stores the DWARF expression stack. Element zero is the first
  633. pushed and last popped.
  634. StackSize - Stores the number of valid elements on the expression stack.
  635. Unit - Stores a pointer to the compilation unit the expression lives in.
  636. AddressSize - Stores the size of a target address.
  637. Pc - Stores the current value of the instruction pointer, which may be
  638. needed for computing the frame base.
  639. ObjectAddress - Stores the base address of the object being evaluated. This
  640. is the value pushed if a push object address op is executed.
  641. TlsBase - Stores the thread local storage base region for this thread and
  642. module. This value is added if a Form TLS Address op is executed.
  643. CurrentFunction - Stores a pointer to the current function.
  644. Location - Stores the final location of the entity. This may end up being a
  645. list.
  646. Constant - Stores a boolean indicating whether or not the expression is
  647. constant or depends on machine state.
  648. --*/
  649. typedef struct _DWARF_LOCATION_CONTEXT {
  650. ULONGLONG Stack[DWARF_EXPRESSION_STACK_SIZE];
  651. ULONG StackSize;
  652. PDWARF_COMPILATION_UNIT Unit;
  653. UCHAR AddressSize;
  654. ULONGLONG Pc;
  655. ULONGLONG ObjectAddress;
  656. ULONGLONG TlsBase;
  657. PFUNCTION_SYMBOL CurrentFunction;
  658. DWARF_LOCATION Location;
  659. BOOL Constant;
  660. } DWARF_LOCATION_CONTEXT, *PDWARF_LOCATION_CONTEXT;
  661. //
  662. // -------------------------------------------------------------------- Globals
  663. //
  664. //
  665. // -------------------------------------------------------- Function Prototypes
  666. //
  667. INT
  668. DwarfLoadSymbols (
  669. PSTR Filename,
  670. IMAGE_MACHINE_TYPE MachineType,
  671. ULONG Flags,
  672. PVOID HostContext,
  673. PDEBUG_SYMBOLS *Symbols
  674. );
  675. /*++
  676. Routine Description:
  677. This routine loads DWARF symbols for the given file.
  678. Arguments:
  679. Filename - Supplies the name of the binary to load symbols from.
  680. MachineType - Supplies the required machine type of the image. Set to
  681. unknown to allow the symbol library to load a file with any machine
  682. type.
  683. Flags - Supplies a bitfield of flags governing the behavior during load.
  684. These flags are specific to each symbol library.
  685. HostContext - Supplies the value to store in the host context field of the
  686. debug symbols.
  687. Symbols - Supplies an optional pointer where a pointer to the symbols will
  688. be returned on success.
  689. Return Value:
  690. 0 on success.
  691. Returns an error number on failure.
  692. --*/
  693. INT
  694. DwarfStackUnwind (
  695. PDEBUG_SYMBOLS Symbols,
  696. ULONGLONG DebasedPc,
  697. PSTACK_FRAME Frame
  698. );
  699. /*++
  700. Routine Description:
  701. This routine attempts to unwind the stack by one frame.
  702. Arguments:
  703. Symbols - Supplies a pointer to the debug symbols.
  704. DebasedPc - Supplies the program counter value, assuming the image were
  705. loaded at its preferred base address (that is, actual PC minus loaded
  706. base difference of the module).
  707. Frame - Supplies a pointer where the basic frame information for this
  708. frame will be returned.
  709. Return Value:
  710. 0 on success.
  711. EOF if there are no more stack frames.
  712. Returns an error code on failure.
  713. --*/