llvm.org GIT mirror llvm / d452246
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 Benjamin Kramer 9 years ago
3 changed file(s) with 37 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
173173 void ReadSymbol64TableEntry(
174174 uint64_t SymbolTableOffset, unsigned Index,
175175 InMemoryStruct &Res) const;
176 void ReadULEB128s(uint64_t Index, SmallVectorImpl &Out) const;
176177
177178 /// @}
178179
88
99 #include "llvm/Object/MachOObject.h"
1010 #include "llvm/ADT/StringRef.h"
11 #include "llvm/ADT/SmallVector.h"
1112 #include "llvm/Support/MemoryBuffer.h"
1213 #include "llvm/Support/Host.h"
1314 #include "llvm/Support/SwapByteOrder.h"
354355 ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res);
355356 }
356357
358
359 void MachOObject::ReadULEB128s(uint64_t Index,
360 SmallVectorImpl &Out) const {
361 const char *ptr = Buffer->getBufferStart() + Index;
362 uint64_t data = 0;
363 uint64_t delta = 0;
364 uint32_t shift = 0;
365 while (true) {
366 assert(ptr < Buffer->getBufferEnd() && "index out of bounds");
367 assert(shift < 64 && "too big for uint64_t");
368
369 uint8_t byte = *ptr++;
370 delta |= ((byte & 0x7F) << shift);
371 shift += 7;
372 if (byte < 0x80) {
373 if (delta == 0)
374 break;
375 data += delta;
376 Out.push_back(data);
377 delta = 0;
378 shift = 0;
379 }
380 }
381 }
382
357383 /* ** */
358384 // Object Dumping Facilities
359385 void MachOObject::dump() const { print(dbgs()); dbgs() << '\n'; }
317317 return Error("unable to read segment load command");
318318
319319 outs() << " ('dataoff', " << LLC->DataOffset << ")\n"
320 << " ('datasize', " << LLC->DataSize << ")\n";
320 << " ('datasize', " << LLC->DataSize << ")\n"
321 << " ('_addresses', [\n";
322
323 SmallVector Addresses;
324 Obj.ReadULEB128s(LLC->DataOffset, Addresses);
325 for (unsigned i = 0, e = Addresses.size(); i != e; ++i)
326 outs() << " # Address " << i << '\n'
327 << " ('address', " << format("0x%x", Addresses[i]) << "),\n";
328
329 outs() << " ])\n";
321330
322331 return 0;
323332 }