blob: 5d3da2169575e29faf4100be036e9f86c2154b82 [file] [log] [blame]
Zachary Turner21473f72015-02-08 00:29:29 +00001//===- PDBSymbolExe.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
Zachary Turner52c9f882015-02-14 03:53:56 +000010#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
11
Zachary Turnera5549172015-02-10 22:43:25 +000012#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13#include "llvm/DebugInfo/PDB/PDBExtras.h"
Zachary Turner21473f72015-02-08 00:29:29 +000014#include "llvm/DebugInfo/PDB/PDBSymbol.h"
Zachary Turner21473f72015-02-08 00:29:29 +000015#include "llvm/Support/ConvertUTF.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/raw_ostream.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000018#include <utility>
Zachary Turner21473f72015-02-08 00:29:29 +000019
Zachary Turner52c9f882015-02-14 03:53:56 +000020#include <utility>
21
Zachary Turner21473f72015-02-08 00:29:29 +000022using namespace llvm;
23
Zachary Turnerc0acf682015-02-15 20:27:53 +000024#define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \
25 case PDB_SymType::Tag: \
26 if ((Flags & Flag) == 0) \
27 continue; \
28 break;
29
Zachary Turner98571ed2015-02-08 22:53:53 +000030PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession,
Zachary Turnerbae16b32015-02-08 20:58:09 +000031 std::unique_ptr<IPDBRawSymbol> Symbol)
32 : PDBSymbol(PDBSession, std::move(Symbol)) {}
Zachary Turner21473f72015-02-08 00:29:29 +000033
Zachary Turnera5549172015-02-10 22:43:25 +000034void PDBSymbolExe::dump(raw_ostream &OS, int Indent,
Zachary Turnerc0acf682015-02-15 20:27:53 +000035 PDB_DumpLevel Level, PDB_DumpFlags Flags) const {
Zachary Turnera5549172015-02-10 22:43:25 +000036 std::string FileName(getSymbolsFileName());
37
Zachary Turnera952c492015-02-13 07:40:03 +000038 OS << stream_indent(Indent) << "Summary for " << FileName << "\n";
Zachary Turnera5549172015-02-10 22:43:25 +000039
Zachary Turnera5549172015-02-10 22:43:25 +000040 uint64_t FileSize = 0;
41 if (!llvm::sys::fs::file_size(FileName, FileSize))
Zachary Turnera952c492015-02-13 07:40:03 +000042 OS << stream_indent(Indent + 2) << "Size: " << FileSize << " bytes\n";
Zachary Turnera5549172015-02-10 22:43:25 +000043 else
Zachary Turnera952c492015-02-13 07:40:03 +000044 OS << stream_indent(Indent + 2) << "Size: (Unable to obtain file size)\n";
Zachary Turnera5549172015-02-10 22:43:25 +000045 PDB_UniqueId Guid = getGuid();
Zachary Turnera952c492015-02-13 07:40:03 +000046 OS << stream_indent(Indent + 2) << "Guid: " << Guid << "\n";
47 OS << stream_indent(Indent + 2) << "Age: " << getAge() << "\n";
48 OS << stream_indent(Indent + 2) << "Attributes: ";
Zachary Turnera5549172015-02-10 22:43:25 +000049 if (hasCTypes())
50 OS << "HasCTypes ";
51 if (hasPrivateSymbols())
52 OS << "HasPrivateSymbols ";
53 OS << "\n";
Zachary Turner2a5c0a22015-02-13 01:23:51 +000054
Zachary Turnerc0acf682015-02-15 20:27:53 +000055 if (Flags & PDB_DF_Children) {
56 if (Flags & PDB_DF_Hidden) {
57 // For some reason, for each SymTag T, this dumps more items of type T
58 // than are dumped by calling dumpChildren(T). In other words, there are
59 // "hidden" symbols. For example, it causes functions to be dumped which
60 // have no address information, whereas specifically dumping only
61 // functions will not find those symbols.
62 //
63 // My suspicion is that in the underlying DIA call, when you call
64 // findChildren, passing a value of SymTagNone means all children
65 // recursively, whereas passing a concrete tag value means only immediate
66 // children of the global scope. So perhaps we need to find these
67 // mysterious missing values by recursing through the hierarchy.
68 //
69 // On the other hand, there may just be some symbols that DIA tries to
70 // hide from you because it thinks you don't care about them. However
71 // experimentation shows that even vtables, for example, can't be found
72 // without an exhaustive search.
73 auto ChildrenEnum = findAllChildren();
74 OS << stream_indent(Indent + 2) << ChildrenEnum->getChildCount()
75 << " symbols";
76
77 while (auto Child = ChildrenEnum->getNext()) {
78 switch (Child->getSymTag()) {
79 SKIP_SYMBOL_IF_FLAG_UNSET(Function, PDB_DF_Functions)
80 SKIP_SYMBOL_IF_FLAG_UNSET(Data, PDB_DF_Data)
81 SKIP_SYMBOL_IF_FLAG_UNSET(Label, PDB_DF_Labels)
82 SKIP_SYMBOL_IF_FLAG_UNSET(PublicSymbol, PDB_DF_PublicSyms)
83 SKIP_SYMBOL_IF_FLAG_UNSET(UDT, PDB_DF_Classes)
84 SKIP_SYMBOL_IF_FLAG_UNSET(Enum, PDB_DF_Enums)
85 SKIP_SYMBOL_IF_FLAG_UNSET(FunctionSig, PDB_DF_Funcsigs)
86 SKIP_SYMBOL_IF_FLAG_UNSET(VTable, PDB_DF_VTables)
87 SKIP_SYMBOL_IF_FLAG_UNSET(Thunk, PDB_DF_Thunks)
88 SKIP_SYMBOL_IF_FLAG_UNSET(Compiland, PDB_DF_ObjFiles)
89 default:
90 continue;
91 }
92 PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed)
93 ? PDB_DumpLevel::Normal
94 : PDB_DumpLevel::Compact;
95 OS << "\n";
96 Child->dump(OS, Indent + 4, ChildLevel, PDB_DF_Children);
97 }
98 } else {
99 if (Flags & PDB_DF_ObjFiles)
100 dumpChildren(OS, "Compilands", PDB_SymType::Compiland, Indent + 4);
101 if (Flags & PDB_DF_Functions)
102 dumpChildren(OS, "Functions", PDB_SymType::Function, Indent + 4);
103 if (Flags & PDB_DF_Data)
104 dumpChildren(OS, "Data", PDB_SymType::Data, Indent + 4);
105 if (Flags & PDB_DF_Labels)
106 dumpChildren(OS, "Labels", PDB_SymType::Label, Indent + 4);
107 if (Flags & PDB_DF_PublicSyms)
108 dumpChildren(OS, "Public Symbols", PDB_SymType::PublicSymbol,
109 Indent + 4);
110 if (Flags & PDB_DF_Classes)
111 dumpChildren(OS, "UDTs", PDB_SymType::UDT, Indent + 4);
112 if (Flags & PDB_DF_Enums)
113 dumpChildren(OS, "Enums", PDB_SymType::Enum, Indent + 4);
114 if (Flags & PDB_DF_Funcsigs)
115 dumpChildren(OS, "Function Signatures", PDB_SymType::FunctionSig,
116 Indent + 4);
117 if (Flags & PDB_DF_Typedefs)
118 dumpChildren(OS, "Typedefs", PDB_SymType::Typedef, Indent + 4);
119 if (Flags & PDB_DF_VTables)
120 dumpChildren(OS, "VTables", PDB_SymType::VTable, Indent + 4);
121 if (Flags & PDB_DF_Thunks)
122 dumpChildren(OS, "Thunks", PDB_SymType::Thunk, Indent + 4);
123 }
124 }
Zachary Turner26ebe3f2015-02-14 03:54:28 +0000125}
126
127void PDBSymbolExe::dumpChildren(raw_ostream &OS, StringRef Label,
128 PDB_SymType ChildType, int Indent) const {
129 auto ChildrenEnum = findAllChildren(ChildType);
130 OS << stream_indent(Indent) << Label << ": (" << ChildrenEnum->getChildCount()
131 << " items)\n";
Zachary Turner2a5c0a22015-02-13 01:23:51 +0000132 while (auto Child = ChildrenEnum->getNext()) {
Zachary Turnerc0acf682015-02-15 20:27:53 +0000133 Child->dump(OS, Indent + 2, PDB_DumpLevel::Normal, PDB_DF_None);
Zachary Turnera952c492015-02-13 07:40:03 +0000134 OS << "\n";
Zachary Turner2a5c0a22015-02-13 01:23:51 +0000135 }
Zachary Turner21473f72015-02-08 00:29:29 +0000136}