Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 1 | //===- DebugInlineeLinesSubsection.cpp ------------------------*- C++-*-===// |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" |
Zachary Turner | 591312c | 2017-05-30 17:13:33 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace llvm::codeview; |
| 19 | |
Zachary Turner | 7e62cd1 | 2017-06-09 17:54:36 +0000 | [diff] [blame] | 20 | Error VarStreamArrayExtractor<InlineeSourceLine>:: |
| 21 | operator()(BinaryStreamRef Stream, uint32_t &Len, InlineeSourceLine &Item) { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 22 | BinaryStreamReader Reader(Stream); |
| 23 | |
| 24 | if (auto EC = Reader.readObject(Item.Header)) |
| 25 | return EC; |
| 26 | |
Zachary Turner | 59e8389 | 2017-05-03 05:34:00 +0000 | [diff] [blame] | 27 | if (HasExtraFiles) { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 28 | uint32_t ExtraFileCount; |
| 29 | if (auto EC = Reader.readInteger(ExtraFileCount)) |
| 30 | return EC; |
| 31 | if (auto EC = Reader.readArray(Item.ExtraFiles, ExtraFileCount)) |
| 32 | return EC; |
| 33 | } |
| 34 | |
| 35 | Len = Reader.getOffset(); |
| 36 | return Error::success(); |
| 37 | } |
| 38 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 39 | DebugInlineeLinesSubsectionRef::DebugInlineeLinesSubsectionRef() |
| 40 | : DebugSubsectionRef(DebugSubsectionKind::InlineeLines) {} |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 41 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 42 | Error DebugInlineeLinesSubsectionRef::initialize(BinaryStreamReader Reader) { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 43 | if (auto EC = Reader.readEnum(Signature)) |
| 44 | return EC; |
| 45 | |
Zachary Turner | 7e62cd1 | 2017-06-09 17:54:36 +0000 | [diff] [blame] | 46 | Lines.getExtractor().HasExtraFiles = hasExtraFiles(); |
| 47 | if (auto EC = Reader.readArray(Lines, Reader.bytesRemaining())) |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 48 | return EC; |
| 49 | |
| 50 | assert(Reader.bytesRemaining() == 0); |
| 51 | return Error::success(); |
| 52 | } |
| 53 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 54 | bool DebugInlineeLinesSubsectionRef::hasExtraFiles() const { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 55 | return Signature == InlineeLinesSignature::ExtraFiles; |
| 56 | } |
| 57 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 58 | DebugInlineeLinesSubsection::DebugInlineeLinesSubsection( |
| 59 | DebugChecksumsSubsection &Checksums, bool HasExtraFiles) |
| 60 | : DebugSubsection(DebugSubsectionKind::InlineeLines), Checksums(Checksums), |
| 61 | HasExtraFiles(HasExtraFiles) {} |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 62 | |
Zachary Turner | 591312c | 2017-05-30 17:13:33 +0000 | [diff] [blame] | 63 | uint32_t DebugInlineeLinesSubsection::calculateSerializedSize() const { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 64 | // 4 bytes for the signature |
| 65 | uint32_t Size = sizeof(InlineeLinesSignature); |
| 66 | |
| 67 | // one header for each entry. |
| 68 | Size += Entries.size() * sizeof(InlineeSourceLineHeader); |
| 69 | if (HasExtraFiles) { |
| 70 | // If extra files are enabled, one count for each entry. |
| 71 | Size += Entries.size() * sizeof(uint32_t); |
| 72 | |
| 73 | // And one file id for each file. |
| 74 | Size += ExtraFileCount * sizeof(uint32_t); |
| 75 | } |
| 76 | assert(Size % 4 == 0); |
| 77 | return Size; |
| 78 | } |
| 79 | |
Zachary Turner | 591312c | 2017-05-30 17:13:33 +0000 | [diff] [blame] | 80 | Error DebugInlineeLinesSubsection::commit(BinaryStreamWriter &Writer) const { |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 81 | InlineeLinesSignature Sig = InlineeLinesSignature::Normal; |
| 82 | if (HasExtraFiles) |
| 83 | Sig = InlineeLinesSignature::ExtraFiles; |
| 84 | |
| 85 | if (auto EC = Writer.writeEnum(Sig)) |
| 86 | return EC; |
| 87 | |
| 88 | for (const auto &E : Entries) { |
| 89 | if (auto EC = Writer.writeObject(E.Header)) |
| 90 | return EC; |
| 91 | |
| 92 | if (!HasExtraFiles) |
| 93 | continue; |
| 94 | |
| 95 | if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size())) |
| 96 | return EC; |
| 97 | if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles))) |
| 98 | return EC; |
| 99 | } |
| 100 | |
| 101 | return Error::success(); |
| 102 | } |
| 103 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 104 | void DebugInlineeLinesSubsection::addExtraFile(StringRef FileName) { |
Zachary Turner | cf468d8 | 2017-05-03 17:11:40 +0000 | [diff] [blame] | 105 | uint32_t Offset = Checksums.mapChecksumOffset(FileName); |
| 106 | |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 107 | auto &Entry = Entries.back(); |
Zachary Turner | cf468d8 | 2017-05-03 17:11:40 +0000 | [diff] [blame] | 108 | Entry.ExtraFiles.push_back(ulittle32_t(Offset)); |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 109 | ++ExtraFileCount; |
| 110 | } |
| 111 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 112 | void DebugInlineeLinesSubsection::addInlineSite(TypeIndex FuncId, |
| 113 | StringRef FileName, |
| 114 | uint32_t SourceLine) { |
Zachary Turner | cf468d8 | 2017-05-03 17:11:40 +0000 | [diff] [blame] | 115 | uint32_t Offset = Checksums.mapChecksumOffset(FileName); |
| 116 | |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 117 | Entries.emplace_back(); |
| 118 | auto &Entry = Entries.back(); |
Zachary Turner | cf468d8 | 2017-05-03 17:11:40 +0000 | [diff] [blame] | 119 | Entry.Header.FileID = Offset; |
Zachary Turner | edef145 | 2017-05-02 16:56:09 +0000 | [diff] [blame] | 120 | Entry.Header.SourceLineNum = SourceLine; |
| 121 | Entry.Header.Inlinee = FuncId; |
| 122 | } |