1 //===-- PdbUtil.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H
11 #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H
13 #include "lldb/Expression/DWARFExpression.h"
14 #include "lldb/Symbol/Variable.h"
15 #include "lldb/lldb-enumerations.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/DebugInfo/CodeView/CodeView.h"
19 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
20 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
21 #include "llvm/DebugInfo/PDB/PDBTypes.h"
23 #include "PdbSymUid.h"
34 namespace lldb_private {
40 enum Kind { Class, Struct, Union, Enum };
42 static CVTagRecord create(llvm::codeview::CVType type);
44 Kind kind() const { return m_kind; }
46 const llvm::codeview::TagRecord &asTag() const {
47 if (m_kind == Struct || m_kind == Class)
54 const llvm::codeview::ClassRecord &asClass() const {
55 assert(m_kind == Struct || m_kind == Class);
59 const llvm::codeview::EnumRecord &asEnum() const {
60 assert(m_kind == Enum);
64 const llvm::codeview::UnionRecord &asUnion() const {
65 assert(m_kind == Union);
69 llvm::StringRef name() const {
70 if (m_kind == Struct || m_kind == Union)
78 CVTagRecord(llvm::codeview::ClassRecord &&c);
79 CVTagRecord(llvm::codeview::UnionRecord &&u);
80 CVTagRecord(llvm::codeview::EnumRecord &&e);
82 llvm::codeview::ClassRecord cvclass;
83 llvm::codeview::EnumRecord cvenum;
84 llvm::codeview::UnionRecord cvunion;
89 struct SegmentOffset {
90 SegmentOffset() = default;
91 SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {}
96 struct SegmentOffsetLength {
97 SegmentOffsetLength() = default;
98 SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)
99 : so(s, o), length(l) {}
104 struct VariableInfo {
105 llvm::StringRef name;
106 llvm::codeview::TypeIndex type;
107 llvm::Optional<DWARFExpression> location;
108 llvm::Optional<Variable::RangeList> ranges;
111 llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);
112 llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);
114 bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);
115 bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);
117 SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);
119 GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);
121 template <typename RecordT> bool IsValidRecord(const RecordT &sym) {
125 inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {
126 // S_PROCREF symbols have 1-based module indices.
127 return sym.Module > 0;
130 bool IsForwardRefUdt(llvm::codeview::CVType cvt);
131 bool IsTagRecord(llvm::codeview::CVType cvt);
132 bool IsClassStructUnion(llvm::codeview::CVType cvt);
134 bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
135 bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
137 lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);
138 llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);
139 llvm::codeview::TypeIndex
140 LookThroughModifierRecord(llvm::codeview::CVType modifier);
142 llvm::StringRef DropNameScope(llvm::StringRef name);
144 VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol);
145 VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id,
146 lldb::ModuleSP module);
148 size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
150 GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
152 PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
154 size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
157 } // namespace lldb_private