mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-02 17:55:18 +00:00
llvm-objdump: Add -s, which prints the contents of each section.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d955cf2366
commit
1e8ba3fa21
@ -3,9 +3,7 @@ RUN: | FileCheck %s -check-prefix COFF-i386
|
|||||||
RUN: llvm-objdump -s %p/TestObjectFiles/trivial-object-test.elf-i386 \
|
RUN: llvm-objdump -s %p/TestObjectFiles/trivial-object-test.elf-i386 \
|
||||||
RUN: | FileCheck %s -check-prefix ELF-i386
|
RUN: | FileCheck %s -check-prefix ELF-i386
|
||||||
|
|
||||||
XFAIL: *
|
COFF-i386: trivial-object-test.coff-i386: file format
|
||||||
|
|
||||||
COFF-i386: trivial-object-test.coff-i386: file format pe-i386
|
|
||||||
COFF-i386: Contents of section .text:
|
COFF-i386: Contents of section .text:
|
||||||
COFF-i386: 0000 83ec0cc7 44240800 000000c7 04240000 ....D$.......$..
|
COFF-i386: 0000 83ec0cc7 44240800 000000c7 04240000 ....D$.......$..
|
||||||
COFF-i386: 0010 0000e800 000000e8 00000000 8b442408 .............D$.
|
COFF-i386: 0010 0000e800 000000e8 00000000 8b442408 .............D$.
|
||||||
@ -13,7 +11,7 @@ COFF-i386: 0020 83c40cc3 ....
|
|||||||
COFF-i386: Contents of section .data:
|
COFF-i386: Contents of section .data:
|
||||||
COFF-i386: 0000 48656c6c 6f20576f 726c6421 00 Hello World!.
|
COFF-i386: 0000 48656c6c 6f20576f 726c6421 00 Hello World!.
|
||||||
|
|
||||||
ELF-i386: trivial-object-test.elf-i386: file format elf32-i386
|
ELF-i386: trivial-object-test.elf-i386: file format
|
||||||
ELF-i386: Contents of section .text:
|
ELF-i386: Contents of section .text:
|
||||||
ELF-i386: 0000 83ec0cc7 44240800 000000c7 04240000 ....D$.......$..
|
ELF-i386: 0000 83ec0cc7 44240800 000000c7 04240000 ....D$.......$..
|
||||||
ELF-i386: 0010 0000e8fc ffffffe8 fcffffff 8b442408 .............D$.
|
ELF-i386: 0010 0000e8fc ffffffe8 fcffffff 8b442408 .............D$.
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "llvm/Object/Archive.h"
|
#include "llvm/Object/Archive.h"
|
||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
@ -60,6 +61,9 @@ Disassembled("d", cl::desc("Alias for --disassemble"),
|
|||||||
static cl::opt<bool>
|
static cl::opt<bool>
|
||||||
Relocations("r", cl::desc("Display the relocation entries in the file"));
|
Relocations("r", cl::desc("Display the relocation entries in the file"));
|
||||||
|
|
||||||
|
static cl::opt<bool>
|
||||||
|
SectionContents("s", cl::desc("Display the content of each section"));
|
||||||
|
|
||||||
static cl::opt<bool>
|
static cl::opt<bool>
|
||||||
MachO("macho", cl::desc("Use MachO specific object file parser"));
|
MachO("macho", cl::desc("Use MachO specific object file parser"));
|
||||||
static cl::alias
|
static cl::alias
|
||||||
@ -158,10 +162,6 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outs() << '\n';
|
|
||||||
outs() << Obj->getFileName()
|
|
||||||
<< ":\tfile format " << Obj->getFileFormatName() << "\n\n";
|
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
for (section_iterator i = Obj->begin_sections(),
|
for (section_iterator i = Obj->begin_sections(),
|
||||||
e = Obj->end_sections();
|
e = Obj->end_sections();
|
||||||
@ -370,13 +370,60 @@ static void PrintSectionHeaders(const ObjectFile *o) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PrintSectionContents(const ObjectFile *o) {
|
||||||
|
error_code ec;
|
||||||
|
for (section_iterator si = o->begin_sections(),
|
||||||
|
se = o->end_sections();
|
||||||
|
si != se; si.increment(ec)) {
|
||||||
|
if (error(ec)) return;
|
||||||
|
StringRef Name;
|
||||||
|
StringRef Contents;
|
||||||
|
uint64_t BaseAddr;
|
||||||
|
if (error(si->getName(Name))) continue;
|
||||||
|
if (error(si->getContents(Contents))) continue;
|
||||||
|
if (error(si->getAddress(BaseAddr))) continue;
|
||||||
|
|
||||||
|
outs() << "Contents of section " << Name << ":\n";
|
||||||
|
|
||||||
|
// Dump out the content as hex and printable ascii characters.
|
||||||
|
for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
|
||||||
|
outs() << format(" %04x ", BaseAddr + addr);
|
||||||
|
// Dump line of hex.
|
||||||
|
for (std::size_t i = 0; i < 16; ++i) {
|
||||||
|
if (i != 0 && i % 4 == 0)
|
||||||
|
outs() << ' ';
|
||||||
|
if (addr + i < end)
|
||||||
|
outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true)
|
||||||
|
<< hexdigit(Contents[addr + i] & 0xF, true);
|
||||||
|
else
|
||||||
|
outs() << " ";
|
||||||
|
}
|
||||||
|
// Print ascii.
|
||||||
|
outs() << " ";
|
||||||
|
for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
|
||||||
|
if (std::isprint(Contents[addr + i] & 0xFF))
|
||||||
|
outs() << Contents[addr + i];
|
||||||
|
else
|
||||||
|
outs() << ".";
|
||||||
|
}
|
||||||
|
outs() << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void DumpObject(const ObjectFile *o) {
|
static void DumpObject(const ObjectFile *o) {
|
||||||
|
outs() << '\n';
|
||||||
|
outs() << o->getFileName()
|
||||||
|
<< ":\tfile format " << o->getFileFormatName() << "\n\n";
|
||||||
|
|
||||||
if (Disassemble)
|
if (Disassemble)
|
||||||
DisassembleObject(o, Relocations);
|
DisassembleObject(o, Relocations);
|
||||||
if (Relocations && !Disassemble)
|
if (Relocations && !Disassemble)
|
||||||
PrintRelocations(o);
|
PrintRelocations(o);
|
||||||
if (SectionHeaders)
|
if (SectionHeaders)
|
||||||
PrintSectionHeaders(o);
|
PrintSectionHeaders(o);
|
||||||
|
if (SectionContents)
|
||||||
|
PrintSectionContents(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Dump each object file in \a a;
|
/// @brief Dump each object file in \a a;
|
||||||
@ -447,7 +494,7 @@ int main(int argc, char **argv) {
|
|||||||
if (InputFilenames.size() == 0)
|
if (InputFilenames.size() == 0)
|
||||||
InputFilenames.push_back("a.out");
|
InputFilenames.push_back("a.out");
|
||||||
|
|
||||||
if (!Disassemble && !Relocations && !SectionHeaders) {
|
if (!Disassemble && !Relocations && !SectionHeaders && !SectionContents) {
|
||||||
cl::PrintHelpMessage();
|
cl::PrintHelpMessage();
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user