ted created this revision. ted added reviewers: clayborg, jingham. Herald added a project: All. ted requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155107 Files: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp =================================================================== --- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -59,8 +59,8 @@ 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; @@ -604,7 +604,7 @@ 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); @@ -1287,6 +1287,8 @@ if (!instr_printer_up) return Instance(); + instr_printer_up->setPrintBranchImmAsAddress(true); + return Instance( new MCDisasmInstance(std::move(instr_info_up), std::move(reg_info_up), std::move(subtarget_info_up), std::move(asm_info_up), @@ -1328,13 +1330,13 @@ } 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();
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp =================================================================== --- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -59,8 +59,8 @@ 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; @@ -604,7 +604,7 @@ 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); @@ -1287,6 +1287,8 @@ if (!instr_printer_up) return Instance(); + instr_printer_up->setPrintBranchImmAsAddress(true); + return Instance( new MCDisasmInstance(std::move(instr_info_up), std::move(reg_info_up), std::move(subtarget_info_up), std::move(asm_info_up), @@ -1328,13 +1330,13 @@ } 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();
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits