DavidSpickett created this revision.
Herald added subscribers: frasercrmck, luismarques, apazos, sameer.abuasal,
s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01,
atanasyan, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook,
johnrusso, rbar, asb, kbarton, nemanjai.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added subscribers: lldb-commits, pcwang-thead, MaskRay.
Herald added a project: LLDB.
Herald added a subscriber: JDevlieghere.
We have some 500 ish uses of the bool plus ref version
so changing them all at once isn't a great idea.
This adds an overload that doesn't take a RegisterInfo&
and returns an optional.
Once I'm done switching all the existing callers I'll
remove the original function.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134536
Files:
lldb/include/lldb/Core/EmulateInstruction.h
lldb/source/Core/EmulateInstruction.cpp
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h
lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h
lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h
lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp
lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h
lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
Index: lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
===================================================================
--- lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
+++ 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<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,
+ uint32_t reg_num) override;
lldb::addr_t ReadPC(bool &success);
bool WritePC(lldb::addr_t pc);
Index: lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
===================================================================
--- lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
+++ 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<RegisterInfo>
+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) {
Index: lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h
===================================================================
--- lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.h
+++ 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<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,
+ uint32_t reg_num) override;
bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan) override;
Index: lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp
===================================================================
--- lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp
+++ 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<RegisterInfo> 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<RegisterInfo>
+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() {
Index: lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h
===================================================================
--- lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h
+++ 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<lldb_private::RegisterInfo>
+ GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override;
bool
CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override;
Index: lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
===================================================================
--- lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
+++ 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<RegisterInfo>
+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 *
Index: lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h
===================================================================
--- lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.h
+++ 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<lldb_private::RegisterInfo>
+ GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override;
bool
CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override;
Index: lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
===================================================================
--- lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
+++ 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<RegisterInfo>
+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 *
Index: lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h
===================================================================
--- lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.h
+++ 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<lldb_private::RegisterInfo>
+ GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override;
bool
CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override;
Index: lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
===================================================================
--- lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ 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<RegisterInfo> 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<RegisterInfo>
+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 *
Index: lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
===================================================================
--- lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
+++ 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<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,
+ uint32_t reg_num) override;
bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan) override;
Index: lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
===================================================================
--- lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -42,7 +42,8 @@
// ITSession implementation
//
-static bool GetARMDWARFRegisterInfo(unsigned reg_num, RegisterInfo ®_info) {
+static llvm::Optional<RegisterInfo> 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<RegisterInfo>
+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 {
Index: lldb/source/Core/EmulateInstruction.cpp
===================================================================
--- lldb/source/Core/EmulateInstruction.cpp
+++ 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<RegisterInfo> info = GetRegisterInfo(reg_kind, reg_num);
+ if (info)
+ reg_info = *info;
+ return info.has_value();
+}
\ No newline at end of file
Index: lldb/include/lldb/Core/EmulateInstruction.h
===================================================================
--- lldb/include/lldb/Core/EmulateInstruction.h
+++ 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<RegisterInfo>
+ GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) = 0;
// Optional overrides
virtual bool SetInstruction(const Opcode &insn_opcode,
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits