[LLDB][ARM] Generalise adding register state in emulation tests and add D registers

Since some s and d registers overlap we will error if we find both.
This prevents you overwriting one with the other in a test case.

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D130462
This commit is contained in:
David Spickett 2022-07-22 14:13:32 +00:00
parent 6082051da1
commit 290c4bc7be
2 changed files with 31 additions and 23 deletions

View file

@ -272,6 +272,23 @@ bool EmulationStateARM::CompareState(EmulationStateARM &other_state) {
return match;
}
bool EmulationStateARM::LoadRegistersStateFromDictionary(
OptionValueDictionary *reg_dict, char kind, int first_reg, int num) {
StreamString sstr;
for (int i = 0; i < num; ++i) {
sstr.Clear();
sstr.Printf("%c%d", kind, i);
OptionValueSP value_sp =
reg_dict->GetValueForKey(ConstString(sstr.GetString()));
if (value_sp.get() == nullptr)
return false;
uint64_t reg_value = value_sp->GetUInt64Value();
StorePseudoRegisterValue(first_reg + i, reg_value);
}
return true;
}
bool EmulationStateARM::LoadStateFromDictionary(
OptionValueDictionary *test_data) {
static ConstString memory_key("memory");
@ -321,18 +338,8 @@ bool EmulationStateARM::LoadStateFromDictionary(
// Load General Registers
OptionValueDictionary *reg_dict = value_sp->GetAsDictionary();
StreamString sstr;
for (int i = 0; i < 16; ++i) {
sstr.Clear();
sstr.Printf("r%d", i);
ConstString reg_name(sstr.GetString());
value_sp = reg_dict->GetValueForKey(reg_name);
if (value_sp.get() == nullptr)
return false;
uint64_t reg_value = value_sp->GetUInt64Value();
StorePseudoRegisterValue(dwarf_r0 + i, reg_value);
}
if (!LoadRegistersStateFromDictionary(reg_dict, 'r', dwarf_r0, 16))
return false;
static ConstString cpsr_name("cpsr");
value_sp = reg_dict->GetValueForKey(cpsr_name);
@ -341,16 +348,13 @@ bool EmulationStateARM::LoadStateFromDictionary(
StorePseudoRegisterValue(dwarf_cpsr, value_sp->GetUInt64Value());
// Load s/d Registers
for (int i = 0; i < 32; ++i) {
sstr.Clear();
sstr.Printf("s%d", i);
ConstString reg_name(sstr.GetString());
value_sp = reg_dict->GetValueForKey(reg_name);
if (value_sp.get() == nullptr)
return false;
uint64_t reg_value = value_sp->GetUInt64Value();
StorePseudoRegisterValue(dwarf_s0 + i, reg_value);
}
// To prevent you giving both types in a state and overwriting
// one or the other, we'll expect to get either all S registers,
// or all D registers. Not a mix of the two.
bool found_s_registers =
LoadRegistersStateFromDictionary(reg_dict, 's', dwarf_s0, 32);
bool found_d_registers =
LoadRegistersStateFromDictionary(reg_dict, 'd', dwarf_d0, 32);
return true;
return found_s_registers != found_d_registers;
}

View file

@ -61,6 +61,10 @@ public:
const lldb_private::RegisterValue &reg_value);
private:
bool LoadRegistersStateFromDictionary(
lldb_private::OptionValueDictionary *reg_dict, char kind, int first_reg,
int num);
uint32_t m_gpr[17] = {0};
struct _sd_regs {
uint32_t s_regs[32]; // sregs 0 - 31 & dregs 0 - 15