1 //===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- 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 #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 11 12 #include "llvm/DebugInfo/PDB/IPDBSession.h" 13 #include "llvm/DebugInfo/PDB/PDBExtras.h" 14 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" 15 #include "llvm/Support/Format.h" 16 #include <utility> 17 18 #include <utility> 19 20 using namespace llvm; 21 22 PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession, 23 std::unique_ptr<IPDBRawSymbol> DataSymbol) 24 : PDBSymbol(PDBSession, std::move(DataSymbol)) {} 25 26 void PDBSymbolData::dump(raw_ostream &OS, int Indent, 27 PDB_DumpLevel Level, PDB_DumpFlags Flags) const { 28 OS << stream_indent(Indent); 29 PDB_LocType Loc = getLocationType(); 30 PDB_DataKind Kind = getDataKind(); 31 switch (Loc) { 32 case PDB_LocType::Static: { 33 uint32_t RVA = getRelativeVirtualAddress(); 34 OS << Kind << " data["; 35 if (RVA != 0) 36 OS << format_hex(RVA, 10); 37 else 38 OS << "???"; 39 break; 40 } 41 case PDB_LocType::TLS: 42 OS << "threadlocal " << Kind << " data["; 43 OS << getAddressSection() << ":" << format_hex(getAddressOffset(), 10); 44 break; 45 case PDB_LocType::RegRel: 46 OS << "regrel " << Kind << " data["; 47 OS << getRegisterId() << " + " << getOffset(); 48 break; 49 case PDB_LocType::ThisRel: { 50 uint32_t Offset = getOffset(); 51 OS << Kind << " data[this + " << format_hex(Offset, 4); 52 break; 53 } 54 case PDB_LocType::Enregistered: 55 OS << "register " << Kind << " data[" << getRegisterId(); 56 break; 57 case PDB_LocType::BitField: { 58 OS << "bitfield data[this + "; 59 uint32_t Offset = getOffset(); 60 uint32_t BitPos = getBitPosition(); 61 uint32_t Length = getLength(); 62 OS << format_hex(Offset, 4) << ":" << BitPos << "," << Length; 63 break; 64 } 65 case PDB_LocType::Slot: 66 OS << getSlot(); 67 break; 68 case PDB_LocType::Constant: { 69 OS << "constant data["; 70 OS << getValue(); 71 break; 72 } 73 case PDB_LocType::IlRel: 74 case PDB_LocType::MetaData: 75 default: 76 OS << "???"; 77 } 78 79 OS << "] "; 80 if (Kind == PDB_DataKind::Member || Kind == PDB_DataKind::StaticMember) { 81 uint32_t ClassId = getClassParentId(); 82 if (auto Class = Session.getSymbolById(ClassId)) { 83 if (auto UDT = dyn_cast<PDBSymbolTypeUDT>(Class.get())) 84 OS << UDT->getName(); 85 else 86 OS << "{class " << Class->getSymTag() << "}"; 87 OS << "::"; 88 } 89 } 90 OS << getName(); 91 }