1 //===-- PdbUtil.h -----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H
10 #define LLDB_PLUGINS_SYMBOLFILENATIVEPDB_PDBUTIL_H
12 #include "lldb/Expression/DWARFExpression.h"
13 #include "lldb/Symbol/Variable.h"
14 #include "lldb/lldb-enumerations.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/DebugInfo/CodeView/CodeView.h"
18 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
19 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
20 #include "llvm/DebugInfo/PDB/PDBTypes.h"
22 #include "PdbSymUid.h"
33 namespace lldb_private {
39 enum Kind { Class, Struct, Union, Enum };
41 static CVTagRecord create(llvm::codeview::CVType type);
43 Kind kind() const { return m_kind; }
45 const llvm::codeview::TagRecord &asTag() const {
46 if (m_kind == Struct || m_kind == Class)
53 const llvm::codeview::ClassRecord &asClass() const {
54 assert(m_kind == Struct || m_kind == Class);
58 const llvm::codeview::EnumRecord &asEnum() const {
59 assert(m_kind == Enum);
63 const llvm::codeview::UnionRecord &asUnion() const {
64 assert(m_kind == Union);
68 llvm::StringRef name() const {
69 if (m_kind == Struct || m_kind == Union)
77 CVTagRecord(llvm::codeview::ClassRecord &&c);
78 CVTagRecord(llvm::codeview::UnionRecord &&u);
79 CVTagRecord(llvm::codeview::EnumRecord &&e);
81 llvm::codeview::ClassRecord cvclass;
82 llvm::codeview::EnumRecord cvenum;
83 llvm::codeview::UnionRecord cvunion;
88 struct SegmentOffset {
89 SegmentOffset() = default;
90 SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {}
95 struct SegmentOffsetLength {
96 SegmentOffsetLength() = default;
97 SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)
98 : so(s, o), length(l) {}
103 struct VariableInfo {
104 llvm::StringRef name;
105 llvm::codeview::TypeIndex type;
106 llvm::Optional<DWARFExpression> location;
107 llvm::Optional<Variable::RangeList> ranges;
110 llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);
111 llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);
113 bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);
114 bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);
116 SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);
118 GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);
120 template <typename RecordT> bool IsValidRecord(const RecordT &sym) {
124 inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {
125 // S_PROCREF symbols have 1-based module indices.
126 return sym.Module > 0;
129 bool IsForwardRefUdt(llvm::codeview::CVType cvt);
130 bool IsTagRecord(llvm::codeview::CVType cvt);
131 bool IsClassStructUnion(llvm::codeview::CVType cvt);
133 bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
134 bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
136 lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);
137 llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);
138 llvm::codeview::TypeIndex
139 LookThroughModifierRecord(llvm::codeview::CVType modifier);
141 llvm::StringRef DropNameScope(llvm::StringRef name);
143 VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol);
144 VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, Block& block,
145 lldb::ModuleSP module);
147 size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
149 GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
151 PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
153 size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
156 } // namespace lldb_private