blob: c01e419f58c0da071387f0369912c70af4d3a624 [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 Turnerb96181c2018-10-22 16:19:07 +000013#include "lldb/lldb-enumerations.h"
14
Zachary Turnera93458b2018-12-06 17:49:15 +000015#include "llvm/DebugInfo/CodeView/CodeView.h"
Zachary Turner307f5ae2018-10-12 19:47:13 +000016#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
Zachary Turner056e4ab2018-11-08 18:50:11 +000017#include "llvm/DebugInfo/CodeView/TypeRecord.h"
Zachary Turner307f5ae2018-10-12 19:47:13 +000018#include "llvm/DebugInfo/PDB/PDBTypes.h"
19
20#include <tuple>
21#include <utility>
22
Zachary Turner6284aee2018-11-16 02:42:32 +000023namespace llvm {
24namespace pdb {
25class TpiStream;
26}
27} // namespace llvm
28
Zachary Turner307f5ae2018-10-12 19:47:13 +000029namespace lldb_private {
30namespace npdb {
31
Zachary Turner6284aee2018-11-16 02:42:32 +000032struct PdbTypeSymId;
33
Zachary Turner056e4ab2018-11-08 18:50:11 +000034struct 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
64private:
65 CVTagRecord(llvm::codeview::ClassRecord &&c);
66 CVTagRecord(llvm::codeview::UnionRecord &&u);
67 CVTagRecord(llvm::codeview::EnumRecord &&e);
Zachary Turner056e4ab2018-11-08 18:50:11 +000068 union {
69 llvm::codeview::ClassRecord cvclass;
70 llvm::codeview::EnumRecord cvenum;
71 llvm::codeview::UnionRecord cvunion;
72 };
Jorge Gorbe Moyad17315d2018-11-08 19:57:59 +000073 Kind m_kind;
Zachary Turner056e4ab2018-11-08 18:50:11 +000074};
75
Zachary Turner307f5ae2018-10-12 19:47:13 +000076struct 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
83struct 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
91llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind);
Zachary Turnerb96181c2018-10-22 16:19:07 +000092llvm::pdb::PDB_SymType CVTypeToPDBType(llvm::codeview::TypeLeafKind kind);
Zachary Turner307f5ae2018-10-12 19:47:13 +000093
94bool SymbolHasAddress(const llvm::codeview::CVSymbol &sym);
95bool SymbolIsCode(const llvm::codeview::CVSymbol &sym);
96
97SegmentOffset GetSegmentAndOffset(const llvm::codeview::CVSymbol &sym);
98SegmentOffsetLength
99GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym);
100
101template <typename RecordT> bool IsValidRecord(const RecordT &sym) {
102 return true;
103}
104
105inline bool IsValidRecord(const llvm::codeview::ProcRefSym &sym) {
106 // S_PROCREF symbols have 1-based module indices.
107 return sym.Module > 0;
108}
109
Zachary Turnerb96181c2018-10-22 16:19:07 +0000110bool IsForwardRefUdt(llvm::codeview::CVType cvt);
Zachary Turner056e4ab2018-11-08 18:50:11 +0000111bool IsTagRecord(llvm::codeview::CVType cvt);
Zachary Turnerb96181c2018-10-22 16:19:07 +0000112
Zachary Turner6284aee2018-11-16 02:42:32 +0000113bool IsForwardRefUdt(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
114bool IsTagRecord(const PdbTypeSymId &id, llvm::pdb::TpiStream &tpi);
115
Zachary Turnerb96181c2018-10-22 16:19:07 +0000116lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access);
117llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt);
Zachary Turner511bff22018-10-30 18:57:08 +0000118llvm::codeview::TypeIndex
119LookThroughModifierRecord(llvm::codeview::CVType modifier);
Zachary Turnerb96181c2018-10-22 16:19:07 +0000120
121llvm::StringRef DropNameScope(llvm::StringRef name);
122
Zachary Turnera93458b2018-12-06 17:49:15 +0000123size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
124lldb::BasicType
125GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind);
126
Zachary Turner307f5ae2018-10-12 19:47:13 +0000127} // namespace npdb
128} // namespace lldb_private
129
130#endif