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