1 //===- FunctionDumper.cpp ------------------------------------ *- C++ *-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "FunctionDumper.h"
12 #include "llvm/DebugInfo/PDB/IPDBSession.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
27 void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS,
28 llvm::FunctionDumper &Dumper) {
29 uint32_t ClassParentId = Symbol.getClassParentId();
31 Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
36 OS << ClassParent->getName() << "::";
40 FunctionDumper::FunctionDumper() : PDBSymDumper(true) {}
42 void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
43 PointerType Pointer, raw_ostream &OS) {
44 auto ReturnType = Symbol.getReturnType();
45 ReturnType->dump(OS, 0, *this);
47 uint32_t ClassParentId = Symbol.getClassParentId();
49 Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
52 if (Pointer == PointerType::None) {
53 OS << Symbol.getCallingConvention() << " ";
55 OS << "(" << ClassParent->getName() << "::)";
57 OS << "(" << Symbol.getCallingConvention() << " ";
59 OS << ClassParent->getName() << "::";
60 if (Pointer == PointerType::Reference)
68 if (auto ChildEnum = Symbol.getArguments()) {
70 while (auto Arg = ChildEnum->getNext()) {
71 Arg->dump(OS, 0, *this);
72 if (++Index < ChildEnum->getChildCount())
78 if (Symbol.isConstType())
80 if (Symbol.isVolatileType())
84 void FunctionDumper::start(const PDBSymbolFunc &Symbol, raw_ostream &OS) {
85 if (Symbol.isVirtual() || Symbol.isPureVirtual())
88 auto Signature = Symbol.getSignature();
90 OS << Symbol.getName();
94 auto ReturnType = Signature->getReturnType();
95 ReturnType->dump(OS, 0, *this);
97 OS << " " << Signature->getCallingConvention() << " ";
98 OS << Symbol.getName();
101 if (auto ChildEnum = Signature->getArguments()) {
103 while (auto Arg = ChildEnum->getNext()) {
104 Arg->dump(OS, 0, *this);
105 if (++Index < ChildEnum->getChildCount())
111 if (Symbol.isConstType())
113 if (Symbol.isVolatileType())
115 if (Symbol.isPureVirtual())
119 void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
121 uint32_t ElementTypeId = Symbol.getTypeId();
122 auto ElementType = Symbol.getSession().getSymbolById(ElementTypeId);
126 ElementType->dump(OS, 0, *this);
127 OS << "[" << Symbol.getLength() << "]";
130 void FunctionDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
132 PDB_BuiltinType Type = Symbol.getBuiltinType();
134 if (Type == PDB_BuiltinType::UInt || Type == PDB_BuiltinType::Int)
135 OS << (8 * Symbol.getLength()) << "_t";
138 void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
140 dumpClassParentWithScopeOperator(Symbol, OS, *this);
141 OS << Symbol.getName();
144 void FunctionDumper::dump(const PDBSymbolTypeFunctionArg &Symbol,
145 raw_ostream &OS, int Indent) {
146 // PDBSymbolTypeFunctionArg is just a shim over the real argument. Just drill
148 // real thing and dump it.
149 uint32_t TypeId = Symbol.getTypeId();
150 auto Type = Symbol.getSession().getSymbolById(TypeId);
153 Type->dump(OS, 0, *this);
156 void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
158 dumpClassParentWithScopeOperator(Symbol, OS, *this);
159 OS << Symbol.getName();
162 void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
164 uint32_t PointeeId = Symbol.getTypeId();
165 auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
169 if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
170 FunctionDumper NestedDumper;
171 PointerType Pointer =
172 Symbol.isReference() ? PointerType::Reference : PointerType::Pointer;
173 NestedDumper.start(*FuncSig, Pointer, OS);
175 if (Symbol.isConstType())
177 if (Symbol.isVolatileType())
179 PointeeType->dump(OS, Indent, *this);
180 OS << (Symbol.isReference() ? "&" : "*");
184 void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
186 OS << Symbol.getName();