DWARFDebugAddr.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DWARFDebugAddr.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_DWARFDEBUGADDR_H
  14. #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
  15. #include "llvm/BinaryFormat/Dwarf.h"
  16. #include "llvm/DebugInfo/DIContext.h"
  17. #include "llvm/Support/Error.h"
  18. #include <cstdint>
  19. #include <vector>
  20. namespace llvm {
  21. class raw_ostream;
  22. class DWARFDataExtractor;
  23. /// A class representing an address table as specified in DWARF v5.
  24. /// The table consists of a header followed by an array of address values from
  25. /// .debug_addr section.
  26. class DWARFDebugAddrTable {
  27. dwarf::DwarfFormat Format;
  28. uint64_t Offset;
  29. /// The total length of the entries for this table, not including the length
  30. /// field itself.
  31. uint64_t Length = 0;
  32. /// The DWARF version number.
  33. uint16_t Version;
  34. /// The size in bytes of an address on the target architecture. For
  35. /// segmented addressing, this is the size of the offset portion of the
  36. /// address.
  37. uint8_t AddrSize;
  38. /// The size in bytes of a segment selector on the target architecture.
  39. /// If the target system uses a flat address space, this value is 0.
  40. uint8_t SegSize;
  41. std::vector<uint64_t> Addrs;
  42. /// Invalidate Length field to stop further processing.
  43. void invalidateLength() { Length = 0; }
  44. Error extractAddresses(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
  45. uint64_t EndOffset);
  46. public:
  47. /// Extract the entire table, including all addresses.
  48. Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
  49. uint16_t CUVersion, uint8_t CUAddrSize,
  50. std::function<void(Error)> WarnCallback);
  51. /// Extract a DWARFv5 address table.
  52. Error extractV5(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
  53. uint8_t CUAddrSize, std::function<void(Error)> WarnCallback);
  54. /// Extract a pre-DWARFv5 address table. Such tables do not have a header
  55. /// and consist only of a series of addresses.
  56. /// See https://gcc.gnu.org/wiki/DebugFission for details.
  57. Error extractPreStandard(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
  58. uint16_t CUVersion, uint8_t CUAddrSize);
  59. void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;
  60. /// Return the address based on a given index.
  61. Expected<uint64_t> getAddrEntry(uint32_t Index) const;
  62. /// Return the full length of this table, including the length field.
  63. /// Return std::nullopt if the length cannot be identified reliably.
  64. std::optional<uint64_t> getFullLength() const;
  65. /// Return the DWARF format of this table.
  66. dwarf::DwarfFormat getFormat() const { return Format; }
  67. /// Return the length of this table.
  68. uint64_t getLength() const { return Length; }
  69. /// Return the version of this table.
  70. uint16_t getVersion() const { return Version; }
  71. /// Return the address size of this table.
  72. uint8_t getAddressSize() const { return AddrSize; }
  73. /// Return the segment selector size of this table.
  74. uint8_t getSegmentSelectorSize() const { return SegSize; }
  75. /// Return the parsed addresses of this table.
  76. ArrayRef<uint64_t> getAddressEntries() const { return Addrs; }
  77. };
  78. } // end namespace llvm
  79. #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif