diff options
author | Prabhu Rajasekaran <prabhukr@google.com> | 2025-05-15 09:30:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-15 09:30:15 -0700 |
commit | 15b20a13e6a35a8c5864080644f9bc39f6dbd573 (patch) | |
tree | eb6031abf061ef6dd894f88347650269c46e7474 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 59c6d70ed8120b8864e5f796e2bf3de5518a0ef0 (diff) | |
download | llvm-15b20a13e6a35a8c5864080644f9bc39f6dbd573.zip llvm-15b20a13e6a35a8c5864080644f9bc39f6dbd573.tar.gz llvm-15b20a13e6a35a8c5864080644f9bc39f6dbd573.tar.bz2 |
[NFC][llvm-objdump] Add ostream param to control console prints (#139931)
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 2f83919..7a778da 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1375,7 +1375,7 @@ 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; @@ -1383,9 +1383,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End, 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; @@ -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; } } @@ -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; @@ -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; @@ -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; } @@ -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'; } } @@ -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; } @@ -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) { @@ -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; @@ -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() { @@ -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); |