DWARFFormValue.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===-- DWARFFormValue.h ----------------------------------------*- 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. #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
  10. #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
  11. #include "llvm/ADT/ArrayRef.h"
  12. #include "llvm/ADT/Optional.h"
  13. #include "llvm/Support/DataExtractor.h"
  14. namespace llvm {
  15. class DWARFUnit;
  16. class raw_ostream;
  17. class DWARFFormValue {
  18. public:
  19. enum FormClass {
  20. FC_Unknown,
  21. FC_Address,
  22. FC_Block,
  23. FC_Constant,
  24. FC_String,
  25. FC_Flag,
  26. FC_Reference,
  27. FC_Indirect,
  28. FC_SectionOffset,
  29. FC_Exprloc
  30. };
  31. private:
  32. struct ValueType {
  33. ValueType() : data(nullptr) {
  34. uval = 0;
  35. }
  36. union {
  37. uint64_t uval;
  38. int64_t sval;
  39. const char* cstr;
  40. };
  41. const uint8_t* data;
  42. };
  43. uint16_t Form; // Form for this value.
  44. ValueType Value; // Contains all data for the form.
  45. public:
  46. DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
  47. uint16_t getForm() const { return Form; }
  48. bool isFormClass(FormClass FC) const;
  49. void dump(raw_ostream &OS, const DWARFUnit *U) const;
  50. /// \brief extracts a value in data at offset *offset_ptr.
  51. ///
  52. /// The passed DWARFUnit is allowed to be nullptr, in which
  53. /// case no relocation processing will be performed and some
  54. /// kind of forms that depend on Unit information are disallowed.
  55. /// \returns whether the extraction succeeded.
  56. bool extractValue(DataExtractor data, uint32_t *offset_ptr,
  57. const DWARFUnit *u);
  58. bool isInlinedCStr() const {
  59. return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr;
  60. }
  61. /// getAsFoo functions below return the extracted value as Foo if only
  62. /// DWARFFormValue has form class is suitable for representing Foo.
  63. Optional<uint64_t> getAsReference(const DWARFUnit *U) const;
  64. Optional<uint64_t> getAsUnsignedConstant() const;
  65. Optional<int64_t> getAsSignedConstant() const;
  66. Optional<const char *> getAsCString(const DWARFUnit *U) const;
  67. Optional<uint64_t> getAsAddress(const DWARFUnit *U) const;
  68. Optional<uint64_t> getAsSectionOffset() const;
  69. Optional<ArrayRef<uint8_t>> getAsBlock() const;
  70. bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
  71. const DWARFUnit *u) const;
  72. static bool skipValue(uint16_t form, DataExtractor debug_info_data,
  73. uint32_t *offset_ptr, const DWARFUnit *u);
  74. static ArrayRef<uint8_t> getFixedFormSizes(uint8_t AddrSize,
  75. uint16_t Version);
  76. private:
  77. void dumpString(raw_ostream &OS, const DWARFUnit *U) const;
  78. };
  79. }
  80. #endif