llvm-vtabledump: Small cleanup

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218505 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2014-09-26 08:01:23 +00:00
parent 72db9e5b09
commit 537364502a

View File

@ -107,23 +107,23 @@ static bool collectRelocationOffsets(
static void dumpVTables(const ObjectFile *Obj) { static void dumpVTables(const ObjectFile *Obj) {
struct CompleteObjectLocator { struct CompleteObjectLocator {
StringRef Symbols[2]; StringRef Symbols[2];
ArrayRef<aligned_little32_t> Data; ArrayRef<little32_t> Data;
}; };
struct ClassHierarchyDescriptor { struct ClassHierarchyDescriptor {
StringRef Symbols[1]; StringRef Symbols[1];
ArrayRef<aligned_little32_t> Data; ArrayRef<little32_t> Data;
}; };
struct BaseClassDescriptor { struct BaseClassDescriptor {
StringRef Symbols[2]; StringRef Symbols[2];
ArrayRef<aligned_little32_t> Data; ArrayRef<little32_t> Data;
}; };
struct TypeDescriptor { struct TypeDescriptor {
StringRef Symbols[1]; StringRef Symbols[1];
ArrayRef<aligned_little32_t> Data; uint64_t AlwaysZero;
StringRef MangledName; StringRef MangledName;
}; };
std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries; std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries;
std::map<StringRef, ArrayRef<aligned_little32_t>> VBTables; std::map<StringRef, ArrayRef<little32_t>> VBTables;
std::map<StringRef, CompleteObjectLocator> COLs; std::map<StringRef, CompleteObjectLocator> COLs;
std::map<StringRef, ClassHierarchyDescriptor> CHDs; std::map<StringRef, ClassHierarchyDescriptor> CHDs;
std::map<std::pair<StringRef, uint64_t>, StringRef> BCAEntries; std::map<std::pair<StringRef, uint64_t>, StringRef> BCAEntries;
@ -158,9 +158,9 @@ static void dumpVTables(const ObjectFile *Obj) {
if (error(SecI->getContents(SecContents))) if (error(SecI->getContents(SecContents)))
return; return;
ArrayRef<aligned_little32_t> VBTableData( ArrayRef<little32_t> VBTableData(
reinterpret_cast<const aligned_little32_t *>(SecContents.data()), reinterpret_cast<const little32_t *>(SecContents.data()),
SecContents.size() / sizeof(aligned_little32_t)); SecContents.size() / sizeof(little32_t));
VBTables[SymName] = VBTableData; VBTables[SymName] = VBTableData;
} }
// Complete object locators in the MS-ABI start with '??_R4' // Complete object locators in the MS-ABI start with '??_R4'
@ -172,8 +172,8 @@ static void dumpVTables(const ObjectFile *Obj) {
if (error(SecI->getContents(SecContents))) if (error(SecI->getContents(SecContents)))
return; return;
CompleteObjectLocator COL; CompleteObjectLocator COL;
COL.Data = ArrayRef<aligned_little32_t>( COL.Data = ArrayRef<little32_t>(
reinterpret_cast<const aligned_little32_t *>(SecContents.data()), 3); reinterpret_cast<const little32_t *>(SecContents.data()), 3);
StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols); StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols);
if (collectRelocatedSymbols(Obj, SecI, I, E)) if (collectRelocatedSymbols(Obj, SecI, I, E))
return; return;
@ -188,8 +188,8 @@ static void dumpVTables(const ObjectFile *Obj) {
if (error(SecI->getContents(SecContents))) if (error(SecI->getContents(SecContents)))
return; return;
ClassHierarchyDescriptor CHD; ClassHierarchyDescriptor CHD;
CHD.Data = ArrayRef<aligned_little32_t>( CHD.Data = ArrayRef<little32_t>(
reinterpret_cast<const aligned_little32_t *>(SecContents.data()), 3); reinterpret_cast<const little32_t *>(SecContents.data()), 3);
StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols); StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols);
if (collectRelocatedSymbols(Obj, SecI, I, E)) if (collectRelocatedSymbols(Obj, SecI, I, E))
return; return;
@ -215,8 +215,8 @@ static void dumpVTables(const ObjectFile *Obj) {
if (error(SecI->getContents(SecContents))) if (error(SecI->getContents(SecContents)))
return; return;
BaseClassDescriptor BCD; BaseClassDescriptor BCD;
BCD.Data = ArrayRef<aligned_little32_t>( BCD.Data = ArrayRef<little32_t>(
reinterpret_cast<const aligned_little32_t *>(SecContents.data()) + 1, reinterpret_cast<const little32_t *>(SecContents.data()) + 1,
5); 5);
StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols); StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols);
if (collectRelocatedSymbols(Obj, SecI, I, E)) if (collectRelocatedSymbols(Obj, SecI, I, E))
@ -231,11 +231,14 @@ static void dumpVTables(const ObjectFile *Obj) {
StringRef SecContents; StringRef SecContents;
if (error(SecI->getContents(SecContents))) if (error(SecI->getContents(SecContents)))
return; return;
uint8_t BytesInAddress = Obj->getBytesInAddress();
const char *DataPtr =
SecContents.drop_front(Obj->getBytesInAddress()).data();
TypeDescriptor TD; TypeDescriptor TD;
TD.Data = makeArrayRef( if (BytesInAddress == 8)
reinterpret_cast<const aligned_little32_t *>( TD.AlwaysZero = *reinterpret_cast<const little64_t *>(DataPtr);
SecContents.drop_front(Obj->getBytesInAddress()).data()), else
Obj->getBytesInAddress() / sizeof(aligned_little32_t)); TD.AlwaysZero = *reinterpret_cast<const little32_t *>(DataPtr);
TD.MangledName = SecContents.drop_front(Obj->getBytesInAddress() * 2); TD.MangledName = SecContents.drop_front(Obj->getBytesInAddress() * 2);
StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols); StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols);
if (collectRelocatedSymbols(Obj, SecI, I, E)) if (collectRelocatedSymbols(Obj, SecI, I, E))
@ -250,11 +253,11 @@ static void dumpVTables(const ObjectFile *Obj) {
StringRef SymName = VFTableEntry.second; StringRef SymName = VFTableEntry.second;
outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n'; outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n';
} }
for (const std::pair<StringRef, ArrayRef<aligned_little32_t>> &VBTable : for (const std::pair<StringRef, ArrayRef<little32_t>> &VBTable :
VBTables) { VBTables) {
StringRef VBTableName = VBTable.first; StringRef VBTableName = VBTable.first;
uint32_t Idx = 0; uint32_t Idx = 0;
for (aligned_little32_t Offset : VBTable.second) { for (little32_t Offset : VBTable.second) {
outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n'; outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n';
Idx += sizeof(Offset); Idx += sizeof(Offset);
} }
@ -298,10 +301,7 @@ static void dumpVTables(const ObjectFile *Obj) {
StringRef TDName = TDPair.first; StringRef TDName = TDPair.first;
const TypeDescriptor &TD = TDPair.second; const TypeDescriptor &TD = TDPair.second;
outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n'; outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n';
uint32_t AlwaysZero = 0; outs() << TDName << "[AlwaysZero]: " << TD.AlwaysZero << '\n';
for (aligned_little32_t Data : TD.Data)
AlwaysZero |= Data;
outs() << TDName << "[AlwaysZero]: " << AlwaysZero << '\n';
outs() << TDName << "[MangledName]: "; outs() << TDName << "[MangledName]: ";
outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)), outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)),
/*UseHexEscapes=*/true) /*UseHexEscapes=*/true)