DWARFDebugAddr.h 3.7 KB

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