Skip to content

Commit c82bf1e

Browse files
committed
[NFC][llvm-objdump] Add quiet disassembly
Add a boolean to control whether object disassembly (disassembleObject()) prints to console. It is always set to `false` 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.
1 parent 899f263 commit c82bf1e

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ bool objdump::UnwindInfo;
349349
static bool Wide;
350350
std::string objdump::Prefix;
351351
uint32_t objdump::PrefixStrip;
352+
static bool QuietDisasm = false;
352353

353354
DebugVarsFormat objdump::DbgVariables = DVDisabled;
354355

@@ -1374,6 +1375,8 @@ static uint64_t dumpARMELFData(uint64_t SectionAddr, uint64_t Index,
13741375
return 1;
13751376
}
13761377

1378+
static raw_ostream &disasmOuts() { return QuietDisasm ? nulls() : outs(); }
1379+
13771380
static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
13781381
ArrayRef<uint8_t> Bytes) {
13791382
// 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,
13831386

13841387
for (; Index < End; ++Index) {
13851388
if (NumBytes == 0)
1386-
outs() << format("%8" PRIx64 ":", SectionAddr + Index);
1389+
disasmOuts() << format("%8" PRIx64 ":", SectionAddr + Index);
13871390
Byte = Bytes.slice(Index)[0];
1388-
outs() << format(" %02x", Byte);
1391+
disasmOuts() << format(" %02x", Byte);
13891392
AsciiData[NumBytes] = isPrint(Byte) ? Byte : '.';
13901393

13911394
uint8_t IndentOffset = 0;
@@ -1400,9 +1403,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
14001403
}
14011404
if (NumBytes == 8) {
14021405
AsciiData[8] = '\0';
1403-
outs() << std::string(IndentOffset, ' ') << " ";
1404-
outs() << reinterpret_cast<char *>(AsciiData);
1405-
outs() << '\n';
1406+
disasmOuts() << std::string(IndentOffset, ' ') << " ";
1407+
disasmOuts() << reinterpret_cast<char *>(AsciiData);
1408+
disasmOuts() << '\n';
14061409
NumBytes = 0;
14071410
}
14081411
}
@@ -2089,10 +2092,10 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
20892092

20902093
if (!PrintedSection) {
20912094
PrintedSection = true;
2092-
outs() << "\nDisassembly of section ";
2095+
disasmOuts() << "\nDisassembly of section ";
20932096
if (!SegmentName.empty())
2094-
outs() << SegmentName << ",";
2095-
outs() << SectionName << ":\n";
2097+
disasmOuts() << SegmentName << ",";
2098+
disasmOuts() << SectionName << ":\n";
20962099
}
20972100

20982101
bool PrintedLabel = false;
@@ -2104,22 +2107,24 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
21042107
const StringRef SymbolName = SymNamesHere[i];
21052108

21062109
if (!PrintedLabel) {
2107-
outs() << '\n';
2110+
disasmOuts() << '\n';
21082111
PrintedLabel = true;
21092112
}
21102113
if (LeadingAddr)
2111-
outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
2112-
SectionAddr + Start + VMAAdjustment);
2114+
disasmOuts() << format(Is64Bits ? "%016" PRIx64 " "
2115+
: "%08" PRIx64 " ",
2116+
SectionAddr + Start + VMAAdjustment);
21132117
if (Obj.isXCOFF() && SymbolDescription) {
2114-
outs() << getXCOFFSymbolDescription(Symbol, SymbolName) << ":\n";
2118+
disasmOuts() << getXCOFFSymbolDescription(Symbol, SymbolName)
2119+
<< ":\n";
21152120
} else
2116-
outs() << '<' << SymbolName << ">:\n";
2121+
disasmOuts() << '<' << SymbolName << ">:\n";
21172122
}
21182123

21192124
// Don't print raw contents of a virtual section. A virtual section
21202125
// doesn't have any contents in the file.
21212126
if (Section.isVirtual()) {
2122-
outs() << "...\n";
2127+
disasmOuts() << "...\n";
21232128
continue;
21242129
}
21252130

@@ -2156,17 +2161,17 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
21562161
do {
21572162
StringRef Line;
21582163
std::tie(Line, ErrMsg) = ErrMsg.split('\n');
2159-
outs() << DT->Context->getAsmInfo()->getCommentString()
2160-
<< " error decoding " << SymNamesHere[SHI] << ": " << Line
2161-
<< '\n';
2164+
disasmOuts() << DT->Context->getAsmInfo()->getCommentString()
2165+
<< " error decoding " << SymNamesHere[SHI] << ": "
2166+
<< Line << '\n';
21622167
} while (!ErrMsg.empty());
21632168

21642169
if (Size) {
2165-
outs() << DT->Context->getAsmInfo()->getCommentString()
2166-
<< " decoding failed region as bytes\n";
2170+
disasmOuts() << DT->Context->getAsmInfo()->getCommentString()
2171+
<< " decoding failed region as bytes\n";
21672172
for (uint64_t I = 0; I < Size; ++I)
2168-
outs() << "\t.byte\t " << format_hex(Bytes[I], 1, /*Upper=*/true)
2169-
<< '\n';
2173+
disasmOuts() << "\t.byte\t "
2174+
<< format_hex(Bytes[I], 1, /*Upper=*/true) << '\n';
21702175
}
21712176
}
21722177

@@ -2203,7 +2208,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22032208
Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass &&
22042209
(*Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass == XCOFF::XMC_PR);
22052210

2206-
formatted_raw_ostream FOS(outs());
2211+
formatted_raw_ostream FOS(disasmOuts());
22072212

22082213
std::unordered_map<uint64_t, std::string> AllLabels;
22092214
std::unordered_map<uint64_t, std::vector<BBAddrMapLabel>> BBAddrMapLabels;
@@ -2551,6 +2556,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
25512556
set_difference(DisasmSymbolSet, FoundDisasmSymbolSet);
25522557
for (StringRef Sym : MissingDisasmSymbolSet.keys())
25532558
reportWarning("failed to disassemble missing symbol " + Sym, FileName);
2559+
QuietDisasm = false;
25542560
}
25552561

25562562
static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {

0 commit comments

Comments
 (0)