Making it easier to understand and harder to misuse.
This only applies to the ReadRegister(const RegisterInfo ®_info) variant.
Depends on D135671
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D135672
uint32_t reg_num, std::string ®_name);
// RegisterInfo variants
- bool ReadRegister(const RegisterInfo ®_info, RegisterValue ®_value);
+ llvm::Optional<RegisterValue> ReadRegister(const RegisterInfo ®_info);
uint64_t ReadRegisterUnsigned(const RegisterInfo ®_info,
uint64_t fail_value, bool *success_ptr);
EmulateInstruction::EmulateInstruction(const ArchSpec &arch) : m_arch(arch) {}
-bool EmulateInstruction::ReadRegister(const RegisterInfo ®_info,
- RegisterValue ®_value) {
- if (m_read_reg_callback != nullptr)
- return m_read_reg_callback(this, m_baton, ®_info, reg_value);
- return false;
+llvm::Optional<RegisterValue>
+EmulateInstruction::ReadRegister(const RegisterInfo ®_info) {
+ if (m_read_reg_callback == nullptr)
+ return {};
+
+ RegisterValue reg_value;
+ bool success = m_read_reg_callback(this, m_baton, ®_info, reg_value);
+ if (success)
+ return reg_value;
+ return {};
}
bool EmulateInstruction::ReadRegister(lldb::RegisterKind reg_kind,
uint32_t reg_num,
RegisterValue ®_value) {
llvm::Optional<RegisterInfo> reg_info = GetRegisterInfo(reg_kind, reg_num);
- if (reg_info)
- return ReadRegister(*reg_info, reg_value);
- return false;
+ if (!reg_info)
+ return false;
+
+ llvm::Optional<RegisterValue> value = ReadRegister(*reg_info);
+ if (value)
+ reg_value = *value;
+ return value.has_value();
}
uint64_t EmulateInstruction::ReadRegisterUnsigned(lldb::RegisterKind reg_kind,
uint64_t EmulateInstruction::ReadRegisterUnsigned(const RegisterInfo ®_info,
uint64_t fail_value,
bool *success_ptr) {
- RegisterValue reg_value;
- if (ReadRegister(reg_info, reg_value))
- return reg_value.GetAsUInt64(fail_value, success_ptr);
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
+ llvm::Optional<RegisterValue> reg_value = ReadRegister(reg_info);
+ if (!reg_value) {
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+ }
+
+ return reg_value->GetAsUInt64(fail_value, success_ptr);
}
bool EmulateInstruction::WriteRegister(const Context &context,
uint64_t address;
uint64_t wb_address;
- RegisterValue data_Rt;
- RegisterValue data_Rt2;
llvm::Optional<RegisterInfo> reg_info_base =
GetRegisterInfo(eRegisterKindLLDB, gpr_x0_arm64 + n);
if (!reg_info_base)
context_t2.SetRegisterToRegisterPlusOffset(*reg_info_Rt2, *reg_info_base,
size);
- if (!ReadRegister(*reg_info_Rt, data_Rt))
+ llvm::Optional<RegisterValue> data_Rt = ReadRegister(*reg_info_Rt);
+ if (!data_Rt)
return false;
- if (data_Rt.GetAsMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_Rt->GetAsMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
+ eByteOrderLittle, error) == 0)
return false;
if (!WriteMemory(context_t, address + 0, buffer, reg_info_Rt->byte_size))
return false;
- if (!ReadRegister(*reg_info_Rt2, data_Rt2))
+ llvm::Optional<RegisterValue> data_Rt2 = ReadRegister(*reg_info_Rt2);
+ if (!data_Rt2)
return false;
- if (data_Rt2.GetAsMemoryData(*reg_info_Rt2, buffer, reg_info_Rt2->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_Rt2->GetAsMemoryData(*reg_info_Rt2, buffer,
+ reg_info_Rt2->byte_size, eByteOrderLittle,
+ error) == 0)
return false;
if (!WriteMemory(context_t2, address + size, buffer,
return false;
}
+ RegisterValue data_Rt;
if (data_Rt.SetFromMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
eByteOrderLittle, error) == 0)
return false;
return false;
}
+ RegisterValue data_Rt2;
if (data_Rt2.SetFromMemoryData(*reg_info_Rt2, buffer,
reg_info_Rt2->byte_size, eByteOrderLittle,
error) == 0)
bool success = false;
uint64_t address;
uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
- RegisterValue data_Rt;
if (n == 31)
address =
Context context;
switch (memop) {
- case MemOp_STORE:
+ case MemOp_STORE: {
if (n == 31 || n == GetFramePointerRegisterNumber()) // if this store is
// based off of the sp
// or fp register
context.SetRegisterToRegisterPlusOffset(*reg_info_Rt, *reg_info_base,
postindex ? 0 : offset);
- if (!ReadRegister(*reg_info_Rt, data_Rt))
+ llvm::Optional<RegisterValue> data_Rt = ReadRegister(*reg_info_Rt);
+ if (!data_Rt)
return false;
- if (data_Rt.GetAsMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_Rt->GetAsMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
+ eByteOrderLittle, error) == 0)
return false;
if (!WriteMemory(context, address, buffer, reg_info_Rt->byte_size))
return false;
- break;
+ } break;
- case MemOp_LOAD:
+ case MemOp_LOAD: {
if (n == 31 || n == GetFramePointerRegisterNumber()) // if this store is
// based off of the sp
// or fp register
if (!ReadMemory(context, address, buffer, reg_info_Rt->byte_size))
return false;
+ RegisterValue data_Rt;
if (data_Rt.SetFromMemoryData(*reg_info_Rt, buffer, reg_info_Rt->byte_size,
eByteOrderLittle, error) == 0)
return false;
if (!WriteRegister(context, *reg_info_Rt, data_Rt))
return false;
- break;
+ } break;
default:
return false;
}
return false;
Context context;
- RegisterValue data_src;
context.type = eContextPushRegisterOnStack;
context.SetRegisterToRegisterPlusOffset(*reg_info_src, *reg_info_base, 0);
uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
Status error;
- if (!ReadRegister(*reg_info_base, data_src))
+ llvm::Optional<RegisterValue> data_src = ReadRegister(*reg_info_base);
+ if (!data_src)
return false;
- if (data_src.GetAsMemoryData(*reg_info_src, buffer, reg_info_src->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_src->GetAsMemoryData(*reg_info_src, buffer,
+ reg_info_src->byte_size, eByteOrderLittle,
+ error) == 0)
return false;
if (!WriteMemory(context, address, buffer, reg_info_src->byte_size))
if (base == dwarf_sp_mips && nonvolatile_reg_p(src)) {
RegisterInfo reg_info_src = {};
Context context;
- RegisterValue data_src;
context.type = eContextPushRegisterOnStack;
context.SetRegisterToRegisterPlusOffset(reg_info_src, *reg_info_base, 0);
uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
Status error;
- if (!ReadRegister(*reg_info_base, data_src))
+ llvm::Optional<RegisterValue> data_src = ReadRegister(*reg_info_base);
+ if (!data_src)
return false;
- if (data_src.GetAsMemoryData(reg_info_src, buffer, reg_info_src.byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_src->GetAsMemoryData(reg_info_src, buffer, reg_info_src.byte_size,
+ eByteOrderLittle, error) == 0)
return false;
if (!WriteMemory(context, address, buffer, reg_info_src.byte_size))
return false;
Context context;
- RegisterValue data_src;
context.type = eContextPushRegisterOnStack;
context.SetRegisterToRegisterPlusOffset(*reg_info_src, *reg_info_base, 0);
uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
Status error;
- if (!ReadRegister(*reg_info_base, data_src))
+ llvm::Optional<RegisterValue> data_src = ReadRegister(*reg_info_base);
+ if (!data_src)
return false;
- if (data_src.GetAsMemoryData(*reg_info_src, buffer, reg_info_src->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_src->GetAsMemoryData(*reg_info_src, buffer,
+ reg_info_src->byte_size, eByteOrderLittle,
+ error) == 0)
return false;
if (!WriteMemory(context, base_address, buffer, reg_info_src->byte_size))
/* We look for sp based non-volatile register stores */
if (nonvolatile_reg_p(src)) {
Context context;
- RegisterValue data_src;
context.type = eContextPushRegisterOnStack;
context.SetRegisterToRegisterPlusOffset(*reg_info_src, *reg_info_base, 0);
uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
Status error;
- if (!ReadRegister(*reg_info_base, data_src))
+ llvm::Optional<RegisterValue> data_src = ReadRegister(*reg_info_base);
+ if (!data_src)
return false;
- if (data_src.GetAsMemoryData(*reg_info_src, buffer, reg_info_src->byte_size,
- eByteOrderLittle, error) == 0)
+ if (data_src->GetAsMemoryData(*reg_info_src, buffer,
+ reg_info_src->byte_size, eByteOrderLittle,
+ error) == 0)
return false;
if (!WriteMemory(context, address, buffer, reg_info_src->byte_size))