Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

785 lines
28 KiB

  1. //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines a bunch of datatypes that are useful for creating and
  11. // walking debug info in LLVM IR form. They essentially provide wrappers around
  12. // the information in the global variables that's needed when constructing the
  13. // DWARF information.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_DEBUGINFO_H
  17. #define LLVM_DEBUGINFO_H
  18. #include "llvm/ADT/SmallPtrSet.h"
  19. #include "llvm/ADT/SmallVector.h"
  20. #include "llvm/ADT/StringRef.h"
  21. #include "llvm/Support/Dwarf.h"
  22. namespace llvm {
  23. class BasicBlock;
  24. class Constant;
  25. class Function;
  26. class GlobalVariable;
  27. class Module;
  28. class Type;
  29. class Value;
  30. class DbgDeclareInst;
  31. class Instruction;
  32. class MDNode;
  33. class NamedMDNode;
  34. class LLVMContext;
  35. class raw_ostream;
  36. class DIFile;
  37. class DISubprogram;
  38. class DILexicalBlock;
  39. class DILexicalBlockFile;
  40. class DIVariable;
  41. class DIType;
  42. class DIObjCProperty;
  43. /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
  44. /// This should not be stored in a container, because the underlying MDNode
  45. /// may change in certain situations.
  46. class DIDescriptor {
  47. public:
  48. enum {
  49. FlagPrivate = 1 << 0,
  50. FlagProtected = 1 << 1,
  51. FlagFwdDecl = 1 << 2,
  52. FlagAppleBlock = 1 << 3,
  53. FlagBlockByrefStruct = 1 << 4,
  54. FlagVirtual = 1 << 5,
  55. FlagArtificial = 1 << 6,
  56. FlagExplicit = 1 << 7,
  57. FlagPrototyped = 1 << 8,
  58. FlagObjcClassComplete = 1 << 9,
  59. FlagObjectPointer = 1 << 10,
  60. FlagVector = 1 << 11,
  61. FlagStaticMember = 1 << 12
  62. };
  63. protected:
  64. const MDNode *DbgNode;
  65. StringRef getStringField(unsigned Elt) const;
  66. unsigned getUnsignedField(unsigned Elt) const {
  67. return (unsigned)getUInt64Field(Elt);
  68. }
  69. uint64_t getUInt64Field(unsigned Elt) const;
  70. int64_t getInt64Field(unsigned Elt) const;
  71. DIDescriptor getDescriptorField(unsigned Elt) const;
  72. template <typename DescTy>
  73. DescTy getFieldAs(unsigned Elt) const {
  74. return DescTy(getDescriptorField(Elt));
  75. }
  76. GlobalVariable *getGlobalVariableField(unsigned Elt) const;
  77. Constant *getConstantField(unsigned Elt) const;
  78. Function *getFunctionField(unsigned Elt) const;
  79. void replaceFunctionField(unsigned Elt, Function *F);
  80. public:
  81. explicit DIDescriptor() : DbgNode(0) {}
  82. explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
  83. explicit DIDescriptor(const DIFile F);
  84. explicit DIDescriptor(const DISubprogram F);
  85. explicit DIDescriptor(const DILexicalBlockFile F);
  86. explicit DIDescriptor(const DILexicalBlock F);
  87. explicit DIDescriptor(const DIVariable F);
  88. explicit DIDescriptor(const DIType F);
  89. bool Verify() const;
  90. operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
  91. MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
  92. unsigned getTag() const {
  93. return getUnsignedField(0) & ~LLVMDebugVersionMask;
  94. }
  95. bool isDerivedType() const;
  96. bool isCompositeType() const;
  97. bool isBasicType() const;
  98. bool isVariable() const;
  99. bool isSubprogram() const;
  100. bool isGlobalVariable() const;
  101. bool isScope() const;
  102. bool isFile() const;
  103. bool isCompileUnit() const;
  104. bool isNameSpace() const;
  105. bool isLexicalBlockFile() const;
  106. bool isLexicalBlock() const;
  107. bool isSubrange() const;
  108. bool isEnumerator() const;
  109. bool isType() const;
  110. bool isGlobal() const;
  111. bool isUnspecifiedParameter() const;
  112. bool isTemplateTypeParameter() const;
  113. bool isTemplateValueParameter() const;
  114. bool isObjCProperty() const;
  115. bool isImportedModule() const;
  116. /// print - print descriptor.
  117. void print(raw_ostream &OS) const;
  118. /// dump - print descriptor to dbgs() with a newline.
  119. void dump() const;
  120. };
  121. /// DISubrange - This is used to represent ranges, for array bounds.
  122. class DISubrange : public DIDescriptor {
  123. friend class DIDescriptor;
  124. void printInternal(raw_ostream &OS) const;
  125. public:
  126. explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
  127. int64_t getLo() const { return getInt64Field(1); }
  128. int64_t getCount() const { return getInt64Field(2); }
  129. bool Verify() const;
  130. };
  131. /// DIArray - This descriptor holds an array of descriptors.
  132. class DIArray : public DIDescriptor {
  133. public:
  134. explicit DIArray(const MDNode *N = 0)
  135. : DIDescriptor(N) {}
  136. unsigned getNumElements() const;
  137. DIDescriptor getElement(unsigned Idx) const {
  138. return getDescriptorField(Idx);
  139. }
  140. };
  141. /// DIScope - A base class for various scopes.
  142. class DIScope : public DIDescriptor {
  143. protected:
  144. friend class DIDescriptor;
  145. void printInternal(raw_ostream &OS) const;
  146. public:
  147. explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
  148. StringRef getFilename() const;
  149. StringRef getDirectory() const;
  150. };
  151. /// DIFile - This is a wrapper for a file.
  152. class DIFile : public DIScope {
  153. friend class DIDescriptor;
  154. public:
  155. explicit DIFile(const MDNode *N = 0) : DIScope(N) {
  156. if (DbgNode && !isFile())
  157. DbgNode = 0;
  158. }
  159. MDNode *getFileNode() const;
  160. bool Verify() const;
  161. };
  162. /// DICompileUnit - A wrapper for a compile unit.
  163. class DICompileUnit : public DIScope {
  164. friend class DIDescriptor;
  165. void printInternal(raw_ostream &OS) const;
  166. public:
  167. explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
  168. unsigned getLanguage() const { return getUnsignedField(2); }
  169. StringRef getProducer() const { return getStringField(3); }
  170. bool isOptimized() const { return getUnsignedField(4) != 0; }
  171. StringRef getFlags() const { return getStringField(5); }
  172. unsigned getRunTimeVersion() const { return getUnsignedField(6); }
  173. DIArray getEnumTypes() const;
  174. DIArray getRetainedTypes() const;
  175. DIArray getSubprograms() const;
  176. DIArray getGlobalVariables() const;
  177. DIArray getImportedModules() const;
  178. StringRef getSplitDebugFilename() const { return getStringField(12); }
  179. /// Verify - Verify that a compile unit is well formed.
  180. bool Verify() const;
  181. };
  182. /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
  183. /// FIXME: it seems strange that this doesn't have either a reference to the
  184. /// type/precision or a file/line pair for location info.
  185. class DIEnumerator : public DIDescriptor {
  186. friend class DIDescriptor;
  187. void printInternal(raw_ostream &OS) const;
  188. public:
  189. explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
  190. StringRef getName() const { return getStringField(1); }
  191. uint64_t getEnumValue() const { return getUInt64Field(2); }
  192. bool Verify() const;
  193. };
  194. /// DIType - This is a wrapper for a type.
  195. /// FIXME: Types should be factored much better so that CV qualifiers and
  196. /// others do not require a huge and empty descriptor full of zeros.
  197. class DIType : public DIScope {
  198. protected:
  199. friend class DIDescriptor;
  200. void printInternal(raw_ostream &OS) const;
  201. // This ctor is used when the Tag has already been validated by a derived
  202. // ctor.
  203. DIType(const MDNode *N, bool, bool) : DIScope(N) {}
  204. public:
  205. /// Verify - Verify that a type descriptor is well formed.
  206. bool Verify() const;
  207. explicit DIType(const MDNode *N);
  208. explicit DIType() {}
  209. DIScope getContext() const { return getFieldAs<DIScope>(2); }
  210. StringRef getName() const { return getStringField(3); }
  211. unsigned getLineNumber() const { return getUnsignedField(4); }
  212. uint64_t getSizeInBits() const { return getUInt64Field(5); }
  213. uint64_t getAlignInBits() const { return getUInt64Field(6); }
  214. // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
  215. // carry this is just plain insane.
  216. uint64_t getOffsetInBits() const { return getUInt64Field(7); }
  217. unsigned getFlags() const { return getUnsignedField(8); }
  218. bool isPrivate() const {
  219. return (getFlags() & FlagPrivate) != 0;
  220. }
  221. bool isProtected() const {
  222. return (getFlags() & FlagProtected) != 0;
  223. }
  224. bool isForwardDecl() const {
  225. return (getFlags() & FlagFwdDecl) != 0;
  226. }
  227. // isAppleBlock - Return true if this is the Apple Blocks extension.
  228. bool isAppleBlockExtension() const {
  229. return (getFlags() & FlagAppleBlock) != 0;
  230. }
  231. bool isBlockByrefStruct() const {
  232. return (getFlags() & FlagBlockByrefStruct) != 0;
  233. }
  234. bool isVirtual() const {
  235. return (getFlags() & FlagVirtual) != 0;
  236. }
  237. bool isArtificial() const {
  238. return (getFlags() & FlagArtificial) != 0;
  239. }
  240. bool isObjectPointer() const {
  241. return (getFlags() & FlagObjectPointer) != 0;
  242. }
  243. bool isObjcClassComplete() const {
  244. return (getFlags() & FlagObjcClassComplete) != 0;
  245. }
  246. bool isVector() const {
  247. return (getFlags() & FlagVector) != 0;
  248. }
  249. bool isStaticMember() const {
  250. return (getFlags() & FlagStaticMember) != 0;
  251. }
  252. bool isValid() const {
  253. return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
  254. }
  255. /// isUnsignedDIType - Return true if type encoding is unsigned.
  256. bool isUnsignedDIType();
  257. /// replaceAllUsesWith - Replace all uses of debug info referenced by
  258. /// this descriptor.
  259. void replaceAllUsesWith(DIDescriptor &D);
  260. void replaceAllUsesWith(MDNode *D);
  261. };
  262. /// DIBasicType - A basic type, like 'int' or 'float'.
  263. class DIBasicType : public DIType {
  264. public:
  265. explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
  266. unsigned getEncoding() const { return getUnsignedField(9); }
  267. /// Verify - Verify that a basic type descriptor is well formed.
  268. bool Verify() const;
  269. };
  270. /// DIDerivedType - A simple derived type, like a const qualified type,
  271. /// a typedef, a pointer or reference, et cetera. Or, a data member of
  272. /// a class/struct/union.
  273. class DIDerivedType : public DIType {
  274. friend class DIDescriptor;
  275. void printInternal(raw_ostream &OS) const;
  276. protected:
  277. explicit DIDerivedType(const MDNode *N, bool, bool)
  278. : DIType(N, true, true) {}
  279. public:
  280. explicit DIDerivedType(const MDNode *N = 0)
  281. : DIType(N, true, true) {}
  282. DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
  283. /// getOriginalTypeSize - If this type is derived from a base type then
  284. /// return base type size.
  285. uint64_t getOriginalTypeSize() const;
  286. /// getObjCProperty - Return property node, if this ivar is
  287. /// associated with one.
  288. MDNode *getObjCProperty() const;
  289. DIType getClassType() const {
  290. assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
  291. return getFieldAs<DIType>(10);
  292. }
  293. Constant *getConstant() const {
  294. assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
  295. return getConstantField(10);
  296. }
  297. /// Verify - Verify that a derived type descriptor is well formed.
  298. bool Verify() const;
  299. };
  300. /// DICompositeType - This descriptor holds a type that can refer to multiple
  301. /// other types, like a function or struct.
  302. /// DICompositeType is derived from DIDerivedType because some
  303. /// composite types (such as enums) can be derived from basic types
  304. // FIXME: Make this derive from DIType directly & just store the
  305. // base type in a single DIType field.
  306. class DICompositeType : public DIDerivedType {
  307. friend class DIDescriptor;
  308. void printInternal(raw_ostream &OS) const;
  309. public:
  310. explicit DICompositeType(const MDNode *N = 0)
  311. : DIDerivedType(N, true, true) {
  312. if (N && !isCompositeType())
  313. DbgNode = 0;
  314. }
  315. DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
  316. void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
  317. unsigned getRunTimeLang() const { return getUnsignedField(11); }
  318. DICompositeType getContainingType() const {
  319. return getFieldAs<DICompositeType>(12);
  320. }
  321. void setContainingType(DICompositeType ContainingType);
  322. DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
  323. /// Verify - Verify that a composite type descriptor is well formed.
  324. bool Verify() const;
  325. };
  326. /// DITemplateTypeParameter - This is a wrapper for template type parameter.
  327. class DITemplateTypeParameter : public DIDescriptor {
  328. public:
  329. explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
  330. DIScope getContext() const { return getFieldAs<DIScope>(1); }
  331. StringRef getName() const { return getStringField(2); }
  332. DIType getType() const { return getFieldAs<DIType>(3); }
  333. StringRef getFilename() const {
  334. return getFieldAs<DIFile>(4).getFilename();
  335. }
  336. StringRef getDirectory() const {
  337. return getFieldAs<DIFile>(4).getDirectory();
  338. }
  339. unsigned getLineNumber() const { return getUnsignedField(5); }
  340. unsigned getColumnNumber() const { return getUnsignedField(6); }
  341. bool Verify() const;
  342. };
  343. /// DITemplateValueParameter - This is a wrapper for template value parameter.
  344. class DITemplateValueParameter : public DIDescriptor {
  345. public:
  346. explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
  347. DIScope getContext() const { return getFieldAs<DIScope>(1); }
  348. StringRef getName() const { return getStringField(2); }
  349. DIType getType() const { return getFieldAs<DIType>(3); }
  350. uint64_t getValue() const { return getUInt64Field(4); }
  351. StringRef getFilename() const {
  352. return getFieldAs<DIFile>(5).getFilename();
  353. }
  354. StringRef getDirectory() const {
  355. return getFieldAs<DIFile>(5).getDirectory();
  356. }
  357. unsigned getLineNumber() const { return getUnsignedField(6); }
  358. unsigned getColumnNumber() const { return getUnsignedField(7); }
  359. bool Verify() const;
  360. };
  361. /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
  362. class DISubprogram : public DIScope {
  363. friend class DIDescriptor;
  364. void printInternal(raw_ostream &OS) const;
  365. public:
  366. explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
  367. DIScope getContext() const { return getFieldAs<DIScope>(2); }
  368. StringRef getName() const { return getStringField(3); }
  369. StringRef getDisplayName() const { return getStringField(4); }
  370. StringRef getLinkageName() const { return getStringField(5); }
  371. unsigned getLineNumber() const { return getUnsignedField(6); }
  372. DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
  373. /// getReturnTypeName - Subprogram return types are encoded either as
  374. /// DIType or as DICompositeType.
  375. StringRef getReturnTypeName() const {
  376. DICompositeType DCT(getFieldAs<DICompositeType>(7));
  377. if (DCT.Verify()) {
  378. DIArray A = DCT.getTypeArray();
  379. DIType T(A.getElement(0));
  380. return T.getName();
  381. }
  382. DIType T(getFieldAs<DIType>(7));
  383. return T.getName();
  384. }
  385. /// isLocalToUnit - Return true if this subprogram is local to the current
  386. /// compile unit, like 'static' in C.
  387. unsigned isLocalToUnit() const { return getUnsignedField(8); }
  388. unsigned isDefinition() const { return getUnsignedField(9); }
  389. unsigned getVirtuality() const { return getUnsignedField(10); }
  390. unsigned getVirtualIndex() const { return getUnsignedField(11); }
  391. DICompositeType getContainingType() const {
  392. return getFieldAs<DICompositeType>(12);
  393. }
  394. unsigned getFlags() const {
  395. return getUnsignedField(13);
  396. }
  397. unsigned isArtificial() const {
  398. return (getUnsignedField(13) & FlagArtificial) != 0;
  399. }
  400. /// isPrivate - Return true if this subprogram has "private"
  401. /// access specifier.
  402. bool isPrivate() const {
  403. return (getUnsignedField(13) & FlagPrivate) != 0;
  404. }
  405. /// isProtected - Return true if this subprogram has "protected"
  406. /// access specifier.
  407. bool isProtected() const {
  408. return (getUnsignedField(13) & FlagProtected) != 0;
  409. }
  410. /// isExplicit - Return true if this subprogram is marked as explicit.
  411. bool isExplicit() const {
  412. return (getUnsignedField(13) & FlagExplicit) != 0;
  413. }
  414. /// isPrototyped - Return true if this subprogram is prototyped.
  415. bool isPrototyped() const {
  416. return (getUnsignedField(13) & FlagPrototyped) != 0;
  417. }
  418. unsigned isOptimized() const;
  419. /// getScopeLineNumber - Get the beginning of the scope of the
  420. /// function, not necessarily where the name of the program
  421. /// starts.
  422. unsigned getScopeLineNumber() const { return getUnsignedField(19); }
  423. /// Verify - Verify that a subprogram descriptor is well formed.
  424. bool Verify() const;
  425. /// describes - Return true if this subprogram provides debugging
  426. /// information for the function F.
  427. bool describes(const Function *F);
  428. Function *getFunction() const { return getFunctionField(15); }
  429. void replaceFunction(Function *F) { replaceFunctionField(15, F); }
  430. DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
  431. DISubprogram getFunctionDeclaration() const {
  432. return getFieldAs<DISubprogram>(17);
  433. }
  434. MDNode *getVariablesNodes() const;
  435. DIArray getVariables() const;
  436. };
  437. /// DIGlobalVariable - This is a wrapper for a global variable.
  438. class DIGlobalVariable : public DIDescriptor {
  439. friend class DIDescriptor;
  440. void printInternal(raw_ostream &OS) const;
  441. public:
  442. explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
  443. DIScope getContext() const { return getFieldAs<DIScope>(2); }
  444. StringRef getName() const { return getStringField(3); }
  445. StringRef getDisplayName() const { return getStringField(4); }
  446. StringRef getLinkageName() const { return getStringField(5); }
  447. StringRef getFilename() const {
  448. return getFieldAs<DIFile>(6).getFilename();
  449. }
  450. StringRef getDirectory() const {
  451. return getFieldAs<DIFile>(6).getDirectory();
  452. }
  453. unsigned getLineNumber() const { return getUnsignedField(7); }
  454. DIType getType() const { return getFieldAs<DIType>(8); }
  455. unsigned isLocalToUnit() const { return getUnsignedField(9); }
  456. unsigned isDefinition() const { return getUnsignedField(10); }
  457. GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
  458. Constant *getConstant() const { return getConstantField(11); }
  459. DIDerivedType getStaticDataMemberDeclaration() const {
  460. return getFieldAs<DIDerivedType>(12);
  461. }
  462. /// Verify - Verify that a global variable descriptor is well formed.
  463. bool Verify() const;
  464. };
  465. /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
  466. /// global etc).
  467. class DIVariable : public DIDescriptor {
  468. friend class DIDescriptor;
  469. void printInternal(raw_ostream &OS) const;
  470. public:
  471. explicit DIVariable(const MDNode *N = 0)
  472. : DIDescriptor(N) {}
  473. DIScope getContext() const { return getFieldAs<DIScope>(1); }
  474. StringRef getName() const { return getStringField(2); }
  475. DIFile getFile() const { return getFieldAs<DIFile>(3); }
  476. unsigned getLineNumber() const {
  477. return (getUnsignedField(4) << 8) >> 8;
  478. }
  479. unsigned getArgNumber() const {
  480. unsigned L = getUnsignedField(4);
  481. return L >> 24;
  482. }
  483. DIType getType() const { return getFieldAs<DIType>(5); }
  484. /// isArtificial - Return true if this variable is marked as "artificial".
  485. bool isArtificial() const {
  486. return (getUnsignedField(6) & FlagArtificial) != 0;
  487. }
  488. bool isObjectPointer() const {
  489. return (getUnsignedField(6) & FlagObjectPointer) != 0;
  490. }
  491. /// getInlinedAt - If this variable is inlined then return inline location.
  492. MDNode *getInlinedAt() const;
  493. /// Verify - Verify that a variable descriptor is well formed.
  494. bool Verify() const;
  495. /// HasComplexAddr - Return true if the variable has a complex address.
  496. bool hasComplexAddress() const {
  497. return getNumAddrElements() > 0;
  498. }
  499. unsigned getNumAddrElements() const;
  500. uint64_t getAddrElement(unsigned Idx) const {
  501. return getUInt64Field(Idx+8);
  502. }
  503. /// isBlockByrefVariable - Return true if the variable was declared as
  504. /// a "__block" variable (Apple Blocks).
  505. bool isBlockByrefVariable() const {
  506. return getType().isBlockByrefStruct();
  507. }
  508. /// isInlinedFnArgument - Return true if this variable provides debugging
  509. /// information for an inlined function arguments.
  510. bool isInlinedFnArgument(const Function *CurFn);
  511. void printExtendedName(raw_ostream &OS) const;
  512. };
  513. /// DILexicalBlock - This is a wrapper for a lexical block.
  514. class DILexicalBlock : public DIScope {
  515. public:
  516. explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
  517. DIScope getContext() const { return getFieldAs<DIScope>(2); }
  518. unsigned getLineNumber() const { return getUnsignedField(3); }
  519. unsigned getColumnNumber() const { return getUnsignedField(4); }
  520. bool Verify() const;
  521. };
  522. /// DILexicalBlockFile - This is a wrapper for a lexical block with
  523. /// a filename change.
  524. class DILexicalBlockFile : public DIScope {
  525. public:
  526. explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
  527. DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
  528. unsigned getLineNumber() const { return getScope().getLineNumber(); }
  529. unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
  530. DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
  531. bool Verify() const;
  532. };
  533. /// DINameSpace - A wrapper for a C++ style name space.
  534. class DINameSpace : public DIScope {
  535. friend class DIDescriptor;
  536. void printInternal(raw_ostream &OS) const;
  537. public:
  538. explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
  539. DIScope getContext() const { return getFieldAs<DIScope>(2); }
  540. StringRef getName() const { return getStringField(3); }
  541. unsigned getLineNumber() const { return getUnsignedField(4); }
  542. bool Verify() const;
  543. };
  544. /// DILocation - This object holds location information. This object
  545. /// is not associated with any DWARF tag.
  546. class DILocation : public DIDescriptor {
  547. public:
  548. explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
  549. unsigned getLineNumber() const { return getUnsignedField(0); }
  550. unsigned getColumnNumber() const { return getUnsignedField(1); }
  551. DIScope getScope() const { return getFieldAs<DIScope>(2); }
  552. DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
  553. StringRef getFilename() const { return getScope().getFilename(); }
  554. StringRef getDirectory() const { return getScope().getDirectory(); }
  555. bool Verify() const;
  556. };
  557. class DIObjCProperty : public DIDescriptor {
  558. friend class DIDescriptor;
  559. void printInternal(raw_ostream &OS) const;
  560. public:
  561. explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
  562. StringRef getObjCPropertyName() const { return getStringField(1); }
  563. DIFile getFile() const { return getFieldAs<DIFile>(2); }
  564. unsigned getLineNumber() const { return getUnsignedField(3); }
  565. StringRef getObjCPropertyGetterName() const {
  566. return getStringField(4);
  567. }
  568. StringRef getObjCPropertySetterName() const {
  569. return getStringField(5);
  570. }
  571. bool isReadOnlyObjCProperty() {
  572. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
  573. }
  574. bool isReadWriteObjCProperty() {
  575. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
  576. }
  577. bool isAssignObjCProperty() {
  578. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
  579. }
  580. bool isRetainObjCProperty() {
  581. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
  582. }
  583. bool isCopyObjCProperty() {
  584. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
  585. }
  586. bool isNonAtomicObjCProperty() {
  587. return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
  588. }
  589. DIType getType() const { return getFieldAs<DIType>(7); }
  590. /// Verify - Verify that a derived type descriptor is well formed.
  591. bool Verify() const;
  592. };
  593. /// \brief An imported module (C++ using directive or similar).
  594. class DIImportedModule : public DIDescriptor {
  595. friend class DIDescriptor;
  596. void printInternal(raw_ostream &OS) const;
  597. public:
  598. explicit DIImportedModule(const MDNode *N) : DIDescriptor(N) { }
  599. DIScope getContext() const { return getFieldAs<DIScope>(1); }
  600. DINameSpace getNameSpace() const { return getFieldAs<DINameSpace>(2); }
  601. unsigned getLineNumber() const { return getUnsignedField(3); }
  602. bool Verify() const;
  603. };
  604. /// getDISubprogram - Find subprogram that is enclosing this scope.
  605. DISubprogram getDISubprogram(const MDNode *Scope);
  606. /// getDICompositeType - Find underlying composite type.
  607. DICompositeType getDICompositeType(DIType T);
  608. /// isSubprogramContext - Return true if Context is either a subprogram
  609. /// or another context nested inside a subprogram.
  610. bool isSubprogramContext(const MDNode *Context);
  611. /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
  612. /// to hold function specific information.
  613. NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
  614. /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
  615. /// suitable to hold function specific information.
  616. NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
  617. /// createInlinedVariable - Create a new inlined variable based on current
  618. /// variable.
  619. /// @param DV Current Variable.
  620. /// @param InlinedScope Location at current variable is inlined.
  621. DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
  622. LLVMContext &VMContext);
  623. /// cleanseInlinedVariable - Remove inlined scope from the variable.
  624. DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
  625. class DebugInfoFinder {
  626. public:
  627. /// processModule - Process entire module and collect debug info
  628. /// anchors.
  629. void processModule(const Module &M);
  630. private:
  631. /// processType - Process DIType.
  632. void processType(DIType DT);
  633. /// processLexicalBlock - Process DILexicalBlock.
  634. void processLexicalBlock(DILexicalBlock LB);
  635. /// processSubprogram - Process DISubprogram.
  636. void processSubprogram(DISubprogram SP);
  637. /// processDeclare - Process DbgDeclareInst.
  638. void processDeclare(const DbgDeclareInst *DDI);
  639. /// processLocation - Process DILocation.
  640. void processLocation(DILocation Loc);
  641. /// addCompileUnit - Add compile unit into CUs.
  642. bool addCompileUnit(DICompileUnit CU);
  643. /// addGlobalVariable - Add global variable into GVs.
  644. bool addGlobalVariable(DIGlobalVariable DIG);
  645. // addSubprogram - Add subprogram into SPs.
  646. bool addSubprogram(DISubprogram SP);
  647. /// addType - Add type into Tys.
  648. bool addType(DIType DT);
  649. public:
  650. typedef SmallVector<MDNode *, 8>::const_iterator iterator;
  651. iterator compile_unit_begin() const { return CUs.begin(); }
  652. iterator compile_unit_end() const { return CUs.end(); }
  653. iterator subprogram_begin() const { return SPs.begin(); }
  654. iterator subprogram_end() const { return SPs.end(); }
  655. iterator global_variable_begin() const { return GVs.begin(); }
  656. iterator global_variable_end() const { return GVs.end(); }
  657. iterator type_begin() const { return TYs.begin(); }
  658. iterator type_end() const { return TYs.end(); }
  659. unsigned compile_unit_count() const { return CUs.size(); }
  660. unsigned global_variable_count() const { return GVs.size(); }
  661. unsigned subprogram_count() const { return SPs.size(); }
  662. unsigned type_count() const { return TYs.size(); }
  663. private:
  664. SmallVector<MDNode *, 8> CUs; // Compile Units
  665. SmallVector<MDNode *, 8> SPs; // Subprograms
  666. SmallVector<MDNode *, 8> GVs; // Global Variables;
  667. SmallVector<MDNode *, 8> TYs; // Types
  668. SmallPtrSet<MDNode *, 64> NodesSeen;
  669. };
  670. } // end namespace llvm
  671. #endif