forked from OSchip/llvm-project
[llvm-pdbutil] Add the ability to truncate stream purpose names.
This will be useful for aligning fields to a fixed with in subsequent patches. llvm-svn: 307204
This commit is contained in:
parent
cb8c7b912d
commit
8120ebf4c7
|
@ -16,6 +16,47 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
std::string llvm::pdb::truncateStringBack(StringRef S, uint32_t MaxLen) {
|
||||
if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3)
|
||||
return S;
|
||||
|
||||
assert(MaxLen >= 3);
|
||||
uint32_t FinalLen = std::min(S.size(), MaxLen - 3);
|
||||
S = S.take_front(FinalLen);
|
||||
return std::string(S) + std::string("...");
|
||||
}
|
||||
|
||||
std::string llvm::pdb::truncateStringFront(StringRef S, uint32_t MaxLen) {
|
||||
if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3)
|
||||
return S;
|
||||
|
||||
assert(MaxLen >= 3);
|
||||
S = S.take_back(MaxLen - 3);
|
||||
return std::string("...") + std::string(S);
|
||||
}
|
||||
|
||||
std::string llvm::pdb::truncateQuotedNameFront(StringRef Label, StringRef Name,
|
||||
uint32_t MaxLen) {
|
||||
uint32_t RequiredExtraChars = Label.size() + 1 + 2;
|
||||
if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
|
||||
return formatv("{0} \"{1}\"", Label, Name).str();
|
||||
|
||||
assert(MaxLen >= RequiredExtraChars);
|
||||
std::string TN = truncateStringFront(Name, MaxLen - RequiredExtraChars);
|
||||
return formatv("{0} \"{1}\"", Label, TN).str();
|
||||
}
|
||||
|
||||
std::string llvm::pdb::truncateQuotedNameBack(StringRef Label, StringRef Name,
|
||||
uint32_t MaxLen) {
|
||||
uint32_t RequiredExtraChars = Label.size() + 1 + 2;
|
||||
if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
|
||||
return formatv("{0} \"{1}\"", Label, Name).str();
|
||||
|
||||
assert(MaxLen >= RequiredExtraChars);
|
||||
std::string TN = truncateStringBack(Name, MaxLen - RequiredExtraChars);
|
||||
return formatv("{0} \"{1}\"", Label, TN).str();
|
||||
}
|
||||
|
||||
std::string llvm::pdb::typesetItemList(ArrayRef<std::string> Opts,
|
||||
uint32_t IndentLevel, uint32_t GroupSize,
|
||||
StringRef Sep) {
|
||||
|
|
|
@ -22,6 +22,13 @@
|
|||
namespace llvm {
|
||||
namespace pdb {
|
||||
|
||||
std::string truncateStringBack(StringRef S, uint32_t MaxLen);
|
||||
static std::string truncateStringFront(StringRef S, uint32_t MaxLen);
|
||||
std::string truncateQuotedNameFront(StringRef Label, StringRef Name,
|
||||
uint32_t MaxLen);
|
||||
std::string truncateQuotedNameBack(StringRef Label, StringRef Name,
|
||||
uint32_t MaxLen);
|
||||
|
||||
#define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text) \
|
||||
if (Enum::TheOpt == (Value & Mask)) \
|
||||
Opts.push_back(Text);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "StreamUtil.h"
|
||||
#include "FormatUtil.h"
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/DenseMapInfo.h"
|
||||
|
@ -18,10 +19,12 @@
|
|||
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
|
||||
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace pdb {
|
||||
void discoverStreamPurposes(PDBFile &File,
|
||||
SmallVectorImpl<std::string> &Purposes) {
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
void llvm::pdb::discoverStreamPurposes(PDBFile &File,
|
||||
SmallVectorImpl<std::string> &Purposes,
|
||||
uint32_t MaxLen) {
|
||||
|
||||
// It's OK if we fail to load some of these streams, we still attempt to print
|
||||
// what we can.
|
||||
|
@ -54,70 +57,67 @@ void discoverStreamPurposes(PDBFile &File,
|
|||
for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
|
||||
std::string Value;
|
||||
if (StreamIdx == OldMSFDirectory)
|
||||
Value = "Old MSF Directory";
|
||||
Value = truncateStringBack("Old MSF Directory", MaxLen);
|
||||
else if (StreamIdx == StreamPDB)
|
||||
Value = "PDB Stream";
|
||||
Value = truncateStringBack("PDB Stream", MaxLen);
|
||||
else if (StreamIdx == StreamDBI)
|
||||
Value = "DBI Stream";
|
||||
Value = truncateStringBack("DBI Stream", MaxLen);
|
||||
else if (StreamIdx == StreamTPI)
|
||||
Value = "TPI Stream";
|
||||
Value = truncateStringBack("TPI Stream", MaxLen);
|
||||
else if (StreamIdx == StreamIPI)
|
||||
Value = "IPI Stream";
|
||||
Value = truncateStringBack("IPI Stream", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
|
||||
Value = "Global Symbol Hash";
|
||||
Value = truncateStringBack("Global Symbol Hash", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
|
||||
Value = "Public Symbol Hash";
|
||||
Value = truncateStringBack("Public Symbol Hash", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
|
||||
Value = "Public Symbol Records";
|
||||
Value = truncateStringBack("Public Symbol Records", MaxLen);
|
||||
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
|
||||
Value = "TPI Hash";
|
||||
Value = truncateStringBack("TPI Hash", MaxLen);
|
||||
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
|
||||
Value = "TPI Aux Hash";
|
||||
Value = truncateStringBack("TPI Aux Hash", MaxLen);
|
||||
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
|
||||
Value = "IPI Hash";
|
||||
Value = truncateStringBack("IPI Hash", MaxLen);
|
||||
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
|
||||
Value = "IPI Aux Hash";
|
||||
Value = truncateStringBack("IPI Aux Hash", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
|
||||
Value = "Exception Data";
|
||||
Value = truncateStringBack("Exception Data", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
|
||||
Value = "Fixup Data";
|
||||
Value = truncateStringBack("Fixup Data", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
|
||||
Value = "FPO Data";
|
||||
Value = truncateStringBack("FPO Data", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
|
||||
Value = "New FPO Data";
|
||||
Value = truncateStringBack("New FPO Data", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
|
||||
Value = "Omap From Source Data";
|
||||
Value = truncateStringBack("Omap From Source Data", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
|
||||
Value = "Omap To Source Data";
|
||||
Value = truncateStringBack("Omap To Source Data", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
|
||||
Value = "Pdata";
|
||||
Value = truncateStringBack("Pdata", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
|
||||
Value = "Section Header Data";
|
||||
Value = truncateStringBack("Section Header Data", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx ==
|
||||
Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
|
||||
Value = "Section Header Original Data";
|
||||
Value = truncateStringBack("Section Header Original Data", MaxLen);
|
||||
else if (Dbi &&
|
||||
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
|
||||
Value = "Token Rid Data";
|
||||
Value = truncateStringBack("Token Rid Data", MaxLen);
|
||||
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
|
||||
Value = "Xdata";
|
||||
Value = truncateStringBack("Xdata", MaxLen);
|
||||
else {
|
||||
auto ModIter = ModStreams.find(StreamIdx);
|
||||
auto NSIter = NamedStreams.find(StreamIdx);
|
||||
if (ModIter != ModStreams.end()) {
|
||||
Value = "Module \"";
|
||||
Value += ModIter->second.getModuleName();
|
||||
Value += "\"";
|
||||
Value = truncateQuotedNameFront(
|
||||
"Module", ModIter->second.getModuleName(), MaxLen);
|
||||
} else if (NSIter != NamedStreams.end()) {
|
||||
Value = "Named Stream \"";
|
||||
Value += NSIter->second;
|
||||
Value += "\"";
|
||||
Value = truncateQuotedNameBack("Named Stream", NSIter->second, MaxLen);
|
||||
} else {
|
||||
Value = "???";
|
||||
}
|
||||
|
@ -135,5 +135,3 @@ void discoverStreamPurposes(PDBFile &File,
|
|||
if (!Info)
|
||||
consumeError(Info.takeError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace llvm {
|
|||
namespace pdb {
|
||||
class PDBFile;
|
||||
void discoverStreamPurposes(PDBFile &File,
|
||||
SmallVectorImpl<std::string> &Purposes);
|
||||
SmallVectorImpl<std::string> &Purposes,
|
||||
uint32_t MaxLen = 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue