Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/test/tools/llvm-objdump/MachO/arm64-disassembly-color.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// RUN: llvm-objdump --disassembler-color=off --disassemble %t | FileCheck %s --check-prefix=NOCOLOR
// RUN: llvm-objdump --disassembler-color=terminal --disassemble %t | FileCheck %s --check-prefix=NOCOLOR

// Test with --macho flag to ensure DisassembleMachO respects color settings
// RUN: llvm-objdump --disassembler-color=on --macho --disassemble %t | FileCheck %s --check-prefix=COLOR
// RUN: llvm-objdump --disassembler-color=off --macho --disassemble %t | FileCheck %s --check-prefix=NOCOLOR

sub sp, sp, #16
str w0, [sp, #12]
ldr w8, [sp, #12]
Expand Down
26 changes: 26 additions & 0 deletions llvm/tools/llvm-objdump/MachODump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7321,6 +7321,19 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
CHECK_TARGET_INFO_CREATION(IP);
// Set the display preference for hex vs. decimal immediates.
IP->setPrintImmHex(PrintImmHex);
// Set up disassembler color output.
switch (DisassemblyColor) {
case ColorOutput::Enable:
IP->setUseColor(true);
break;
case ColorOutput::Auto:
IP->setUseColor(outs().has_colors());
break;
case ColorOutput::Disable:
case ColorOutput::Invalid:
IP->setUseColor(false);
break;
}
// Comment stream and backing vector.
SmallString<128> CommentsToEmit;
raw_svector_ostream CommentStream(CommentsToEmit);
Expand Down Expand Up @@ -7374,6 +7387,19 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
CHECK_THUMB_TARGET_INFO_CREATION(ThumbIP);
// Set the display preference for hex vs. decimal immediates.
ThumbIP->setPrintImmHex(PrintImmHex);
// Set up disassembler color output.
switch (DisassemblyColor) {
case ColorOutput::Enable:
ThumbIP->setUseColor(true);
break;
case ColorOutput::Auto:
ThumbIP->setUseColor(outs().has_colors());
break;
case ColorOutput::Disable:
case ColorOutput::Invalid:
ThumbIP->setUseColor(false);
break;
}
}

#undef CHECK_TARGET_INFO_CREATION
Expand Down
9 changes: 1 addition & 8 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,6 @@ class BBAddrMapInfo {

#define DEBUG_TYPE "objdump"

enum class ColorOutput {
Auto,
Enable,
Disable,
Invalid,
};

static uint64_t AdjustVMA;
static bool AllHeaders;
static std::string ArchName;
Expand All @@ -310,7 +303,7 @@ bool objdump::SymbolDescription;
bool objdump::TracebackTable;
static std::vector<std::string> DisassembleSymbols;
static bool DisassembleZeroes;
static ColorOutput DisassemblyColor;
ColorOutput objdump::DisassemblyColor;
DIDumpType objdump::DwarfDumpType;
static bool DynamicRelocations;
static bool FaultMapSection;
Expand Down
8 changes: 8 additions & 0 deletions llvm/tools/llvm-objdump/llvm-objdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ namespace objdump {

enum DebugFormat { DFASCII, DFDisabled, DFInvalid, DFLimitsOnly, DFUnicode };

enum class ColorOutput {
Auto,
Enable,
Disable,
Invalid,
};

extern bool ArchiveHeaders;
extern int DbgIndent;
extern DebugFormat DbgVariables;
Expand All @@ -51,6 +58,7 @@ extern bool Demangle;
extern bool Disassemble;
extern bool DisassembleAll;
extern std::vector<std::string> DisassemblerOptions;
extern ColorOutput DisassemblyColor;
extern DIDumpType DwarfDumpType;
extern std::vector<std::string> FilterSections;
extern bool LeadingAddr;
Expand Down