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