1*0b57cec5SDimitry Andric //===- NativeSymbolEnumerator.cpp - info about enumerators ------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h"
10*0b57cec5SDimitry Andric
11*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
13*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
14*0b57cec5SDimitry Andric
15*0b57cec5SDimitry Andric using namespace llvm;
16*0b57cec5SDimitry Andric using namespace llvm::codeview;
17*0b57cec5SDimitry Andric using namespace llvm::pdb;
18*0b57cec5SDimitry Andric
NativeSymbolEnumerator(NativeSession & Session,SymIndexId Id,const NativeTypeEnum & Parent,codeview::EnumeratorRecord Record)19*0b57cec5SDimitry Andric NativeSymbolEnumerator::NativeSymbolEnumerator(
20*0b57cec5SDimitry Andric NativeSession &Session, SymIndexId Id, const NativeTypeEnum &Parent,
21*0b57cec5SDimitry Andric codeview::EnumeratorRecord Record)
22*0b57cec5SDimitry Andric : NativeRawSymbol(Session, PDB_SymType::Data, Id), Parent(Parent),
23*0b57cec5SDimitry Andric Record(std::move(Record)) {}
24*0b57cec5SDimitry Andric
~NativeSymbolEnumerator()25*0b57cec5SDimitry Andric NativeSymbolEnumerator::~NativeSymbolEnumerator() {}
26*0b57cec5SDimitry Andric
dump(raw_ostream & OS,int Indent,PdbSymbolIdField ShowIdFields,PdbSymbolIdField RecurseIdFields) const27*0b57cec5SDimitry Andric void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent,
28*0b57cec5SDimitry Andric PdbSymbolIdField ShowIdFields,
29*0b57cec5SDimitry Andric PdbSymbolIdField RecurseIdFields) const {
30*0b57cec5SDimitry Andric NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
31*0b57cec5SDimitry Andric dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
32*0b57cec5SDimitry Andric PdbSymbolIdField::ClassParent, ShowIdFields,
33*0b57cec5SDimitry Andric RecurseIdFields);
34*0b57cec5SDimitry Andric dumpSymbolIdField(OS, "lexicalParentId", getLexicalParentId(), Indent,
35*0b57cec5SDimitry Andric Session, PdbSymbolIdField::LexicalParent, ShowIdFields,
36*0b57cec5SDimitry Andric RecurseIdFields);
37*0b57cec5SDimitry Andric dumpSymbolField(OS, "name", getName(), Indent);
38*0b57cec5SDimitry Andric dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
39*0b57cec5SDimitry Andric PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
40*0b57cec5SDimitry Andric dumpSymbolField(OS, "dataKind", getDataKind(), Indent);
41*0b57cec5SDimitry Andric dumpSymbolField(OS, "locationType", getLocationType(), Indent);
42*0b57cec5SDimitry Andric dumpSymbolField(OS, "constType", isConstType(), Indent);
43*0b57cec5SDimitry Andric dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
44*0b57cec5SDimitry Andric dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
45*0b57cec5SDimitry Andric dumpSymbolField(OS, "value", getValue(), Indent);
46*0b57cec5SDimitry Andric }
47*0b57cec5SDimitry Andric
getClassParentId() const48*0b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getClassParentId() const {
49*0b57cec5SDimitry Andric return Parent.getSymIndexId();
50*0b57cec5SDimitry Andric }
51*0b57cec5SDimitry Andric
getLexicalParentId() const52*0b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getLexicalParentId() const { return 0; }
53*0b57cec5SDimitry Andric
getName() const54*0b57cec5SDimitry Andric std::string NativeSymbolEnumerator::getName() const {
55*0b57cec5SDimitry Andric return std::string(Record.Name);
56*0b57cec5SDimitry Andric }
57*0b57cec5SDimitry Andric
getTypeId() const58*0b57cec5SDimitry Andric SymIndexId NativeSymbolEnumerator::getTypeId() const {
59*0b57cec5SDimitry Andric return Parent.getTypeId();
60*0b57cec5SDimitry Andric }
61*0b57cec5SDimitry Andric
getDataKind() const62*0b57cec5SDimitry Andric PDB_DataKind NativeSymbolEnumerator::getDataKind() const {
63*0b57cec5SDimitry Andric return PDB_DataKind::Constant;
64*0b57cec5SDimitry Andric }
65*0b57cec5SDimitry Andric
getLocationType() const66*0b57cec5SDimitry Andric PDB_LocType NativeSymbolEnumerator::getLocationType() const {
67*0b57cec5SDimitry Andric return PDB_LocType::Constant;
68*0b57cec5SDimitry Andric }
69*0b57cec5SDimitry Andric
isConstType() const70*0b57cec5SDimitry Andric bool NativeSymbolEnumerator::isConstType() const { return false; }
71*0b57cec5SDimitry Andric
isVolatileType() const72*0b57cec5SDimitry Andric bool NativeSymbolEnumerator::isVolatileType() const { return false; }
73*0b57cec5SDimitry Andric
isUnalignedType() const74*0b57cec5SDimitry Andric bool NativeSymbolEnumerator::isUnalignedType() const { return false; }
75*0b57cec5SDimitry Andric
getValue() const76*0b57cec5SDimitry Andric Variant NativeSymbolEnumerator::getValue() const {
77*0b57cec5SDimitry Andric const NativeTypeBuiltin &BT = Parent.getUnderlyingBuiltinType();
78*0b57cec5SDimitry Andric
79*0b57cec5SDimitry Andric switch (BT.getBuiltinType()) {
80*0b57cec5SDimitry Andric case PDB_BuiltinType::Int:
81*0b57cec5SDimitry Andric case PDB_BuiltinType::Long:
82*0b57cec5SDimitry Andric case PDB_BuiltinType::Char: {
83*0b57cec5SDimitry Andric assert(Record.Value.isSignedIntN(BT.getLength() * 8));
84*0b57cec5SDimitry Andric int64_t N = Record.Value.getSExtValue();
85*0b57cec5SDimitry Andric switch (BT.getLength()) {
86*0b57cec5SDimitry Andric case 1:
87*0b57cec5SDimitry Andric return Variant{static_cast<int8_t>(N)};
88*0b57cec5SDimitry Andric case 2:
89*0b57cec5SDimitry Andric return Variant{static_cast<int16_t>(N)};
90*0b57cec5SDimitry Andric case 4:
91*0b57cec5SDimitry Andric return Variant{static_cast<int32_t>(N)};
92*0b57cec5SDimitry Andric case 8:
93*0b57cec5SDimitry Andric return Variant{static_cast<int64_t>(N)};
94*0b57cec5SDimitry Andric }
95*0b57cec5SDimitry Andric break;
96*0b57cec5SDimitry Andric }
97*0b57cec5SDimitry Andric case PDB_BuiltinType::UInt:
98*0b57cec5SDimitry Andric case PDB_BuiltinType::ULong: {
99*0b57cec5SDimitry Andric assert(Record.Value.isIntN(BT.getLength() * 8));
100*0b57cec5SDimitry Andric uint64_t U = Record.Value.getZExtValue();
101*0b57cec5SDimitry Andric switch (BT.getLength()) {
102*0b57cec5SDimitry Andric case 1:
103*0b57cec5SDimitry Andric return Variant{static_cast<uint8_t>(U)};
104*0b57cec5SDimitry Andric case 2:
105*0b57cec5SDimitry Andric return Variant{static_cast<uint16_t>(U)};
106*0b57cec5SDimitry Andric case 4:
107*0b57cec5SDimitry Andric return Variant{static_cast<uint32_t>(U)};
108*0b57cec5SDimitry Andric case 8:
109*0b57cec5SDimitry Andric return Variant{static_cast<uint64_t>(U)};
110*0b57cec5SDimitry Andric }
111*0b57cec5SDimitry Andric break;
112*0b57cec5SDimitry Andric }
113*0b57cec5SDimitry Andric case PDB_BuiltinType::Bool: {
114*0b57cec5SDimitry Andric assert(Record.Value.isIntN(BT.getLength() * 8));
115*0b57cec5SDimitry Andric uint64_t U = Record.Value.getZExtValue();
116*0b57cec5SDimitry Andric return Variant{static_cast<bool>(U)};
117*0b57cec5SDimitry Andric }
118*0b57cec5SDimitry Andric default:
119*0b57cec5SDimitry Andric assert(false && "Invalid enumeration type");
120*0b57cec5SDimitry Andric break;
121*0b57cec5SDimitry Andric }
122*0b57cec5SDimitry Andric
123 return Variant{Record.Value.getSExtValue()};
124 }
125