DWARFDebugAranges.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/ADT/STLFunctionalExtras.h"
  17. #include <cstdint>
  18. #include <vector>
  19. namespace llvm {
  20. class DWARFDataExtractor;
  21. class Error;
  22. class DWARFContext;
  23. class DWARFDebugAranges {
  24. public:
  25. void generate(DWARFContext *CTX);
  26. uint64_t findAddress(uint64_t Address) const;
  27. private:
  28. void clear();
  29. void extract(DWARFDataExtractor DebugArangesData,
  30. function_ref<void(Error)> RecoverableErrorHandler,
  31. function_ref<void(Error)> WarningHandler);
  32. /// Call appendRange multiple times and then call construct.
  33. void appendRange(uint64_t CUOffset, uint64_t LowPC, uint64_t HighPC);
  34. void construct();
  35. struct Range {
  36. explicit Range(uint64_t LowPC, uint64_t HighPC, uint64_t CUOffset)
  37. : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
  38. void setHighPC(uint64_t HighPC) {
  39. if (HighPC == -1ULL || HighPC <= LowPC)
  40. Length = 0;
  41. else
  42. Length = HighPC - LowPC;
  43. }
  44. uint64_t HighPC() const {
  45. if (Length)
  46. return LowPC + Length;
  47. return -1ULL;
  48. }
  49. bool operator<(const Range &other) const {
  50. return LowPC < other.LowPC;
  51. }
  52. uint64_t LowPC; /// Start of address range.
  53. uint64_t Length; /// End of address range (not including this address).
  54. uint64_t CUOffset; /// Offset of the compile unit or die.
  55. };
  56. struct RangeEndpoint {
  57. uint64_t Address;
  58. uint64_t CUOffset;
  59. bool IsRangeStart;
  60. RangeEndpoint(uint64_t Address, uint64_t CUOffset, bool IsRangeStart)
  61. : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
  62. bool operator<(const RangeEndpoint &Other) const {
  63. return Address < Other.Address;
  64. }
  65. };
  66. using RangeColl = std::vector<Range>;
  67. using RangeCollIterator = RangeColl::const_iterator;
  68. std::vector<RangeEndpoint> Endpoints;
  69. RangeColl Aranges;
  70. DenseSet<uint64_t> ParsedCUOffsets;
  71. };
  72. } // end namespace llvm
  73. #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGARANGES_H
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif