DWARFDebugRangeList.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //===-- DWARFDebugRangeList.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_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
  10. #define LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H
  11. #include "llvm/Support/DataExtractor.h"
  12. #include <vector>
  13. namespace llvm {
  14. class raw_ostream;
  15. /// DWARFAddressRangesVector - represents a set of absolute address ranges.
  16. typedef std::vector<std::pair<uint64_t, uint64_t>> DWARFAddressRangesVector;
  17. class DWARFDebugRangeList {
  18. public:
  19. struct RangeListEntry {
  20. // A beginning address offset. This address offset has the size of an
  21. // address and is relative to the applicable base address of the
  22. // compilation unit referencing this range list. It marks the beginning
  23. // of an address range.
  24. uint64_t StartAddress;
  25. // An ending address offset. This address offset again has the size of
  26. // an address and is relative to the applicable base address of the
  27. // compilation unit referencing this range list. It marks the first
  28. // address past the end of the address range. The ending address must
  29. // be greater than or equal to the beginning address.
  30. uint64_t EndAddress;
  31. // The end of any given range list is marked by an end of list entry,
  32. // which consists of a 0 for the beginning address offset
  33. // and a 0 for the ending address offset.
  34. bool isEndOfListEntry() const {
  35. return (StartAddress == 0) && (EndAddress == 0);
  36. }
  37. // A base address selection entry consists of:
  38. // 1. The value of the largest representable address offset
  39. // (for example, 0xffffffff when the size of an address is 32 bits).
  40. // 2. An address, which defines the appropriate base address for
  41. // use in interpreting the beginning and ending address offsets of
  42. // subsequent entries of the location list.
  43. bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
  44. assert(AddressSize == 4 || AddressSize == 8);
  45. if (AddressSize == 4)
  46. return StartAddress == -1U;
  47. else
  48. return StartAddress == -1ULL;
  49. }
  50. };
  51. private:
  52. // Offset in .debug_ranges section.
  53. uint32_t Offset;
  54. uint8_t AddressSize;
  55. std::vector<RangeListEntry> Entries;
  56. public:
  57. DWARFDebugRangeList() { clear(); }
  58. void clear();
  59. void dump(raw_ostream &OS) const;
  60. bool extract(DataExtractor data, uint32_t *offset_ptr);
  61. const std::vector<RangeListEntry> &getEntries() { return Entries; }
  62. /// getAbsoluteRanges - Returns absolute address ranges defined by this range
  63. /// list. Has to be passed base address of the compile unit referencing this
  64. /// range list.
  65. DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const;
  66. };
  67. } // namespace llvm
  68. #endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H