llvm.org GIT mirror llvm / b9c28bc
[llvm-pdbdump] Display full enum definitions. This will now display enum definitions both at the global scope as well as nested inside of classes. Additionally, it will no longer display enums at the global scope if the enum is nested. Instead, it will omit the definition of the enum globally and instead emit it in the corresponding class definition. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231215 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 4 years ago
15 changed file(s) with 188 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
2525
2626 void dump(PDBSymDumper &Dumper) const override;
2727
28 std::unique_ptr getClassParent() const;
29 std::unique_ptr getUnderlyingType() const;
30
2831 FORWARD_SYMBOL_METHOD(getBuiltinType)
2932 FORWARD_SYMBOL_METHOD(getClassParentId)
3033 FORWARD_SYMBOL_METHOD(getUnmodifiedTypeId)
302302 OS << Value.Int64;
303303 break;
304304 case PDB_VariantType::Int8:
305 OS << Value.Int8;
305 OS << static_cast(Value.Int8);
306306 break;
307307 case PDB_VariantType::Single:
308308 OS << Value.Single;
317317 OS << Value.UInt64;
318318 break;
319319 case PDB_VariantType::UInt8:
320 OS << Value.UInt8;
320 OS << static_cast(Value.UInt8);
321321 break;
322322 default:
323323 OS << Value.Type;
88
99 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
1010
11 #include "llvm/DebugInfo/PDB/IPDBSession.h"
1112 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
1215
1316 #include
1417
1821 std::unique_ptr Symbol)
1922 : PDBSymbol(PDBSession, std::move(Symbol)) {}
2023
24 std::unique_ptr PDBSymbolTypeEnum::getClassParent() const {
25 return Session.getConcreteSymbolById(getClassParentId());
26 }
27
28 std::unique_ptr
29 PDBSymbolTypeEnum::getUnderlyingType() const {
30 return Session.getConcreteSymbolById(getTypeId());
31 }
32
2133 void PDBSymbolTypeEnum::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
0 ; RUN: llvm-pdbdump -symbols %p/Inputs/symbolformat.pdb | FileCheck --check-prefix=SYM_FORMAT %s
11 ; RUN: llvm-pdbdump -types %p/Inputs/symbolformat.pdb | FileCheck --check-prefix=TYPES_FORMAT %s
2 ; RUN: llvm-pdbdump -types -class-definitions %p/Inputs/symbolformat.pdb | FileCheck --check-prefix=FULL_CLASS %s
32 ; RUN: llvm-pdbdump -globals %p/Inputs/symbolformat.pdb | FileCheck --check-prefix=GLOBALS %s
43
54 ; The format is func [0x+ - 0x-]
2423 ; TYPES_FORMAT-DAG: typedef int IntType
2524 ; TYPES_FORMAT-DAG: typedef class A ClassAType
2625 ; TYPES_FORMAT: Classes
27 ; TYPES_FORMAT-DAG: class A
28 ; TYPES_FORMAT-DAG: class B
29
30 ; FULL_CLASS: ---TYPES---
31 ; FULL_CLASS: Classes
32 ; FULL_CLASS-DAG: struct A {
33 ; FULL_CLASS: public:
34 ; FULL_CLASS: virtual void PureFunc() = 0
35 ; FULL_CLASS: virtual void VirtualFunc()
36 ; FULL_CLASS: void RegularFunc()
37 ; FULL_CLASS: }
38 ; FULL_CLASS-DAG: struct MemberTest {
39 ; FULL_CLASS: data +0x00 MemberTest::NestedEnum m_nested_enum
40 ; FULL_CLASS: data +0x04 int m_typedef
41 ; FULL_CLASS: data +0x08 bool m_bool
42 ; FULL_CLASS: data +0x09 char m_char
43 ; FULL_CLASS: data +0x0a wchar_t m_wchar_t
44 ; FULL_CLASS: data +0x0c int m_int
45 ; FULL_CLASS: data +0x10 unsigned m_unsigned
46 ; FULL_CLASS: data +0x14 long m_long
47 ; FULL_CLASS: data +0x18 unsigned long m_unsigned_long
48 ; FULL_CLASS: data +0x20 __int64 m_int64
49 ; FULL_CLASS: data +0x28 unsigned __int64 m_unsigned_int64
50 ; FULL_CLASS: data +0x30 float m_float
51 ; FULL_CLASS: data +0x38 double m_double
52 ; FULL_CLASS: data +0x40 void (__cdecl *m_pfn_2_args)(int, double)
53 ; FULL_CLASS: }
26 ; TYPES_FORMAT: struct A {
27 ; TYPES_FORMAT: public:
28 ; TYPES_FORMAT: virtual void PureFunc() = 0
29 ; TYPES_FORMAT: virtual void VirtualFunc()
30 ; TYPES_FORMAT: void RegularFunc()
31 ; TYPES_FORMAT: }
32 ; TYPES_FORMAT-DAG: struct MemberTest {
33 ; TYPES_FORMAT: data +0x00 MemberTest::NestedEnum m_nested_enum
34 ; TYPES_FORMAT: data +0x04 int m_typedef
35 ; TYPES_FORMAT: data +0x08 bool m_bool
36 ; TYPES_FORMAT: data +0x09 char m_char
37 ; TYPES_FORMAT: data +0x0a wchar_t m_wchar_t
38 ; TYPES_FORMAT: data +0x0c int m_int
39 ; TYPES_FORMAT: data +0x10 unsigned m_unsigned
40 ; TYPES_FORMAT: data +0x14 long m_long
41 ; TYPES_FORMAT: data +0x18 unsigned long m_unsigned_long
42 ; TYPES_FORMAT: data +0x20 __int64 m_int64
43 ; TYPES_FORMAT: data +0x28 unsigned __int64 m_unsigned_int64
44 ; TYPES_FORMAT: data +0x30 float m_float
45 ; TYPES_FORMAT: data +0x38 double m_double
46 ; TYPES_FORMAT: data +0x40 void (__cdecl *m_pfn_2_args)(int, double)
47 ; TYPES_FORMAT: }
5448
5549 ; GLOBALS: ---GLOBALS---
5650 ; GLOBALS-DAG: func [{{.*}}] (FPO) unsigned __cdecl fpo_func(unsigned n)
0 ; RUN: llvm-pdbdump -types %p/Inputs/ClassLayoutTest.pdb > %t
1 ; RUN: FileCheck -input-file=%t %s -check-prefix=GLOBAL_ENUM
2 ; RUN: FileCheck -input-file=%t %s -check-prefix=MEMBER_ENUM
3
4 ; GLOBAL_ENUM: ---TYPES---
5 ; GLOBAL_ENUM: Enums:
6 ; GLOBAL_ENUM: enum GlobalsTest::Enum {
7 ; GLOBAL_ENUM-NEXT: Val1 = 0
8 ; GLOBAL_ENUM-NEXT: }
9
10 ; MEMBER_ENUM: ---TYPES---
11 ; MEMBER_ENUM: Classes:
12 ; MEMBER_ENUM: struct __vc_attributes::threadingAttribute {
13 ; MEMBER_ENUM-NEXT: enum threading_e {
14 ; MEMBER_ENUM-NEXT: apartment = 1
15 ; MEMBER_ENUM-NEXT: single = 2
16 ; MEMBER_ENUM-NEXT: free = 3
17 ; MEMBER_ENUM-NEXT: neutral = 4
18 ; MEMBER_ENUM-NEXT: both = 5
19 ; MEMBER_ENUM-NEXT: }
None ; RUN: llvm-pdbdump -symbols -globals -class-definitions -types %p/Inputs/FilterTest.pdb \
0 ; RUN: llvm-pdbdump -symbols -globals -types %p/Inputs/FilterTest.pdb \
11 ; RUN: | FileCheck --check-prefix=NO_FILTER %s
2 ; RUN: llvm-pdbdump -class-definitions -types -exclude-types="GlobalTypedef|NestedTypedef" \
2 ; RUN: llvm-pdbdump -types -exclude-types="GlobalTypedef|NestedTypedef" \
33 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_TYPEDEFS %s
4 ; RUN: llvm-pdbdump -class-definitions -types -exclude-types="GlobalEnum|NestedEnum" \
4 ; RUN: llvm-pdbdump -types -exclude-types="GlobalEnum|NestedEnum" \
55 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_ENUMS %s
6 ; RUN: llvm-pdbdump -class-definitions -types -symbols -globals \
7 ; RUN: -exclude-symbols="MemberVar|GlobalVar" %p/Inputs/FilterTest.pdb | FileCheck \
8 ; RUN: --check-prefix=EXCLUDE_VARS %s
9 ; RUN: llvm-pdbdump -types -class-definitions -exclude-types="FilterTestClass" \
6 ; RUN: llvm-pdbdump -types -symbols -globals -exclude-symbols="MemberVar|GlobalVar" \
7 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_VARS %s
8 ; RUN: llvm-pdbdump -types -exclude-types="FilterTestClass" \
109 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_WHOLE_CLASS %s
1110 ; RUN: llvm-pdbdump -symbols -globals -exclude-compilands="FilterTest.obj" \
1211 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_COMPILAND %s
77 BuiltinDumper.cpp
88 ClassDefinitionDumper.cpp
99 CompilandDumper.cpp
10 EnumDumper.cpp
1011 FunctionDumper.cpp
1112 LinePrinter.cpp
1213 TypeDumper.cpp
77 //===----------------------------------------------------------------------===//
88
99 #include "ClassDefinitionDumper.h"
10 #include "EnumDumper.h"
1011 #include "FunctionDumper.h"
1112 #include "LinePrinter.h"
1213 #include "llvm-pdbdump.h"
172173 return;
173174
174175 Printer.NewLine();
175 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
176 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
176 EnumDumper Dumper(Printer);
177 Dumper.start(Symbol);
177178 }
178179
179180 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
0 //===- EnumDumper.cpp -------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "EnumDumper.h"
10
11 #include "BuiltinDumper.h"
12 #include "LinePrinter.h"
13 #include "llvm-pdbdump.h"
14
15 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
18
19 using namespace llvm;
20
21 EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
22
23 void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
24 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
25 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
26 if (!opts::NoEnumDefs) {
27 auto BuiltinType = Symbol.getUnderlyingType();
28 if (BuiltinType->getBuiltinType() != PDB_BuiltinType::Int ||
29 BuiltinType->getLength() != 4) {
30 Printer << " : ";
31 BuiltinDumper Dumper(Printer);
32 Dumper.start(*BuiltinType);
33 }
34 Printer << " {";
35 Printer.Indent();
36 auto EnumValues = Symbol.findAllChildren();
37 while (auto EnumValue = EnumValues->getNext()) {
38 if (EnumValue->getDataKind() != PDB_DataKind::Constant)
39 continue;
40 Printer.NewLine();
41 WithColor(Printer, PDB_ColorItem::Identifier).get()
42 << EnumValue->getName();
43 Printer << " = ";
44 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
45 << EnumValue->getValue();
46 }
47 Printer.Unindent();
48 Printer.NewLine();
49 Printer << "}";
50 }
51 }
0 //===- EnumDumper.h - -------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_TOOLS_LLVMPDBDUMP_ENUMDUMPER_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_ENUMDUMPER_H
11
12 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
13
14 namespace llvm {
15
16 class LinePrinter;
17
18 class EnumDumper : public PDBSymDumper {
19 public:
20 EnumDumper(LinePrinter &P);
21
22 void start(const PDBSymbolTypeEnum &Symbol);
23
24 private:
25 LinePrinter &Printer;
26 };
27 }
28
29 #endif
88
99 #include "TypeDumper.h"
1010
11 #include "BuiltinDumper.h"
1112 #include "ClassDefinitionDumper.h"
13 #include "EnumDumper.h"
1214 #include "LinePrinter.h"
1315 #include "llvm-pdbdump.h"
1416 #include "TypedefDumper.h"
1517
1618 #include "llvm/DebugInfo/PDB/IPDBSession.h"
1719 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
1821 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
1922 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
2023 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
2124
2225 using namespace llvm;
2326
24 TypeDumper::TypeDumper(LinePrinter &P, bool ClassDefs)
25 : PDBSymDumper(true), Printer(P), FullClassDefs(ClassDefs) {}
27 TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
2628
2729 void TypeDumper::start(const PDBSymbolExe &Exe) {
2830 auto Enums = Exe.findAllChildren();
5860 return;
5961 if (Printer.IsTypeExcluded(Symbol.getName()))
6062 return;
63 // Dump member enums when dumping their class definition.
64 if (Symbol.isNested())
65 return;
66
6167 Printer.NewLine();
62
63 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
64 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
68 EnumDumper Dumper(Printer);
69 Dumper.start(Symbol);
6570 }
6671
6772 void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
8186
8287 Printer.NewLine();
8388
84 if (FullClassDefs) {
89 if (opts::NoClassDefs) {
90 WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
91 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
92 } else {
8593 ClassDefinitionDumper Dumper(Printer);
8694 Dumper.start(Symbol);
87 } else {
88 WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
89 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
9095 }
9196 }
1717
1818 class TypeDumper : public PDBSymDumper {
1919 public:
20 TypeDumper(LinePrinter &P, bool ClassDefs);
20 TypeDumper(LinePrinter &P);
2121
2222 void start(const PDBSymbolExe &Exe);
2323
2727
2828 private:
2929 LinePrinter &Printer;
30 bool FullClassDefs;
3130 };
3231 }
3332
1616 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
1717 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
1818 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
1920 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
2021 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
2122 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
3536 if (Printer.IsSymbolExcluded(Var.getName()))
3637 return;
3738
38 Printer.NewLine();
39 Printer << "data ";
40
4139 auto VarType = Var.getType();
4240
4341 switch (auto LocType = Var.getLocationType()) {
4442 case PDB_LocType::Static:
45 Printer << "[";
43 Printer.NewLine();
44 Printer << "data [";
4645 WithColor(Printer, PDB_ColorItem::Address).get()
4746 << format_hex(Var.getRelativeVirtualAddress(), 10);
4847 Printer << "] ";
5049 dumpSymbolTypeAndName(*VarType, Var.getName());
5150 break;
5251 case PDB_LocType::Constant:
52 if (isa(*VarType))
53 break;
54 Printer.NewLine();
55 Printer << "data ";
5356 WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
5457 dumpSymbolTypeAndName(*VarType, Var.getName());
5558 Printer << " = ";
5659 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue();
5760 break;
5861 case PDB_LocType::ThisRel:
62 Printer.NewLine();
63 Printer << "data ";
5964 WithColor(Printer, PDB_ColorItem::Offset).get()
6065 << "+" << format_hex(Var.getOffset(), 4) << " ";
6166 dumpSymbolTypeAndName(*VarType, Var.getName());
6267 break;
6368 case PDB_LocType::BitField:
69 Printer.NewLine();
70 Printer << "data ";
6471 WithColor(Printer, PDB_ColorItem::Offset).get()
6572 << "+" << format_hex(Var.getOffset(), 4) << " ";
6673 dumpSymbolTypeAndName(*VarType, Var.getName());
6875 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getLength();
6976 break;
7077 default:
78 Printer.NewLine();
79 Printer << "data ";
7180 Printer << "unknown(" << LocType << ") ";
7281 WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName();
7382 break;
6666 cl::cat(TypeCategory));
6767 cl::opt Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
6868 cl::opt
69 ClassDefs("class-definitions",
70 cl::desc("Display full class definitions (implies -types)"),
71 cl::cat(TypeCategory));
72 cl::opt
7369 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
7470 cl::cat(TypeCategory));
7571
9389 ExcludeSystemLibraries("no-system-libs",
9490 cl::desc("Don't show symbols from system libraries"),
9591 cl::cat(FilterCategory));
92 cl::opt NoClassDefs("no-class-definitions",
93 cl::desc("Don't display full class definitions"),
94 cl::cat(FilterCategory));
95 cl::opt NoEnumDefs("no-enum-definitions",
96 cl::desc("Don't display full enum definitions"),
97 cl::cat(FilterCategory));
9698 }
9799
98100 static void dumpInput(StringRef Path) {
170172 Printer.NewLine();
171173 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
172174 Printer.Indent();
173 TypeDumper Dumper(Printer, opts::ClassDefs);
175 TypeDumper Dumper(Printer);
174176 Dumper.start(*GlobalScope);
175177 Printer.Unindent();
176178 }
232234 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
233235
234236 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
235 if (opts::ClassDefs)
236 opts::Types = true;
237237 if (opts::All) {
238238 opts::Compilands = true;
239239 opts::Symbols = true;
240240 opts::Globals = true;
241241 opts::Types = true;
242 opts::ClassDefs = true;
243242 }
244243 if (opts::ExcludeCompilerGenerated) {
245244 opts::ExcludeTypes.push_back("__vc_attributes");
1717 extern llvm::cl::opt Symbols;
1818 extern llvm::cl::opt Globals;
1919 extern llvm::cl::opt Types;
20 extern llvm::cl::opt ClassDefs;
2120 extern llvm::cl::opt All;
2221
2322 extern llvm::cl::opt ExcludeCompilerGenerated;
2423
24 extern llvm::cl::opt NoClassDefs;
25 extern llvm::cl::opt NoEnumDefs;
2526 extern llvm::cl::list ExcludeTypes;
2627 extern llvm::cl::list ExcludeSymbols;
2728 extern llvm::cl::list ExcludeCompilands;