1 | //===- NativeSymbolEnumerator.cpp - info about enumerators ------*- 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 | #include "llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h" |
10 | |
11 | #include "llvm/DebugInfo/PDB/Native/NativeSession.h" |
12 | #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" |
13 | #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" |
14 | |
15 | using namespace llvm; |
16 | using namespace llvm::codeview; |
17 | using namespace llvm::pdb; |
18 | |
19 | NativeSymbolEnumerator::NativeSymbolEnumerator( |
20 | NativeSession &Session, SymIndexId Id, const NativeTypeEnum &Parent, |
21 | codeview::EnumeratorRecord Record) |
22 | : NativeRawSymbol(Session, PDB_SymType::Data, Id), Parent(Parent), |
23 | Record(std::move(Record)) {} |
24 | |
25 | NativeSymbolEnumerator::~NativeSymbolEnumerator() = default; |
26 | |
27 | void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent, |
28 | PdbSymbolIdField ShowIdFields, |
29 | PdbSymbolIdField RecurseIdFields) const { |
30 | NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields); |
31 | dumpSymbolIdField(OS, Name: "classParentId" , Value: getClassParentId(), Indent, Session, |
32 | FieldId: PdbSymbolIdField::ClassParent, ShowFlags: ShowIdFields, |
33 | RecurseFlags: RecurseIdFields); |
34 | dumpSymbolIdField(OS, Name: "lexicalParentId" , Value: getLexicalParentId(), Indent, |
35 | Session, FieldId: PdbSymbolIdField::LexicalParent, ShowFlags: ShowIdFields, |
36 | RecurseFlags: RecurseIdFields); |
37 | dumpSymbolField(OS, Name: "name" , Value: getName(), Indent); |
38 | dumpSymbolIdField(OS, Name: "typeId" , Value: getTypeId(), Indent, Session, |
39 | FieldId: PdbSymbolIdField::Type, ShowFlags: ShowIdFields, RecurseFlags: RecurseIdFields); |
40 | dumpSymbolField(OS, Name: "dataKind" , Value: getDataKind(), Indent); |
41 | dumpSymbolField(OS, Name: "locationType" , Value: getLocationType(), Indent); |
42 | dumpSymbolField(OS, Name: "constType" , Value: isConstType(), Indent); |
43 | dumpSymbolField(OS, Name: "unalignedType" , Value: isUnalignedType(), Indent); |
44 | dumpSymbolField(OS, Name: "volatileType" , Value: isVolatileType(), Indent); |
45 | dumpSymbolField(OS, Name: "value" , Value: getValue(), Indent); |
46 | } |
47 | |
48 | SymIndexId NativeSymbolEnumerator::getClassParentId() const { |
49 | return Parent.getSymIndexId(); |
50 | } |
51 | |
52 | SymIndexId NativeSymbolEnumerator::getLexicalParentId() const { return 0; } |
53 | |
54 | std::string NativeSymbolEnumerator::getName() const { |
55 | return std::string(Record.Name); |
56 | } |
57 | |
58 | SymIndexId NativeSymbolEnumerator::getTypeId() const { |
59 | return Parent.getTypeId(); |
60 | } |
61 | |
62 | PDB_DataKind NativeSymbolEnumerator::getDataKind() const { |
63 | return PDB_DataKind::Constant; |
64 | } |
65 | |
66 | PDB_LocType NativeSymbolEnumerator::getLocationType() const { |
67 | return PDB_LocType::Constant; |
68 | } |
69 | |
70 | bool NativeSymbolEnumerator::isConstType() const { return false; } |
71 | |
72 | bool NativeSymbolEnumerator::isVolatileType() const { return false; } |
73 | |
74 | bool NativeSymbolEnumerator::isUnalignedType() const { return false; } |
75 | |
76 | Variant NativeSymbolEnumerator::getValue() const { |
77 | const NativeTypeBuiltin &BT = Parent.getUnderlyingBuiltinType(); |
78 | |
79 | switch (BT.getBuiltinType()) { |
80 | case PDB_BuiltinType::Int: |
81 | case PDB_BuiltinType::Long: |
82 | case PDB_BuiltinType::Char: { |
83 | assert(Record.Value.isSignedIntN(BT.getLength() * 8)); |
84 | int64_t N = Record.Value.getSExtValue(); |
85 | switch (BT.getLength()) { |
86 | case 1: |
87 | return Variant{static_cast<int8_t>(N)}; |
88 | case 2: |
89 | return Variant{static_cast<int16_t>(N)}; |
90 | case 4: |
91 | return Variant{static_cast<int32_t>(N)}; |
92 | case 8: |
93 | return Variant{static_cast<int64_t>(N)}; |
94 | } |
95 | break; |
96 | } |
97 | case PDB_BuiltinType::UInt: |
98 | case PDB_BuiltinType::ULong: { |
99 | assert(Record.Value.isIntN(BT.getLength() * 8)); |
100 | uint64_t U = Record.Value.getZExtValue(); |
101 | switch (BT.getLength()) { |
102 | case 1: |
103 | return Variant{static_cast<uint8_t>(U)}; |
104 | case 2: |
105 | return Variant{static_cast<uint16_t>(U)}; |
106 | case 4: |
107 | return Variant{static_cast<uint32_t>(U)}; |
108 | case 8: |
109 | return Variant{static_cast<uint64_t>(U)}; |
110 | } |
111 | break; |
112 | } |
113 | case PDB_BuiltinType::Bool: { |
114 | assert(Record.Value.isIntN(BT.getLength() * 8)); |
115 | uint64_t U = Record.Value.getZExtValue(); |
116 | return Variant{static_cast<bool>(U)}; |
117 | } |
118 | default: |
119 | assert(false && "Invalid enumeration type" ); |
120 | break; |
121 | } |
122 | |
123 | return Variant{Record.Value.getSExtValue()}; |
124 | } |
125 | |