[Lldb-commits] [PATCH] D159234: [llvm-objdump] Enable assembly highlighting in llvm-objdump

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 30 16:07:11 PDT 2023


JDevlieghere created this revision.
JDevlieghere added reviewers: MaskRay, jhenderson.
Herald added a project: All.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Enable assembly highlighting in llvm-objdump.


https://reviews.llvm.org/D159234

Files:
  llvm/include/llvm/Support/FormattedStream.h
  llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s
  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
@@ -901,6 +901,7 @@
   if (!InstPrinter)
     reportError(Obj.getFileName(),
                 "no instruction printer for target " + TripleName);
+  InstPrinter->setUseColor(!NoColor);
   InstPrinter->setPrintImmHex(PrintImmHex);
   InstPrinter->setPrintBranchImmAsAddress(true);
   InstPrinter->setSymbolizeOperands(SymbolizeOperands);
Index: llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s
@@ -0,0 +1,25 @@
+// RUN: llvm-mc -triple arm64-apple-macosx %s -filetype=obj -o %t
+// RUN: llvm-objdump --color --disassemble %t | FileCheck %s --check-prefix=COLOR
+// RUN: llvm-objdump --no-color --disassemble %t | FileCheck %s --check-prefix=NOCOLOR
+
+sub	sp, sp, #16
+str	w0, [sp, #12]
+ldr	w8, [sp, #12]
+ldr	w9, [sp, #12]
+mul	w0, w8, w9
+add	sp, sp, #16
+
+
+// COLOR: sub	sp, sp, #0x10
+// COLOR: str	w0, [sp, #0xc]
+// COLOR: ldr	w8, [sp, #0xc]
+// COLOR: ldr	w9, [sp, #0xc]
+// COLOR: mul	w0, w8, w9
+// COLOR: add	sp, sp, #0x10
+
+// NOCOLOR: sub	sp, sp, #0x10
+// NOCOLOR: str	w0, [sp, #0xc]
+// NOCOLOR: ldr	w8, [sp, #0xc]
+// NOCOLOR: ldr	w9, [sp, #0xc]
+// NOCOLOR: mul	w0, w8, w9
+// NOCOLOR: add	sp, sp, #0x10
Index: llvm/include/llvm/Support/FormattedStream.h
===================================================================
--- llvm/include/llvm/Support/FormattedStream.h
+++ llvm/include/llvm/Support/FormattedStream.h
@@ -145,11 +145,6 @@
     return *this;
   }
 
-  raw_ostream &changeColor(enum Colors Color, bool Bold, bool BG) override {
-    TheStream->changeColor(Color, Bold, BG);
-    return *this;
-  }
-
   bool is_displayed() const override {
     return TheStream->is_displayed();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159234.554851.patch
Type: text/x-patch
Size: 2110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230830/26ce9ecb/attachment-0001.bin>


More information about the lldb-commits mailing list