Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 1 | //===- ModuleDebugLineFragment.cpp -------------------------------*- C++-*-===// |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +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 | |
| 10 | #include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" |
| 11 | |
| 12 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
| 13 | #include "llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | using namespace llvm::codeview; |
| 17 | |
| 18 | Error LineColumnExtractor::extract(BinaryStreamRef Stream, uint32_t &Len, |
| 19 | LineColumnEntry &Item, |
| 20 | const LineFragmentHeader *Header) { |
| 21 | using namespace codeview; |
| 22 | const LineBlockFragmentHeader *BlockHeader; |
| 23 | BinaryStreamReader Reader(Stream); |
| 24 | if (auto EC = Reader.readObject(BlockHeader)) |
| 25 | return EC; |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 26 | bool HasColumn = Header->Flags & uint16_t(LF_HaveColumns); |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 27 | uint32_t LineInfoSize = |
| 28 | BlockHeader->NumLines * |
| 29 | (sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0)); |
| 30 | if (BlockHeader->BlockSize < sizeof(LineBlockFragmentHeader)) |
| 31 | return make_error<CodeViewError>(cv_error_code::corrupt_record, |
| 32 | "Invalid line block record size"); |
| 33 | uint32_t Size = BlockHeader->BlockSize - sizeof(LineBlockFragmentHeader); |
| 34 | if (LineInfoSize > Size) |
| 35 | return make_error<CodeViewError>(cv_error_code::corrupt_record, |
| 36 | "Invalid line block record size"); |
| 37 | // The value recorded in BlockHeader->BlockSize includes the size of |
| 38 | // LineBlockFragmentHeader. |
| 39 | Len = BlockHeader->BlockSize; |
| 40 | Item.NameIndex = BlockHeader->NameIndex; |
| 41 | if (auto EC = Reader.readArray(Item.LineNumbers, BlockHeader->NumLines)) |
| 42 | return EC; |
| 43 | if (HasColumn) { |
| 44 | if (auto EC = Reader.readArray(Item.Columns, BlockHeader->NumLines)) |
| 45 | return EC; |
| 46 | } |
| 47 | return Error::success(); |
| 48 | } |
| 49 | |
Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 50 | ModuleDebugLineFragmentRef::ModuleDebugLineFragmentRef() |
| 51 | : ModuleDebugFragmentRef(ModuleDebugFragmentKind::Lines) {} |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 52 | |
Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 53 | Error ModuleDebugLineFragmentRef::initialize(BinaryStreamReader Reader) { |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 54 | if (auto EC = Reader.readObject(Header)) |
| 55 | return EC; |
| 56 | |
| 57 | if (auto EC = |
| 58 | Reader.readArray(LinesAndColumns, Reader.bytesRemaining(), Header)) |
| 59 | return EC; |
| 60 | |
| 61 | return Error::success(); |
| 62 | } |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 63 | |
Zachary Turner | 7cc13e5 | 2017-05-01 16:46:39 +0000 | [diff] [blame^] | 64 | bool ModuleDebugLineFragmentRef::hasColumnInfo() const { |
| 65 | return !!(Header->Flags & LF_HaveColumns); |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 66 | } |