-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NFC][llvm-objdump] Add ostream param to control console prints #139931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-binary-utilities Author: Prabhu Rajasekaran (Prabhuk) ChangesAdd a boolean to control whether object disassembly This is introduced to support the upcoming Full diff: https://github.com/llvm/llvm-project/pull/139931.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 2f839199712eb..0e1be02f52e60 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -349,6 +349,7 @@ bool objdump::UnwindInfo;
static bool Wide;
std::string objdump::Prefix;
uint32_t objdump::PrefixStrip;
+static bool QuietDisasm = false;
DebugVarsFormat objdump::DbgVariables = DVDisabled;
@@ -1374,6 +1375,8 @@ static uint64_t dumpARMELFData(uint64_t SectionAddr, uint64_t Index,
return 1;
}
+static raw_ostream &disasmOuts() { return QuietDisasm ? nulls() : outs(); }
+
static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
ArrayRef<uint8_t> Bytes) {
// print out data up to 8 bytes at a time in hex and ascii
@@ -1383,9 +1386,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);
+ disasmOuts() << format("%8" PRIx64 ":", SectionAddr + Index);
Byte = Bytes.slice(Index)[0];
- outs() << format(" %02x", Byte);
+ disasmOuts() << format(" %02x", Byte);
AsciiData[NumBytes] = isPrint(Byte) ? Byte : '.';
uint8_t IndentOffset = 0;
@@ -1400,9 +1403,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';
+ disasmOuts() << std::string(IndentOffset, ' ') << " ";
+ disasmOuts() << reinterpret_cast<char *>(AsciiData);
+ disasmOuts() << '\n';
NumBytes = 0;
}
}
@@ -2089,10 +2092,10 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
if (!PrintedSection) {
PrintedSection = true;
- outs() << "\nDisassembly of section ";
+ disasmOuts() << "\nDisassembly of section ";
if (!SegmentName.empty())
- outs() << SegmentName << ",";
- outs() << SectionName << ":\n";
+ disasmOuts() << SegmentName << ",";
+ disasmOuts() << SectionName << ":\n";
}
bool PrintedLabel = false;
@@ -2104,22 +2107,24 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
const StringRef SymbolName = SymNamesHere[i];
if (!PrintedLabel) {
- outs() << '\n';
+ disasmOuts() << '\n';
PrintedLabel = true;
}
if (LeadingAddr)
- outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
- SectionAddr + Start + VMAAdjustment);
+ disasmOuts() << format(Is64Bits ? "%016" PRIx64 " "
+ : "%08" PRIx64 " ",
+ SectionAddr + Start + VMAAdjustment);
if (Obj.isXCOFF() && SymbolDescription) {
- outs() << getXCOFFSymbolDescription(Symbol, SymbolName) << ":\n";
+ disasmOuts() << getXCOFFSymbolDescription(Symbol, SymbolName)
+ << ":\n";
} else
- outs() << '<' << SymbolName << ">:\n";
+ disasmOuts() << '<' << 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";
+ disasmOuts() << "...\n";
continue;
}
@@ -2156,17 +2161,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';
+ disasmOuts() << 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";
+ disasmOuts() << 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';
+ disasmOuts() << "\t.byte\t "
+ << format_hex(Bytes[I], 1, /*Upper=*/true) << '\n';
}
}
@@ -2203,7 +2208,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass &&
(*Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass == XCOFF::XMC_PR);
- formatted_raw_ostream FOS(outs());
+ formatted_raw_ostream FOS(disasmOuts());
std::unordered_map<uint64_t, std::string> AllLabels;
std::unordered_map<uint64_t, std::vector<BBAddrMapLabel>> BBAddrMapLabels;
@@ -2551,6 +2556,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
set_difference(DisasmSymbolSet, FoundDisasmSymbolSet);
for (StringRef Sym : MissingDisasmSymbolSet.keys())
reportWarning("failed to disassemble missing symbol " + Sym, FileName);
+ QuietDisasm = false;
}
static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer instead adding an extra argument to disassembleObject
(and other functions like dumpELFData
) representing the output stream.
--call-graph-info
implementation could then pass null()
as the argument when invoking disassembleObject
.
Add a function param to control whether object disassembly (disassembleObject()) prints to console. It is always set to `outs()` which makes this change an NFC. This is introduced to support the upcoming `--call-graph-info` option which will utilize the `disassembleObject` function to collect function and call site addresses without printing to console by passing `nulls()` instead of `outs()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title and description need to be updated. Please also wait for @jh7370 to take a look before merging this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Add a function param to control whether object disassembly
(disassembleObject()) prints to console. It is always set to
outs()
which makes this change an NFC.
This is introduced to support the upcoming
--call-graph-info
optionwhich will utilize the
disassembleObject
function to collect functionand call site addresses without printing to console by passing
nulls()
instead of
outs()
.