Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong number of registers #98

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions libafl/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
int gdb_write_register(CPUState* cpu, uint8_t* mem_buf, int reg);

static __thread GByteArray* libafl_qemu_mem_buf = NULL;
static __thread int num_regs = 0;

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

int libafl_qemu_num_regs(CPUState* cpu)
{
CPUClass* cc = CPU_GET_CLASS(cpu);
return cc->gdb_num_core_regs;
if (!num_regs) {
CPUClass* cc = CPU_GET_CLASS(cpu);

if (cc->gdb_num_core_regs) {
num_regs = cc->gdb_num_core_regs;
} else {
const GDBFeature *feature = gdb_find_static_feature(cc->gdb_core_xml_file);

g_assert(feature);
g_assert(feature->num_regs > 0);

num_regs = feature->num_regs;
}
}

return num_regs;
}

void libafl_flush_jit(void)
Expand Down
Loading