[PATCH] D107028: [llvm-objdump][NFC] Add quiet disassembly

Necip Fazil Yildiran via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 28 21:49:05 PDT 2021


necipfazil created this revision.
Herald added a subscriber: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
necipfazil requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add a boolean to control whether object disassembly (disassembleObject())
prints. It is always set to false, which makes this an NFC.

It will be set for the upcoming --call-graph-info option, which will utilize
disassembleObject() to collect function and call site addresses.

Patch 1/6: Extract call graph information from binary

Original RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-June/151044.html
Updated RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-July/151739.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107028

Files:
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -219,6 +219,8 @@
 std::string objdump::Prefix;
 uint32_t objdump::PrefixStrip;
 
+static bool QuietDisasm;
+
 DebugVarsFormat objdump::DbgVariables = DVDisabled;
 
 int objdump::DbgIndent = 52;
@@ -1062,6 +1064,8 @@
   FOS.flush();
 }
 
+static raw_ostream &disasmOuts() { return QuietDisasm ? nulls() : outs(); }
+
 static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
                               MCContext &Ctx, MCDisassembler *PrimaryDisAsm,
                               MCDisassembler *SecondaryDisAsm,
@@ -1281,25 +1285,26 @@
 
       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";
       }
 
-      outs() << '\n';
+      disasmOuts() << '\n';
       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(Symbols[SI], SymbolName) << ":\n";
+        disasmOuts() << getXCOFFSymbolDescription(Symbols[SI], 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;
       }
 
@@ -1323,11 +1328,11 @@
       //
       if (Status.hasValue()) {
         if (Status.getValue() == MCDisassembler::Fail) {
-          outs() << "// Error in decoding " << SymbolName
-                 << " : Decoding failed region as bytes.\n";
+          disasmOuts() << "// Error in decoding " << SymbolName
+                       << " : 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";
           }
         }
       } else {
@@ -1355,7 +1360,7 @@
                              Symbols[SI].Type != ELF::STT_OBJECT &&
                              !DisassembleAll;
       bool DumpARMELFData = false;
-      formatted_raw_ostream FOS(outs());
+      formatted_raw_ostream FOS(disasmOuts());
 
       std::unordered_map<uint64_t, std::string> AllLabels;
       if (SymbolizeOperands)
@@ -2543,6 +2548,8 @@
     llvm::cl::ParseCommandLineOptions(2, Argv);
   }
 
+  QuietDisasm = false;
+
   // objdump defaults to a.out if no filenames specified.
   if (InputFilenames.empty())
     InputFilenames.push_back("a.out");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107028.362624.patch
Type: text/x-patch
Size: 3415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210729/44e81289/attachment-0001.bin>


More information about the llvm-commits mailing list