blob: 863f999a70f629bc5c8b4cac89c6559a068792fc [file] [log] [blame]
Zachary Turner307f5ae2018-10-12 19:47:13 +00001//===-- 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 Turner594c85e2018-12-17 19:43:33 +000013#include "lldb/Expression/DWARFExpression.h"
14#include "lldb/Symbol/Variable.h"
Zachary Turnerb96181c2018-10-22 16:19:07 +000015#include "lldb/lldb-enumerations.h"
16
Zachary Turner594c85e2018-12-17 19:43:33 +000017#include "llvm/ADT/Optional.h"
Zachary Turnera93458b2018-12-06 17:49:15 +000018#include "llvm/DebugInfo/CodeView/CodeView.h"
Zachary Turner307f5ae2018-10-12 19:47:13 +000019#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
Zachary Turner056e4ab2018-11-08 18:50:11 +000020#include "llvm/DebugInfo/CodeView/TypeRecord.h"
Zachary Turner307f5ae2018-10-12 19:47:13 +000021#include "llvm/DebugInfo/PDB/PDBTypes.h"
22
Zachary Turner594c85e2018-12-17 19:43:33 +000023#include "PdbSymUid.h"
24
Zachary Turner307f5ae2018-10-12 19:47:13 +000025#include <tuple>
26#include <utility>
27
Zachary Turner6284aee2018-11-16 02:42:32 +000028namespace llvm {
29namespace pdb {
30class TpiStream;
31}
32} // namespace llvm
33
Zachary Turner307f5ae2018-10-12 19:47:13 +000034namespace lldb_private {
35namespace npdb {
36
Zachary Turner594c85e2018-12-17 19:43:33 +000037class PdbIndex;
Zachary Turner6284aee2018-11-16 02:42:32 +000038
Zachary Turner056e4ab2018-11-08 18:50:11 +000039struct CVTagRecord {
40 enum Kind { Class, Struct, Union, Enum };
41
42 static CVTagRecord create(llvm::codeview::CVType type);
43
44 Kind kind() const { return m_kind; }
45
46 const llvm::codeview::TagRecord &asTag() const {
47 if (m_kind == Struct || m_kind == Class)
48 return cvclass;
49 if (m_kind == Enum)
50 return cvenum;
51 return cvunion;
52 }
53
54 const llvm::codeview::ClassRecord &asClass() const {
55 assert(m_kind == Struct || m_kind == Class);
56 return cvclass;
57 }
58
59 const llvm::codeview::EnumRecord &asEnum() const {
60 assert(m_kind == Enum);
61 return cvenum;
62 }
63
64 const llvm::codeview::UnionRecord &asUnion() const {
65 assert(m_kind == Union);
66 return cvunion;
67 }
68
69private:
70 CVTagRecord(llvm::codeview::ClassRecord &&c);
71 CVTagRecord(llvm::codeview::UnionRecord &&u);
72 CVTagRecord(llvm::codeview::EnumRecord &&e);
Zachary Turner056e4ab2018-11-08 18:50:11 +000073 union {
74 llvm::codeview::ClassRecord cvclass;
75 llvm::codeview::EnumRecord cvenum;
76 llvm::codeview::UnionRecord cvunion;
77 };
Jorge Gorbe Moyad17315d2018-11-08 19:57:59 +000078 Kind m_kind;
Zachary Turner056e4ab2018-11-08 18:50:11 +000079};
80
Zachary Turner307f5ae2018-10-12 19:47:13 +000081struct SegmentOffset {
82 SegmentOffset() = default;
83 SegmentOffset(uint16_t s, uint32_t o) : segment(s), offset(o) {}
84 uint16_t segment = 0;
85 uint32_t offset = 0;
86};
87
88struct SegmentOffsetLength {
89 SegmentOffsetLength() = default;
90 SegmentOffsetLength(uint16_t s, uint32_t o, uint32_t l)
91 : so(s, o), length(l) {}
92 SegmentOffset so;
93 uint32_t length = 0;
94};
95
Zachary Turner594c85e2018-12-17 19:43:33 +000096struct VariableInfo {
97 llvm::StringRef name;
98 llvm::codeview::TypeIndex type;
99 llvm::Optional<DWARFExpression> location;
100 llvm::Optional<Variable::RangeList> ranges;
101};
102
Zachary Turner307f5ae2018-10-12 19:47:13 +0000103llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);
Zachary Turnerb96181c2018-10-22 16:19:07 +0000104llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);
Zachary Turner307f5ae2018-10-12 19:47:13 +0000105
106bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);
107bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);
108
109SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);
110SegmentOffsetLength
111GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);
112
113template <typename RecordT> bool IsValidRecord(const RecordT &sym) {
114 return true;
115}
116
117inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {
118 // S_PROCREF symbols have 1-based module indices.
119 return sym.Module > 0;
120}
121
Zachary Turnerb96181c2018-10-22 16:19:07 +0000122bool IsForwardRefUdt(llvm::codeview::CVType cvt);
Zachary Turner056e4ab2018-11-08 18:50:11 +0000123bool IsTagRecord(llvm::codeview::CVType cvt);
Zachary Turner594c85e2018-12-17 19:43:33 +0000124bool IsClassStructUnion(llvm::codeview::CVType cvt);
Zachary Turnerb96181c2018-10-22 16:19:07 +0000125
Zachary Turner6284aee2018-11-16 02:42:32 +0000126bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
127bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
128
Zachary Turnerb96181c2018-10-22 16:19:07 +0000129lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);
130llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);
Zachary Turner511bff22018-10-30 18:57:08 +0000131llvm::codeview::TypeIndex
132LookThroughModifierRecord(llvm::codeview::CVType modifier);
Zachary Turnerb96181c2018-10-22 16:19:07 +0000133
134llvm::StringRef DropNameScope(llvm::StringRef name);
135
Zachary Turner594c85e2018-12-17 19:43:33 +0000136VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol);
137VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id,
138 lldb::ModuleSP module);
139
Zachary Turnera93458b2018-12-06 17:49:15 +0000140size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
141lldb::BasicType
142GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
143
Zachary Turner594c85e2018-12-17 19:43:33 +0000144PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
145
146size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi);
147
Zachary Turner307f5ae2018-10-12 19:47:13 +0000148} // namespace npdb
149} // namespace lldb_private
150
151#endif