Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- DebugInlineeLinesSubsection.h ----------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H |
| 10 | #define LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H |
| 11 | |
| 12 | #include "llvm/ADT/StringRef.h" |
| 13 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
| 14 | #include "llvm/DebugInfo/CodeView/DebugSubsection.h" |
| 15 | #include "llvm/DebugInfo/CodeView/Line.h" |
| 16 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
| 17 | #include "llvm/Support/BinaryStreamArray.h" |
| 18 | #include "llvm/Support/BinaryStreamReader.h" |
| 19 | #include "llvm/Support/BinaryStreamRef.h" |
| 20 | #include "llvm/Support/Endian.h" |
| 21 | #include "llvm/Support/Error.h" |
| 22 | #include <cstdint> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace llvm { |
| 26 | |
| 27 | namespace codeview { |
| 28 | |
| 29 | class DebugChecksumsSubsection; |
| 30 | |
| 31 | enum class InlineeLinesSignature : uint32_t { |
| 32 | Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE |
| 33 | ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX |
| 34 | }; |
| 35 | |
| 36 | struct InlineeSourceLineHeader { |
| 37 | TypeIndex Inlinee; // ID of the function that was inlined. |
| 38 | support::ulittle32_t FileID; // Offset into FileChecksums subsection. |
| 39 | support::ulittle32_t SourceLineNum; // First line of inlined code. |
| 40 | // If extra files present: |
| 41 | // ulittle32_t ExtraFileCount; |
| 42 | // ulittle32_t Files[]; |
| 43 | }; |
| 44 | |
| 45 | struct InlineeSourceLine { |
| 46 | const InlineeSourceLineHeader *Header; |
| 47 | FixedStreamArray<support::ulittle32_t> ExtraFiles; |
| 48 | }; |
| 49 | |
| 50 | } // end namespace codeview |
| 51 | |
| 52 | template <> struct VarStreamArrayExtractor<codeview::InlineeSourceLine> { |
| 53 | Error operator()(BinaryStreamRef Stream, uint32_t &Len, |
| 54 | codeview::InlineeSourceLine &Item); |
| 55 | |
| 56 | bool HasExtraFiles = false; |
| 57 | }; |
| 58 | |
| 59 | namespace codeview { |
| 60 | |
| 61 | class DebugInlineeLinesSubsectionRef final : public DebugSubsectionRef { |
| 62 | using LinesArray = VarStreamArray<InlineeSourceLine>; |
| 63 | using Iterator = LinesArray::Iterator; |
| 64 | |
| 65 | public: |
| 66 | DebugInlineeLinesSubsectionRef(); |
| 67 | |
| 68 | static bool classof(const DebugSubsectionRef *S) { |
| 69 | return S->kind() == DebugSubsectionKind::InlineeLines; |
| 70 | } |
| 71 | |
| 72 | Error initialize(BinaryStreamReader Reader); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 73 | Error initialize(BinaryStreamRef Section) { |
| 74 | return initialize(BinaryStreamReader(Section)); |
| 75 | } |
| 76 | |
| 77 | bool valid() const { return Lines.valid(); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 78 | bool hasExtraFiles() const; |
| 79 | |
| 80 | Iterator begin() const { return Lines.begin(); } |
| 81 | Iterator end() const { return Lines.end(); } |
| 82 | |
| 83 | private: |
| 84 | InlineeLinesSignature Signature; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 85 | LinesArray Lines; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | class DebugInlineeLinesSubsection final : public DebugSubsection { |
| 89 | public: |
| 90 | struct Entry { |
| 91 | std::vector<support::ulittle32_t> ExtraFiles; |
| 92 | InlineeSourceLineHeader Header; |
| 93 | }; |
| 94 | |
| 95 | DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums, |
| 96 | bool HasExtraFiles = false); |
| 97 | |
| 98 | static bool classof(const DebugSubsection *S) { |
| 99 | return S->kind() == DebugSubsectionKind::InlineeLines; |
| 100 | } |
| 101 | |
| 102 | Error commit(BinaryStreamWriter &Writer) const override; |
| 103 | uint32_t calculateSerializedSize() const override; |
| 104 | |
| 105 | void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine); |
| 106 | void addExtraFile(StringRef FileName); |
| 107 | |
| 108 | bool hasExtraFiles() const { return HasExtraFiles; } |
| 109 | void setHasExtraFiles(bool Has) { HasExtraFiles = Has; } |
| 110 | |
| 111 | std::vector<Entry>::const_iterator begin() const { return Entries.begin(); } |
| 112 | std::vector<Entry>::const_iterator end() const { return Entries.end(); } |
| 113 | |
| 114 | private: |
| 115 | DebugChecksumsSubsection &Checksums; |
| 116 | bool HasExtraFiles = false; |
| 117 | uint32_t ExtraFileCount = 0; |
| 118 | std::vector<Entry> Entries; |
| 119 | }; |
| 120 | |
| 121 | } // end namespace codeview |
| 122 | |
| 123 | } // end namespace llvm |
| 124 | |
| 125 | #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGINLINEELINESSUBSECTION_H |