diff options
Diffstat (limited to 'lldb/source/Plugins/Disassembler')
-rw-r--r-- | lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp (renamed from lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp) | 158 | ||||
-rw-r--r-- | lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h (renamed from lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h) | 6 |
2 files changed, 56 insertions, 108 deletions
diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp index dbdb3520087e..6427d8d176c8 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -1,4 +1,4 @@ -//===-- DisassemblerLLVMC.cpp -----------------------------------*- C++ -*-===// +//===-- DisassemblerLLVMC.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -43,6 +43,8 @@ using namespace lldb; using namespace lldb_private; +LLDB_PLUGIN_DEFINE(DisassemblerLLVMC) + class DisassemblerLLVMC::MCDisasmInstance { public: static std::unique_ptr<MCDisasmInstance> @@ -86,76 +88,18 @@ public: : Instruction(address, addr_class), m_disasm_wp(std::static_pointer_cast<DisassemblerLLVMC>( disasm.shared_from_this())), - m_does_branch(eLazyBoolCalculate), m_has_delay_slot(eLazyBoolCalculate), - m_is_call(eLazyBoolCalculate), m_is_valid(false), m_using_file_addr(false) {} ~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; - } - } - } - } - return m_does_branch == eLazyBoolYes; + VisitInstruction(); + return m_does_branch; } 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; - } - } - } - } - return m_has_delay_slot == eLazyBoolYes; + VisitInstruction(); + return m_has_delay_slot; } DisassemblerLLVMC::MCDisasmInstance *GetDisasmToUse(bool &is_alternate_isa) { @@ -367,16 +311,8 @@ public: } break; } - m_mnemonics = mnemonic_strm.GetString(); + m_mnemonics = std::string(mnemonic_strm.GetString()); return; - } else { - if (m_does_branch == eLazyBoolCalculate) { - const bool can_branch = mc_disasm_ptr->CanBranch(inst); - if (can_branch) - m_does_branch = eLazyBoolYes; - else - m_does_branch = eLazyBoolNo; - } } static RegularExpression s_regex( @@ -774,7 +710,7 @@ public: s.PutCString(")"); break; case Operand::Type::Register: - s.PutCString(op.m_register.AsCString()); + s.PutCString(op.m_register.GetStringRef()); break; case Operand::Type::Sum: s.PutCString("("); @@ -866,42 +802,54 @@ public: } 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; - } - } - } - } - return m_is_call == eLazyBoolYes; + VisitInstruction(); + return m_is_call; } protected: std::weak_ptr<DisassemblerLLVMC> m_disasm_wp; - LazyBool m_does_branch; - LazyBool m_has_delay_slot; - LazyBool m_is_call; - bool m_is_valid; + + bool m_is_valid = false; bool m_using_file_addr; + bool m_has_visited_instruction = false; + + // Be conservative. If we didn't understand the instruction, say it: + // - Might branch + // - Does not have a delay slot + // - Is not a call + bool m_does_branch = true; + bool m_has_delay_slot = false; + bool m_is_call = false; + + void VisitInstruction() { + if (m_has_visited_instruction) + return; + + 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_has_visited_instruction = true; + m_does_branch = mc_disasm_ptr->CanBranch(inst); + m_has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst); + m_is_call = mc_disasm_ptr->IsCall(inst); + } private: DisassemblerLLVMC::MCDisasmInstance * @@ -1414,7 +1362,7 @@ const char *DisassemblerLLVMC::SymbolLookup(uint64_t value, uint64_t *type_ptr, // If Address::Dump returned a multi-line description, most commonly // seen when we have multiple levels of inlined functions at an // address, only show the first line. - std::string str = ss.GetString(); + std::string str = std::string(ss.GetString()); size_t first_eol_char = str.find_first_of("\r\n"); if (first_eol_char != std::string::npos) { str.erase(first_eol_char); diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h index fd5775056d33..9b3741bdd18f 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef liblldb_DisassemblerLLVMC_h_ -#define liblldb_DisassemblerLLVMC_h_ +#ifndef LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H +#define LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H #include <memory> #include <mutex> @@ -82,4 +82,4 @@ protected: std::unique_ptr<MCDisasmInstance> m_alternate_disasm_up; }; -#endif // liblldb_DisassemblerLLVM_h_ +#endif // LLDB_SOURCE_PLUGINS_DISASSEMBLER_LLVMC_DISASSEMBLERLLVMC_H |