Skip to content

Commit 2b5e4bf

Browse files
authored
Fix wrong number of registers (#98)
* fix num regs in case it's stored in xml file
1 parent ace3646 commit 2b5e4bf

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

libafl/cpu.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
int gdb_write_register(CPUState* cpu, uint8_t* mem_buf, int reg);
2020

2121
static __thread GByteArray* libafl_qemu_mem_buf = NULL;
22+
static __thread int num_regs = 0;
2223

2324
#ifdef CONFIG_USER_ONLY
2425
static __thread CPUArchState* libafl_qemu_env;
@@ -133,8 +134,22 @@ int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val)
133134

134135
int libafl_qemu_num_regs(CPUState* cpu)
135136
{
136-
CPUClass* cc = CPU_GET_CLASS(cpu);
137-
return cc->gdb_num_core_regs;
137+
if (!num_regs) {
138+
CPUClass* cc = CPU_GET_CLASS(cpu);
139+
140+
if (cc->gdb_num_core_regs) {
141+
num_regs = cc->gdb_num_core_regs;
142+
} else {
143+
const GDBFeature *feature = gdb_find_static_feature(cc->gdb_core_xml_file);
144+
145+
g_assert(feature);
146+
g_assert(feature->num_regs > 0);
147+
148+
num_regs = feature->num_regs;
149+
}
150+
}
151+
152+
return num_regs;
138153
}
139154

140155
void libafl_flush_jit(void)

0 commit comments

Comments
 (0)