Teach macho-dump to dump the uleb128s referred to by linkedit_data segments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138836 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2011-08-30 22:10:58 +00:00
parent a7710edd98
commit d4522460d4
3 changed files with 37 additions and 1 deletions

View File

@ -174,6 +174,7 @@ public:
void ReadSymbol64TableEntry(
uint64_t SymbolTableOffset, unsigned Index,
InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
/// @}

View File

@ -9,6 +9,7 @@
#include "llvm/Object/MachOObject.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/SwapByteOrder.h"
@ -355,6 +356,31 @@ void MachOObject::ReadSymbol64TableEntry(uint64_t SymbolTableOffset,
ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res);
}
void MachOObject::ReadULEB128s(uint64_t Index,
SmallVectorImpl<uint64_t> &Out) const {
const char *ptr = Buffer->getBufferStart() + Index;
uint64_t data = 0;
uint64_t delta = 0;
uint32_t shift = 0;
while (true) {
assert(ptr < Buffer->getBufferEnd() && "index out of bounds");
assert(shift < 64 && "too big for uint64_t");
uint8_t byte = *ptr++;
delta |= ((byte & 0x7F) << shift);
shift += 7;
if (byte < 0x80) {
if (delta == 0)
break;
data += delta;
Out.push_back(data);
delta = 0;
shift = 0;
}
}
}
/* ** */
// Object Dumping Facilities
void MachOObject::dump() const { print(dbgs()); dbgs() << '\n'; }

View File

@ -318,7 +318,16 @@ static int DumpLinkeditDataCommand(MachOObject &Obj,
return Error("unable to read segment load command");
outs() << " ('dataoff', " << LLC->DataOffset << ")\n"
<< " ('datasize', " << LLC->DataSize << ")\n";
<< " ('datasize', " << LLC->DataSize << ")\n"
<< " ('_addresses', [\n";
SmallVector<uint64_t, 8> Addresses;
Obj.ReadULEB128s(LLC->DataOffset, Addresses);
for (unsigned i = 0, e = Addresses.size(); i != e; ++i)
outs() << " # Address " << i << '\n'
<< " ('address', " << format("0x%x", Addresses[i]) << "),\n";
outs() << " ])\n";
return 0;
}