OSDN Git Service

Sort the remaining #include lines in include/... and lib/....
[android-x86/external-llvm.git] / lib / DebugInfo / DWARF / DWARFDebugPubTable.cpp
1 //===- DWARFDebugPubTable.cpp ---------------------------------------------===//
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
10 #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/DataExtractor.h"
13 #include "llvm/Support/Dwarf.h"
14 #include "llvm/Support/Format.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include <cstdint>
17
18 using namespace llvm;
19 using namespace dwarf;
20
21 DWARFDebugPubTable::DWARFDebugPubTable(StringRef Data, bool LittleEndian,
22                                        bool GnuStyle)
23     : GnuStyle(GnuStyle) {
24   DataExtractor PubNames(Data, LittleEndian, 0);
25   uint32_t Offset = 0;
26   while (PubNames.isValidOffset(Offset)) {
27     Sets.push_back({});
28     Set &SetData = Sets.back();
29
30     SetData.Length = PubNames.getU32(&Offset);
31     SetData.Version = PubNames.getU16(&Offset);
32     SetData.Offset = PubNames.getU32(&Offset);
33     SetData.Size = PubNames.getU32(&Offset);
34
35     while (Offset < Data.size()) {
36       uint32_t DieRef = PubNames.getU32(&Offset);
37       if (DieRef == 0)
38         break;
39       uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0;
40       const char *Name = PubNames.getCStr(&Offset);
41       SetData.Entries.push_back(
42           {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
43     }
44   }
45 }
46
47 void DWARFDebugPubTable::dump(StringRef Name, raw_ostream &OS) const {
48   OS << "\n." << Name << " contents:\n";
49   for (const Set &S : Sets) {
50     OS << "length = " << format("0x%08x", S.Length);
51     OS << " version = " << format("0x%04x", S.Version);
52     OS << " unit_offset = " << format("0x%08x", S.Offset);
53     OS << " unit_size = " << format("0x%08x", S.Size) << '\n';
54     OS << (GnuStyle ? "Offset     Linkage  Kind     Name\n"
55                     : "Offset     Name\n");
56
57     for (const Entry &E : S.Entries) {
58       OS << format("0x%8.8x ", E.SecOffset);
59       if (GnuStyle) {
60         StringRef EntryLinkage =
61             GDBIndexEntryLinkageString(E.Descriptor.Linkage);
62         StringRef EntryKind = dwarf::GDBIndexEntryKindString(E.Descriptor.Kind);
63         OS << format("%-8s", EntryLinkage.data()) << ' '
64            << format("%-8s", EntryKind.data()) << ' ';
65       }
66       OS << '\"' << E.Name << "\"\n";
67     }
68   }
69 }