1 //===- Line.h ---------------------------------------------------*- C++ -*-===// 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 #ifndef LLVM_DEBUGINFO_CODEVIEW_LINE_H 11 #define LLVM_DEBUGINFO_CODEVIEW_LINE_H 12 13 #include "llvm/DebugInfo/CodeView/TypeIndex.h" 14 #include "llvm/Support/Endian.h" 15 #include <cinttypes> 16 17 namespace llvm { 18 namespace codeview { 19 20 using llvm::support::ulittle32_t; 21 22 class LineInfo { 23 public: 24 enum : uint32_t { 25 AlwaysStepIntoLineNumber = 0xfeefee, 26 NeverStepIntoLineNumber = 0xf00f00 27 }; 28 29 enum : int { EndLineDeltaShift = 24 }; 30 31 enum : uint32_t { 32 StartLineMask = 0x00ffffff, 33 EndLineDeltaMask = 0x7f000000, 34 StatementFlag = 0x80000000u 35 }; 36 37 LineInfo(uint32_t StartLine, uint32_t EndLine, bool IsStatement); LineInfo(uint32_t LineData)38 LineInfo(uint32_t LineData) : LineData(LineData) {} 39 getStartLine()40 uint32_t getStartLine() const { return LineData & StartLineMask; } 41 getLineDelta()42 uint32_t getLineDelta() const { 43 return (LineData & EndLineDeltaMask) >> EndLineDeltaShift; 44 } 45 getEndLine()46 uint32_t getEndLine() const { return getStartLine() + getLineDelta(); } 47 isStatement()48 bool isStatement() const { return (LineData & StatementFlag) != 0; } 49 getRawData()50 uint32_t getRawData() const { return LineData; } 51 isAlwaysStepInto()52 bool isAlwaysStepInto() const { 53 return getStartLine() == AlwaysStepIntoLineNumber; 54 } 55 isNeverStepInto()56 bool isNeverStepInto() const { 57 return getStartLine() == NeverStepIntoLineNumber; 58 } 59 60 private: 61 uint32_t LineData; 62 }; 63 64 class ColumnInfo { 65 private: 66 static const uint32_t StartColumnMask = 0x0000ffffu; 67 static const uint32_t EndColumnMask = 0xffff0000u; 68 static const int EndColumnShift = 16; 69 70 public: ColumnInfo(uint16_t StartColumn,uint16_t EndColumn)71 ColumnInfo(uint16_t StartColumn, uint16_t EndColumn) { 72 ColumnData = 73 (static_cast<uint32_t>(StartColumn) & StartColumnMask) | 74 ((static_cast<uint32_t>(EndColumn) << EndColumnShift) & EndColumnMask); 75 } 76 getStartColumn()77 uint16_t getStartColumn() const { 78 return static_cast<uint16_t>(ColumnData & StartColumnMask); 79 } 80 getEndColumn()81 uint16_t getEndColumn() const { 82 return static_cast<uint16_t>((ColumnData & EndColumnMask) >> 83 EndColumnShift); 84 } 85 getRawData()86 uint32_t getRawData() const { return ColumnData; } 87 88 private: 89 uint32_t ColumnData; 90 }; 91 92 class Line { 93 private: 94 int32_t CodeOffset; 95 LineInfo LineInf; 96 ColumnInfo ColumnInf; 97 98 public: Line(int32_t CodeOffset,uint32_t StartLine,uint32_t EndLine,uint16_t StartColumn,uint16_t EndColumn,bool IsStatement)99 Line(int32_t CodeOffset, uint32_t StartLine, uint32_t EndLine, 100 uint16_t StartColumn, uint16_t EndColumn, bool IsStatement) 101 : CodeOffset(CodeOffset), LineInf(StartLine, EndLine, IsStatement), 102 ColumnInf(StartColumn, EndColumn) {} 103 Line(int32_t CodeOffset,LineInfo LineInf,ColumnInfo ColumnInf)104 Line(int32_t CodeOffset, LineInfo LineInf, ColumnInfo ColumnInf) 105 : CodeOffset(CodeOffset), LineInf(LineInf), ColumnInf(ColumnInf) {} 106 getLineInfo()107 LineInfo getLineInfo() const { return LineInf; } 108 getColumnInfo()109 ColumnInfo getColumnInfo() const { return ColumnInf; } 110 getCodeOffset()111 int32_t getCodeOffset() const { return CodeOffset; } 112 getStartLine()113 uint32_t getStartLine() const { return LineInf.getStartLine(); } 114 getLineDelta()115 uint32_t getLineDelta() const { return LineInf.getLineDelta(); } 116 getEndLine()117 uint32_t getEndLine() const { return LineInf.getEndLine(); } 118 getStartColumn()119 uint16_t getStartColumn() const { return ColumnInf.getStartColumn(); } 120 getEndColumn()121 uint16_t getEndColumn() const { return ColumnInf.getEndColumn(); } 122 isStatement()123 bool isStatement() const { return LineInf.isStatement(); } 124 isAlwaysStepInto()125 bool isAlwaysStepInto() const { return LineInf.isAlwaysStepInto(); } 126 isNeverStepInto()127 bool isNeverStepInto() const { return LineInf.isNeverStepInto(); } 128 }; 129 130 enum class InlineeLinesSignature : uint32_t { 131 Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE 132 ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX 133 }; 134 135 struct InlineeSourceLine { 136 TypeIndex Inlinee; // ID of the function that was inlined. 137 ulittle32_t FileID; // Offset into FileChecksums subsection. 138 ulittle32_t SourceLineNum; // First line of inlined code. 139 // If extra files present: 140 // ulittle32_t ExtraFileCount; 141 // ulittle32_t Files[]; 142 }; 143 144 struct FileChecksum { 145 ulittle32_t FileNameOffset; // Byte offset of filename in global string table. 146 uint8_t ChecksumSize; // Number of bytes of checksum. 147 uint8_t ChecksumKind; // FileChecksumKind 148 // Checksum bytes follow. 149 }; 150 151 } // namespace codeview 152 } // namespace llvm 153 154 #endif 155