Add reg tracing capability (for devs)

This commit is contained in:
David Guillen Fandos 2021-12-11 11:27:59 +01:00
parent 31451d16ff
commit 2419b77b28
5 changed files with 33 additions and 12 deletions

View File

@ -1238,21 +1238,34 @@ static void trace_instruction(u32 pc, u32 mode)
printf("Executed arm %x\n", pc);
else
printf("Executed thumb %x\n", pc);
#ifdef TRACE_REGISTERS
print_regs();
#endif
}
#ifdef TRACE_INSTRUCTIONS
#define emit_trace_instruction(pc, mode) \
#define emit_trace_instruction(pc, mode, regt) \
{ \
unsigned i; \
for (i = 0; i < 15; i++) { \
if (regt[i] != mem_reg) { \
ARM_STR_IMM(0, regt[i], reg_base, (i*4)); \
} \
} \
generate_save_flags(); \
ARM_STMDB_WB(0, ARMREG_SP, 0x500C); \
arm_load_imm_32bit(reg_a0, pc); \
arm_load_imm_32bit(reg_a1, mode); \
generate_function_far_call(armfn_debug_trace); \
ARM_LDMIA_WB(0, ARMREG_SP, 0x500C); \
generate_restore_flags();
generate_restore_flags(); \
}
#define emit_trace_thumb_instruction(pc) \
emit_trace_instruction(pc, 0)
emit_trace_instruction(pc, 0, thumb_register_allocation)
#define emit_trace_arm_instruction(pc) \
emit_trace_instruction(pc, 1)
emit_trace_instruction(pc, 1, arm_register_allocation)
#else
#define emit_trace_thumb_instruction(pc)
#define emit_trace_arm_instruction(pc)

16
main.c
View File

@ -269,14 +269,16 @@ u32 file_length(FILE *fp)
return length;
}
void change_ext(const char *src, char *buffer, const char *extension)
void print_regs(void)
{
char *dot_position;
strcpy(buffer, src);
dot_position = strrchr(buffer, '.');
if(dot_position)
strcpy(dot_position, extension);
printf("R0=%08x R1=%08x R2=%08x R3=%08x "
"R4=%08x R5=%08x R6=%08x R7=%08x "
"R8=%08x R9=%08x R10=%08x R11=%08x "
"R12=%08x R13=%08x R14=%08x\n",
reg[0], reg[1], reg[2], reg[3],
reg[4], reg[5], reg[6], reg[7],
reg[8], reg[9], reg[10], reg[11],
reg[12], reg[13], reg[14]);
}
bool main_read_savestate(const u8 *src)

2
main.h
View File

@ -92,7 +92,7 @@ extern u32 num_skipped_frames;
extern int dynarec_enable;
extern boot_mode selected_boot_mode;
void change_ext(const char *src, char *buffer, const char *extension);
void print_regs(void);
#endif

View File

@ -1877,6 +1877,9 @@ u32 execute_store_cpsr_body(u32 _cpsr, u32 address)
printf("Executed arm %x\n", pc);
else
printf("Executed thumb %x\n", pc);
#ifdef TRACE_REGISTERS
print_regs();
#endif
}
#define emit_trace_instruction(pc, mode) \

View File

@ -678,6 +678,9 @@ typedef enum
printf("Executed arm %x\n", pc);
else
printf("Executed thumb %x\n", pc);
#ifdef TRACE_REGISTERS
print_regs();
#endif
}
#define emit_trace_instruction(pc, mode) \