Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,17 +1375,17 @@ static uint64_t dumpARMELFData(uint64_t SectionAddr, uint64_t Index,
}

static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
ArrayRef<uint8_t> Bytes) {
ArrayRef<uint8_t> Bytes, raw_ostream &OS) {
// print out data up to 8 bytes at a time in hex and ascii
uint8_t AsciiData[9] = {'\0'};
uint8_t Byte;
int NumBytes = 0;

for (; Index < End; ++Index) {
if (NumBytes == 0)
outs() << format("%8" PRIx64 ":", SectionAddr + Index);
OS << format("%8" PRIx64 ":", SectionAddr + Index);
Byte = Bytes.slice(Index)[0];
outs() << format(" %02x", Byte);
OS << format(" %02x", Byte);
AsciiData[NumBytes] = isPrint(Byte) ? Byte : '.';

uint8_t IndentOffset = 0;
Expand All @@ -1400,9 +1400,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
}
if (NumBytes == 8) {
AsciiData[8] = '\0';
outs() << std::string(IndentOffset, ' ') << " ";
outs() << reinterpret_cast<char *>(AsciiData);
outs() << '\n';
OS << std::string(IndentOffset, ' ') << " ";
OS << reinterpret_cast<char *>(AsciiData);
OS << '\n';
NumBytes = 0;
}
}
Expand Down Expand Up @@ -1666,7 +1666,7 @@ static void
disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
DisassemblerTarget &PrimaryTarget,
std::optional<DisassemblerTarget> &SecondaryTarget,
SourcePrinter &SP, bool InlineRelocs) {
SourcePrinter &SP, bool InlineRelocs, raw_ostream &OS) {
DisassemblerTarget *DT = &PrimaryTarget;
bool PrimaryIsThumb = false;
SmallVector<std::pair<uint64_t, uint64_t>, 0> CHPECodeMap;
Expand Down Expand Up @@ -2089,10 +2089,10 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,

if (!PrintedSection) {
PrintedSection = true;
outs() << "\nDisassembly of section ";
OS << "\nDisassembly of section ";
if (!SegmentName.empty())
outs() << SegmentName << ",";
outs() << SectionName << ":\n";
OS << SegmentName << ",";
OS << SectionName << ":\n";
}

bool PrintedLabel = false;
Expand All @@ -2104,22 +2104,22 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
const StringRef SymbolName = SymNamesHere[i];

if (!PrintedLabel) {
outs() << '\n';
OS << '\n';
PrintedLabel = true;
}
if (LeadingAddr)
outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
SectionAddr + Start + VMAAdjustment);
OS << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
SectionAddr + Start + VMAAdjustment);
if (Obj.isXCOFF() && SymbolDescription) {
outs() << getXCOFFSymbolDescription(Symbol, SymbolName) << ":\n";
OS << getXCOFFSymbolDescription(Symbol, SymbolName) << ":\n";
} else
outs() << '<' << SymbolName << ">:\n";
OS << '<' << SymbolName << ">:\n";
}

// Don't print raw contents of a virtual section. A virtual section
// doesn't have any contents in the file.
if (Section.isVirtual()) {
outs() << "...\n";
OS << "...\n";
continue;
}

Expand Down Expand Up @@ -2156,17 +2156,17 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
do {
StringRef Line;
std::tie(Line, ErrMsg) = ErrMsg.split('\n');
outs() << DT->Context->getAsmInfo()->getCommentString()
<< " error decoding " << SymNamesHere[SHI] << ": " << Line
<< '\n';
OS << DT->Context->getAsmInfo()->getCommentString()
<< " error decoding " << SymNamesHere[SHI] << ": " << Line
<< '\n';
} while (!ErrMsg.empty());

if (Size) {
outs() << DT->Context->getAsmInfo()->getCommentString()
<< " decoding failed region as bytes\n";
OS << DT->Context->getAsmInfo()->getCommentString()
<< " decoding failed region as bytes\n";
for (uint64_t I = 0; I < Size; ++I)
outs() << "\t.byte\t " << format_hex(Bytes[I], 1, /*Upper=*/true)
<< '\n';
OS << "\t.byte\t " << format_hex(Bytes[I], 1, /*Upper=*/true)
<< '\n';
}
}

Expand All @@ -2179,13 +2179,13 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Start += Size;
break;
}

formatted_raw_ostream FOS(OS);
Index = Start;
if (SectionAddr < StartAddress)
Index = std::max<uint64_t>(Index, StartAddress - SectionAddr);

if (DisassembleAsELFData) {
dumpELFData(SectionAddr, Index, End, Bytes);
dumpELFData(SectionAddr, Index, End, Bytes, FOS);
Index = End;
continue;
}
Expand All @@ -2203,8 +2203,6 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass &&
(*Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass == XCOFF::XMC_PR);

formatted_raw_ostream FOS(outs());

std::unordered_map<uint64_t, std::string> AllLabels;
std::unordered_map<uint64_t, std::vector<BBAddrMapLabel>> BBAddrMapLabels;
if (SymbolizeOperands) {
Expand Down Expand Up @@ -2553,7 +2551,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
reportWarning("failed to disassemble missing symbol " + Sym, FileName);
}

static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
static void disassembleObject(ObjectFile *Obj, bool InlineRelocs,
raw_ostream &OS) {
// If information useful for showing the disassembly is missing, try to find a
// more complete binary and disassemble that instead.
OwningBinary<Binary> FetchedBinary;
Expand Down Expand Up @@ -2679,7 +2678,7 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
"Unrecognized disassembler option: " + Opt);

disassembleObject(*Obj, *DbgObj, PrimaryTarget, SecondaryTarget, SP,
InlineRelocs);
InlineRelocs, OS);
}

void Dumper::printRelocations() {
Expand Down Expand Up @@ -3340,7 +3339,7 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
if (SectionContents)
printSectionContents(O);
if (Disassemble)
disassembleObject(O, Relocations);
disassembleObject(O, Relocations, outs());
if (UnwindInfo)
printUnwindInfo(O);

Expand Down