[Lldb-commits] [lldb] 523110d - Add support for llvm::MCInstPrinter::setPrintBranchImmAsAddress

Ted Woodward via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 22 12:16:24 PDT 2023


Author: Ted Woodward
Date: 2023-08-22T14:16:14-05:00
New Revision: 523110d654a286607790e7637da6be312de3a7c7

URL: https://github.com/llvm/llvm-project/commit/523110d654a286607790e7637da6be312de3a7c7
DIFF: https://github.com/llvm/llvm-project/commit/523110d654a286607790e7637da6be312de3a7c7.diff

LOG: Add support for llvm::MCInstPrinter::setPrintBranchImmAsAddress

llvm::MCInstPrinter has an option, controlled by setPrintBranchImmAsAddress,
to print branch targets as immediate addresses instead of offsets.
Turn this on in lldb, so targets that support this flag will print addresses
instead of offsets.

This requires the address of the instruction be provided, but fortunately
it's calculated right before the call to PrintMCInst.

Reviewed By: jasonmolenda, DavidSpickett

Differential Revision: https://reviews.llvm.org/D155107

Added: 
    

Modified: 
    lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index b4fdcbd783570a..2e0e8e8cf7d36c 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -60,8 +60,8 @@ class DisassemblerLLVMC::MCDisasmInstance {
 
   uint64_t GetMCInst(const uint8_t *opcode_data, size_t opcode_data_len,
                      lldb::addr_t pc, llvm::MCInst &mc_inst) const;
-  void PrintMCInst(llvm::MCInst &mc_inst, std::string &inst_string,
-                   std::string &comments_string);
+  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);
   bool CanBranch(llvm::MCInst &mc_inst) const;
   bool HasDelaySlot(llvm::MCInst &mc_inst) const;
@@ -607,7 +607,7 @@ class InstructionLLVMC : public lldb_private::Instruction {
 
         if (inst_size > 0) {
           mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
-          mc_disasm_ptr->PrintMCInst(inst, out_string, comment_string);
+          mc_disasm_ptr->PrintMCInst(inst, pc, out_string, comment_string);
 
           if (!comment_string.empty()) {
             AppendComment(comment_string);
@@ -1290,6 +1290,8 @@ DisassemblerLLVMC::MCDisasmInstance::Create(const char *triple, const char *cpu,
   if (!instr_printer_up)
     return Instance();
 
+  instr_printer_up->setPrintBranchImmAsAddress(true);
+
   // Not all targets may have registered createMCInstrAnalysis().
   std::unique_ptr<llvm::MCInstrAnalysis> instr_analysis_up(
       curr_target->createMCInstrAnalysis(instr_info_up.get()));
@@ -1337,13 +1339,13 @@ uint64_t DisassemblerLLVMC::MCDisasmInstance::GetMCInst(
 }
 
 void DisassemblerLLVMC::MCDisasmInstance::PrintMCInst(
-    llvm::MCInst &mc_inst, std::string &inst_string,
+    llvm::MCInst &mc_inst, lldb::addr_t pc, std::string &inst_string,
     std::string &comments_string) {
   llvm::raw_string_ostream inst_stream(inst_string);
   llvm::raw_string_ostream comments_stream(comments_string);
 
   m_instr_printer_up->setCommentStream(comments_stream);
-  m_instr_printer_up->printInst(&mc_inst, 0, llvm::StringRef(),
+  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();


        


More information about the lldb-commits mailing list