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