Skip to content

Commit 999a491

Browse files
Ted WoodwardJDevlieghere
authored andcommitted
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 (cherry picked from commit 523110d)
1 parent 67203b8 commit 999a491

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class DisassemblerLLVMC::MCDisasmInstance {
6060

6161
uint64_t GetMCInst(const uint8_t *opcode_data, size_t opcode_data_len,
6262
lldb::addr_t pc, llvm::MCInst &mc_inst) const;
63-
void PrintMCInst(llvm::MCInst &mc_inst, std::string &inst_string,
64-
std::string &comments_string);
63+
void PrintMCInst(llvm::MCInst &mc_inst, lldb::addr_t pc,
64+
std::string &inst_string, std::string &comments_string);
6565
void SetStyle(bool use_hex_immed, HexImmediateStyle hex_style);
6666
bool CanBranch(llvm::MCInst &mc_inst) const;
6767
bool HasDelaySlot(llvm::MCInst &mc_inst) const;
@@ -607,7 +607,7 @@ class InstructionLLVMC : public lldb_private::Instruction {
607607

608608
if (inst_size > 0) {
609609
mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
610-
mc_disasm_ptr->PrintMCInst(inst, out_string, comment_string);
610+
mc_disasm_ptr->PrintMCInst(inst, pc, out_string, comment_string);
611611

612612
if (!comment_string.empty()) {
613613
AppendComment(comment_string);
@@ -1290,6 +1290,8 @@ DisassemblerLLVMC::MCDisasmInstance::Create(const char *triple, const char *cpu,
12901290
if (!instr_printer_up)
12911291
return Instance();
12921292

1293+
instr_printer_up->setPrintBranchImmAsAddress(true);
1294+
12931295
// Not all targets may have registered createMCInstrAnalysis().
12941296
std::unique_ptr<llvm::MCInstrAnalysis> instr_analysis_up(
12951297
curr_target->createMCInstrAnalysis(instr_info_up.get()));
@@ -1337,13 +1339,13 @@ uint64_t DisassemblerLLVMC::MCDisasmInstance::GetMCInst(
13371339
}
13381340

13391341
void DisassemblerLLVMC::MCDisasmInstance::PrintMCInst(
1340-
llvm::MCInst &mc_inst, std::string &inst_string,
1342+
llvm::MCInst &mc_inst, lldb::addr_t pc, std::string &inst_string,
13411343
std::string &comments_string) {
13421344
llvm::raw_string_ostream inst_stream(inst_string);
13431345
llvm::raw_string_ostream comments_stream(comments_string);
13441346

13451347
m_instr_printer_up->setCommentStream(comments_stream);
1346-
m_instr_printer_up->printInst(&mc_inst, 0, llvm::StringRef(),
1348+
m_instr_printer_up->printInst(&mc_inst, pc, llvm::StringRef(),
13471349
*m_subtarget_info_up, inst_stream);
13481350
m_instr_printer_up->setCommentStream(llvm::nulls());
13491351
comments_stream.flush();

0 commit comments

Comments
 (0)