DebugInlineeLinesSubsection.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //===- DebugInlineeLinesSubsection.h ----------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H
  9. #define LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H
  10. #include "llvm/ADT/StringRef.h"
  11. #include "llvm/DebugInfo/CodeView/CodeView.h"
  12. #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
  13. #include "llvm/DebugInfo/CodeView/Line.h"
  14. #include "llvm/DebugInfo/CodeView/TypeIndex.h"
  15. #include "llvm/Support/BinaryStreamArray.h"
  16. #include "llvm/Support/BinaryStreamReader.h"
  17. #include "llvm/Support/BinaryStreamRef.h"
  18. #include "llvm/Support/Endian.h"
  19. #include "llvm/Support/Error.h"
  20. #include <cstdint>
  21. #include <vector>
  22. namespace llvm {
  23. namespace codeview {
  24. class DebugChecksumsSubsection;
  25. enum class InlineeLinesSignature : uint32_t {
  26. Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE
  27. ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX
  28. };
  29. struct InlineeSourceLineHeader {
  30. TypeIndex Inlinee; // ID of the function that was inlined.
  31. support::ulittle32_t FileID; // Offset into FileChecksums subsection.
  32. support::ulittle32_t SourceLineNum; // First line of inlined code.
  33. // If extra files present:
  34. // ulittle32_t ExtraFileCount;
  35. // ulittle32_t Files[];
  36. };
  37. struct InlineeSourceLine {
  38. const InlineeSourceLineHeader *Header;
  39. FixedStreamArray<support::ulittle32_t> ExtraFiles;
  40. };
  41. } // end namespace codeview
  42. template <> struct VarStreamArrayExtractor<codeview::InlineeSourceLine> {
  43. Error operator()(BinaryStreamRef Stream, uint32_t &Len,
  44. codeview::InlineeSourceLine &Item);
  45. bool HasExtraFiles = false;
  46. };
  47. namespace codeview {
  48. class DebugInlineeLinesSubsectionRef final : public DebugSubsectionRef {
  49. using LinesArray = VarStreamArray<InlineeSourceLine>;
  50. using Iterator = LinesArray::Iterator;
  51. public:
  52. DebugInlineeLinesSubsectionRef();
  53. static bool classof(const DebugSubsectionRef *S) {
  54. return S->kind() == DebugSubsectionKind::InlineeLines;
  55. }
  56. Error initialize(BinaryStreamReader Reader);
  57. Error initialize(BinaryStreamRef Section) {
  58. return initialize(BinaryStreamReader(Section));
  59. }
  60. bool valid() const { return Lines.valid(); }
  61. bool hasExtraFiles() const;
  62. Iterator begin() const { return Lines.begin(); }
  63. Iterator end() const { return Lines.end(); }
  64. private:
  65. InlineeLinesSignature Signature;
  66. LinesArray Lines;
  67. };
  68. class DebugInlineeLinesSubsection final : public DebugSubsection {
  69. public:
  70. struct Entry {
  71. std::vector<support::ulittle32_t> ExtraFiles;
  72. InlineeSourceLineHeader Header;
  73. };
  74. DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums,
  75. bool HasExtraFiles = false);
  76. static bool classof(const DebugSubsection *S) {
  77. return S->kind() == DebugSubsectionKind::InlineeLines;
  78. }
  79. Error commit(BinaryStreamWriter &Writer) const override;
  80. uint32_t calculateSerializedSize() const override;
  81. void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine);
  82. void addExtraFile(StringRef FileName);
  83. bool hasExtraFiles() const { return HasExtraFiles; }
  84. void setHasExtraFiles(bool Has) { HasExtraFiles = Has; }
  85. std::vector<Entry>::const_iterator begin() const { return Entries.begin(); }
  86. std::vector<Entry>::const_iterator end() const { return Entries.end(); }
  87. private:
  88. DebugChecksumsSubsection &Checksums;
  89. bool HasExtraFiles = false;
  90. uint32_t ExtraFileCount = 0;
  91. std::vector<Entry> Entries;
  92. };
  93. } // end namespace codeview
  94. } // end namespace llvm
  95. #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H