Index: lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp =================================================================== --- lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -78,6 +78,42 @@ }; class InstructionLLVMC : public lldb_private::Instruction { +private: + void VisitInstruction() { + // Be conservative. If we didn't understand the instruction, say it: + // - Might branch + // - Does not have a delay slot + // - Is not a call + m_does_branch = eLazyBoolYes; + m_has_delay_slot = eLazyBoolNo; + m_is_call = eLazyBoolNo; + + DisassemblerScope disasm(*this); + if (!disasm) + return; + + DataExtractor data; + if (!m_opcode.GetData(data)) + return; + + bool is_alternate_isa; + lldb::addr_t pc = m_address.GetFileAddress(); + DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = + GetDisasmToUse(is_alternate_isa, disasm); + const uint8_t *opcode_data = data.GetDataStart(); + const size_t opcode_data_len = data.GetByteSize(); + llvm::MCInst inst; + const size_t inst_size = + mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); + if (inst_size == 0) + return; + + m_does_branch = mc_disasm_ptr->CanBranch(inst) ? eLazyBoolYes : eLazyBoolNo; + m_has_delay_slot = + mc_disasm_ptr->HasDelaySlot(inst) ? eLazyBoolYes : eLazyBoolNo; + m_is_call = mc_disasm_ptr->IsCall(inst) ? eLazyBoolYes : eLazyBoolNo; + } + public: InstructionLLVMC(DisassemblerLLVMC &disasm, const lldb_private::Address &address, @@ -92,68 +128,14 @@ ~InstructionLLVMC() override = default; bool DoesBranch() override { - if (m_does_branch == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - // Be conservative, if we didn't understand the instruction, say it - // might branch... - if (inst_size == 0) - m_does_branch = eLazyBoolYes; - else { - const bool can_branch = mc_disasm_ptr->CanBranch(inst); - if (can_branch) - m_does_branch = eLazyBoolYes; - else - m_does_branch = eLazyBoolNo; - } - } - } - } + if (m_does_branch == eLazyBoolCalculate) + VisitInstruction(); return m_does_branch == eLazyBoolYes; } bool HasDelaySlot() override { - if (m_has_delay_slot == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - // if we didn't understand the instruction, say it doesn't have a - // delay slot... - if (inst_size == 0) - m_has_delay_slot = eLazyBoolNo; - else { - const bool has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst); - if (has_delay_slot) - m_has_delay_slot = eLazyBoolYes; - else - m_has_delay_slot = eLazyBoolNo; - } - } - } - } + if (m_has_delay_slot == eLazyBoolCalculate) + VisitInstruction(); return m_has_delay_slot == eLazyBoolYes; } @@ -865,32 +847,8 @@ } bool IsCall() override { - if (m_is_call == eLazyBoolCalculate) { - DisassemblerScope disasm(*this); - if (disasm) { - DataExtractor data; - if (m_opcode.GetData(data)) { - bool is_alternate_isa; - lldb::addr_t pc = m_address.GetFileAddress(); - - DisassemblerLLVMC::MCDisasmInstance *mc_disasm_ptr = - GetDisasmToUse(is_alternate_isa, disasm); - const uint8_t *opcode_data = data.GetDataStart(); - const size_t opcode_data_len = data.GetByteSize(); - llvm::MCInst inst; - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - if (inst_size == 0) { - m_is_call = eLazyBoolNo; - } else { - if (mc_disasm_ptr->IsCall(inst)) - m_is_call = eLazyBoolYes; - else - m_is_call = eLazyBoolNo; - } - } - } - } + if (m_is_call == eLazyBoolCalculate) + VisitInstruction(); return m_is_call == eLazyBoolYes; }