diff options
author | Sam Clegg <sbc@chromium.org> | 2017-04-25 17:11:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 17:11:43 -0700 |
commit | 27b992d8bc9a359a5d4256835d2d965ce92eda69 (patch) | |
tree | b1706d6ea14f59d7e88c6e6aebed9470859bfa94 /src/binary-reader-objdump.cc | |
parent | 7f333885d7ad84036b8fcac7df3c8ce8cb6d9c33 (diff) | |
download | wabt-27b992d8bc9a359a5d4256835d2d965ce92eda69.tar.gz wabt-27b992d8bc9a359a5d4256835d2d965ce92eda69.tar.bz2 wabt-27b992d8bc9a359a5d4256835d2d965ce92eda69.zip |
Improve wasmdump output for relocations and data segments (#406)
For data segments, print the file offsets so they match
the file offsets shown when dumping relocations.
For relocations, only show the addend when one is present
and correctly display negative addends in the same way that
objdump does (e.g. symbol_foo-0x10 and symbol_foo+0x10)
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r-- | src/binary-reader-objdump.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index a57ec1bb..b11ad42e 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -126,7 +126,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase { virtual Result OnReloc(RelocType type, uint32_t offset, uint32_t index, - int32_t addend); + uint32_t addend); }; BinaryReaderObjdumpPrepass::BinaryReaderObjdumpPrepass(const uint8_t* data, @@ -144,7 +144,7 @@ Result BinaryReaderObjdumpPrepass::OnFunctionName(uint32_t index, Result BinaryReaderObjdumpPrepass::OnReloc(RelocType type, uint32_t offset, uint32_t index, - int32_t addend) { + uint32_t addend) { BinaryReaderObjdumpBase::OnReloc(type, offset, index, addend); if (reloc_section == BinarySection::Code) { options->code_relocations.emplace_back(type, offset, index, addend); @@ -478,7 +478,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase { virtual Result OnReloc(RelocType type, uint32_t offset, uint32_t index, - int32_t addend); + uint32_t addend); private: bool ShouldPrintDetails(); @@ -807,7 +807,7 @@ Result BinaryReaderObjdump::OnDataSegmentData(uint32_t index, const void* src_data, uint32_t size) { if (ShouldPrintDetails()) { - out_stream->WriteMemoryDump(src_data, size, 0, " - ", nullptr, + out_stream->WriteMemoryDump(src_data, size, state->offset - size, " - ", nullptr, PrintChars::Yes); } return Result::Ok; @@ -824,11 +824,22 @@ Result BinaryReaderObjdump::OnRelocCount(uint32_t count, Result BinaryReaderObjdump::OnReloc(RelocType type, uint32_t offset, uint32_t index, - int32_t addend) { + uint32_t addend) { uint32_t total_offset = section_starts[static_cast<size_t>(reloc_section)] + offset; - PrintDetails(" - %-18s idx=%#-4x addend=%#-4x offset=%#x(file=%#x)\n", - get_reloc_type_name(type), index, addend, offset, total_offset); + PrintDetails(" - %-18s offset=%#08x(file=%#08x) index=%#08x", + get_reloc_type_name(type), offset, total_offset, index); + if (addend) { + int32_t signed_addend = static_cast<int32_t>(addend); + if (signed_addend < 0) { + PrintDetails("-"); + signed_addend = -signed_addend; + } else { + PrintDetails("+"); + } + PrintDetails("%#x", signed_addend); + } + PrintDetails("\n"); return Result::Ok; } |