| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 1 | //===-- PdbUtil.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 LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H |
| 11 | #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H |
| 12 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 13 | #include "lldb/Expression/DWARFExpression.h" |
| 14 | #include "lldb/Symbol/Variable.h" |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 15 | #include "lldb/lldb-enumerations.h" |
| 16 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 17 | #include "llvm/ADT/Optional.h" |
| Zachary Turner | a93458b | 2018-12-06 17:49:15 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/SymbolRecord.h" |
| Zachary Turner | 056e4ab | 2018-11-08 18:50:11 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/TypeRecord.h" |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/PDB/PDBTypes.h" |
| 22 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 23 | #include "PdbSymUid.h" |
| 24 | |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 25 | #include <tuple> |
| 26 | #include <utility> |
| 27 | |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 28 | namespace llvm { |
| 29 | namespace pdb { |
| 30 | class TpiStream; |
| 31 | } |
| 32 | } // namespace llvm |
| 33 | |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 34 | namespace lldb_private { |
| 35 | namespace npdb { |
| 36 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 37 | class PdbIndex; |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 38 | |
| Zachary Turner | 056e4ab | 2018-11-08 18:50:11 +0000 | [diff] [blame] | 39 | struct CVTagRecord { |
| 40 | enum Kind { Class, Struct, Union, Enum }; |
| 41 | |
| 42 | static CVTagRecord create(llvm::codeview::CVType type); |
| 43 | |
| 44 | Kind kind() const { return m_kind; } |
| 45 | |
| 46 | const llvm::codeview::TagRecord &asTag() const { |
| 47 | if (m_kind == Struct || m_kind == Class) |
| 48 | return cvclass; |
| 49 | if (m_kind == Enum) |
| 50 | return cvenum; |
| 51 | return cvunion; |
| 52 | } |
| 53 | |
| 54 | const llvm::codeview::ClassRecord &asClass() const { |
| 55 | assert(m_kind == Struct || m_kind == Class); |
| 56 | return cvclass; |
| 57 | } |
| 58 | |
| 59 | const llvm::codeview::EnumRecord &asEnum() const { |
| 60 | assert(m_kind == Enum); |
| 61 | return cvenum; |
| 62 | } |
| 63 | |
| 64 | const llvm::codeview::UnionRecord &asUnion() const { |
| 65 | assert(m_kind == Union); |
| 66 | return cvunion; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | CVTagRecord(llvm::codeview::ClassRecord &&c); |
| 71 | CVTagRecord(llvm::codeview::UnionRecord &&u); |
| 72 | CVTagRecord(llvm::codeview::EnumRecord &&e); |
| Zachary Turner | 056e4ab | 2018-11-08 18:50:11 +0000 | [diff] [blame] | 73 | union { |
| 74 | llvm::codeview::ClassRecord cvclass; |
| 75 | llvm::codeview::EnumRecord cvenum; |
| 76 | llvm::codeview::UnionRecord cvunion; |
| 77 | }; |
| Jorge Gorbe Moya | d17315d | 2018-11-08 19:57:59 +0000 | [diff] [blame] | 78 | Kind m_kind; |
| Zachary Turner | 056e4ab | 2018-11-08 18:50:11 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 81 | struct SegmentOffset { |
| 82 | SegmentOffset() = default; |
| 83 | SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {} |
| 84 | uint16_t segment = 0; |
| 85 | uint32_t offset = 0; |
| 86 | }; |
| 87 | |
| 88 | struct SegmentOffsetLength { |
| 89 | SegmentOffsetLength() = default; |
| 90 | SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l) |
| 91 | : so(s, o), length(l) {} |
| 92 | SegmentOffset so; |
| 93 | uint32_t length = 0; |
| 94 | }; |
| 95 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 96 | struct VariableInfo { |
| 97 | llvm::StringRef name; |
| 98 | llvm::codeview::TypeIndex type; |
| 99 | llvm::Optional<DWARFExpression> location; |
| 100 | llvm::Optional<Variable::RangeList> ranges; |
| 101 | }; |
| 102 | |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 103 | llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind); |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 104 | llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind); |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 105 | |
| 106 | bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym); |
| 107 | bool SymbolIsCode(const llvm::codeview::CVSymbol &sym); |
| 108 | |
| 109 | SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym); |
| 110 | SegmentOffsetLength |
| 111 | GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym); |
| 112 | |
| 113 | template <typename RecordT> bool IsValidRecord(const RecordT &sym) { |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) { |
| 118 | // S_PROCREF symbols have 1-based module indices. |
| 119 | return sym.Module > 0; |
| 120 | } |
| 121 | |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 122 | bool IsForwardRefUdt(llvm::codeview::CVType cvt); |
| Zachary Turner | 056e4ab | 2018-11-08 18:50:11 +0000 | [diff] [blame] | 123 | bool IsTagRecord(llvm::codeview::CVType cvt); |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 124 | bool IsClassStructUnion(llvm::codeview::CVType cvt); |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 125 | |
| Zachary Turner | 6284aee | 2018-11-16 02:42:32 +0000 | [diff] [blame] | 126 | bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi); |
| 127 | bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi); |
| 128 | |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 129 | lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access); |
| 130 | llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt); |
| Zachary Turner | 511bff2 | 2018-10-30 18:57:08 +0000 | [diff] [blame] | 131 | llvm::codeview::TypeIndex |
| 132 | LookThroughModifierRecord(llvm::codeview::CVType modifier); |
| Zachary Turner | b96181c | 2018-10-22 16:19:07 +0000 | [diff] [blame] | 133 | |
| 134 | llvm::StringRef DropNameScope(llvm::StringRef name); |
| 135 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 136 | VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol); |
| 137 | VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, |
| 138 | lldb::ModuleSP module); |
| 139 | |
| Zachary Turner | a93458b | 2018-12-06 17:49:15 +0000 | [diff] [blame] | 140 | size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind); |
| 141 | lldb::BasicType |
| 142 | GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind); |
| 143 | |
| Zachary Turner | 594c85e | 2018-12-17 19:43:33 +0000 | [diff] [blame^] | 144 | PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi); |
| 145 | |
| 146 | size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi); |
| 147 | |
| Zachary Turner | 307f5ae | 2018-10-12 19:47:13 +0000 | [diff] [blame] | 148 | } // namespace npdb |
| 149 | } // namespace lldb_private |
| 150 | |
| 151 | #endif |