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