LLVM  4.0.0
CVTypeDumper.cpp
Go to the documentation of this file.
1 //===-- CVTypeDumper.cpp - CodeView type info dumper ------------*- 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 
18 
19 using namespace llvm;
20 using namespace llvm::codeview;
21 
23  TypeDatabaseVisitor DBV(TypeDB);
24  TypeDeserializer Deserializer;
26  Pipeline.addCallbackToPipeline(Deserializer);
27  Pipeline.addCallbackToPipeline(DBV);
28  Pipeline.addCallbackToPipeline(Dumper);
29 
30  CVTypeVisitor Visitor(Pipeline);
31 
32  CVType RecordCopy = Record;
33  if (auto EC = Visitor.visitTypeRecord(RecordCopy))
34  return EC;
35  return Error::success();
36 }
37 
39  TypeVisitorCallbacks &Dumper) {
40  TypeDatabaseVisitor DBV(TypeDB);
41  TypeDeserializer Deserializer;
43  Pipeline.addCallbackToPipeline(Deserializer);
44  Pipeline.addCallbackToPipeline(DBV);
45  Pipeline.addCallbackToPipeline(Dumper);
46 
47  CVTypeVisitor Visitor(Pipeline);
48 
49  if (auto EC = Visitor.visitTypeStream(Types))
50  return EC;
51  return Error::success();
52 }
53 
55  msf::ByteStream Stream(Data);
56  CVTypeArray Types;
57  msf::StreamReader Reader(Stream);
58  if (auto EC = Reader.readArray(Types, Reader.getLength()))
59  return EC;
60 
61  return dump(Types, Dumper);
62 }
63 
65  TypeIndex TI, TypeDatabase &DB) {
66  StringRef TypeName;
67  if (!TI.isNoneType())
68  TypeName = DB.getTypeName(TI);
69  if (!TypeName.empty())
70  Printer.printHex(FieldName, TypeName, TI.getIndex());
71  else
72  Printer.printHex(FieldName, TI.getIndex());
73 }
StringRef getTypeName(TypeIndex Index) const
bool isNoneType() const
Definition: TypeIndex.h:107
uint32_t getLength() const
Definition: StreamReader.h:107
print alias Alias Set Printer
Error visitTypeStream(const CVTypeArray &Types)
Visits the type records in Data. Sets the error flag on parse failures.
A 32-bit type reference.
Definition: TypeIndex.h:89
uint32_t getIndex() const
Definition: TypeIndex.h:103
Error visitTypeRecord(CVType &Record)
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Definition: StreamReader.h:62
void printHex(StringRef Label, T Value)
Error dump(const CVType &Record, TypeVisitorCallbacks &Dumper)
Dumps one type record.
static ErrorSuccess success()
Create a success value.
Dumper for CodeView type streams found in COFF object files and PDB files.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
static void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI, TypeDatabase &DB)
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks)