Skip to content

Commit

Permalink
Disassemble instructions using current CPU state
Browse files Browse the repository at this point in the history
While this means we have to allocate a temporary buffer for the textual
trace format, I don't see another workaround for the fact that we print
the instruction disassembly after the instruction has executed and
therefore has modified state (such as env->thumb) that affects the
disassembly of instructions.

Fixes: #255
  • Loading branch information
arichardson committed Jun 18, 2024
1 parent b168573 commit d09d659
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions accel/tcg/log_instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct cpu_log_instr_info {
/* Generic instruction opcode buffer */
int insn_size;
char insn_bytes[TARGET_MAX_INSN_SIZE];
char *insn_disas_text; /* Only needed for text output format. */
#define cpu_log_iinfo_endzero mem
/*
* For now we allow multiple accesses to be tied to one instruction.
Expand Down Expand Up @@ -349,8 +350,9 @@ static void emit_text_entry(CPUArchState *env, cpu_log_instr_info_t *iinfo)
rcu_read_lock();
logfile = qatomic_rcu_read(&qemu_logfile);
if (logfile) {
target_disas_buf(logfile->fd, env_cpu(env), iinfo->insn_bytes,
sizeof(iinfo->insn_bytes), iinfo->pc, 1);
fprintf(logfile->fd, "%s", iinfo->insn_disas_text);
free(iinfo->insn_disas_text);
iinfo->insn_disas_text = NULL;
}
rcu_read_unlock();

Expand Down Expand Up @@ -1058,6 +1060,18 @@ void qemu_log_instr(CPUArchState *env, target_ulong pc, const char *insn,
iinfo->pc = pc;
iinfo->insn_size = size;
memcpy(iinfo->insn_bytes, insn, size);
if (qemu_log_instr_format == QLI_FMT_TEXT) {
/*
* We have to diassemble now, since instruction side-effects could
* change the CPU execution mode.
*/
size_t disas_len = 0;
FILE *stream = open_memstream(&iinfo->insn_disas_text, &disas_len);
target_disas_buf(stream, env_cpu(env), iinfo->insn_bytes,
iinfo->insn_size, iinfo->pc, 1);
fclose(stream);
/* Allocated buffer is freed in log_instr_emit(). */
}
}

void qemu_log_instr_asid(CPUArchState *env, uint16_t asid)
Expand Down

0 comments on commit d09d659

Please sign in to comment.