LLDB mainline
PdbUtil.h
Go to the documentation of this file.
1//===-- PdbUtil.h -----------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBUTIL_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBUTIL_H
11
15
16#include "llvm/DebugInfo/CodeView/CodeView.h"
17#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
18#include "llvm/DebugInfo/CodeView/TypeRecord.h"
19#include "llvm/DebugInfo/PDB/PDBTypes.h"
20
21#include "PdbSymUid.h"
22
23#include <tuple>
24#include <utility>
25
26namespace llvm {
27namespace pdb {
28class TpiStream;
29}
30} // namespace llvm
31
32namespace lldb_private {
33namespace npdb {
34
35class PdbIndex;
36
38 enum Kind { Class, Struct, Union, Enum };
39
40 static CVTagRecord create(llvm::codeview::CVType type);
41
42 Kind kind() const { return m_kind; }
43
44 const llvm::codeview::TagRecord &asTag() const {
45 if (m_kind == Struct || m_kind == Class)
46 return cvclass;
47 if (m_kind == Enum)
48 return cvenum;
49 return cvunion;
50 }
51
52 const llvm::codeview::ClassRecord &asClass() const {
53 assert(m_kind == Struct || m_kind == Class);
54 return cvclass;
55 }
56
57 const llvm::codeview::EnumRecord &asEnum() const {
58 assert(m_kind == Enum);
59 return cvenum;
60 }
61
62 const llvm::codeview::UnionRecord &asUnion() const {
63 assert(m_kind == Union);
64 return cvunion;
65 }
66
67 llvm::StringRef name() const {
68 if (m_kind == Struct || m_kind == Class)
69 return cvclass.Name;
70 if (m_kind == Enum)
71 return cvenum.Name;
72 return cvunion.Name;
73 }
74
76 if (m_kind == Struct || m_kind == Class)
78 if (m_kind == Enum)
80
81 assert(m_kind == Union);
83 }
84
85private:
86 CVTagRecord(llvm::codeview::ClassRecord &&c);
87 CVTagRecord(llvm::codeview::UnionRecord &&u);
88 CVTagRecord(llvm::codeview::EnumRecord &&e);
89 union {
90 llvm::codeview::ClassRecord cvclass;
91 llvm::codeview::EnumRecord cvenum;
92 llvm::codeview::UnionRecord cvunion;
93 };
95};
96
98 SegmentOffset() = default;
99 SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {}
100 uint16_t segment = 0;
101 uint32_t offset = 0;
102};
103
106 SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)
107 : so(s, o), length(l) {}
109 uint32_t length = 0;
110};
111
113 llvm::StringRef name;
114 llvm::codeview::TypeIndex type;
117};
118
119llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);
120llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);
121
122bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);
123bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);
124
125SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);
127GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);
128
129template <typename RecordT> bool IsValidRecord(const RecordT &sym) {
130 return true;
131}
132
133inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {
134 // S_PROCREF symbols have 1-based module indices.
135 return sym.Module > 0;
136}
137
138bool IsForwardRefUdt(llvm::codeview::CVType cvt);
139bool IsTagRecord(llvm::codeview::CVType cvt);
140bool IsClassStructUnion(llvm::codeview::CVType cvt);
141
142bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
143bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
144
145lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);
146llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);
147llvm::codeview::TypeIndex
148LookThroughModifierRecord(llvm::codeview::CVType modifier);
149
150llvm::StringRef DropNameScope(llvm::StringRef name);
151
152VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol);
154 Block &func_block, lldb::ModuleSP module);
155
156size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
158GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
159
160PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
161
162size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
163
164} // namespace npdb
165} // namespace lldb_private
166
167#endif
A class that describes a single lexical block.
Definition Block.h:41
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
PdbIndex - Lazy access to the important parts of a PDB file.
Definition PdbIndex.h:47
bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym)
llvm::StringRef DropNameScope(llvm::StringRef name)
Definition PdbUtil.cpp:599
llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind)
size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym)
lldb::BasicType GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol)
SegmentOffsetLength GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym)
bool IsTagRecord(llvm::codeview::CVType cvt)
Definition PdbUtil.cpp:517
bool IsValidRecord(const RecordT &sym)
Definition PdbUtil.h:129
llvm::codeview::TypeIndex LookThroughModifierRecord(llvm::codeview::CVType modifier)
VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, Block &func_block, lldb::ModuleSP module)
Definition PdbUtil.cpp:734
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access)
llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt)
llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind)
size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
Definition PdbUtil.cpp:1069
PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
bool IsClassStructUnion(llvm::codeview::CVType cvt)
Definition PdbUtil.cpp:529
bool SymbolIsCode(const llvm::codeview::CVSymbol &sym)
A class that represents a running process on the host machine.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
std::shared_ptr< lldb_private::Module > ModuleSP
llvm::codeview::EnumRecord cvenum
Definition PdbUtil.h:91
CompilerContextKind contextKind() const
Definition PdbUtil.h:75
const llvm::codeview::UnionRecord & asUnion() const
Definition PdbUtil.h:62
static CVTagRecord create(llvm::codeview::CVType type)
Definition PdbUtil.cpp:198
const llvm::codeview::ClassRecord & asClass() const
Definition PdbUtil.h:52
CVTagRecord(llvm::codeview::EnumRecord &&e)
llvm::codeview::UnionRecord cvunion
Definition PdbUtil.h:92
llvm::codeview::ClassRecord cvclass
Definition PdbUtil.h:90
const llvm::codeview::EnumRecord & asEnum() const
Definition PdbUtil.h:57
CVTagRecord(llvm::codeview::ClassRecord &&c)
const llvm::codeview::TagRecord & asTag() const
Definition PdbUtil.h:44
llvm::StringRef name() const
Definition PdbUtil.h:67
CVTagRecord(llvm::codeview::UnionRecord &&u)
SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)
Definition PdbUtil.h:106
SegmentOffset(uint16_t s, uint32_t o)
Definition PdbUtil.h:99
DWARFExpressionList location
Definition PdbUtil.h:115
llvm::codeview::TypeIndex type
Definition PdbUtil.h:114