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

Disassemble instructions using current CPU state #256

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
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
Loading