Index: source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h =================================================================== --- source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h +++ source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h @@ -77,6 +77,17 @@ uint64_t ReferencePC, const char **ReferenceName); + struct Guard { + DisassemblerLLVMC *m_instance; + Guard(DisassemblerLLVMC *instance, InstructionLLVMC *inst, + const lldb_private::ExecutionContext *exe_ctx = nullptr) + : m_instance(instance) { + m_instance->Lock(inst, exe_ctx); + } + + ~Guard() { m_instance->Unlock(); } + }; + void Lock(InstructionLLVMC *inst, const lldb_private::ExecutionContext *exe_ctx) { m_mutex.lock(); Index: source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp =================================================================== --- source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -100,7 +100,7 @@ if (m_does_branch == eLazyBoolCalculate) { std::shared_ptr disasm_sp(GetDisassembler()); if (disasm_sp) { - disasm_sp->Lock(this, NULL); + DisassemblerLLVMC::Guard guard(disasm_sp.get(), this); DataExtractor data; if (m_opcode.GetData(data)) { bool is_alternate_isa; @@ -125,7 +125,6 @@ m_does_branch = eLazyBoolNo; } } - disasm_sp->Unlock(); } } return m_does_branch == eLazyBoolYes; @@ -135,7 +134,7 @@ if (m_has_delay_slot == eLazyBoolCalculate) { std::shared_ptr disasm_sp(GetDisassembler()); if (disasm_sp) { - disasm_sp->Lock(this, NULL); + DisassemblerLLVMC::Guard guard(disasm_sp.get(), this); DataExtractor data; if (m_opcode.GetData(data)) { bool is_alternate_isa; @@ -160,7 +159,6 @@ m_has_delay_slot = eLazyBoolNo; } } - disasm_sp->Unlock(); } } return m_has_delay_slot == eLazyBoolYes; @@ -261,10 +259,13 @@ const addr_t pc = m_address.GetFileAddress(); llvm::MCInst inst; - disasm_sp->Lock(this, NULL); - const size_t inst_size = - mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst); - disasm_sp->Unlock(); + size_t inst_size; + { + DisassemblerLLVMC::Guard guard(disasm_sp.get(), this); + inst_size = mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, + pc, inst); + } + if (inst_size == 0) m_opcode.Clear(); else { @@ -878,7 +879,7 @@ if (m_is_call == eLazyBoolCalculate) { std::shared_ptr disasm_sp(GetDisassembler()); if (disasm_sp) { - disasm_sp->Lock(this, NULL); + DisassemblerLLVMC::Guard guard(disasm_sp.get(), this); DataExtractor data; if (m_opcode.GetData(data)) { bool is_alternate_isa; @@ -900,7 +901,6 @@ m_is_call = eLazyBoolNo; } } - disasm_sp->Unlock(); } } return m_is_call == eLazyBoolYes;