llvm.org GIT mirror llvm / 8ba482d
[llvm-pdbutil] Add the ability to truncate stream purpose names. This will be useful for aligning fields to a fixed with in subsequent patches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307204 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
4 changed file(s) with 83 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
1414
1515 using namespace llvm;
1616 using namespace llvm::pdb;
17
18 std::string llvm::pdb::truncateStringBack(StringRef S, uint32_t MaxLen) {
19 if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3)
20 return S;
21
22 assert(MaxLen >= 3);
23 uint32_t FinalLen = std::min(S.size(), MaxLen - 3);
24 S = S.take_front(FinalLen);
25 return std::string(S) + std::string("...");
26 }
27
28 std::string llvm::pdb::truncateStringFront(StringRef S, uint32_t MaxLen) {
29 if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3)
30 return S;
31
32 assert(MaxLen >= 3);
33 S = S.take_back(MaxLen - 3);
34 return std::string("...") + std::string(S);
35 }
36
37 std::string llvm::pdb::truncateQuotedNameFront(StringRef Label, StringRef Name,
38 uint32_t MaxLen) {
39 uint32_t RequiredExtraChars = Label.size() + 1 + 2;
40 if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
41 return formatv("{0} \"{1}\"", Label, Name).str();
42
43 assert(MaxLen >= RequiredExtraChars);
44 std::string TN = truncateStringFront(Name, MaxLen - RequiredExtraChars);
45 return formatv("{0} \"{1}\"", Label, TN).str();
46 }
47
48 std::string llvm::pdb::truncateQuotedNameBack(StringRef Label, StringRef Name,
49 uint32_t MaxLen) {
50 uint32_t RequiredExtraChars = Label.size() + 1 + 2;
51 if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
52 return formatv("{0} \"{1}\"", Label, Name).str();
53
54 assert(MaxLen >= RequiredExtraChars);
55 std::string TN = truncateStringBack(Name, MaxLen - RequiredExtraChars);
56 return formatv("{0} \"{1}\"", Label, TN).str();
57 }
1758
1859 std::string llvm::pdb::typesetItemList(ArrayRef Opts,
1960 uint32_t IndentLevel, uint32_t GroupSize,
2020
2121 namespace llvm {
2222 namespace pdb {
23
24 std::string truncateStringBack(StringRef S, uint32_t MaxLen);
25 static std::string truncateStringFront(StringRef S, uint32_t MaxLen);
26 std::string truncateQuotedNameFront(StringRef Label, StringRef Name,
27 uint32_t MaxLen);
28 std::string truncateQuotedNameBack(StringRef Label, StringRef Name,
29 uint32_t MaxLen);
2330
2431 #define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text) \
2532 if (Enum::TheOpt == (Value & Mask)) \
77 //===----------------------------------------------------------------------===//
88
99 #include "StreamUtil.h"
10 #include "FormatUtil.h"
1011
1112 #include "llvm/ADT/DenseMap.h"
1213 #include "llvm/ADT/DenseMapInfo.h"
1718 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
1819 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
1920
20 namespace llvm {
21 namespace pdb {
22 void discoverStreamPurposes(PDBFile &File,
23 SmallVectorImpl &Purposes) {
21 using namespace llvm;
22 using namespace llvm::pdb;
23
24 void llvm::pdb::discoverStreamPurposes(PDBFile &File,
25 SmallVectorImpl &Purposes,
26 uint32_t MaxLen) {
2427
2528 // It's OK if we fail to load some of these streams, we still attempt to print
2629 // what we can.
5356 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
5457 std::string Value;
5558 if (StreamIdx == OldMSFDirectory)
56 Value = "Old MSF Directory";
59 Value = truncateStringBack("Old MSF Directory", MaxLen);
5760 else if (StreamIdx == StreamPDB)
58 Value = "PDB Stream";
61 Value = truncateStringBack("PDB Stream", MaxLen);
5962 else if (StreamIdx == StreamDBI)
60 Value = "DBI Stream";
63 Value = truncateStringBack("DBI Stream", MaxLen);
6164 else if (StreamIdx == StreamTPI)
62 Value = "TPI Stream";
65 Value = truncateStringBack("TPI Stream", MaxLen);
6366 else if (StreamIdx == StreamIPI)
64 Value = "IPI Stream";
67 Value = truncateStringBack("IPI Stream", MaxLen);
6568 else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
66 Value = "Global Symbol Hash";
69 Value = truncateStringBack("Global Symbol Hash", MaxLen);
6770 else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
68 Value = "Public Symbol Hash";
71 Value = truncateStringBack("Public Symbol Hash", MaxLen);
6972 else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
70 Value = "Public Symbol Records";
73 Value = truncateStringBack("Public Symbol Records", MaxLen);
7174 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
72 Value = "TPI Hash";
75 Value = truncateStringBack("TPI Hash", MaxLen);
7376 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
74 Value = "TPI Aux Hash";
77 Value = truncateStringBack("TPI Aux Hash", MaxLen);
7578 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
76 Value = "IPI Hash";
79 Value = truncateStringBack("IPI Hash", MaxLen);
7780 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
78 Value = "IPI Aux Hash";
81 Value = truncateStringBack("IPI Aux Hash", MaxLen);
7982 else if (Dbi &&
8083 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
81 Value = "Exception Data";
84 Value = truncateStringBack("Exception Data", MaxLen);
8285 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
83 Value = "Fixup Data";
86 Value = truncateStringBack("Fixup Data", MaxLen);
8487 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
85 Value = "FPO Data";
88 Value = truncateStringBack("FPO Data", MaxLen);
8689 else if (Dbi &&
8790 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
88 Value = "New FPO Data";
91 Value = truncateStringBack("New FPO Data", MaxLen);
8992 else if (Dbi &&
9093 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
91 Value = "Omap From Source Data";
94 Value = truncateStringBack("Omap From Source Data", MaxLen);
9295 else if (Dbi &&
9396 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
94 Value = "Omap To Source Data";
97 Value = truncateStringBack("Omap To Source Data", MaxLen);
9598 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
96 Value = "Pdata";
99 Value = truncateStringBack("Pdata", MaxLen);
97100 else if (Dbi &&
98101 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
99 Value = "Section Header Data";
102 Value = truncateStringBack("Section Header Data", MaxLen);
100103 else if (Dbi &&
101104 StreamIdx ==
102105 Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
103 Value = "Section Header Original Data";
106 Value = truncateStringBack("Section Header Original Data", MaxLen);
104107 else if (Dbi &&
105108 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
106 Value = "Token Rid Data";
109 Value = truncateStringBack("Token Rid Data", MaxLen);
107110 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
108 Value = "Xdata";
111 Value = truncateStringBack("Xdata", MaxLen);
109112 else {
110113 auto ModIter = ModStreams.find(StreamIdx);
111114 auto NSIter = NamedStreams.find(StreamIdx);
112115 if (ModIter != ModStreams.end()) {
113 Value = "Module \"";
114 Value += ModIter->second.getModuleName();
115 Value += "\"";
116 Value = truncateQuotedNameFront(
117 "Module", ModIter->second.getModuleName(), MaxLen);
116118 } else if (NSIter != NamedStreams.end()) {
117 Value = "Named Stream \"";
118 Value += NSIter->second;
119 Value += "\"";
119 Value = truncateQuotedNameBack("Named Stream", NSIter->second, MaxLen);
120120 } else {
121121 Value = "???";
122122 }
134134 if (!Info)
135135 consumeError(Info.takeError());
136136 }
137 }
138 }
1717 namespace pdb {
1818 class PDBFile;
1919 void discoverStreamPurposes(PDBFile &File,
20 SmallVectorImpl &Purposes);
20 SmallVectorImpl &Purposes,
21 uint32_t MaxLen = 0);
2122 }
2223 }
2324