DWARFDebugAranges.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DWARFDebugAranges.h --------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
  14. #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
  15. #include "llvm/ADT/DenseSet.h"
  16. #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
  17. #include <cstdint>
  18. #include <vector>
  19. namespace llvm {
  20. class DWARFContext;
  21. class DWARFDebugAranges {
  22. public:
  23. void generate(DWARFContext *CTX);
  24. uint64_t findAddress(uint64_t Address) const;
  25. private:
  26. void clear();
  27. void extract(DWARFDataExtractor DebugArangesData,
  28. function_ref<void(Error)> RecoverableErrorHandler);
  29. /// Call appendRange multiple times and then call construct.
  30. void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);
  31. void construct();
  32. struct Range {
  33. explicit Range(uint64_t LowPC, uint64_t HighPC, uint64_t CUOffset)
  34. : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
  35. void setHighPC(uint64_t HighPC) {
  36. if (HighPC == -1ULL || HighPC <= LowPC)
  37. Length = 0;
  38. else
  39. Length = HighPC - LowPC;
  40. }
  41. uint64_t HighPC() const {
  42. if (Length)
  43. return LowPC + Length;
  44. return -1ULL;
  45. }
  46. bool operator<(const Range &other) const {
  47. return LowPC < other.LowPC;
  48. }
  49. uint64_t LowPC; /// Start of address range.
  50. uint64_t Length; /// End of address range (not including this address).
  51. uint64_t CUOffset; /// Offset of the compile unit or die.
  52. };
  53. struct RangeEndpoint {
  54. uint64_t Address;
  55. uint64_t CUOffset;
  56. bool IsRangeStart;
  57. RangeEndpoint(uint64_t Address, uint64_t CUOffset, bool IsRangeStart)
  58. : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
  59. bool operator<(const RangeEndpoint &Other) const {
  60. return Address < Other.Address;
  61. }
  62. };
  63. using RangeColl = std::vector<Range>;
  64. using RangeCollIterator = RangeColl::const_iterator;
  65. std::vector<RangeEndpoint> Endpoints;
  66. RangeColl Aranges;
  67. DenseSet<uint64_t> ParsedCUOffsets;
  68. };
  69. } // end namespace llvm
  70. #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif