llvm.org GIT mirror llvm / e1a6c0f
Properly parse the TypeServer2 record. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294046 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
9 changed file(s) with 94 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
0 //===- Formatters.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_DEBUGINFO_CODEVIEW_FORMATTERS_H
10 #define LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H
11
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/FormatAdapters.h"
15
16 namespace llvm {
17 namespace codeview {
18 namespace detail {
19 class GuidAdapter final : public llvm::FormatAdapter> {
20 ArrayRef Guid;
21
22 public:
23 explicit GuidAdapter(ArrayRef Guid);
24 explicit GuidAdapter(StringRef Guid);
25 void format(llvm::raw_ostream &Stream, StringRef Style);
26 };
27 }
28
29 inline detail::GuidAdapter fmt_guid(StringRef Item) {
30 return detail::GuidAdapter(Item);
31 }
32 }
33 }
34
35 #endif
2929 raw_ostream &operator<<(raw_ostream &OS, const PDB_Lang &Lang);
3030 raw_ostream &operator<<(raw_ostream &OS, const PDB_SymType &Tag);
3131 raw_ostream &operator<<(raw_ostream &OS, const PDB_MemberAccess &Access);
32 raw_ostream &operator<<(raw_ostream &OS, const PDB_UniqueId &Guid);
3233 raw_ostream &operator<<(raw_ostream &OS, const PDB_UdtType &Type);
33 raw_ostream &operator<<(raw_ostream &OS, const PDB_UniqueId &Id);
3434 raw_ostream &operator<<(raw_ostream &OS, const PDB_Machine &Machine);
3535
3636 raw_ostream &operator<<(raw_ostream &OS, const Variant &Value);
2121 explicit FormatAdapter(T &&Item) : Item(Item) {}
2222
2323 T Item;
24
25 static_assert(!detail::uses_missing_provider::value,
26 "Item does not have a format provider!");
2724 };
2825
2926 namespace detail {
44 CVTypeDumper.cpp
55 CVTypeVisitor.cpp
66 EnumTables.cpp
7 Formatters.cpp
78 Line.cpp
89 ModuleSubstream.cpp
910 ModuleSubstreamVisitor.cpp
0 //===- Formatters.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 "llvm/DebugInfo/CodeView/Formatters.h"
10
11 using namespace llvm;
12 using namespace llvm::codeview;
13 using namespace llvm::codeview::detail;
14
15 GuidAdapter::GuidAdapter(StringRef Guid)
16 : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
17
18 GuidAdapter::GuidAdapter(ArrayRef Guid)
19 : FormatAdapter(std::move(Guid)) {}
20
21 void GuidAdapter::format(llvm::raw_ostream &Stream, StringRef Style) {
22 static const char *Lookup = "0123456789ABCDEF";
23
24 assert(Item.size() == 16 && "Expected 16-byte GUID");
25 Stream << "{";
26 for (int i = 0; i < 16;) {
27 uint8_t Byte = Item[i];
28 uint8_t HighNibble = (Byte >> 4) & 0xF;
29 uint8_t LowNibble = Byte & 0xF;
30 Stream << Lookup[HighNibble] << Lookup[LowNibble];
31 ++i;
32 if (i >= 4 && i <= 10 && i % 2 == 0)
33 Stream << "-";
34 }
35 Stream << "}";
36 }
None //===-- TypeDumpVisitor.cpp - CodeView type info dumper -----------*- C++
1 //-*-===//
0 //===-- TypeDumpVisitor.cpp - CodeView type info dumper ----------*- C++-*-===//
21 //
32 // The LLVM Compiler Infrastructure
43 //
1211 #include "llvm/ADT/SmallString.h"
1312 #include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
1413 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
14 #include "llvm/DebugInfo/CodeView/Formatters.h"
1515 #include "llvm/DebugInfo/CodeView/TypeDatabase.h"
1616 #include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
1717 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
1919 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
2020 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
2121 #include "llvm/DebugInfo/MSF/ByteStream.h"
22 #include "llvm/Support/FormatVariadic.h"
2223 #include "llvm/Support/ScopedPrinter.h"
2324
2425 using namespace llvm;
335336 }
336337
337338 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) {
338 W->printBinary("Signature", TS.getGuid());
339 W->printString("Guid", formatv("{0}", fmt_guid(TS.getGuid())).str());
339340 W->printNumber("Age", TS.getAge());
340341 W->printString("Name", TS.getName());
341342 return Error::success();
367367
368368 Error TypeRecordMapping::visitKnownRecord(CVType &CVR,
369369 TypeServer2Record &Record) {
370 error(IO.mapGuid(Record.Guid));
371 error(IO.mapInteger(Record.Age));
372 error(IO.mapStringZ(Record.Name));
370373 return Error::success();
371374 }
372375
99 #include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h"
1010 #include "llvm/ADT/ArrayRef.h"
1111 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/DebugInfo/CodeView/Formatters.h"
1213 #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
1314 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
1415 #include "llvm/DebugInfo/PDB/PDBExtras.h"
177178 }
178179
179180 namespace llvm {
180 raw_ostream &operator<<(raw_ostream &OS, const GUID &Guid) {
181 const PDB_UniqueId *Id = reinterpret_cast(&Guid);
182 OS << *Id;
181 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const GUID &G) {
182 StringRef GuidBytes(reinterpret_cast(&G), sizeof(G));
183 codeview::detail::GuidAdapter A(GuidBytes);
184 A.format(OS, "");
183185 return OS;
184186 }
185187 }
99 #include "llvm/DebugInfo/PDB/PDBExtras.h"
1010
1111 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/DebugInfo/CodeView/Formatters.h"
1213
1314 using namespace llvm;
1415 using namespace llvm::pdb;
258259 return OS;
259260 }
260261
262 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_UniqueId &Guid) {
263 codeview::detail::GuidAdapter A(Guid.Guid);
264 A.format(OS, "");
265 return OS;
266 }
267
261268 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_UdtType &Type) {
262269 switch (Type) {
263270 CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Class, "class", OS)
265272 CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Interface, "interface", OS)
266273 CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Union, "union", OS)
267274 }
268 return OS;
269 }
270
271 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_UniqueId &Id) {
272 static const char *Lookup = "0123456789ABCDEF";
273
274 static_assert(sizeof(PDB_UniqueId) == 16, "Expected 16-byte GUID");
275 ArrayRef GuidBytes(reinterpret_cast(&Id), 16);
276 OS << "{";
277 for (int i=0; i < 16;) {
278 uint8_t Byte = GuidBytes[i];
279 uint8_t HighNibble = (Byte >> 4) & 0xF;
280 uint8_t LowNibble = Byte & 0xF;
281 OS << Lookup[HighNibble] << Lookup[LowNibble];
282 ++i;
283 if (i>=4 && i<=10 && i%2==0)
284 OS << "-";
285 }
286 OS << "}";
287275 return OS;
288276 }
289277