817279bc3db819671d15200e6fd0bc9a77c4b697
[oota-llvm.git] / lib / DebugInfo / PDB / PDBSymbolFunc.cpp
1 //===- PDBSymbolFunc.cpp - --------------------------------------*- 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/PDBSymbolFunc.h"
11
12 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13 #include "llvm/DebugInfo/PDB/IPDBSession.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
19 #include "llvm/Support/Format.h"
20 #include <utility>
21
22 using namespace llvm;
23 PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession,
24                              std::unique_ptr<IPDBRawSymbol> Symbol)
25     : PDBSymbol(PDBSession, std::move(Symbol)) {}
26
27 std::unique_ptr<PDBSymbolTypeFunctionSig> PDBSymbolFunc::getSignature() const {
28   return Session.getConcreteSymbolById<PDBSymbolTypeFunctionSig>(getTypeId());
29 }
30
31 void PDBSymbolFunc::dump(raw_ostream &OS, int Indent,
32                          PDB_DumpLevel Level) const {
33   OS << stream_indent(Indent);
34   // if (getName() == "__crtCreateThreadpoolWait") {
35   //  RawSymbol->dump(OS, Indent+2, Level);
36   //  OS.flush();
37   //}
38   if (Level >= PDB_DumpLevel::Normal) {
39     uint32_t FuncStart = getRelativeVirtualAddress();
40     uint32_t FuncEnd = FuncStart + getLength();
41     if (FuncStart == 0 && FuncEnd == 0) {
42       OS << "func [???] ";
43     } else {
44       OS << "func ";
45       OS << "[" << format_hex(FuncStart, 8);
46       if (auto DebugStart = findOneChild<PDBSymbolFuncDebugStart>())
47         OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
48       OS << " - " << format_hex(FuncEnd, 8);
49       if (auto DebugEnd = findOneChild<PDBSymbolFuncDebugEnd>())
50         OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
51       OS << "] ";
52     }
53
54     PDB_RegisterId Reg = getLocalBasePointerRegisterId();
55     if (Reg == PDB_RegisterId::VFrame)
56       OS << "(VFrame)";
57     else if (hasFramePointer())
58       OS << "(" << Reg << ")";
59     else
60       OS << "(FPO)";
61
62     OS << " ";
63     if (auto FuncSig = getSignature()) {
64       // If we have a signature, dump the name with the signature.
65       if (auto ReturnType = FuncSig->getReturnType()) {
66         ReturnType->dump(OS, 0, PDB_DumpLevel::Compact);
67         OS << " ";
68       }
69
70       OS << FuncSig->getCallingConvention() << " ";
71
72       if (auto ClassParent = FuncSig->getClassParent()) {
73         ClassParent->dump(OS, 0, PDB_DumpLevel::Compact);
74         OS << "::";
75       }
76
77       OS << getName();
78       FuncSig->dumpArgList(OS);
79     } else {
80       uint32_t ClassId = getClassParentId();
81       if (ClassId != 0) {
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         }
88       }
89       OS << getName();
90     }
91   } else {
92     OS << getName();
93   }
94 }