Re-sort #include lines using my handy dandy ./utils/sort_includes.py
[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 "llvm/DebugInfo/PDB/IPDBSession.h"
11 #include "llvm/DebugInfo/PDB/PDBExtras.h"
12 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
14 #include "llvm/Support/Format.h"
15 #include <utility>
16
17 using namespace llvm;
18
19 PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession,
20                              std::unique_ptr<IPDBRawSymbol> DataSymbol)
21     : PDBSymbol(PDBSession, std::move(DataSymbol)) {}
22
23 void PDBSymbolData::dump(raw_ostream &OS, int Indent,
24                          PDB_DumpLevel Level) const {
25   OS << stream_indent(Indent);
26   PDB_LocType Loc = getLocationType();
27   PDB_DataKind Kind = getDataKind();
28   if (Level >= PDB_DumpLevel::Normal) {
29     switch (Loc) {
30     case PDB_LocType::Static: {
31       uint32_t RVA = getRelativeVirtualAddress();
32       OS << Kind << " data[";
33       if (RVA != 0)
34         OS << format_hex(RVA, 10);
35       else
36         OS << "???";
37       break;
38     }
39     case PDB_LocType::TLS:
40       OS << "threadlocal " << Kind << " data[";
41       OS << getAddressSection() << ":" << format_hex(getAddressOffset(), 10);
42       break;
43     case PDB_LocType::RegRel:
44       OS << "regrel " << Kind << " data[";
45       OS << getRegisterId() << " + " << getOffset();
46       break;
47     case PDB_LocType::ThisRel: {
48       uint32_t Offset = getOffset();
49       OS << Kind << " data[this + " << format_hex(Offset, 4);
50       break;
51     }
52     case PDB_LocType::Enregistered:
53       OS << "register " << Kind << " data[" << getRegisterId();
54       break;
55     case PDB_LocType::BitField: {
56       OS << "bitfield data[this + ";
57       uint32_t Offset = getOffset();
58       uint32_t BitPos = getBitPosition();
59       uint32_t Length = getLength();
60       OS << format_hex(Offset, 4) << ":" << BitPos << "," << Length;
61       break;
62     }
63     case PDB_LocType::Slot:
64       OS << getSlot();
65       break;
66     case PDB_LocType::Constant: {
67       OS << "constant data[";
68       OS << getValue();
69       break;
70     }
71     case PDB_LocType::IlRel:
72     case PDB_LocType::MetaData:
73     default:
74       OS << "???";
75     }
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();
90 }