diff --git a/lldb/include/lldb/Core/EmulateInstruction.h b/lldb/include/lldb/Core/EmulateInstruction.h --- a/lldb/include/lldb/Core/EmulateInstruction.h +++ b/lldb/include/lldb/Core/EmulateInstruction.h @@ -375,8 +375,11 @@ virtual bool TestEmulation(Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) = 0; - virtual bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - RegisterInfo ®_info) = 0; + bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, + RegisterInfo ®_info); + + virtual llvm::Optional + GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) = 0; // Optional overrides virtual bool SetInstruction(const Opcode &insn_opcode, diff --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp --- a/lldb/source/Core/EmulateInstruction.cpp +++ b/lldb/source/Core/EmulateInstruction.cpp @@ -582,3 +582,12 @@ unwind_plan.Clear(); return false; } + +bool EmulateInstruction::GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_num, + RegisterInfo ®_info) { + llvm::Optional info = GetRegisterInfo(reg_kind, reg_num); + if (info) + reg_info = *info; + return info.has_value(); +} \ No newline at end of file diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h @@ -135,8 +135,9 @@ bool TestEmulation(Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override; - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + llvm::Optional GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_num) override; bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan) override; diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp @@ -42,7 +42,8 @@ // ITSession implementation // -static bool GetARMDWARFRegisterInfo(unsigned reg_num, RegisterInfo ®_info) { +static llvm::Optional GetARMDWARFRegisterInfo(unsigned reg_num) { + RegisterInfo reg_info; ::memset(®_info, 0, sizeof(RegisterInfo)); ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); @@ -594,9 +595,9 @@ break; default: - return false; + return {}; } - return true; + return reg_info; } // A8.6.50 @@ -782,9 +783,9 @@ return true; } -bool EmulateInstructionARM::GetRegisterInfo(lldb::RegisterKind reg_kind, - uint32_t reg_num, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionARM::GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_num) { if (reg_kind == eRegisterKindGeneric) { switch (reg_num) { case LLDB_REGNUM_GENERIC_PC: @@ -808,13 +809,13 @@ reg_num = dwarf_cpsr; break; default: - return false; + return {}; } } if (reg_kind == eRegisterKindDWARF) - return GetARMDWARFRegisterInfo(reg_num, reg_info); - return false; + return GetARMDWARFRegisterInfo(reg_num); + return {}; } uint32_t EmulateInstructionARM::GetFramePointerRegisterNumber() const { diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h --- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h +++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h @@ -65,8 +65,10 @@ return false; } - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - lldb_private::RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + + llvm::Optional + GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override; bool CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override; diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp --- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp +++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp @@ -51,11 +51,10 @@ LLDB_PLUGIN_DEFINE_ADV(EmulateInstructionARM64, InstructionARM64) -static bool LLDBTableGetRegisterInfo(uint32_t reg_num, RegisterInfo ®_info) { +static llvm::Optional LLDBTableGetRegisterInfo(uint32_t reg_num) { if (reg_num >= std::size(g_register_infos_arm64_le)) - return false; - reg_info = g_register_infos_arm64_le[reg_num]; - return true; + return {}; + return g_register_infos_arm64_le[reg_num]; } #define No_VFP 0 @@ -144,9 +143,9 @@ return false; } -bool EmulateInstructionARM64::GetRegisterInfo(RegisterKind reg_kind, - uint32_t reg_num, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionARM64::GetRegisterInfo(RegisterKind reg_kind, + uint32_t reg_num) { if (reg_kind == eRegisterKindGeneric) { switch (reg_num) { case LLDB_REGNUM_GENERIC_PC: @@ -171,13 +170,13 @@ break; default: - return false; + return {}; } } if (reg_kind == eRegisterKindLLDB) - return LLDBTableGetRegisterInfo(reg_num, reg_info); - return false; + return LLDBTableGetRegisterInfo(reg_num); + return {}; } EmulateInstructionARM64::Opcode * diff --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h --- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h +++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h @@ -80,8 +80,10 @@ return false; } - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - lldb_private::RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + + llvm::Optional + GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override; bool CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override; diff --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp --- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp +++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp @@ -585,9 +585,9 @@ return nullptr; } -bool EmulateInstructionMIPS::GetRegisterInfo(RegisterKind reg_kind, - uint32_t reg_num, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionMIPS::GetRegisterInfo(RegisterKind reg_kind, + uint32_t reg_num) { if (reg_kind == eRegisterKindGeneric) { switch (reg_num) { case LLDB_REGNUM_GENERIC_PC: @@ -611,11 +611,12 @@ reg_num = dwarf_sr_mips; break; default: - return false; + return {}; } } if (reg_kind == eRegisterKindDWARF) { + RegisterInfo reg_info; ::memset(®_info, 0, sizeof(RegisterInfo)); ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); @@ -636,7 +637,7 @@ reg_info.format = eFormatVectorOfUInt8; reg_info.encoding = eEncodingVector; } else { - return false; + return {}; } reg_info.name = GetRegisterName(reg_num, false); @@ -662,9 +663,9 @@ default: break; } - return true; + return reg_info; } - return false; + return {}; } EmulateInstructionMIPS::MipsOpcode * diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h @@ -72,8 +72,10 @@ return false; } - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - lldb_private::RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + + llvm::Optional + GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override; bool CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override; diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp @@ -572,9 +572,9 @@ return nullptr; } -bool EmulateInstructionMIPS64::GetRegisterInfo(RegisterKind reg_kind, - uint32_t reg_num, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionMIPS64::GetRegisterInfo(RegisterKind reg_kind, + uint32_t reg_num) { if (reg_kind == eRegisterKindGeneric) { switch (reg_num) { case LLDB_REGNUM_GENERIC_PC: @@ -598,11 +598,12 @@ reg_num = dwarf_sr_mips64; break; default: - return false; + return {}; } } if (reg_kind == eRegisterKindDWARF) { + RegisterInfo reg_info; ::memset(®_info, 0, sizeof(RegisterInfo)); ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); @@ -623,7 +624,7 @@ reg_info.format = eFormatVectorOfUInt8; reg_info.encoding = eEncodingVector; } else { - return false; + return {}; } reg_info.name = GetRegisterName(reg_num, false); @@ -649,9 +650,9 @@ default: break; } - return true; + return reg_info; } - return false; + return {}; } EmulateInstructionMIPS64::MipsOpcode * diff --git a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h --- a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h +++ b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h @@ -61,8 +61,10 @@ return false; } - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + + llvm::Optional GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_num) override; bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan) override; diff --git a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp --- a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp +++ b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp @@ -58,16 +58,15 @@ return arch.GetTriple().isPPC64(); } -static bool LLDBTableGetRegisterInfo(uint32_t reg_num, RegisterInfo ®_info) { +static llvm::Optional LLDBTableGetRegisterInfo(uint32_t reg_num) { if (reg_num >= std::size(g_register_infos_ppc64le)) - return false; - reg_info = g_register_infos_ppc64le[reg_num]; - return true; + return {}; + return g_register_infos_ppc64le[reg_num]; } -bool EmulateInstructionPPC64::GetRegisterInfo(RegisterKind reg_kind, - uint32_t reg_num, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionPPC64::GetRegisterInfo(RegisterKind reg_kind, + uint32_t reg_num) { if (reg_kind == eRegisterKindGeneric) { switch (reg_num) { case LLDB_REGNUM_GENERIC_PC: @@ -88,13 +87,13 @@ break; default: - return false; + return {}; } } if (reg_kind == eRegisterKindLLDB) - return LLDBTableGetRegisterInfo(reg_num, reg_info); - return false; + return LLDBTableGetRegisterInfo(reg_num); + return {}; } bool EmulateInstructionPPC64::ReadInstruction() { diff --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h --- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h +++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h @@ -76,8 +76,10 @@ bool EvaluateInstruction(uint32_t options) override; bool TestEmulation(Stream *out_stream, ArchSpec &arch, OptionValueDictionary *test_data) override; - bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, - RegisterInfo ®_info) override; + using EmulateInstruction::GetRegisterInfo; + + llvm::Optional GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_num) override; lldb::addr_t ReadPC(bool &success); bool WritePC(lldb::addr_t pc); diff --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp --- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp +++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp @@ -1286,9 +1286,9 @@ LLDB_REGNUM_GENERIC_PC, pc); } -bool EmulateInstructionRISCV::GetRegisterInfo(lldb::RegisterKind reg_kind, - uint32_t reg_index, - RegisterInfo ®_info) { +llvm::Optional +EmulateInstructionRISCV::GetRegisterInfo(lldb::RegisterKind reg_kind, + uint32_t reg_index) { if (reg_kind == eRegisterKindGeneric) { switch (reg_index) { case LLDB_REGNUM_GENERIC_PC: @@ -1320,10 +1320,9 @@ RegisterInfoPOSIX_riscv64::GetRegisterInfoCount(m_arch); if (reg_index >= length || reg_kind != eRegisterKindLLDB) - return false; + return {}; - reg_info = array[reg_index]; - return true; + return array[reg_index]; } bool EmulateInstructionRISCV::SetTargetTriple(const ArchSpec &arch) {