aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2023-09-01 14:20:08 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2023-09-01 14:47:45 -0700
commita69f78b080ef7efd2854ba199248713d956ea40c (patch)
treefd4a4e1361d47a1bb6947309bcff8f367f727d2b /lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
parenta168135487107c0af5908c69129a78bc3403b64d (diff)
downloadllvm-a69f78b080ef7efd2854ba199248713d956ea40c.zip
llvm-a69f78b080ef7efd2854ba199248713d956ea40c.tar.gz
llvm-a69f78b080ef7efd2854ba199248713d956ea40c.tar.bz2
[lldb] Add syntax color highlighting for disassembly
Add support for syntax color highlighting disassembly in LLDB. This patch relies on 77d1032516e7, which introduces support for syntax highlighting in MC. Currently only AArch64 and X86 have color support, but other interested backends can adopt WithColor in their respective MCInstPrinter. Differential revision: https://reviews.llvm.org/D159164
Diffstat (limited to 'lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp')
-rw-r--r--lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index 2e0e8e8..be0715d 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -63,6 +63,8 @@ public:
void PrintMCInst(llvm::MCInst &mc_inst, lldb::addr_t pc,
std::string &inst_string, std::string &comments_string);
void SetStyle(bool use_hex_immed, HexImmediateStyle hex_style);
+ void SetUseColor(bool use_color);
+ bool GetUseColor() const;
bool CanBranch(llvm::MCInst &mc_inst) const;
bool HasDelaySlot(llvm::MCInst &mc_inst) const;
bool IsCall(llvm::MCInst &mc_inst) const;
@@ -565,7 +567,9 @@ public:
if (m_opcode.GetData(data)) {
std::string out_string;
+ std::string markup_out_string;
std::string comment_string;
+ std::string markup_comment_string;
DisassemblerScope disasm(*this, exe_ctx);
if (disasm) {
@@ -607,7 +611,14 @@ public:
if (inst_size > 0) {
mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
+
+ const bool saved_use_color = mc_disasm_ptr->GetUseColor();
+ mc_disasm_ptr->SetUseColor(false);
mc_disasm_ptr->PrintMCInst(inst, pc, out_string, comment_string);
+ mc_disasm_ptr->SetUseColor(true);
+ mc_disasm_ptr->PrintMCInst(inst, pc, markup_out_string,
+ markup_comment_string);
+ mc_disasm_ptr->SetUseColor(saved_use_color);
if (!comment_string.empty()) {
AppendComment(comment_string);
@@ -672,6 +683,11 @@ public:
m_opcode_name = matches[1].str();
m_mnemonics = matches[2].str();
}
+ matches.clear();
+ if (s_regex.Execute(markup_out_string, &matches)) {
+ m_markup_opcode_name = matches[1].str();
+ m_markup_mnemonics = matches[2].str();
+ }
}
}
}
@@ -1344,10 +1360,12 @@ void DisassemblerLLVMC::MCDisasmInstance::PrintMCInst(
llvm::raw_string_ostream inst_stream(inst_string);
llvm::raw_string_ostream comments_stream(comments_string);
+ inst_stream.enable_colors(m_instr_printer_up->getUseColor());
m_instr_printer_up->setCommentStream(comments_stream);
m_instr_printer_up->printInst(&mc_inst, pc, llvm::StringRef(),
*m_subtarget_info_up, inst_stream);
m_instr_printer_up->setCommentStream(llvm::nulls());
+
comments_stream.flush();
static std::string g_newlines("\r\n");
@@ -1374,6 +1392,14 @@ void DisassemblerLLVMC::MCDisasmInstance::SetStyle(
}
}
+void DisassemblerLLVMC::MCDisasmInstance::SetUseColor(bool use_color) {
+ m_instr_printer_up->setUseColor(use_color);
+}
+
+bool DisassemblerLLVMC::MCDisasmInstance::GetUseColor() const {
+ return m_instr_printer_up->getUseColor();
+}
+
bool DisassemblerLLVMC::MCDisasmInstance::CanBranch(
llvm::MCInst &mc_inst) const {
if (m_instr_analysis_up)