DebugInlineeLinesSubsection.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DebugInlineeLinesSubsection.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_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H
  14. #define LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/DebugInfo/CodeView/CodeView.h"
  17. #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
  18. #include "llvm/DebugInfo/CodeView/Line.h"
  19. #include "llvm/DebugInfo/CodeView/TypeIndex.h"
  20. #include "llvm/Support/BinaryStreamArray.h"
  21. #include "llvm/Support/BinaryStreamReader.h"
  22. #include "llvm/Support/BinaryStreamRef.h"
  23. #include "llvm/Support/Endian.h"
  24. #include "llvm/Support/Error.h"
  25. #include <cstdint>
  26. #include <vector>
  27. namespace llvm {
  28. namespace codeview {
  29. class DebugChecksumsSubsection;
  30. enum class InlineeLinesSignature : uint32_t {
  31. Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE
  32. ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX
  33. };
  34. struct InlineeSourceLineHeader {
  35. TypeIndex Inlinee; // ID of the function that was inlined.
  36. support::ulittle32_t FileID; // Offset into FileChecksums subsection.
  37. support::ulittle32_t SourceLineNum; // First line of inlined code.
  38. // If extra files present:
  39. // ulittle32_t ExtraFileCount;
  40. // ulittle32_t Files[];
  41. };
  42. struct InlineeSourceLine {
  43. const InlineeSourceLineHeader *Header;
  44. FixedStreamArray<support::ulittle32_t> ExtraFiles;
  45. };
  46. } // end namespace codeview
  47. template <> struct VarStreamArrayExtractor<codeview::InlineeSourceLine> {
  48. Error operator()(BinaryStreamRef Stream, uint32_t &Len,
  49. codeview::InlineeSourceLine &Item);
  50. bool HasExtraFiles = false;
  51. };
  52. namespace codeview {
  53. class DebugInlineeLinesSubsectionRef final : public DebugSubsectionRef {
  54. using LinesArray = VarStreamArray<InlineeSourceLine>;
  55. using Iterator = LinesArray::Iterator;
  56. public:
  57. DebugInlineeLinesSubsectionRef();
  58. static bool classof(const DebugSubsectionRef *S) {
  59. return S->kind() == DebugSubsectionKind::InlineeLines;
  60. }
  61. Error initialize(BinaryStreamReader Reader);
  62. Error initialize(BinaryStreamRef Section) {
  63. return initialize(BinaryStreamReader(Section));
  64. }
  65. bool valid() const { return Lines.valid(); }
  66. bool hasExtraFiles() const;
  67. Iterator begin() const { return Lines.begin(); }
  68. Iterator end() const { return Lines.end(); }
  69. private:
  70. InlineeLinesSignature Signature;
  71. LinesArray Lines;
  72. };
  73. class DebugInlineeLinesSubsection final : public DebugSubsection {
  74. public:
  75. struct Entry {
  76. std::vector<support::ulittle32_t> ExtraFiles;
  77. InlineeSourceLineHeader Header;
  78. };
  79. DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums,
  80. bool HasExtraFiles = false);
  81. static bool classof(const DebugSubsection *S) {
  82. return S->kind() == DebugSubsectionKind::InlineeLines;
  83. }
  84. Error commit(BinaryStreamWriter &Writer) const override;
  85. uint32_t calculateSerializedSize() const override;
  86. void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine);
  87. void addExtraFile(StringRef FileName);
  88. bool hasExtraFiles() const { return HasExtraFiles; }
  89. void setHasExtraFiles(bool Has) { HasExtraFiles = Has; }
  90. std::vector<Entry>::const_iterator begin() const { return Entries.begin(); }
  91. std::vector<Entry>::const_iterator end() const { return Entries.end(); }
  92. private:
  93. DebugChecksumsSubsection &Checksums;
  94. bool HasExtraFiles = false;
  95. uint32_t ExtraFileCount = 0;
  96. std::vector<Entry> Entries;
  97. };
  98. } // end namespace codeview
  99. } // end namespace llvm
  100. #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H
  101. #ifdef __GNUC__
  102. #pragma GCC diagnostic pop
  103. #endif