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