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