xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/SymbolFile/NativePDB/PdbSymUid.h (revision dda2819751e49c83612958492e38917049128b41)
1061da546Spatrick //===-- PdbSymUid.h ---------------------------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick // A unique identification scheme for Pdb records.
9061da546Spatrick // The scheme is to partition a 64-bit integer into an 8-bit tag field, which
10061da546Spatrick // will contain some value from the PDB_SymType enumeration.  The format of the
11061da546Spatrick // other 48-bits depend on the tag, but must be sufficient to locate the
12061da546Spatrick // corresponding entry in the underlying PDB file quickly.  For example, for
13061da546Spatrick // a compile unit, we use 2 bytes to represent the index, which allows fast
14061da546Spatrick // access to the compile unit's information.
15061da546Spatrick //===----------------------------------------------------------------------===//
16061da546Spatrick 
17*dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBSYMUID_H
18*dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBSYMUID_H
19061da546Spatrick 
20061da546Spatrick #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
21061da546Spatrick #include "llvm/DebugInfo/PDB/PDBTypes.h"
22061da546Spatrick #include "llvm/Support/Compiler.h"
23061da546Spatrick 
24061da546Spatrick #include "lldb/Utility/LLDBAssert.h"
25061da546Spatrick #include "lldb/lldb-types.h"
26061da546Spatrick 
27061da546Spatrick namespace lldb_private {
28061da546Spatrick namespace npdb {
29061da546Spatrick 
30061da546Spatrick enum class PdbSymUidKind : uint8_t {
31061da546Spatrick   Compiland,
32061da546Spatrick   CompilandSym,
33061da546Spatrick   PublicSym,
34061da546Spatrick   GlobalSym,
35061da546Spatrick   Type,
36061da546Spatrick   FieldListMember
37061da546Spatrick };
38061da546Spatrick 
39061da546Spatrick struct PdbCompilandId {
40061da546Spatrick   // 0-based index of module in PDB
41061da546Spatrick   uint16_t modi;
42061da546Spatrick };
43061da546Spatrick 
44061da546Spatrick struct PdbCompilandSymId {
45061da546Spatrick   PdbCompilandSymId() = default;
PdbCompilandSymIdPdbCompilandSymId46061da546Spatrick   PdbCompilandSymId(uint16_t modi, uint32_t offset)
47061da546Spatrick       : modi(modi), offset(offset) {}
48061da546Spatrick   // 0-based index of module in PDB
49061da546Spatrick   uint16_t modi = 0;
50061da546Spatrick 
51061da546Spatrick   // Offset of symbol's record in module stream.  This is
52061da546Spatrick   // offset by 4 from the CVSymbolArray's notion of offset
53061da546Spatrick   // due to the debug magic at the beginning of the stream.
54061da546Spatrick   uint32_t offset = 0;
55061da546Spatrick };
56061da546Spatrick 
57061da546Spatrick struct PdbGlobalSymId {
58061da546Spatrick   PdbGlobalSymId() = default;
PdbGlobalSymIdPdbGlobalSymId59061da546Spatrick   PdbGlobalSymId(uint32_t offset, bool is_public)
60061da546Spatrick       : offset(offset), is_public(is_public) {}
61061da546Spatrick 
62061da546Spatrick   // Offset of symbol's record in globals or publics stream.
63061da546Spatrick   uint32_t offset = 0;
64061da546Spatrick 
65061da546Spatrick   // True if this symbol is in the public stream, false if it's in the globals
66061da546Spatrick   // stream.
67061da546Spatrick   bool is_public = false;
68061da546Spatrick };
69061da546Spatrick 
70061da546Spatrick struct PdbTypeSymId {
71061da546Spatrick   PdbTypeSymId() = default;
72061da546Spatrick   PdbTypeSymId(llvm::codeview::TypeIndex index, bool is_ipi = false)
indexPdbTypeSymId73061da546Spatrick       : index(index), is_ipi(is_ipi) {}
74061da546Spatrick 
75061da546Spatrick   // The index of the of the type in the TPI or IPI stream.
76061da546Spatrick   llvm::codeview::TypeIndex index;
77061da546Spatrick 
78061da546Spatrick   // True if this symbol comes from the IPI stream, false if it's from the TPI
79061da546Spatrick   // stream.
80061da546Spatrick   bool is_ipi = false;
81061da546Spatrick };
82061da546Spatrick 
83061da546Spatrick struct PdbFieldListMemberId {
84061da546Spatrick   // The TypeIndex of the LF_FIELDLIST record.
85061da546Spatrick   llvm::codeview::TypeIndex index;
86061da546Spatrick 
87061da546Spatrick   // The offset from the beginning of the LF_FIELDLIST record to this record.
88061da546Spatrick   uint16_t offset = 0;
89061da546Spatrick };
90061da546Spatrick 
91061da546Spatrick class PdbSymUid {
92061da546Spatrick   uint64_t m_repr = 0;
93061da546Spatrick 
94061da546Spatrick public:
95061da546Spatrick   PdbSymUid() = default;
PdbSymUid(uint64_t repr)96061da546Spatrick   PdbSymUid(uint64_t repr) : m_repr(repr) {}
97061da546Spatrick   PdbSymUid(const PdbCompilandId &cid);
98061da546Spatrick   PdbSymUid(const PdbCompilandSymId &csid);
99061da546Spatrick   PdbSymUid(const PdbGlobalSymId &gsid);
100061da546Spatrick   PdbSymUid(const PdbTypeSymId &tsid);
101061da546Spatrick   PdbSymUid(const PdbFieldListMemberId &flmid);
102061da546Spatrick 
toOpaqueId()103061da546Spatrick   uint64_t toOpaqueId() const { return m_repr; }
104061da546Spatrick 
105061da546Spatrick   PdbSymUidKind kind() const;
106061da546Spatrick 
107061da546Spatrick   PdbCompilandId asCompiland() const;
108061da546Spatrick   PdbCompilandSymId asCompilandSym() const;
109061da546Spatrick   PdbGlobalSymId asGlobalSym() const;
110061da546Spatrick   PdbTypeSymId asTypeSym() const;
111061da546Spatrick   PdbFieldListMemberId asFieldListMember() const;
112061da546Spatrick };
113061da546Spatrick 
toOpaqueUid(const T & cid)114061da546Spatrick template <typename T> uint64_t toOpaqueUid(const T &cid) {
115061da546Spatrick   return PdbSymUid(cid).toOpaqueId();
116061da546Spatrick }
117061da546Spatrick 
118061da546Spatrick struct SymbolAndUid {
119061da546Spatrick   llvm::codeview::CVSymbol sym;
120061da546Spatrick   PdbSymUid uid;
121061da546Spatrick };
122061da546Spatrick } // namespace npdb
123061da546Spatrick } // namespace lldb_private
124061da546Spatrick 
125061da546Spatrick #endif
126