llvm-pdbdump: Re-order header files according to LLVM style guide.
[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 (Level >= PDB_DumpLevel::Normal) {
35     uint32_t FuncStart = getRelativeVirtualAddress();
36     uint32_t FuncEnd = FuncStart + getLength();
37     if (FuncStart == 0 && FuncEnd == 0) {
38       OS << "func [???] ";
39     } else {
40       OS << "func ";
41       OS << "[" << format_hex(FuncStart, 8);
42       if (auto DebugStart = findOneChild<PDBSymbolFuncDebugStart>())
43         OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
44       OS << " - " << format_hex(FuncEnd, 8);
45       if (auto DebugEnd = findOneChild<PDBSymbolFuncDebugEnd>())
46         OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
47       OS << "] ";
48     }
49
50     PDB_RegisterId Reg = getLocalBasePointerRegisterId();
51     if (Reg == PDB_RegisterId::VFrame)
52       OS << "(VFrame)";
53     else if (hasFramePointer())
54       OS << "(" << Reg << ")";
55     else
56       OS << "(FPO)";
57
58     OS << " ";
59     if (auto FuncSig = getSignature()) {
60       // If we have a signature, dump the name with the signature.
61       if (auto ReturnType = FuncSig->getReturnType()) {
62         ReturnType->dump(OS, 0, PDB_DumpLevel::Compact);
63         OS << " ";
64       }
65
66       OS << FuncSig->getCallingConvention() << " ";
67
68       if (auto ClassParent = FuncSig->getClassParent()) {
69         ClassParent->dump(OS, 0, PDB_DumpLevel::Compact);
70         OS << "::";
71       }
72
73       OS << getName();
74       FuncSig->dumpArgList(OS);
75     } else {
76       uint32_t ClassId = getClassParentId();
77       if (ClassId != 0) {
78         if (auto Class = Session.getSymbolById(ClassId)) {
79           if (auto UDT = dyn_cast<PDBSymbolTypeUDT>(Class.get()))
80             OS << UDT->getName() << "::";
81           else
82             OS << "{class " << Class->getSymTag() << "}::";
83         }
84       }
85       OS << getName();
86     }
87   } else {
88     OS << getName();
89   }
90 }