[llvm-commits] [llvm] r138836 - in /llvm/trunk: include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp
Benjamin Kramer
benny.kra at googlemail.com
Tue Aug 30 15:10:58 PDT 2011
Author: d0k
Date: Tue Aug 30 17:10:58 2011
New Revision: 138836
URL: http://llvm.org/viewvc/llvm-project?rev=138836&view=rev
Log:
Teach macho-dump to dump the uleb128s referred to by linkedit_data segments.
Modified:
llvm/trunk/include/llvm/Object/MachOObject.h
llvm/trunk/lib/Object/MachOObject.cpp
llvm/trunk/tools/macho-dump/macho-dump.cpp
Modified: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=138836&r1=138835&r2=138836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Tue Aug 30 17:10:58 2011
@@ -174,6 +174,7 @@
void ReadSymbol64TableEntry(
uint64_t SymbolTableOffset, unsigned Index,
InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
+ void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
/// @}
Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=138836&r1=138835&r2=138836&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Tue Aug 30 17:10:58 2011
@@ -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 @@
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'; }
Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=138836&r1=138835&r2=138836&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Tue Aug 30 17:10:58 2011
@@ -318,7 +318,16 @@
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;
}
More information about the llvm-commits
mailing list